Browse Source

Merge branch 'master' of http://39.98.194.76:3000/txct/wanyue_app

gorden 6 months ago
parent
commit
3ed2167d36

+ 11 - 0
app/admin/controller/consultant/CustomController.php

@@ -182,4 +182,15 @@ class CustomController extends Curd
     {
         return CustomService::exportData($request);
     }
+
+    /**
+     * Notes: 按月统计
+     * User: yb
+     * Date: 2024/8/21
+     * Time: 15:54
+     */
+    public function statisticsByMonth()
+    {
+        return CustomService::statisticsMonth();
+    }
 }

+ 1 - 1
app/admin/controller/consultant/TeamController.php

@@ -28,7 +28,7 @@ class TeamController extends Curd
         $order = $request->get('order', 'desc');
         $field = $field ?? 'dept_addtimes';
         $where['dept_category'] = '获客团队';
-        $deptIds = TeamService::getIdsByUser(1);
+        $deptIds = TeamService::getIdsByUser();
         if (false === $deptIds) {
             //无权限
             $where['dept_id'] = ['=', 0];

+ 3 - 1
app/admin/service/consultant/ConsultantService.php

@@ -23,7 +23,7 @@ class ConsultantService
         $where = [];
         $whereDept = [];
         $whereTopDept = [];
-        $deptIds = TeamService::getIdsByUser(1);
+        $deptIds = TeamService::getIdsByUser();
         if (false === $deptIds) {
             //无权限
             $where[] = ['dept_id', '=', 0];
@@ -125,6 +125,7 @@ class ConsultantService
             'mobile' => $params['mobile'],
             'dept_id' => $params['dept_id'],
             'top_dept_id' => $topDeptId,
+            'job' => $params['job'] ?? '顾问',
             'gender' => $params['gender'] ?? 1,
             'password' => $password,
             'status' => $params['status'] ?? 1,
@@ -184,6 +185,7 @@ class ConsultantService
         $updateData = [
             'name' => $params['name'],
             'mobile' => $params['mobile'],
+            'job' => $params['job'] ?? '顾问',
             'gender' => $params['gender'] ?? 1,
             'status' => $params['status'] ?? 1,
             'relation_user_id' => $params['relation_user_id'] ?? null,

+ 100 - 0
app/admin/service/consultant/CustomService.php

@@ -65,6 +65,12 @@ class CustomService
                 $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
             }];
         }
+        if (!empty($params['mobile'])) {
+            $mobile = $params['mobile'];
+            $where[] = [function($query) use ($mobile) {
+                $query->where('mobile', 'like', "%{$mobile}%");
+            }];
+        }
         if (!empty($params['report_status'])) {
             if ($params['report_status'] == -1) {
                 //待审核
@@ -162,6 +168,42 @@ class CustomService
                 }];
             }
         }
+        if (isset($params['require_area'])) {
+            if (is_numeric($params['require_area'])) {
+                $where[] = ['require_area', '=', ($params['require_area'] + 1)];
+            }
+        }
+        if (isset($params['requirement'])) {
+            if (is_numeric($params['requirement'])) {
+                $where[] = ['requirement', '=', ($params['requirement'] + 1)];
+            }
+        }
+        if (isset($params['age_range'])) {
+            if (is_numeric($params['age_range'])) {
+                $where[] = ['age_range', '=', ($params['age_range'] + 1)];
+            }
+        }
+        if (isset($params['visit_type'])) {
+            if (is_numeric($params['visit_type'])) {
+                $where[] = ['visit_type', '=', $params['visit_type']];
+            }
+        }
+        if (isset($params['region'])) {
+            if (is_numeric($params['region'])) {
+                $where[] = ['region', '=', ($params['region'] + 1)];
+            }
+        }
+        if (isset($params['purpose'])) {
+            if (is_numeric($params['purpose'])) {
+                $where[] = ['purpose', '=', ($params['purpose'] + 1)];
+            }
+        }
+        if (isset($params['level'])) {
+            if (is_numeric($params['level'])) {
+                $where[] = ['level', '=', ($params['level'] + 1)];
+            }
+        }
+
         return $where;
     }
 
@@ -790,6 +832,64 @@ class CustomService
 
     }
 
