zory 2 månader sedan
förälder
incheckning
0cf77aec32

+ 27 - 0
app/controller/admin/Expert.php

@@ -6,6 +6,7 @@ use app\extra\basic\Base;
 use app\extra\service\blue\ExpertService;
 use app\middleware\AuthMiddleware;
 use app\model\blue\BlueExpert;
+use app\model\blue\BlueExpertPlatform;
 use DI\Attribute\Inject;
 use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Middleware;
@@ -43,5 +44,31 @@ class Expert extends Base
         }
     }
 
+    #[Route(path: "platform",methods: "get")]
+    public function getPlatform(): Response
+    {
+        try {
+            $param = $this->_valid([
+                "id.require"    => trans("empty.require")
+            ]);
+            if (!is_array($param)) return error($param);
+            $user = $this->model->where("id",$param['id'])->findOrEmpty();
+            if ($user->isEmpty()) return errorTrans("empty.data");
+            $platform = (new BlueExpertPlatform)->where("openid",$user['openid'])->append(['source_name','aweme_count_format','follower_count_format','total_favorited_format'])->withAttr(['source_name' => function($data,$resp){
+                return $this->service->source[$resp['source']];
+            },'aweme_count_format' => function($data,$resp){
+//                return formatMoneyKw($resp['aweme_count'],1);
+                return $resp['aweme_count'];
+            },'follower_count_format' => function($data,$resp){
+                return formatMoneyKw($resp['follower_count'],1);
+            },'total_favorited_format' => function($data,$resp){
+                return formatMoneyKw($resp['total_favorited'],1);
+            }])->select()->toArray();
+            return success("ok",$platform);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
 
 }

+ 20 - 0
app/controller/api/Page.php

@@ -3,6 +3,7 @@
 namespace app\controller\api;
 
 use app\extra\basic\Base;
+use app\extra\tools\DouyinUserInfo;
 use app\model\system\SystemData;
 use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
@@ -98,4 +99,23 @@ class Page extends Base
         }
     }
 
+
+    /**
+     * 数据字典
+     * @param Request $request
+     * @return Response
+     */
+    #[Route(path: "dy",methods: "get")]
+    public function getDyUserData(Request $request): Response
+    {
+        try {
+            $url = "https://v.douyin.com/pVGt_Mbl_0Y/";
+            $data = (new DouyinUserInfo)->getInfo($url);
+            print_r($data);
+            return successTrans("success.data",$data);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
 }

+ 13 - 3
app/extra/service/blue/ExpertService.php

@@ -8,6 +8,12 @@ use app\model\blue\BlueExpert;
 class ExpertService extends Service
 {
 
+    public array $source = [
+        "douyin"        => "抖音",
+        "kuaishou"      => "快手",
+        "xiaohongshu"   => "小红书",
+        "tengxun"       => "视频号"
+    ];
 
     /**
      * 列表
@@ -16,7 +22,11 @@ class ExpertService extends Service
     public function getList(array $param = [])
     {
         $this->mode = new BlueExpert();
-        return $this->searchVal($param,$this->searchFilter($param))->paginate([
+        return $this->searchVal($param,$this->searchFilter($param))->with(['platform' => function($query){
+            $query->field("openid,source")->append(['source_name'])->withAttr(['source_name' => function($data,$resp){
+                return $this->source[$resp['source']];
+            }]);
+        }])->paginate([
             "list_rows" => $param['pageSize'],
             "page"      => $param['page']
         ]);
@@ -32,8 +42,8 @@ class ExpertService extends Service
     {
         $filter = [];
         !empty($param['type']) && $filter[] = ["type", '=', $param['type']];
-        !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
-        !empty($param['name']) && $filter[] = ["name", 'like', "%{$param['name']}%"];
+        !empty($param['status']) && $filter[] = ["status", '=', ($param['status']-1)];
+        !empty($param['truename']) && $filter[] = ["truename", 'like', "%{$param['truename']}%"];
         return $filter;
     }
 

+ 21 - 0
app/extra/tools/DouyinUserInfo.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace app\extra\tools;
+
+use yzh52521\EasyHttp\Http;
+
+class DouyinUserInfo
+{
+
+    public function getInfo(string $url = ""): array
+    {
+        $user = Http::asJson()->post("https://douyin.wtf/api/douyin/web/get_all_sec_user_id",[$url])->array();
+        if ($user['code'] <> 200) return [0,'用户信息获取失败'];
+        $userData = Http::asJson()->get("https://douyin.wtf/api/douyin/web/handler_user_profile",[
+            "sec_user_id" => $user['data'][0]
+        ])->array();
+        if ($userData['code'] <> 200) return [0,'用户信息获取失败'];
+        return [1,$userData['data']];
+    }
+
+}

+ 3 - 3
app/functions.php

@@ -640,9 +640,10 @@ if (!function_exists('formatMoneyKw')) {
     /**
      * 金额格式化 千k 万w
      * @param float|int $num 原始金额
+     * @param int $decimal
      * @return string
      */
-    function formatMoneyKw(float|int $num): string
+    function formatMoneyKw(float|int $num,int $decimal = 2): string
     {
         // 先转浮点
         $num = (float)$num;
@@ -659,9 +660,8 @@ if (!function_exists('formatMoneyKw')) {
             // 小于1000直接返回字符串
             return (string)$num;
         }
-
         // 保留2位小数,去除末尾多余0和小数点
-        $val = rtrim(rtrim(sprintf('%.2f', $val), '0'), '.');
+        $val = rtrim(rtrim(sprintf("%.{$decimal}f", $val), '0'), '.');
         return $val . $unit;
     }
 }

+ 6 - 0
app/model/blue/BlueExpert.php

@@ -3,6 +3,7 @@
 namespace app\model\blue;
 
 use app\extra\basic\Model;
+use think\model\relation\HasMany;
 use think\model\relation\HasOne;
 
 
@@ -54,4 +55,9 @@ class BlueExpert extends Model
         return $this->hasOne(BlueUserOpen::class,"openid","openid");
     }
 
+    public function platform(): HasMany
+    {
+        return $this->hasMany(BlueExpertPlatform::class,"openid","openid");
+    }
+
 }

+ 44 - 0
app/model/blue/BlueExpertPlatform.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace app\model\blue;
+
+use app\extra\basic\Model;
+
+
+/**
+ * @property integer $id (主键)
+ * @property mixed $openid 
+ * @property mixed $source
+ */
+class BlueExpertPlatform 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 = "blue_expert_platform";
+    
+    /**
+     * 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;
+
+
+}