Zory пре 4 часа
родитељ
комит
02d75bb894

+ 61 - 0
app/controller/admin/Store.php

@@ -5,6 +5,7 @@ namespace app\controller\admin;
 use app\extra\basic\Base;
 use app\middleware\AuthMiddleware;
 use app\model\saas\SaasStore;
+use app\model\saas\SaasStoreCategory;
 use app\service\saas\GoodsService;
 use app\service\saas\StoreService;
 use DI\Attribute\Inject;
@@ -144,4 +145,64 @@ class Store extends Base
         }
     }
 
+    /**
+     * 新增店铺品类授权
+     * @param Request $request
+     * @return Response
+     */
+    #[PostMapping("cate")]
+    public function addCategory(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "poi_id.require"        => trans("empty.require"),
+                "category.require"      => trans("empty.require"),
+                "product_type.require"  => trans("empty.require"),
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $storeMode = (new SaasStoreCategory);
+            $inData = [];
+            foreach ($param['category'] as $key => $value) {
+                if (!isset($value[2])) return error("请选择正确的品类");
+                $lastId = $value[2];
+                $storeCategory = $storeMode->where("category_id",$lastId)->where("poi_id",$param['poi_id'])->with(['cate'])->findOrEmpty();
+                if (!$storeCategory->isEmpty()) return error("【{$storeCategory['cate']['name']}】已存在,请勿重复添加");
+                $inData[$key] = [
+                    "category_id"   => $value[2],
+                    "poi_id"        => $param['poi_id'],
+                    "product_type"  => json_encode($param["product_type"]),
+                ];
+            }
+            $state = $storeMode->insertAll($inData);
+            if (!$state) return errorTrans("error.data");
+            return successTrans("success.data");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+    /**
+     * 删除店铺品类授权
+     * @param Request $request
+     * @return Response
+     */
+    #[PostMapping("cate/del")]
+    public function delCategory(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "poi_id.require"    => trans("empty.require"),
+                "id.require"        => trans("empty.require")
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $data = (new SaasStoreCategory)->where(['poi_id' => $param['poi_id'],'category_id' => $param['id']])->findOrEmpty();
+            if ($data->isEmpty()) return errorTrans("error.data");
+            $state = $data->delete();
+            if (!$state) return errorTrans("error.data");
+            return successTrans("success.data");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
 }

+ 67 - 0
app/controller/merchant/Category.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace app\controller\merchant;
+
+use app\extra\basic\Base;
+use app\extra\tools\DataExtend;
+use app\middleware\AuthMiddleware;
+use app\model\saas\SaasStoreCategory;
+use app\service\saas\CategoryService;
+use app\service\saas\GoodsService;
+use DI\Attribute\Inject;
+use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\GetMapping;
+use LinFly\Annotation\Attributes\Route\Middleware;
+use support\Request;
+use support\Response;
+
+
+#[Controller("/api/merchant/category"),Middleware(AuthMiddleware::class)]
+class Category extends Base
+{
+
+
+    #[Inject]
+    protected CategoryService $service;
+
+    #[Inject]
+    protected GoodsService $goodsService;
+
+    #[Inject]
+    protected SaasStoreCategory $model;
+
+    #[GetMapping('list')]
+    public function getCategoryList(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "poi.default"   => $request->user['store_id']
+            ]);
+            if (!is_array($param)) return error($param);
+            $data = $this->service->setModel()->getList([],null,false);
+            $tree = DataExtend::arr2tree($data,"category_id","parent_id");
+            $storeCate = $this->model->where("poi_id",$param['poi'])->column('product_type',"category_id");
+            if (empty($storeCate)) return successTrans(100010,[],200);
+            $storeIds = [];
+            $storeTypes = [];
+            foreach ($storeCate as $k=>$v){
+                $storeIds[] = $k;
+                $productType = !empty($v) ? json_decode($v,true) : [];
+                $typeData = [];
+                foreach ($this->goodsService->productType() as $key => $value) {
+                    if (in_array($value['key'],$productType)) {
+                        $typeData[] = $value;
+                    }
+                }
+                $storeTypes[$k] = $typeData;
+            }
+            $resp = filterTreeByTargets($tree,$storeIds);
+            addTypesRecursive($resp,$storeTypes);
+            return successTrans(100010,$resp,200);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
+}

