Browse Source

feat:分销我的团队增加手机号和姓名的搜索

super-yimizi 2 days ago
parent
commit
9cbea43ec0

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

@@ -40,8 +40,7 @@ class Order extends Base
         if (!$validate->scene('calculate')->check($postData)) {
             $this->error($validate->getError());
         }   
-        $userId = $this->auth->id;     
-        $config = get_addon_config('shop');
+        $userId = $this->auth->id;  
         $address_id = $postData['address_id'] ?? 0; // 地址id
         $user_coupon_id = $postData['user_coupon_id'] ?? 0; // 优惠券
         $profile_id = $postData['profile_id'] ?? 0; // 档案ID

+ 16 - 2
application/api/controller/commission/Agent.php

@@ -209,7 +209,7 @@ class Agent extends Commission
     {
         $params = $this->request->param();
         
-        // 使用验证器验证分页参数:page, page_size, time_filter, start_date, end_date
+        // 使用验证器验证分页参数:page, page_size, time_filter, start_date, end_date, search_keyword
         $validate = new \app\api\validate\Agent();
         if (!$validate->scene('team')->check($params)) {
             $this->error($validate->getError());
@@ -222,6 +222,7 @@ class Agent extends Commission
         $timeFilter = isset($params['time_filter']) ? $params['time_filter'] : 'all';
         $startDate = isset($params['start_date']) ? $params['start_date'] : '';
         $endDate = isset($params['end_date']) ? $params['end_date'] : '';
+        $searchKeyword = isset($params['search_keyword']) ? trim($params['search_keyword']) : '';
 
         // 构建查询条件数组
         $whereConditions = [
@@ -239,7 +240,20 @@ class Agent extends Commission
                 }
             }
         }
-        $data = UserModel::where($whereConditions)->field('id,username,nickname,avatar,mobile,bind_time,commission,order_count,total_consume,status,parent_user_id')
+
+        // 构建查询对象
+        $query = UserModel::where($whereConditions);
+
+        // 添加搜索条件(按姓名和手机号搜索)
+        if (!empty($searchKeyword)) {
+            $query->where(function ($q) use ($searchKeyword) {
+                $q->whereLike('nickname', '%' . $searchKeyword . '%')
+                  ->whereOr('username', 'like', '%' . $searchKeyword . '%')
+                  ->whereOr('mobile', 'like', '%' . $searchKeyword . '%');
+            });
+        }
+
+        $data = $query->field('id,username,nickname,avatar,mobile,bind_time,commission,order_count,total_consume,status,parent_user_id')
             ->with(['agent' => function ($query) {
                 return $query->with('level_info')->field('user_id,agent_type,child_user_count_all,child_order_money_all');
             }])

+ 3 - 1
application/api/validate/Agent.php

@@ -12,6 +12,7 @@ class Agent extends Validate
         'time_filter' => 'in:all,recent_7_days,recent_30_days,recent_90_days,current_year,custom',
         'start_date' => 'date|requireIf:time_filter,custom',
         'end_date' => 'date|requireIf:time_filter,custom|afterWith:start_date',
+        'search_keyword' => 'max:50',
     ];
 
     protected $message = [
@@ -25,9 +26,10 @@ class Agent extends Validate
         'end_date.date' => '结束日期格式不正确',
         'end_date.requireIf' => '选择自定义时间段时,结束日期不能为空',
         'end_date.afterWith' => '结束日期必须大于等于开始日期',
+        'search_keyword.max' => '搜索关键词长度不能超过50个字符',
     ];
 
     protected $scene = [
-        'team' => ['page', 'page_size', 'time_filter', 'start_date', 'end_date'],
+        'team' => ['page', 'page_size', 'time_filter', 'start_date', 'end_date', 'search_keyword'],
     ];
 }