Browse Source

fix:代理商标题

super-yimizi 21 hours ago
parent
commit
8c45730b87

+ 14 - 12
application/api/controller/Withdraw.php

@@ -4,7 +4,6 @@ namespace app\api\controller;
 
 use think\Db;
 use think\exception\HttpResponseException;
-use app\common\model\Withdraw as WithdrawModel;
 use app\common\Service\Withdraw as WithdrawService;
 use app\api\validate\Withdraw as WithdrawValidate;
 
@@ -18,22 +17,17 @@ class Withdraw extends Base
     {
         $params = $this->request->param();
         
-        // 使用验证器验证分页参数
+        // 使用验证器验证查询参数:status, page, page_size
         $validate = new WithdrawValidate();
         if (!$validate->scene('index')->check($params)) {
             $this->error($validate->getError());
         }
         
         $user = auth_user();
+        $withdrawService = new WithdrawService($user);
         
-        // 使用验证后的参数
-        $page_size = isset($params['page_size']) ? (int)$params['page_size'] : 10;
-        
-        $withdraws = WithdrawModel::where(['user_id' => $user->id])
-            ->order('id desc')
-            ->paginate($page_size)->each(function ($withdraw) {
-                $withdraw->hidden(['withdraw_info']);
-            });
+        // 通过服务获取提现记录列表
+        $withdraws = $withdrawService->getWithdrawList($params);
 
         $this->success('获取成功', $withdraws);
     }
@@ -48,6 +42,16 @@ class Withdraw extends Base
         $this->success('提现规则', $config);
     }
 
+    // 提现状态列表
+    public function statusList()
+    {
+        $user = auth_user();
+        $withdrawService = new WithdrawService($user);
+        $statusList = $withdrawService->getStatusList();
+
+        $this->success('状态列表', $statusList);
+    }
+
 
     // 发起提现请求
     public function apply()
@@ -91,8 +95,6 @@ class Withdraw extends Base
             }
         }
 