+    /**
+     * Notes: 前12个月统计数据
+     * User: yb
+     * Date: 2024/8/21
+     * Time: 15:56
+     */
+    public static function statisticsMonth()
+    {
+        $months = month_12();
+        sort($months);
+        $startDate = $months[0];
+        $startDateTime = strtotime($startDate.'/01 00:00:00');
+        $endDateTime = time();
+        $where = [
+            ['created_at', '>=', $startDateTime],
+            ['created_at', '<=', $endDateTime]
+        ];
+        $currentTime = time();
+        $diffNums = self::DIFF_TIME;
+        $deptIds = TeamService::getIdsByUser();
+        if (false === $deptIds) {
+            //无权限
+            $where[] = ['dept_id', '=', 0];
+        } else if (is_array($deptIds)) {
+            //指定团队下的权限
+            if (!empty($params['dept_id'])) {
+                $deptId = end($params['dept_id']);
+                $deptIds = SysDept::where('dept_super_path','like', "%/{$deptId}/%")->where('dept_category', '=', TeamService::DEPT_CATEGORY)->pluck('dept_id')->toArray();
+            }
+            $where[] = [function($query) use ($deptIds) {
+                $query->whereIn('dept_id', $deptIds);
+            }];
+        } else {
+            if (!empty($params['dept_id'])) {
+                $deptId = end($params['dept_id']);
+                $deptIds = SysDept::where('dept_super_path','like', "%/{$deptId}/%")->where('dept_category', '=', TeamService::DEPT_CATEGORY)->pluck('dept_id')->toArray();
+                $where[] = [function($query) use ($deptIds) {
+                    $query->whereIn('dept_id', $deptIds);
+                }];
+            }
+        }
+        $selectRaw = Db::raw("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y/%m') as date,count(*) as nums");
+        $groupRaw = Db::raw("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y/%m')");
+        $totalData = MarketCustomer::where($where)->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
+        $payData = MarketCustomer::where($where)->where([['current_status', '=', 3], ['check_status', '=', 2]])->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
+        $visitData = MarketCustomer::where($where)->where([['current_status', '=', 2], ['check_status', '=', 2]])->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
+        $dealData = MarketCustomer::where($where)->where([['current_status', '=', 4], ['check_status', '=', 2]])->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
+        $returnData = [
+            'total' => $totalData->pluck('nums','date'),
+            'pay' => $payData->pluck('nums','date'),
+            'visit' => $visitData->pluck('nums','date'),
+            'deal' => $dealData->pluck('nums','date'),
+            'date' => $months
+        ];
+        return json_success('请求成功', $returnData);
+
+    }
+
     /**
      * Notes: 导出数据
      * User: yb

+ 42 - 0
app/api/controller/custom/MarketCustom.php

@@ -0,0 +1,42 @@
+<?php
+
+
+namespace app\api\controller\custom;
+
+
+use app\model\MarketCustomer;
+use support\Request;
+
+class MarketCustom
+{
+    public function updateStatus(Request $request)
+    {
+        $params = $request->post();
+        if (empty($params['mobile'])) {
+            return json_fail('手机号不能为空');
+        }
+        $mobile = $params['mobile'];
+        $where = [
+            ['mobile', '=', $mobile],
+            [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]
+        ];
+        $info = MarketCustomer::where($where)->first();
+        if (empty($info)) {
+            return json_fail('客户不存在');
+        }
+        $info->current_status = 3;
+        $result = $info->save();
+        if ($result) {
+            return json_success('修改成功');
+        } else {
+            return json_fail('修改失败');
+        }
+    }
+}

+ 13 - 0
app/wechat/controller/CustomController.php

@@ -165,4 +165,17 @@ class CustomController extends IndexController
         }
         return CustomService::checkCustom($params);
     }
+
+    /**
+     * Notes: 校验客户是否已经登记
+     * User: yb
+     * Date: 2024/8/21
+     * Time: 9:37
+     * @param Request $request
+     */
+    public function checkMobile(Request $request)
+    {
+        $params = $request->post();
+        return CustomService::checkPhone($params);
+    }
 }

+ 45 - 0
app/wechat/service/CustomService.php

@@ -609,6 +609,51 @@ class CustomService
 
     }
 
