Browse Source

fix:初始化接口增加分销地址

super-yimizi 10 hours ago
parent
commit
825c70be89

+ 1 - 2
application/api/controller/Common.php

@@ -40,8 +40,6 @@ class Common extends Base
 
         $platform  = $this->request->header('platform');
         //  转换
-
-
         //如果非服务端中转模式需要修改为中转
         if ($upload['storage'] != 'local' && isset($upload['uploadmode']) && $upload['uploadmode'] != 'server') {
             //临时修改上传模式为服务端中转
@@ -122,6 +120,7 @@ class Common extends Base
         $data['platform'] = [
             'payment' => $arrPlatformConfigs['payment']['methods'] ?? [],
         ];
+        $data['commission_url'] = $arrConfig['commission_url']??"";
 
         $this->success('', $data);
     }

+ 13 - 54
application/api/controller/Test.php

@@ -7,14 +7,14 @@ use app\common\model\Order as OrderModel;
 use app\common\model\User as UserModel;
 use think\Hook;
 use think\Db;
-
+use app\common\Service\Commission\Agent as AgentService;
 /**
  * 测试控制器
  * 仅用于开发和测试环境
  */
 class Test extends Api
 {
-    protected $noNeedLogin = [];
+    protected $noNeedLogin = ['getCommissionStats'];
     protected $noNeedRight = ['*'];
 
     /**
@@ -68,61 +68,20 @@ class Test extends Api
     /**
      * 获取分销统计数据
      */
-    private function getCommissionStats($order, $user)
+    public function getCommissionStats()
     {
-        // 查询分销订单
-        $commissionOrders = Db::name('commission_order')
-            ->where('order_id', $order->id)
-            ->select();
-
-        // 查询佣金记录
-        $rewards = Db::name('commission_reward')
-            ->alias('r')
-            ->leftJoin('commission_order o', 'r.commission_order_id = o.id')
-            ->where('o.order_id', $order->id)
-            ->field('r.*')
-            ->select();
-
-        // 查询用户分销商信息
-        $agent = Db::name('shop_commission_agent')
-            ->where('user_id', $user->id)
-            ->find();
-
-        // 查询用户的上级关系
-        $parentInfo = null;
-        if ($user->parent_user_id > 0) {
-            $parentUser = UserModel::where('id', $user->parent_user_id)->find();
-            if ($parentUser) {
-                $parentAgent = Db::name('shop_commission_agent')
-                    ->where('user_id', $parentUser->id)
-                    ->find();
-                
-                $parentInfo = [
-                    'parent_user_id' => $parentUser->id,
-                    'parent_nickname' => $parentUser->nickname,
-                    'parent_is_agent' => !empty($parentAgent),
-                    'bind_time' => $user->bind_time ? date('Y-m-d H:i:s', $user->bind_time) : null
-                ];
-            }
+        //$userId = $payload['user_id'];
+        $userId = $this->request->param('user_id');
+        if (empty($userId)) {
+            $this->error('请提供用户ID');
         }
+        $agent = new AgentService($userId);
 
-        return [
-            'user_commission' => $user->commission,
-            'agent_info' => $agent ? [
-                'agent_id' => $agent['id'],
-                'agent_type' => $agent['agent_type'],
-                'total_income' => $agent['total_income'],
-                'withdrawn_amount' => $agent['withdrawn_amount'],
-                'child_user_count_all' => $agent['child_user_count_all'],
-                'child_order_money_all' => $agent['child_order_money_all'],
-            ] : null,
-            'parent_info' => $parentInfo,
-            'commission_orders_count' => count($commissionOrders),
-            'commission_orders' => $commissionOrders,
-            'rewards_count' => count($rewards),
-            'rewards' => $rewards,
-            'total_reward_amount' => array_sum(array_column($rewards, 'commission'))
-        ];
+        if ($agent->user) {
+            Db::transaction(function () use ($agent) {
+                $agent->runAgentUpgradePlan();
+            });
+        }
     }
 
     /**

+ 5 - 1
application/common/Service/Commission/Agent.php

@@ -310,6 +310,7 @@ class Agent
     public function runAgentUpgradePlan($upgrade = true)
     {
         if ($this->isAgentAvaliable()) {
+           
             // 获取下级直推团队用户信息
             $nextUserTeam = $this->getNextUserTeam();
 
@@ -366,7 +367,10 @@ class Agent
             $child_agent_level_all = $this->childAgentLevelCount(array_column($nextAgentTeam, 'child_agent_level_all'), $this->agent->child_agent_level_first);
             ksort($child_agent_level_all);
             $this->agent->child_agent_level_all = $child_agent_level_all;
-
+            // echo "<pre>";
+            // print_r($this->agent->child_agent_level_all);
+            // echo "</pre>";
+            // exit;
             $this->agent->save();
 
             // 分销商自动升级