Разлика између датотеке није приказан због своје велике величине
+ 155 - 0
app/controller/merchant/Star.php


+ 36 - 0
app/functions.php

@@ -651,4 +651,40 @@ if(! function_exists('addTypesRecursive'))
             }
         }
     }
+}
+
+
+if(! function_exists('emojiToUnicode'))
+{
+    /**
+     * @param string $str
+     * @return string
+     */
+    function emojiToUnicode(string $str): string
+    {
+        return trim(json_encode($str, JSON_UNESCAPED_SLASHES), '"');
+    }
+}
+
+if(! function_exists('unicodeToEmoji'))
+{
+    function unicodeToEmoji(string $str): string
+    {
+        return json_decode("\"{$str}\"");
+    }
+}
+
+if(! function_exists('removeEmoji2'))
+{
+    /**
+     * 清除字符串中所有emoji表情
+     * @param string $str
+     * @return string
+     */
+    function removeEmoji2(string $str): string
+    {
+        // 匹配绝大部分emoji Unicode区间
+        $pattern = '/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F680}-\x{1F6FF}\x{1F1E0}-\x{1F1FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}\xFE00-\xFE0F\x{1F900}-\x{1F9FF}]/u';
+        return preg_replace($pattern, '', $str);
+    }
 }

+ 61 - 0
app/model/saas/SaasStar.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace app\model\saas;
+
+use app\extra\basic\Model;
+
+
+/**
+ * @property integer $id (主键)
+ * @property mixed $poi_id 
+ * @property string $nick_name 昵称
+ * @property string $unique_id 抖音号
+ * @property string $avatar_url 
+ * @property string $city_name 
+ * @property mixed $uid 抖音唯一ID
+ * @property string $fans_count 
+ * @property mixed $fans_tag_list 粉丝标签
+ * @property string $talent_level_display 带货力
+ * @property string $talent_item_level_display 视频带货力
+ * @property string $talent_live_level_display 直播
+ * @property string $content_level_display 内容力
+ * @property string $credit_score_display 信用分
+ * @property string $rank_display 视频榜
+ * @property mixed $create_at
+ */
+class SaasStar extends Model
+{
+    /**
+     * The connection name for the model.
+     *
+     * @var string|null
+     */
+    protected $connection = 'mysql';
+    
+    /**
+     * The table associated with the model.
+     *
+     * @var string
+     */
+    protected string $table = "saas_star";
+    
+    /**
+     * The primary key associated with the table.
+     *
+     * @var string
+     */
+    protected string $primaryKey = "id";
+    
+    /**
+     * Indicates if the model should be timestamped.
+     *
+     * @var bool
+     */
+    public bool $timestamps = false;
+
+    public function getShowNicknameAttr($data): string
+    {
+        return unicodeToEmoji($data);
+    }
+
+}

+ 9 - 4
app/model/saas/SaasStoreCategory.php

@@ -3,13 +3,14 @@
 namespace app\model\saas;
 
 use app\extra\basic\Model;
+use think\model\relation\HasOne;
 
 
 /**
- * @property integer $id (主键)
- * @property mixed $product_type 
- * @property integer $category_id 
- * @property integer $poi_id 
+ * @property integer $id (主键)
+ * @property mixed $product_type 
+ * @property integer $category_id 
+ * @property integer $poi_id 
  * @property mixed $create_at
  */
 class SaasStoreCategory extends Model
@@ -42,5 +43,9 @@ class SaasStoreCategory extends Model
      */
     public bool $timestamps = false;
 
+    public function cate(): HasOne
+    {
+        return $this->hasOne(SaasCategory::class, "category_id", "category_id");
+    }
 
 }

+ 34 - 0
app/service/saas/StarService.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace app\service\saas;
+
+use app\extra\basic\Service;
+use app\model\saas\SaasStar;
+
+class StarService extends Service
+{
+
+    /**
+     *
+     * @return $this
+     */
+    public function setModel()
+    {
+        $this->mode = (new SaasStar);
+        return $this;
+    }
+
+
+    /**
+     *
+     * @param array $param
+     * @return array
+     */
+    public function searchFilter(array $param = []): array
+    {
+        $filter = [];
+        !empty($param['name']) && $filter[] = ["nick_name", 'like', "%{$param['name']}%"];
+        return $filter;
+    }
+
+}

Неке датотеке нису приказане због велике количине промена