+    /**
+     * Notes: 检查客户是否已经登记
+     * User: yb
+     * Date: 2024/8/21
+     * Time: 9:40
+     * @param $params
+     * @return \support\Response
+     */
+    public static function checkPhone($params)
+    {
+        if (empty($params['mobile'])) {
+            return json_fail('请输入联系电话');
+        }
+        $mobile = $params['mobile'];
+        //添加和编辑
+        if (!empty($params['id'])) {
+            //编辑的情况
+            if (false === strpos($mobile,'****')) {
+                //校验手机号格式
+                $validate = new CustomValidate();
+                if (!$validate->scene('phone')->check(['mobile' => $mobile])) {
+                    return  json_fail($validate->getError());
+                }
+                //修改手机号操作
+                if (MarketCustomer::checkCustomExists($mobile, $params['id'])) {
+                    return json_fail('客户已经登记过了');
+                }
+            }
+            return json_success('请求成功',['is_ex' => 2]);
+        } else {
+            $validate = new CustomValidate();
+            if (!$validate->scene('phone')->check(['mobile' => $mobile])) {
+                return  json_fail($validate->getError());
+            }
+            //添加
+            $result = MarketCustomer::checkCustomExists($mobile);
+            if ($result) {
+                $isEx = 1;
+            } else {
+                $isEx = 2;
+            }
+            return json_success('请求成功',['is_ex' => $isEx]);
+        }
+    }
+
     /**
      * Notes: 对手机号加密处理
      * User: yb

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

@@ -62,6 +62,8 @@ class FollowService
                     $customInfo->current_status = 2;
                 }
             }
+            $customInfo->follow_num = $customInfo->follow_num + 1;
+            $customInfo->level = $insertData['intention_type'];
             $customInfo->visit_time = $insertData['follow_time'];
             $customInfo->save();
             $result = MarketCustomerFollow::insert($insertData);
@@ -89,9 +91,14 @@ class FollowService
         $page = $params['page'] ?? 1;
         $size = $params['size'] ?? 10;
         $ids = UserService::getIds();
+        //查询顾问下的客户信息
+        $customIds = [];
+        if (!empty($ids)) {
+            $customIds = MarketCustomer::whereIn('consultant_id', $ids)->pluck('id')->toArray();
+        }
         $where = [
-            [function($query) use ($ids) {
-            $query->whereIn('consultant_id',$ids);
+            [function($query) use ($customIds) {
+            $query->whereIn('market_customer_id',$customIds);
             }]
         ];
         $whereCustom = [];

+ 1 - 0
route/admin.php

@@ -639,6 +639,7 @@ Route::group('/admin', function () {
             Route::get('/moveLogs', [\app\admin\controller\consultant\CustomController::class, 'moveLogs']);
             Route::post('/check', [\app\admin\controller\consultant\CustomController::class, 'checkCustom']);
             Route::get('/statistics', [\app\admin\controller\consultant\CustomController::class, 'statisticsIndex']);
+            Route::get('/statistics_month', [\app\admin\controller\consultant\CustomController::class, 'statisticsByMonth']);
             Route::get('/export', [\app\admin\controller\consultant\CustomController::class, 'exportData']);
         });
     });

+ 3 - 0
route/api.php

@@ -3,6 +3,9 @@
 use Webman\Route;
 
 Route::group('/api',function (){
+    Route::group('/market_custom', function (){
+        Route::post('/update', [\app\api\controller\custom\MarketCustom::class,'updateStatus']);
+    });
     Route::group('/pay',function (){
         Route::post('/alipay',[\app\api\controller\pay\AlipayController::class,'index']);
         Route::post('/wxpay',[\app\api\controller\pay\WxpayController::class,'index']);

+ 1 - 0
route/wechat.php

@@ -28,6 +28,7 @@ Route::group('/wechat',function (){
         Route::post('/move', [\app\wechat\controller\CustomController::class, 'moveCustom']);
         Route::post('/logs', [\app\wechat\controller\CustomController::class, 'moveLogs']);
         Route::post('/check', [\app\wechat\controller\CustomController::class, 'checkCustom']);
+        Route::post('/mobile', [\app\wechat\controller\CustomController::class, 'checkMobile']);
     });
     Route::group('/follow', function () {
         Route::post('/add', [\app\wechat\controller\FollowController::class, 'addFollow']);