Browse Source

Merge branch 'master' into dev

gorden 6 months ago
parent
commit
82f5398a5d

+ 10 - 3
app/admin/controller/consultant/CustomController.php

@@ -121,12 +121,19 @@ class CustomController extends Curd
     public function moveCustom(Request $request)
     {
         $params = $request->post();
-        if (empty($params['consultant_id'])) {
-            return json_fail('请选择目标顾问');
+        if (empty($params['move_type'])) {
+            if (empty($params['consultant_id'])) {
+                return json_fail('请选择目标顾问');
+            }
+        } else {
+            if (empty($params['dept_id'])) {
+                return json_fail('请选择目标团队');
+            }
         }
         if (empty($params['move_market_customer_id']) && empty($params['move_consultant_id'])) {
             return json_fail('请选择需要转移的客户或顾问');
         }
+
         return CustomService::moveCustom($params);
     }
 
@@ -144,7 +151,7 @@ class CustomController extends Curd
     }
 
     /**
-     * Notes: 报备审核
+     * Notes: 转到访审核
      * User: yb
      * Date: 2024/8/16
      * Time: 15:55

+ 48 - 38
app/admin/controller/finance/IncomeAndExpendController.php

@@ -12,7 +12,7 @@ class IncomeAndExpendController
 {
 
     public function list(Request $request)
-    {        
+    {
         $days = $request->get('days');
         if (!empty($days)) {
             $days[0] = strtotime($days[0]);
@@ -25,7 +25,7 @@ class IncomeAndExpendController
             $days[1] = strtotime(date('Y-m-d', $days[1]) . " 23:59:59");
         } else {
             $month = date('Ym');
-            $days[0] = strtotime(date('Y-m').'-01');
+            $days[0] = strtotime(date('Y-m') . '-01');
             $days[1] = time();
         }
         $premises = $request->get('premises', DeptService::getPremisesList());
@@ -34,69 +34,77 @@ class IncomeAndExpendController
         //     $premisesKeyValue[$item['key']] = $item['label'];
         // }
         $premisesKey = [];
-        foreach($premises as $item){
+        foreach ($premises as $item) {
             $premisesKey[] = $item['key'];
         }
 
-        $dayNum = ($days[1] - $days[0])/(60*60*24);
-        $currentDay = date('Y-m-d',$days[0]);
-        $data =[];
-        $statistics = ['income_amount'=>0,'income_wxpay'=>0,'income_alipay'=>0,'income_qrcode'=>0,'expend_amount'=>0,'expend_wxpay'=>0,'expend_alipay'=>0];
-        for($i=0;$i<=$dayNum;$i++){
+        $dayNum = ($days[1] - $days[0]) / (60 * 60 * 24);
+        $currentDay = date('Y-m-d', $days[0]);
+        $data = [];
+        $statistics = ['income_amount' => 0, 'income_wxpay' => 0, 'income_alipay' => 0, 'income_money' => 0, 'expend_amount' => 0, 'expend_wxpay' => 0, 'expend_alipay' => 0, 'expend_money' => 0];
+        for ($i = 0; $i <= $dayNum; $i++) {
             $dayData = [];
             $dayData['day'] = $currentDay;
             // 收入
-            if(Util::schema()->hasTable("data_income_{$month}")){
+            if (Util::schema()->hasTable("data_income_{$month}")) {
                 $wxpay = Db::table("data_income_{$month}")
-                ->where('data_income_days',$currentDay)
-                ->where('data_income_pay_type','WXPAY')
-                ->whereIn('join_data_income_dept_id',$premisesKey)
-                ->selectRaw("data_income_pay_type,SUM(data_income_amount) as data_income_amount")
-                ->groupBy('data_income_pay_type')
-                ->first();
-    
+                    ->where('data_income_days', $currentDay)
+                    ->where('data_income_pay_type', 'WXPAY')
+                    ->whereIn('join_data_income_dept_id', $premisesKey)
+                    ->selectRaw("data_income_pay_type,SUM(data_income_amount) as data_income_amount")
+                    ->groupBy('data_income_pay_type')
+                    ->first();
+
                 $alipay = Db::table("data_income_{$month}")
-                    ->where('data_income_days',$currentDay)
-                    ->where('data_income_pay_type','ALIPAY')
-                    ->whereIn('join_data_income_dept_id',$premisesKey)
+                    ->where('data_income_days', $currentDay)
+                    ->where('data_income_pay_type', 'ALIPAY')
+                    ->whereIn('join_data_income_dept_id', $premisesKey)
                     ->selectRaw("data_income_pay_type,SUM(data_income_amount) as data_income_amount")
                     ->groupBy('data_income_pay_type')
                     ->first();
-    
+
                 $qrcode = Db::table("data_income_{$month}")
-                    ->where('data_income_days',$currentDay)
-                    ->where('data_income_pay_type','QRCODE')
-                    ->whereIn('join_data_income_dept_id',$premisesKey)
+                    ->where('data_income_days', $currentDay)
+                    ->where('data_income_pay_type', 'MONEY')
+                    ->whereIn('join_data_income_dept_id', $premisesKey)
                     ->selectRaw("data_income_pay_type,SUM(data_income_amount) as data_income_amount")
                     ->groupBy('data_income_pay_type')
                     ->first();
             }
-            
+
             $dayData['income']['wxpay'] = $wxpay->data_income_amount ?? 0.00;
             $statistics['income_wxpay'] += $dayData['income']['wxpay'];
             $dayData['income']['alipay'] = $alipay->data_income_amount ?? 0.00;
             $statistics['income_alipay'] += $dayData['income']['alipay'];
-            $dayData['income']['qrcode'] = $qrcode->data_income_amount ?? 0.00;
-            $statistics['income_qrcode'] += $dayData['income']['qrcode'];
+            $dayData['income']['money'] = $qrcode->data_income_amount ?? 0.00;
+            $statistics['income_money'] += $dayData['income']['money'];
 
-            $dayData['income']['amount'] = $dayData['income']['wxpay']+$dayData['income']['alipay']+$dayData['income']['qrcode'];
+            $dayData['income']['amount'] = $dayData['income']['wxpay'] + $dayData['income']['alipay'] + $dayData['income']['money'];
 
             $statistics['income_amount'] += $dayData['income']['amount'];
 
             // 支出
-            if(Util::schema()->hasTable("data_income_{$month}")){
+            if (Util::schema()->hasTable("data_income_{$month}")) {
                 $extendWxpay = Db::table("data_expend_{$month}")
-                    ->where('data_expend_days',$currentDay)
-                    ->where('data_expend_pay_type','WXPAY')
-                    ->whereIn('join_data_expend_dept_id',$premisesKey)
+                    ->where('data_expend_days', $currentDay)
+                    ->where('data_expend_pay_type', 'WXPAY')
+                    ->whereIn('join_data_expend_dept_id', $premisesKey)
                     ->selectRaw("data_expend_pay_type,SUM(data_expend_amount) as data_expend_amount")
                     ->groupBy('data_expend_pay_type')
                     ->first();
 
                 $extendAlipay = Db::table("data_expend_{$month}")
-                    ->where('data_expend_days',$currentDay)
-                    ->where('data_expend_pay_type','ALIPAY')
-                    ->whereIn('join_data_expend_dept_id',$premisesKey)
+                    ->where('data_expend_days', $currentDay)
+                    ->where('data_expend_pay_type', 'ALIPAY')
+                    ->whereIn('join_data_expend_dept_id', $premisesKey)
+                    ->selectRaw("data_expend_pay_type,SUM(data_expend_amount) as data_expend_amount")
+                    ->groupBy('data_expend_pay_type')
+                    ->first();
+
+                $extendMoney = Db::table("data_expend_{$month}")
+                    ->where('data_expend_days', $currentDay)
+                    ->where('data_expend_pay_type', 'MONEY')
+                    ->whereIn('join_data_expend_dept_id', $premisesKey)
                     ->selectRaw("data_expend_pay_type,SUM(data_expend_amount) as data_expend_amount")
                     ->groupBy('data_expend_pay_type')
                     ->first();
@@ -105,21 +113,23 @@ class IncomeAndExpendController
             $statistics['expend_wxpay'] += $dayData['expend']['wxpay'];
             $dayData['expend']['alipay'] = $extendAlipay->data_expend_amount ?? 0.00;
             $statistics['expend_alipay'] += $dayData['expend']['alipay'];
-            $dayData['expend']['amount'] = $dayData['expend']['wxpay']+$dayData['expend']['alipay'];
+            $dayData['expend']['money'] = $extendMoney->data_expend_amount ?? 0.00;
+            $statistics['expend_money'] += $dayData['expend']['money'];
+            $dayData['expend']['amount'] = $dayData['expend']['wxpay'] + $dayData['expend']['alipay'] + $dayData['expend']['money'];
 
             $statistics['expend_amount'] += $dayData['expend']['amount'];
 
             // 当前日期+1
-            $currentDay = date('Y-m-d',strtotime("+1 days",strtotime($currentDay)));
+            $currentDay = date('Y-m-d', strtotime("+1 days", strtotime($currentDay)));
 
             // 没有数据,跳过
-            if($dayData['expend']['amount'] == 0 && $dayData['income']['amount'] == 0){
+            if ($dayData['expend']['amount'] == 0 && $dayData['income']['amount'] == 0) {
                 continue;
             }
 
             $data[] = $dayData;
         }
 
-        return json_success('',['rows'=>$data,'statistics'=>$statistics]);
+        return json_success('', ['rows' => $data, 'statistics' => $statistics]);
     }
 }

+ 32 - 8
app/admin/controller/order/WholeController.php

@@ -78,9 +78,15 @@ class WholeController extends Curd
             $where['order_addtimes'][0] = strtotime(date('Y-m-d') . ' 00:00:00');
             $where['order_addtimes'][1] = strtotime(date('Y-m-d') . ' 23:59:59');
         } else if ($type == 'todayOrderAmount') {
-            $where['order_status_payment'] = 'SUCCESS';
-            $where['order_addtimes'][0] = strtotime(date('Y-m-d') . ' 00:00:00');
-            $where['order_addtimes'][1] = strtotime(date('Y-m-d') . ' 23:59:59');
+            $todayTimeUnix = strtotime(date('Y-m-d') . ' 00:00:00');
+            $groupIds = PayDetail::whereRaw('CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) > ? ', [$todayTimeUnix])
+                ->where('join_pay_order_id', '<>', '')
+                ->where('pay_category', '<>', 'RETURN')
+                ->where('pay_category', '<>', 'RECHARGE')
+                ->where('pay_category', '<>', 'CLEAR')
+                ->pluck('join_pay_order_id')
+                ->toArray();
+            $where['order_groupby'] = ['in', $groupIds];
         }
         $field = $field ?? 'order_addtimes';
         if (!empty($where['order_status_system']) && in_array($where['order_status_system'], ['PENDING', 'WAITING', 'SENDING', 'RECVING', 'SIGNED', 'CONFIRM'])) {
@@ -795,7 +801,7 @@ class WholeController extends Curd
             $order->order_is_complete = 'Y';
             $systemStatus = 'DONE';
         }
-        if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL'){
+        if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') {
             $systemStatus = "WAITING";
         }
         Db::beginTransaction();
@@ -1040,6 +1046,7 @@ class WholeController extends Curd
                         'pay_prepayid' => $params['pay_category'],
                         'pay_json_request' => json_encode($params),
                         'pay_json_response' => $params['pay_json_response'],
+                        'join_pay_object_json' => !empty($params['orderId']) ? json_encode(['order_id' => $params['orderId']]) : '[]',
                         'pay_addtimes' => time()
                     ];
 
@@ -1111,6 +1118,7 @@ class WholeController extends Curd
                 $payData['pay_json_response'] = $payData['pay_status'] == 'SUCCESS' ? json_encode([
                     'pay-result' => '支付成功', 'result-datetime' => date('Y-m-d H:i:s')
                 ]) : '[]';
+                $payData['join_pay_object_json'] = !empty($params['orderId']) ? json_encode(['order_id' => $params['orderId']]) : '[]';
                 $payData['pay_addtimes'] = time();
 
                 PayDetail::insert($payData);
@@ -1364,7 +1372,7 @@ class WholeController extends Curd
             $order->order_is_complete = 'Y';
             $systemStatus = 'DONE';
         }
-        if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL'){
+        if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') {
             $systemStatus = "WAITING";
         }
         $payDetail = PayDetail::where('join_pay_order_id', $order->order_groupby)->first();
@@ -1929,7 +1937,7 @@ class WholeController extends Curd
                     $params['order_is_complete'] = 'Y';
                     $systemStatus = 'DONE';
                 }
-                if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL'){
+                if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') {
                     $systemStatus = "WAITING";
                 }
             }
@@ -2503,7 +2511,7 @@ class WholeController extends Curd
                     $params['order_is_complete'] = 'Y';
                     $systemStatus = 'DONE';
                 }
-                if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL'){
+                if ($params['goods_classify'] == 'PACKAGE' && $params['delivery'] == 'ARRIVAL') {
                     $systemStatus = "WAITING";
                 }
             }
@@ -3053,10 +3061,11 @@ class WholeController extends Curd
                 'pay_amount' => $params['order_amount_pay'],
                 'pay_prepayid' => $payPrepayid,
                 'pay_paytimes' => date('Y-m-d H:i:s'),
+                'join_pay_object_json' => !empty($params['orderId']) ? json_encode(['order_id' => $params['orderId']]) : '[]',
                 'pay_json_request' => json_encode($params),
                 'pay_json_response' => $params['pay_json_response'] ?? '[]',
                 'pay_remark' => $params['order_remark'] ?? '',
-                'pay_addtimes' => time()
+                'pay_addtimes' => time(),
             ];
 
             PayDetail::insert($data);
@@ -4010,6 +4019,7 @@ class WholeController extends Curd
 
     public function exportOrder(Request $request)
     {
+        $type = $request->get('type', '');
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
         $where['order_category'] = ['<>', 'RECHARGE'];
         if (!empty($request->get('order_ids'))) {
@@ -4019,6 +4029,20 @@ class WholeController extends Curd
             $where['order_addtimes'][0] = strtotime($where['order_addtimes'][0]);
             $where['order_addtimes'][1] = strtotime($where['order_addtimes'][1]);
         }
+        if ($type == 'todayOrder' && empty($where['order_addtimes'])) {
+            $where['order_addtimes'][0] = strtotime(date('Y-m-d') . ' 00:00:00');
+            $where['order_addtimes'][1] = strtotime(date('Y-m-d') . ' 23:59:59');
+        } else if ($type == 'todayOrderAmount') {
+            $todayTimeUnix = strtotime(date('Y-m-d') . ' 00:00:00');
+            $groupIds = PayDetail::whereRaw('CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) > ? ', [$todayTimeUnix])
+                ->where('join_pay_order_id', '<>', '')
+                ->where('pay_category', '<>', 'RETURN')
+                ->where('pay_category', '<>', 'RECHARGE')
+                ->where('pay_category', '<>', 'CLEAR')
+                ->pluck('join_pay_order_id')
+                ->toArray();
+            $where['order_groupby'] = ['in', $groupIds];
+        }
         if ($request->get('goods_classify') || $request->get('goods_name')) {
             $where['order_id'] = '';
             $goodsClassify = $request->get('goods_classify', '');

+ 12 - 4
app/admin/service/consultant/ConsultantService.php

@@ -112,10 +112,14 @@ class ConsultantService
         }
         $type = 2;
         if (!empty($params['type'])) {
-            if (in_array($params['type'], [1,2])) {
+            if (in_array($params['type'], [1,2,3])) {
                 $type = $params['type'];
-                if ($type == 2) {
+                if ($type != 1) {
                     $params['relation_user_id'] = null;
+                } else {
+                    if (empty($params['relation_user_id'])) {
+                        return json_fail('请绑定后台账号');
+                    }
                 }
             }
         }
@@ -175,10 +179,14 @@ class ConsultantService
         }
         $type = 2;
         if (!empty($params['type'])) {
-            if (in_array($params['type'], [1,2])) {
+            if (in_array($params['type'], [1,2,3])) {
                 $type = $params['type'];
-                if ($type == 2) {
+                if ($type != 1) {
                     $params['relation_user_id'] = null;
+                } else {
+                    if (empty($params['relation_user_id'])) {
+                        return json_fail('请绑定后台账号');
+                    }
                 }
             }
         }

+ 118 - 58
app/admin/service/consultant/CustomService.php

@@ -72,28 +72,29 @@ class CustomService
             }];
         }
         if (!empty($params['report_status'])) {
-            if ($params['report_status'] == -1) {
-                //待审核
-                $where[] = ['check_status', '=', 1];
-            } else {
-                $where[] = ['check_status', '=', 2];
-            }
-            if ($params['report_status'] == 1) {
-                //已报备
-                $where[] = [function($query) use ($diffNums, $currentTime) {
-                    $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
-                }];
-            } else if ($params['report_status'] == 3) {
-                //已锁定
-                $where[] = [function($query) {
-                    $query->whereIn('current_status', [2,3,4]);
-                }];
-            } else if ($params['report_status'] == 2) {
-                //已失效
-                $where[] = [function($query) use ($diffNums, $currentTime){
-                    $query->orWhere('current_status', '=', -1)->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 1 AND check_status = 2)");
-                }];
-            }
+            $where[] = ['check_status', '=', $params['report_status']];
+//            if ($params['report_status'] == -1) {
+//                //待审核
+//                $where[] = ['check_status', '=', 1];
+//            } else {
+//                $where[] = ['check_status', '=', 2];
+//            }
+//            if ($params['report_status'] == 1) {
+//                //已报备
+//                $where[] = [function($query) use ($diffNums, $currentTime) {
+//                    $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
+//                }];
+//            } else if ($params['report_status'] == 3) {
+//                //已锁定
+//                $where[] = [function($query) {
+//                    $query->whereIn('current_status', [2,3,4]);
+//                }];
+//            } else if ($params['report_status'] == 2) {
+//                //已失效
+//                $where[] = [function($query) use ($diffNums, $currentTime){
+//                    $query->orWhere('current_status', '=', -1)->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 1 AND check_status = 2)");
+//                }];
+//            }
         }
         if (!empty($params['consultant_name'])) {
             $consultantIds = Consultant::where('name', 'like', "%{$params['consultant_name']}%")->pluck('id');
@@ -131,9 +132,13 @@ class CustomService
 
         if (!empty($params['current_status'])) {
             $currentStatus = $params['current_status'];
-            $where[] = [function($query) use ($currentStatus){
-                $query->where('current_status', '=', $currentStatus)->where('check_status', '=', 2);
-            }];
+            if ($currentStatus == 1) {
+                $where[] = ['current_status', '=', $currentStatus];
+            } else {
+                $where[] = [function($query) use ($currentStatus){
+                    $query->where('current_status', '=', $currentStatus)->where('check_status', '<>', 1);
+                }];
+            }
         }
         if (!empty($params['consultant_id'])) {
             $where[] = ['consultant_id', '=', $params['consultant_id']];
@@ -203,6 +208,24 @@ class CustomService
                 $where[] = ['level', '=', ($params['level'] + 1)];
             }
         }
+        if (!empty($params['belong_status'])) {
+            $belongStatus = $params['belong_status'];
+            if ($belongStatus == 1) {
+                //未流入公池
+                $where[] = ['belong_status', '=', 1];
+                $where[] = [function($query) use ($diffNums, $currentTime){
+                    $query->orWhereRaw("check_status IN (-1, 1)")
+                        ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
+                        ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
+                }];
+            } else {
+                //已经流入公池
+                $where[] = [function($query) use ($diffNums, $currentTime){
+                    $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
+                }];
+            }
+        }
+
 
         return $where;
     }
@@ -303,6 +326,7 @@ class CustomService
             'check_status' => 1,
             'visit_time' => $params['visit_time'] ?? null,
             'note' => $params['note'] ?? '',
+            'belong_status' => 1,
             'current_status' => $params['current_status'] ?? null,
             'created_at' => time()
         ];
@@ -533,15 +557,21 @@ class CustomService
     public static function moveCustom($params)
     {
         $userId = JwtToken::getCurrentId();
-        $currentConsultantId = $params['consultant_id']; //当前顾问
+        $moveType = $params['move_type'] ?? 0;
+        if ($moveType == 1) {
+            $currentDeptId = $params['dept_id'];
+            $currentConsultantId = 0;
+        } else {
+            $currentConsultantId = $params['consultant_id'] ?? 0; //当前顾问
+            $consultantInfo = Consultant::firstWhere(['id' => $currentConsultantId]);
+            if (empty($consultantInfo)) {
+                return json_fail('顾问不存在');
+            }
+            $currentDeptId = $consultantInfo->dept_id; //当前部门
+        }
         $consultantIds = $params['move_consultant_id'] ?? [];
         $customIds = $params['move_market_customer_id'] ?? [];
         $note = $params['note'] ?? '';
-        $consultantInfo = Consultant::firstWhere(['id' => $currentConsultantId]);
-        if (empty($consultantInfo)) {
-            return json_fail('顾问不存在');
-        }
-        $currentDeptId = $consultantInfo->dept_id; //当前部门
         $logsInertData  = [];
         $now = time();
         $whereCustom = [];
@@ -580,6 +610,13 @@ class CustomService
         $result = false;
         try {
             foreach ($customList as $item) {
+                if ($currentConsultantId != 0) {
+                    //移交至指定顾问
+                    $item->visit_time = time();
+                } else {
+                    //移交至其他团队
+                    $item->visit_time = time() - self::DIFF_TIME;
+                }
                 $item->consultant_id = $currentConsultantId;
                 $item->dept_id = $currentDeptId;
                 $item->save();
@@ -682,16 +719,26 @@ class CustomService
                 $query->whereBetween('created_at', $createdDate);
             }];
         }
-        $paginator = MarketCustomerLogs::with(['custom', 'beforeMan', 'currentMan', 'opBackPerson', 'opFrontPerson'])
-            ->whereHas('custom', function ($query) use ($whereCustom) {
-                $query->where($whereCustom);
-            })
-            ->whereHas('currentMan', function ($query) use ($whereCurrent) {
-                $query->where($whereCurrent);
-            })
-            ->whereHas('beforeMan', function ($query) use ($whereBefore) {
-                $query->where($whereBefore);
-            })
+        $paginator = MarketCustomerLogs::with(['custom' => function($query) {
+            $query->select('id', 'name', 'mobile');
+        }, 'beforeMan' => function($query) {
+            $query->select('id', 'name', 'mobile');
+        }, 'currentMan' => function($query) {
+            $query->select('id', 'name', 'mobile');
+        }, 'beforeDept' => function($query) {
+            $query->select('dept_id', 'dept_name');
+        }, 'currentDept' => function($query) {
+            $query->select('dept_id', 'dept_name');
+        }])
+//            ->whereHas('custom', function ($query) use ($whereCustom) {
+//                $query->where($whereCustom);
+//            })
+//            ->whereHas('currentMan', function ($query) use ($whereCurrent) {
+//                $query->where($whereCurrent);
+//            })
+//            ->whereHas('beforeMan', function ($query) use ($whereBefore) {
+//                $query->where($whereBefore);
+//            })
             ->where($where)
             ->orderBy('created_at', 'desc')
             ->paginate($limit, '*', 'page', $page);
@@ -731,7 +778,7 @@ class CustomService
         }
         $status = $info->check_status;
         if ($status != 1) {
-            return json_fail('客户不是待审核状态');
+            return json_fail('客户不是待转到访状态');
         }
         $mobile = $info->mobile;
         if ($checkStatus == 2) {
@@ -743,10 +790,15 @@ class CustomService
         Db::beginTransaction();
         try {
             $info->check_status = $checkStatus;
+            $info->current_status = $checkStatus;
             if ($checkStatus == -1) {
                 //拒绝录入拒绝理由
                 $info->check_note = $params['note'] ?? '无拒绝理由';
             }
+            if ($checkStatus == 2) {
+                //更新到访保护期时间
+                $info->visit_time = time();
+            }
             $info->check_time = time();
             $info->check_admin_id = $adminId;
             $result = $info->save();
@@ -757,7 +809,7 @@ class CustomService
                     ['check_status', '=', 1],
                     ['id', '<>', $customId]
                 ];
-                MarketCustomer::where($where)->update(['check_time' => time(),'check_status' => -1,'check_note' => '客户已经被其他顾问报备']);
+                MarketCustomer::where($where)->update(['check_time' => time(),'check_status' => -1, 'current_status' => -1,'check_note' => '客户已经被其他登记']);
             }
             Db::commit();
         }catch (BusinessException|\Exception $e){
@@ -765,9 +817,9 @@ class CustomService
             return json_fail($e->getMessage());
         }
         if ($result) {
-            return json_success('审核成功');
+            return json_success('操作成功');
         } else {
-            return json_fail('审核失败');
+            return json_fail('操作失败');
         }
 
 
@@ -786,14 +838,18 @@ class CustomService
         $where = self::commonSearch($params);
         //客户总数
         $total = MarketCustomer::where($where)->count();
-        //待审核
-        $checkTotal = MarketCustomer::where($where)->where('check_status', 1)->count();
+        //公池客户
+        $pubTotal = MarketCustomer::where($where)->where([[function($query){
+            $diffNums = self::DIFF_TIME;
+            $query->orWhereRaw("((visit_time + {$diffNums}) - UNIX_TIMESTAMP() <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
+        }]])->count();
         //已报备
-        $reportTotal = MarketCustomer::where($where)->where(
+        $checkTotal = MarketCustomer::where($where)->where('check_status', 1)->count();
+        //已到访
+        $visitTotal = MarketCustomer::where($where)->where(
             [[function($query) {
-                $currentTime = time();
                 $diffNums = self::DIFF_TIME;
-                $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0) AND current_status = 1 AND check_status = 2");
+                $query->whereRaw("((visit_time + {$diffNums}) - UNIX_TIMESTAMP() > 0) AND current_status = 2 AND check_status = 2")->where('belong_status', 1);
             }]]
         )->count();
         //已来电
@@ -801,31 +857,35 @@ class CustomService
             $query->where('check_status', '=', 2)->where('current_status', '=', 1);
         }]])->count();
         //已到访
-        $visitTotal = MarketCustomer::where($where)->where([[function($query) {
-            $query->where('check_status', '=', 2)->where('current_status', '=', 2);
-        }]])->count();
+//        $visitTotal = MarketCustomer::where($where)->where([[function($query) {
+//            $query->where('check_status', '=', 2)->where('current_status', '=', 2);
+//        }]])->count();
         //已缴费
         $payTotal = MarketCustomer::where($where)->where([[function($query) {
-            $query->where('check_status', '=', 2)->where('current_status', '=', 3);
+            $query->where('check_status', '=', 2)->where('current_status', '=', 3)->where('belong_status', 1);
         }]])->count();
         //已成交
         $dealTotal = MarketCustomer::where($where)->where([[function($query) {
-            $query->where('check_status', '=', 2)->where('current_status', '=', 4);
+            $query->where('check_status', '=', 2)->where('current_status', '=', 4)->where('belong_status', 1);
         }]])->count();
-        //已到访 + 已缴费 + 已成交 / 客户总数
+        //已缴费 + 已成交 / 客户总数
+        //报备失败
+        $failTotal = MarketCustomer::where($where)->where('current_status', -1)->count();
         $rant = 0;
         if ($total > 0) {
-            $rant = $payTotal + $dealTotal / $total;
+            $rant = ($payTotal + $dealTotal) / $total;
         }
         $rant = sprintf('%.2f', $rant);
         $data = [
             'total' => $total,
+            'pub_total' => $pubTotal,
             'check_total' => $checkTotal,
-            'report_total' => $reportTotal,
+            'report_total' => 0,
             'mobile_total' => $mobileTotal,
             'visit_total' => $visitTotal,
             'pay_total' => $payTotal,
             'deal_total' => $dealTotal,
+            'fail_total' => $failTotal,
             'rant' => $rant,
         ];
         return json_success('请求成功', $data);

+ 2 - 3
app/admin/service/order/OrderService.php

@@ -376,6 +376,7 @@ class OrderService
             'pay_prepayid' => $params['pay_category'],
             'pay_json_request' => json_encode($params),
             'pay_json_response' => $params['pay_json_response'] ?? '[]',
+            'join_pay_object_json' => !empty($params['orderId']) ? json_encode(['order_id'=>$params['orderId']]) : '[]',
             'pay_addtimes' => time()
         ];
 
@@ -398,9 +399,6 @@ class OrderService
             $payDetail->pay_category = $params['goods_classify'] ?? '';
             $payDetail->pay_prepayid = $params['pay_category'];
             $payDetail->pay_json_request = json_encode($params);
-            $payDetail->pay_json_response = $params['pay_json_response'] ?? json_encode([
-                'pay-result' => '支付成功', 'result-datetime' => date('Y-m-d H:i:s')
-            ]);
             $payDetail->pay_addtimes = time();
         }
         if ($payDetail->pay_prepayid == $qrcodePrepayId) {
@@ -412,6 +410,7 @@ class OrderService
         $payDetail->pay_amount = $params['order_amount_pay'];
         $payDetail->pay_paytimes = date('Y-m-d H:i:s');
         $payDetail->pay_status = 'SUCCESS';
+        $payDetail->join_pay_object_json = !empty($params['orderId']) ? json_encode(['order_id'=>$params['orderId']]) : '[]';
         $payDetail->save();
     }
 

+ 9 - 5
app/admin/service/statistics/OrderService.php

@@ -4,6 +4,7 @@ namespace app\admin\service\statistics;
 
 use app\model\Order;
 use app\model\OrderReturn;
+use app\model\PayDetail;
 use support\Db;
 
 class OrderService
@@ -15,11 +16,14 @@ class OrderService
         // 今日订单
         $data['todayOrder'] = Order::where('order_addtimes', '>', $todayTimeUnix)->where('order_category', '<>', 'RECHARGE')->count();
         // 今日收入
-        $data['todayRevenue'] = Order::where('order_status_payment', 'SUCCESS')
-            ->where('order_addtimes', '>', $todayTimeUnix)
-            ->where('order_category', '<>', 'RETURN')
-            ->where('order_category', '<>', 'RECHARGE')
-            ->sum('order_amount_pay');
+//        $couponDetails = Db::select("select * from app_coupon_detail where coupon_detail_deadline_datetime != '' AND CAST(UNIX_TIMESTAMP(coupon_detail_deadline_datetime) as SIGNED) < " . time());
+
+        $data['todayRevenue'] = PayDetail::whereRaw('CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) > ? ' , [$todayTimeUnix])
+            ->where('join_pay_order_id','<>','')
+            ->where('pay_category', '<>', 'RETURN')
+            ->where('pay_category', '<>', 'RECHARGE')
+            ->where('pay_category', '<>', 'CLEAR')
+            ->sum('pay_amount');
         // 今日充值额
         $data['todayRecharge'] = Order::where('order_status_payment', 'SUCCESS')
             ->where('order_addtimes', '>', $todayTimeUnix)

+ 13 - 7
app/model/MarketCustomer.php

@@ -144,14 +144,20 @@ class MarketCustomer extends Model
     {
         $where = [
             ['mobile', '=', $mobile],
+            ['check_status', '=', 2],
             [function($query) {
-            $query->orWhere(function ($query){
-                $diffNums = (60 * 60 * 24 * 30);
-                $currentTime = time();
-                $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
-            })->orWhereIn('current_status', [2,3,4]);
-            }],
-            ['check_status', '=', 2]
+            $query->whereIn('current_status', [2,3,4]);
+            }]
+//            [function($query) {
+//            $query->orWhere(function ($query){
+//                $diffNums = (60 * 60 * 24 * 30);
+//                $currentTime = time();
+//                $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 2);
+//            })->orWhereIn('current_status', [2,3,4]);
+//            }],
+
+
+
         ];
         if (!empty($id)) {
             $where[] = ['id', '<>', $id];

+ 7 - 0
app/model/MarketCustomerLogs.php

@@ -42,4 +42,11 @@ class MarketCustomerLogs extends Model
         return $this->belongsTo(Consultant::class, 'change_consultant_id');
     }
 
+    public function beforeDept(){
+        return $this->belongsTo(SysDept::class, 'before_dept_id');
+    }
+
+    public function currentDept(){
+        return $this->belongsTo(SysDept::class, 'dept_id');
+    }
 }

+ 76 - 46
app/wechat/service/CustomService.php

@@ -16,6 +16,7 @@ use Tinywan\Jwt\JwtToken;
 class CustomService
 {
     const DIFF_TIME = (60 * 60 * 24 * 30);
+    const CHECK_NOTE = '该客户已在其他顾问那到访';
     /**
      * Notes: 选项配置
      * User: yb
@@ -57,7 +58,14 @@ class CustomService
         $type = $consultantInfo->type;
         $currentTime = time();
         $diffNums = self::DIFF_TIME;
-        $where = [];
+        $where = [
+            ['consultant_id', '<>', 0],
+            [function($query) use ($diffNums, $currentTime){
+            $query->orWhereRaw("check_status IN (-1, 1)")
+                ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
+                ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
+        }]
+        ];
         $whereFollow = [];
         if ($type == 1) {
             //团队下所有的
@@ -75,10 +83,13 @@ class CustomService
                 }];
             }
 
-        } else {
+        } else if ($type == 2){
             //个人的
             $where[] = ['consultant_id', '=', $consultantId];
             $whereFollow[] = ['consultant_id', '=', $consultantId];
+        } else {
+            //所有团队的
+
         }
         if (!empty($params['custom'])) {
             $keywords = $params['custom'];
@@ -125,7 +136,7 @@ class CustomService
         if (!empty($params['current_status'])) {
             $currentStatus = $params['current_status'];
             $where[] = [function($query) use ($currentStatus) {
-                $query->where('current_status', $currentStatus)->where('check_status', 2);
+                $query->where('current_status', $currentStatus);
             }];
         }
         if (!empty($params['created_at'])) {
@@ -162,14 +173,14 @@ class CustomService
             }
         }
         //本日新增
-        $date = date('Y-m-d');
-        $start = strtotime($date.' 00:00:00');
-        $end = strtotime($date.' 23:59:59');
-        $newNums = MarketCustomer::where($where)->whereBetween('created_at', [$start, $end])->count();
-        $followNums = MarketCustomerFollow::where($whereFollow)->whereBetween('created_at', [$start, $end])->count();
+//        $date = date('Y-m-d');
+//        $start = strtotime($date.' 00:00:00');
+//        $end = strtotime($date.' 23:59:59');
+//        $newNums = MarketCustomer::where($where)->whereBetween('created_at', [$start, $end])->count();
+//        $followNums = MarketCustomerFollow::where($whereFollow)->whereBetween('created_at', [$start, $end])->count();
         $data = [
-            'new_follow_num' => $followNums,
-            'new_custom_num' => $newNums,
+            'new_follow_num' => $followNums ?? 0,
+            'new_custom_num' => $newNums ?? 0,
             'total' => $total,
             'rows' => $items
         ];
@@ -187,31 +198,21 @@ class CustomService
      */
     public static function myCustomList($params)
     {
+        $currentTime = time();
+        $diffNums = self::DIFF_TIME;
         $page = $params['page'] ?? 1;
         $size = $params['size'] ?? 10;
         //查询有效顾问信息
         $consultantId = JwtToken::getCurrentId();
-        $consultantInfo = Consultant::firstWhere(['id' => $consultantId]);
-        $deptId = $consultantInfo->dept_id;
-        $type = $consultantInfo->type;
-        $where = [];
-        if ($type == 1) {
-            //团队下所有的
-            $deptIds = TeamService::getIds($deptId);
-            $where[] = [function($query) use ($deptIds) {
-                $query->whereIn('dept_id', $deptIds);
-            }];
-        } else {
-            //个人的
-            $where[] = ['consultant_id', '=', $consultantId];
-        }
-        $where[] = ['check_status', '=', 2];
-        $where[] = [function($query) {
-            $query->orWhere(function ($query){
-                $diffNums = (60 * 60 * 24 * 30);
-                $currentTime = time();
-                $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
-            })->orWhereIn('current_status', [2,3,4]);
+        $where = [
+            ['consultant_id', '=', $consultantId],
+            ['current_status', '<>', '-1'],
+            ['check_status', '<>', '-1']
+        ];
+        $where[] = [function($query) use ($diffNums, $currentTime){
+            $query->orWhereRaw("check_status IN (-1, 1)")
+                ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
+                ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
         }];
         if (!empty($params['custom'])) {
             $keywords = $params['custom'];
@@ -246,7 +247,7 @@ class CustomService
         $mobile = $params['mobile'];
         //查询客户手机号是否已经存在
         if (MarketCustomer::checkCustomExists($mobile)) {
-            return json_fail('客户已经登记过了');
+            return json_fail('客户已经到访');
         }
         //查询顾问信息
         $consultantId = JwtToken::getCurrentId();
@@ -274,14 +275,10 @@ class CustomService
             'visit_time' => time(),
             'note' => $params['note'] ?? '',
             'check_status' => 1,
-            'current_status' => $params['current_status'] ?? null,
+            'current_status' => 1,
+            'belong_status' => 1,
             'created_at' => time()
         ];
-        if ($insertData['type'] == 1) {
-            $insertData['current_status'] = 1;
-        } else if ($insertData['type'] == 2) {
-            $insertData['current_status'] = 2;
-        }
         Db::beginTransaction();
         try {
             $customId = MarketCustomer::insertGetId($insertData);
@@ -414,19 +411,51 @@ class CustomService
     {
         $customId = $params['id'];
         $currentStatus = $params['current_status'];
-        if (!in_array($currentStatus, [-1, 3, 4])) {
+        if (!in_array($currentStatus, [-1, 2, 3, 4])) {
             return json_fail('状态值非法');
         }
         $info = MarketCustomer::firstWhere(['id' => $customId]);
         if (empty($info)) {
             return json_fail('客户不存在');
         }
-        $info->current_status = $currentStatus;
-        $result = $info->save();
+        if ($info->current_status != 1) {
+            return json_fail('客户非已报备状态');
+        }
+        if ($currentStatus >= 2) {
+            //验证是否已经存在其他到访客户
+            if (MarketCustomer::checkCustomExists($info->mobile)) {
+                return json_fail('操作失败,客户已存在');
+            }
+        }
+        Db::beginTransaction();
+        $result = false;
+        try {
+            if ($currentStatus == 2) {
+                $info->visit_time = time();
+            }
+            $info->current_status = $currentStatus;
+            $result = $info->save();
+            if ($result) {
+                if ($currentStatus >= 2) {
+                    $where = [
+                        ['id', '<>', $customId]
+                    ];
+                    //将其他的改为无效客户
+                    MarketCustomer::where($where)->where('check_status', 2)->update(['current_status' => -1]);
+                    //将待审核的改为拒绝
+                    MarketCustomer::where($where)->where('check_status', 1)->update(['check_status' => -1, 'check_note' => self::CHECK_NOTE]);
+                }
+            }
+            Db::commit();
+        }catch (BusinessException|\Exception $e){
+            Db::rollBack();
+            return json_fail($e->getMessage());
+        }
+
         if ($result) {
-            return json_success('更新成功');
+            return json_success('操作成功');
         } else {
-            return json_fail('更新失败');
+            return json_fail('操作失败');
         }
     }
 
@@ -445,7 +474,7 @@ class CustomService
         if (empty($userInfo)) {
             return json_fail('管理员信息不存在');
         }
-        if ($userInfo->type != 1) {
+        if (!in_array($userInfo->type, [1,3])) {
             return json_fail('操作权限不足');
         }
         $relationUserId = $userInfo->relation_user_id;
@@ -566,7 +595,7 @@ class CustomService
         }
         $status = $info->check_status;
         if ($status != 1) {
-            return json_fail('客户不是待审核状态');
+            return json_fail('客户不是待状态');
         }
         $mobile = $info->mobile;
         if ($checkStatus == 2) {
@@ -582,6 +611,7 @@ class CustomService
                 //拒绝录入拒绝理由
                 $info->check_note = $params['note'] ?? '无拒绝理由';
             }
+            $info->current_status = $checkStatus;
             $info->check_time = time();
             $info->check_admin_id = $adminId;
             $info->check_consultant_id = $userId;
@@ -593,7 +623,7 @@ class CustomService
                     ['check_status', '=', 1],
                     ['id', '<>', $customId]
                 ];
-                MarketCustomer::where($where)->update(['check_time' => time(),'check_status' => -1,'check_note' => '客户已经被其他顾问报备']);
+                MarketCustomer::where($where)->update(['current_status' => -1, 'check_time' => time(),'check_status' => -1,'check_note' => self::CHECK_NOTE]);
             }
             Db::commit();
         }catch (BusinessException|\Exception $e){

+ 9 - 17
app/wechat/service/FollowService.php

@@ -25,24 +25,21 @@ class FollowService
         //查询客户是否存在
         $where = [
             ['consultant_id', '=', $consultantId],
-            ['id', '=', $params['market_customer_id']]
+            ['id', '=', $params['market_customer_id']],
+            [function($query){
+            $diffNums = CustomService::DIFF_TIME;
+                $query->orWhereRaw("check_status IN (-1, 1)")
+                    ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
+                    ->orWhereRaw("((visit_time + {$diffNums}) - UNIX_TIMESTAMP() > 0 AND current_status = 2 AND check_status = 2)");
+            }],
         ];
         $customInfo = MarketCustomer::where($where)->first();
         if (empty($customInfo)) {
             return json_fail('客户不存在');
         }
         $currentStatus = $customInfo->current_status;
-        if ($currentStatus == -1) {
-            return json_fail('无效客户,无法跟进');
-        }
-        if ($currentStatus == 1) {
-            $visitTime = $customInfo->visit_time;
-            $now = time();
-            $start = strtotime($visitTime);
-            $end = $start + CustomService::DIFF_TIME;
-            if ($end < $now) {
-                return json_fail('已失效,请重新添加客户信息');
-            }
+        if ($currentStatus == -1 || $customInfo->check_status == -1) {
+            return json_fail('报备失败客户,无法跟进');
         }
         $insertData = [
             'market_customer_id' => $params['market_customer_id'],
@@ -57,11 +54,6 @@ class FollowService
         $result = false;
         Db::beginTransaction();
         try {
-            if ($currentStatus == 1) {
-                if ($insertData['visit_type'] == 2) {
-                    $customInfo->current_status = 2;
-                }
-            }
             $customInfo->follow_num = $customInfo->follow_num + 1;
             $customInfo->level = $insertData['intention_type'];
             $customInfo->visit_time = $insertData['follow_time'];

+ 26 - 34
app/wechat/service/UserService.php

@@ -332,9 +332,12 @@ class UserService
                 $where[] = ['id', '<>', $userId];
             }
             $ids = Consultant::where($where)->pluck('id')->toArray();
-        } else {
+        } else if ($userInfo->type == 2){
             //普通账号
             $ids[] = $userId;
+        } else if ($userInfo->type == 3) {
+            //判客账户
+            $ids = Consultant::pluck('id')->toArray();
         }
         return $ids;
     }
@@ -352,11 +355,16 @@ class UserService
         $currentTime = time();
         $diffNums = CustomService::DIFF_TIME;
 
-        $where = [
+        $whereFollow = $where = [
             [function($query) use ($userIds) {
             $query->whereIn('consultant_id', $userIds);
             }]
         ];
+        $where[] = [function($query) use ($diffNums, $currentTime){
+            $query->orWhereRaw("check_status IN (-1, 1)")
+                ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
+                ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
+        }];
         //客户总量
         $customNums = MarketCustomer::where($where)->count();
         if (!empty($params['time'])) {
@@ -372,18 +380,15 @@ class UserService
         $where[] = [function($query) use ($start, $end) {
             $query->whereBetween('created_at', [$start, $end]);
         }];
-        //待审核客户数量
-        $checkCustomNums = MarketCustomer::where($where)->where('check_status', '=', 1)->count();
+        $whereFollow[] = [function($query) use ($start, $end) {
+            $query->whereBetween('created_at', [$start, $end]);
+        }];
+        //待转到访客户数量
+        $checkCustomNums = MarketCustomer::where($where)->where('check_status', 1)->where('current_status', 1)->count();
         //新增客户
         $newCustomNums = MarketCustomer::where($where)->count();
         //已报备客户数
-        $whereReport = [
-            [function($query) use ($diffNums, $currentTime) {
-                $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
-            }],
-            ['check_status', '=', 2]
-        ];
-        $reportCustomNums = MarketCustomer::where($where)->where($whereReport)->count();
+        $reportCustomNums = MarketCustomer::where($where)->where('current_status', 1)->count();
         //已到访客户数量
         $visitCustomNums = MarketCustomer::where($where)->where('current_status', 2)->where('check_status', 2)->count();
         //已缴费客户数量
@@ -391,25 +396,13 @@ class UserService
         //已成交客户数量
         $dealCustomNums = MarketCustomer::where($where)->where('current_status', 4)->where('check_status', 2)->count();
         //新增跟进记录数量
-        $newFollowNums = MarketCustomerFollow::where($where)->count();
-        //男女性别占比
-        $whereEffective = [
-            [function($query) {
-                $query->orWhere(function ($query){
-                    $diffNums = (60 * 60 * 24 * 30);
-                    $currentTime = time();
-                    $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
-                })->orWhereIn('current_status', [2,3,4]);
-            }],
-            ['check_status', '=', 2]
-        ];
-
+        $newFollowNums = MarketCustomerFollow::where($whereFollow)->count();
         /* 男女数量 */
         $genderDataNums = [
             ['label' => '男', 'value' => 1, 'nums' => 0],
             ['label' => '女', 'value' => 2, 'nums' => 0],
         ];
-        $genderData = MarketCustomer::where($where)->select(Db::raw('gender, count(*) as nums'))->where($whereEffective)->groupBy('gender')->get();
+        $genderData = MarketCustomer::where($where)->select(Db::raw('gender, count(*) as nums'))->groupBy('gender')->get();
         if (!$genderData->isEmpty()) {
             $genderData = $genderData->toArray();
             foreach ($genderDataNums as $genderKey => $genderVal) {
@@ -428,7 +421,7 @@ class UserService
             ['label' => 'D类', 'value' => 4, 'nums' => 0],
             ['label' => '其他', 'value' => "", 'nums' => 0],
         ];
-        $levelData = MarketCustomer::where($where)->select(Db::raw('level, count(*) as nums'))->where($whereEffective)->groupBy('level')->get();
+        $levelData = MarketCustomer::where($where)->select(Db::raw('level, count(*) as nums'))->groupBy('level')->get();
         if (!$levelData->isEmpty()) {
             $levelData = $levelData->toArray();
             $levelData = array_column($levelData, 'nums', 'level');
@@ -461,20 +454,19 @@ class UserService
      */
     public static function customTrend($params)
     {
+        $currentTime = time();
+        $diffNums = CustomService::DIFF_TIME;
         //统计客户总数
         $userIds = self::getIds();
         $where = [
             [function($query) use ($userIds) {
                 $query->whereIn('consultant_id', $userIds);
             }],
-            [function($query) {
-                $query->orWhere(function ($query){
-                    $diffNums = (60 * 60 * 24 * 30);
-                    $currentTime = time();
-                    $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
-                })->orWhereIn('current_status', [2,3,4]);
-            }],
-            ['check_status', '=', 2]
+            [function($query) use ($diffNums, $currentTime){
+                $query->orWhereRaw("check_status IN (-1, 1)")
+                    ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
+                    ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
+            }]
         ];
         $whereTrend = [];
         if (!empty($params['type'])) {