-
-
         // 支付宝提现+自动打款
         if ($withdraw->withdraw_type === 'alipay' && $withdrawService->config['auto_arrival']) {
             try {

+ 128 - 43
application/api/controller/commission/Agent.php

@@ -63,49 +63,11 @@ class Agent extends Commission
             // 添加代理商类型描述(使用枚举类)
             $data['agent_type_text'] = AgentType::getTypeText($data['agent_type']);
             
-            // 如果是区域代理商,添加管辖区域信息
-            if (AgentType::isRegionalAgent($data['agent_type'])) {
-                $areaInfo = [];
-                
-                // 获取省份信息
-                if (!empty($data['manage_province_id'])) {
-                    $provinceInfo = \app\common\model\Area::where('id', $data['manage_province_id'])->find();
-                    if ($provinceInfo) {
-                        $areaInfo['province_name'] = $provinceInfo['name'];
-                        $areaInfo['province_id'] = $data['manage_province_id'];
-                    }
-                }
-                
-                // 获取城市信息  
-                if (!empty($data['manage_city_id'])) {
-                    $cityInfo = \app\common\model\Area::where('id', $data['manage_city_id'])->find();
-                    if ($cityInfo) {
-                        $areaInfo['city_name'] = $cityInfo['name'];
-                        $areaInfo['city_id'] = $data['manage_city_id'];
-                    }
-                }
-                
-                // 获取区域信息
-                if (!empty($data['manage_district_id'])) {
-                    $districtInfo = \app\common\model\Area::where('id', $data['manage_district_id'])->find();
-                    if ($districtInfo) {
-                        $areaInfo['district_name'] = $districtInfo['name'];
-                        $areaInfo['district_id'] = $data['manage_district_id'];
-                    }
-                }
-                
-                $data['manage_area'] = $areaInfo;
-                
-                // 生成管辖区域描述文本
-                $areaText = [];
-                if (isset($areaInfo['province_name'])) $areaText[] = $areaInfo['province_name'];
-                if (isset($areaInfo['city_name'])) $areaText[] = $areaInfo['city_name'];  
-                if (isset($areaInfo['district_name'])) $areaText[] = $areaInfo['district_name'];
-                $data['manage_area_text'] = implode('-', $areaText);
-            } else {
-                $data['manage_area'] = null;
-                $data['manage_area_text'] = '-';
-            }
+            // 构造代理商身份描述和区域信息
+            $identityData = $this->buildAgentIdentityData($data);
+            $data['agent_identity_title'] = $identityData['title'];
+            $data['manage_area'] = $identityData['area_info'];
+            $data['manage_area_text'] = $identityData['area_text'];
             
             // 获取用户基本信息和佣金数据
             $user = $this->service->user;
@@ -129,6 +91,129 @@ class Agent extends Commission
         $this->success('分销商信息', $data);
     }
 
+    /**
+     * 构造代理商身份数据(包括标题和区域信息)
+     * @param array $agentData 代理商数据
+     * @return array
+     */
+    private function buildAgentIdentityData($agentData)
+    {
+        $result = [
+            'title' => '普通代理商',
+            'area_info' => null,
+            'area_text' => '-'
+        ];
+
+        switch ($agentData['agent_type']) {
+            case AgentType::NORMAL:
+                $result['title'] = '普通代理商';
+                break;
+                
+            case AgentType::PROVINCE:
+                // 省级代理商:山东省代理商
+                if (!empty($agentData['manage_province_id'])) {
+                    $provinceInfo = \app\common\model\Area::where('id', $agentData['manage_province_id'])->find();
+                    if ($provinceInfo) {
+                        $result['title'] = $provinceInfo['name'] . '代理商';
+                        $result['area_info'] = [
+                            'province_name' => $provinceInfo['name'],
+                            'province_id' => $agentData['manage_province_id']
+                        ];
+                        $result['area_text'] = $provinceInfo['name'];
+                    } else {
+                        $result['title'] = '省级代理商';
+                    }
+                } else {
+                    $result['title'] = '省级代理商';
+                }
+                break;
+                
+            case AgentType::CITY:
+                // 市级代理商:临沂市代理商
+                $areaInfo = [];
+                $areaText = [];
+                
+                // 获取省份信息
+                if (!empty($agentData['manage_province_id'])) {
+                    $provinceInfo = \app\common\model\Area::where('id', $agentData['manage_province_id'])->find();
+                    if ($provinceInfo) {
+                        $areaInfo['province_name'] = $provinceInfo['name'];
+                        $areaInfo['province_id'] = $agentData['manage_province_id'];
+                        $areaText[] = $provinceInfo['name'];
+                    }
+                }
+                
+                // 获取城市信息
+                if (!empty($agentData['manage_city_id'])) {
+                    $cityInfo = \app\common\model\Area::where('id', $agentData['manage_city_id'])->find();
+                    if ($cityInfo) {
+                        $result['title'] = $cityInfo['name'] . '代理商';
+                        $areaInfo['city_name'] = $cityInfo['name'];
+                        $areaInfo['city_id'] = $agentData['manage_city_id'];
+                        $areaText[] = $cityInfo['name'];
+                    } else {
+                        $result['title'] = '市级代理商';
+                    }
+                } else {
+                    $result['title'] = '市级代理商';
+                }
+                
+                if (!empty($areaInfo)) {
+                    $result['area_info'] = $areaInfo;
+                    $result['area_text'] = implode('-', $areaText);
+                }
+                break;
+                
+            case AgentType::DISTRICT:
+                // 区级代理商:兰山区代理商
+                $areaInfo = [];
+                $areaText = [];
+                
+                // 获取省份信息
+                if (!empty($agentData['manage_province_id'])) {
+                    $provinceInfo = \app\common\model\Area::where('id', $agentData['manage_province_id'])->find();
+                    if ($provinceInfo) {
+                        $areaInfo['province_name'] = $provinceInfo['name'];
+                        $areaInfo['province_id'] = $agentData['manage_province_id'];
+                        $areaText[] = $provinceInfo['name'];
+                    }
+                }
+                
+                // 获取城市信息
+                if (!empty($agentData['manage_city_id'])) {
+                    $cityInfo = \app\common\model\Area::where('id', $agentData['manage_city_id'])->find();
+                    if ($cityInfo) {
+                        $areaInfo['city_name'] = $cityInfo['name'];
+                        $areaInfo['city_id'] = $agentData['manage_city_id'];
+                        $areaText[] = $cityInfo['name'];
+                    }
+                }
+                
+                // 获取区域信息
+                if (!empty($agentData['manage_district_id'])) {
+                    $districtInfo = \app\common\model\Area::where('id', $agentData['manage_district_id'])->find();
+                    if ($districtInfo) {
+                        $result['title'] = $districtInfo['name'] . '代理商';
+                        $areaInfo['district_name'] = $districtInfo['name'];
+                        $areaInfo['district_id'] = $agentData['manage_district_id'];
+                        $areaText[] = $districtInfo['name'];
+                    } else {
+                        $result['title'] = '区域代理商';
+                    }
+                } else {
+                    $result['title'] = '区域代理商';
+                }
+                
+                if (!empty($areaInfo)) {
+                    $result['area_info'] = $areaInfo;
+                    $result['area_text'] = implode('-', $areaText);
+                }
+                break;
+        }
+
+        return $result;
+    }
+
 
     // 我的团队
     public function team()

+ 4 - 1
application/api/validate/Withdraw.php

@@ -11,6 +11,7 @@ class Withdraw extends Validate
         'amount' => 'require|float|gt:0',
         'account_id' => 'require|integer|gt:0',
         'withdraw_sn' => 'require',
+        'status' => 'integer|in:-3,-2,-1,0,1,2',
         'page' => 'integer|egt:1',
         'page_size' => 'integer|between:1,100',
     ];
