Browse Source

图片加域名

moonsflyer 9 months ago
parent
commit
17ba467330

+ 1 - 1
app/api/lists/service/ServiceLists.php

@@ -87,7 +87,7 @@ class ServiceLists extends BaseApiDataLists implements ListsSearchInterface
             ->where($this->queryWhere())
             ->where($this->searchWhere)
             ->orderRaw($orderRaw)
-            ->append(['type_desc','cate_desc','area_desc'])
+            ->append(['type_desc','cate_desc','area_desc','images'])
             ->limit($this->limitOffset, $this->limitLength)
             ->select()->toArray();
 

+ 77 - 0
app/common/model/agricultural_machinery/UserService.php

@@ -17,6 +17,7 @@ namespace app\common\model\agricultural_machinery;
 use app\common\model\agricultural_machinery\ServiceCategory;
 use app\common\model\BaseModel;
 use app\common\model\asset\AssetArea;
+use app\common\service\FileService;
 use think\model\concern\SoftDelete;
 
 /**
@@ -105,4 +106,80 @@ class UserService extends BaseModel
 
         return['area_str'=>$area_str,'area_arr'=>$area_list];
     }
+
+    /**
+     * @notes 设置图片域名
+     * @param $value
+     * @param $data
+     * @return array|string|string[]|null
+     * @author 段誉
+     * @date 2022/9/28 10:17
+     */
+    public function getContentAttr($value, $data)
+    {
+        return get_file_domain($value);
+    }
+
+
+    /**
+     * @notes 清除图片域名
+     * @param $value
+     * @param $data
+     * @return array|string|string[]
+     * @author 段誉
+     * @date 2022/9/28 10:17
+     */
+    public function setContentAttr($value, $data)
+    {
+        return clear_file_domain($value);
+    }
+
+    /**
+     * @notes 清除图片域名
+     * @param $value
+     * @param $data
+     * @return array|string|string[]
+     * @author 段誉
+     * @date 2022/9/28 10:17
+     */
+    public function setImagesAttr($value)
+    {
+        $imagesArr = explode(',',$value);
+        $imagesStr = '';
+        foreach($imagesArr as $k=>$v){
+            if($k==0){
+                $imagesStr = clear_file_domain($v);
+            }else{
+                $imagesStr .=','. clear_file_domain($v);
+            }
+
+        }
+        return $imagesStr;
+    }
+    /**
+     * @notes 加图片域名
+     * @param $value
+     * @param $data
+     * @return array|string|string[]
+     * @author 段誉
+     * @date 2022/9/28 10:17
+     */
+    public function getImagesAttr($value,$data)
+    {
+
+        $imagesArr = explode(',',$data['images']);
+
+        $imagesStr = '';
+
+        foreach($imagesArr as $k=>$v){
+
+            if($k==0){
+                $imagesStr =  FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
+            }else{
+                $imagesStr .=','. FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
+            }
+
+        }
+        return $imagesStr;
+    }
 }