作者 lyh

gx

... ... @@ -419,28 +419,18 @@ if (!function_exists('getImageUrl')) {
* @method :post
* @time :2023/7/20 16:46
*/
function getImageUrl($hash){
if(is_array($hash)){
foreach ($hash as $v){
function getImageUrl($path,$location = 1){
if(is_array($path)){
foreach ($path as $v){
$url[] = getImageUrl($v);
}
}else{
$imageModel = new Image();
if (strpos($hash, '.') !== false) {
$info = $imageModel->read(['path'=>['like','%'.$hash.'%']]);
}else{
$info = $imageModel->read(['hash'=>$hash]);
}
if(!empty($info)){
if($info['is_cos'] == 1){
if($location == 1){
$cos = config('filesystems.disks.cos');
$cosCdn = $cos['cdn'];
$url = $cosCdn.$info['path'];
}else{
$url = url($info['path']);
}
$url = $cosCdn.$path;
}else{
$url = url($hash);
$url = url($path);
}
}
return $url;
... ... @@ -454,8 +444,8 @@ if (!function_exists('getFileUrl')) {
* @method :post
* @time :2023/7/20 16:46
*/
function getFileUrl($hash){
if(is_array($hash)){
function getFileUrl($path,$location = 1){
if(is_array($path)){
foreach ($hash as $v){
$url[] = getFileUrl($v);
}
... ...
... ... @@ -31,15 +31,15 @@ class CategoryController extends BaseController
*/
public function index(Category $category)
{
if(!empty($this->map['title'])){
$this->map['title'] = ['like','%'.$this->map['title'].'%'];
}
$this->map['project_id'] = $this->user['project_id'];
$this->map = $this->searchParam();
$filed = ['id', 'project_id', 'pid', 'title', 'image', 'route','keywords', 'describe', 'status','created_at'];
$list = $category->list($this->map,'id',$filed);
$data = [];
if(!empty($list)){
foreach ($list as $k =>$v){
$v['url'] = $this->user['domain'] . $v['url'];
$v['product_num'] = Product::where('category_id','like' ,'%,'.$v['id'].',%')->count();;
$v['image_link'] = getImageUrl($v['image']);
$v = $this->handleParam($v);
$list[$k] = $v;
}
... ... @@ -49,17 +49,18 @@ class CategoryController extends BaseController
}
/**
* @remark :分类处理参数
* @name :handleParam
* @remark :搜索参数处理
* @name :searchParam
* @author :lyh
* @method :post
* @time :2023/8/17 11:10
* @time :2023/9/14 14:57
*/
public function handleParam($v){
$v['url'] = $this->user['domain'] . $v['url'];
$v['product_num'] = Product::where('category_id','like' ,'%,'.$v['id'].',%')->count();;
$v['image_link'] = getImageUrl($v['image']);
return $v;
public function searchParam(){
if(!empty($this->map['title'])){
$this->map['title'] = ['like','%'.$this->map['title'].'%'];
}
$this->map['project_id'] = $this->user['project_id'];
return $this->map;
}
/**
... ...
... ... @@ -226,12 +226,14 @@ class Project extends Base
public function getNoticeFileAttribute($value)
{
$value = Arr::s2a($value);
if(!empty($value)) {
$value = Arr::s2a($value);
foreach ($value as &$v) {
if(!empty($v['url'])){
$v['url'] = getFileUrl($v['url']);
}
}
}
return $value;
}
... ... @@ -245,12 +247,14 @@ class Project extends Base
public function getConfirmFileAttribute($value)
{
$value = Arr::s2a($value);
if(!empty($value)) {
$value = Arr::s2a($value);
foreach ($value as &$v) {
if(!empty($v['url'])){
$v['url'] = getFileUrl($v['url']);
}
}
}
return $value;
}
... ...