@@ -25,6 +26,8 @@ class Withdraw extends Validate
         'account_id.integer' => '账户ID必须为整数',
         'account_id.gt' => '请选择正确的提现账户',
         'withdraw_sn.require' => '未找到您的提现信息',
+        'status.integer' => '状态必须为整数',
+        'status.in' => '请选择正确的状态',
         'page.integer' => '页码必须为整数',
         'page.egt' => '页码必须大于等于1',
         'page_size.integer' => '分页大小必须为整数',
@@ -32,7 +35,7 @@ class Withdraw extends Validate
     ];
 
     protected $scene = [
-        'index' => ['page', 'page_size'],
+        'index' => ['status', 'page', 'page_size'],
         'apply' => ['type', 'amount', 'account_id'],
         'transfer' => ['type', 'withdraw_sn'],
         'retry' => ['type', 'withdraw_sn'],

+ 46 - 1
application/common/Service/Withdraw.php

@@ -42,6 +42,52 @@ class Withdraw
         $this->config = $config;
     }
 
+    /**
+     * 获取用户提现记录列表
+     * @param array $params 查询参数
+     * @return \think\Paginator
+     */
+    public function getWithdrawList($params = [])
+    {
+        // 构建查询条件
+        $where = ['user_id' => $this->user->id];
+        
+        // 状态筛选
+        if (isset($params['status']) && $params['status'] !== '') {
+            $where['status'] = (int)$params['status'];
+        }
+        
+        // 分页参数
+        $page_size = isset($params['page_size']) ? (int)$params['page_size'] : 10;
+        
+        // 查询提现记录
+        $withdraws = WithdrawModel::where($where)
+            ->order('id desc')
+            ->paginate($page_size)
+            ->each(function ($withdraw) {
+                // 隐藏敏感信息
+                $withdraw->hidden(['withdraw_info']);
+            });
+
+        return $withdraws;
+    }
+
+    /**
+     * 获取提现状态列表
+     * @return array
+     */
+    public function getStatusList()
+    {
+        return [
+            -3 => '撤销提现',
+            -2 => '提现失败', 
+            -1 => '已拒绝',
+            0 => '待审核',
+            1 => '处理中',
+            2 => '已处理'
+        ];
+    }
+
 
     // 发起提现申请
     public function apply($params)
@@ -192,7 +238,6 @@ class Withdraw
     // 支付宝提现
     public function handleAlipayWithdraw($withdraw)
     {
-        operate_disabled();
 
         Db::startTrans();
         try {

+ 11 - 0
application/common/model/Withdraw.php

@@ -63,6 +63,17 @@ class Withdraw extends Model
     }
 
     /**
+     * 状态获取器
+     */
+    public function getStatusTextAttr($value, $data)
+    {
+        $value = $value ?: ($data['status'] ?? null);
+        
+        $list = $this->statusList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+    /**
      * 类型获取器
      */
     public function getWithdrawTypeTextAttr($value, $data)