|  | @@ -59,7 +59,6 @@ class CustomService
 | 
	
		
			
				|  |  |          $currentTime = time();
 | 
	
		
			
				|  |  |          $diffNums = self::DIFF_TIME;
 | 
	
		
			
				|  |  |          $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)")
 | 
	
	
		
			
				|  | @@ -74,7 +73,10 @@ class CustomService
 | 
	
		
			
				|  |  |                  $query->whereIn('dept_id', $deptIds);
 | 
	
		
			
				|  |  |              }];
 | 
	
		
			
				|  |  |              if (!empty($params['consultant_id'])) {
 | 
	
		
			
				|  |  | -                $where[] = ['consultant_id', '=', $params['consultant_id']];
 | 
	
		
			
				|  |  | +                $consultantId = $params['consultant_id'];
 | 
	
		
			
				|  |  | +                $where[] = [function($query) use ($consultantId) {
 | 
	
		
			
				|  |  | +                    $query->orWhere('consultant_id', $consultantId)->orWhere('report_consultant_id', $consultantId);
 | 
	
		
			
				|  |  | +                }];
 | 
	
		
			
				|  |  |                  $whereFollow[] = ['consultant_id', '=', $params['consultant_id']];
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  $consultantIds = UserService::getIds(1);
 | 
	
	
		
			
				|  | @@ -85,7 +87,9 @@ class CustomService
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          } else if ($type == 2){
 | 
	
		
			
				|  |  |              //个人的
 | 
	
		
			
				|  |  | -            $where[] = ['consultant_id', '=', $consultantId];
 | 
	
		
			
				|  |  | +            $where[] = [function($query) use ($consultantId){
 | 
	
		
			
				|  |  | +                $query->orWhere('consultant_id', $consultantId)->orWhere('report_consultant_id', $consultantId);
 | 
	
		
			
				|  |  | +            }];
 | 
	
		
			
				|  |  |              $whereFollow[] = ['consultant_id', '=', $consultantId];
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              //所有团队的
 | 
	
	
		
			
				|  | @@ -156,7 +160,7 @@ class CustomService
 | 
	
		
			
				|  |  |          $fn = function ($query) {
 | 
	
		
			
				|  |  |              $query->select('name', 'mobile', 'id');
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  | -        $paginator = MarketCustomer::with(['consultant' => $fn])->where($where)->orderBy('visit_time', 'desc')->paginate($size, '*', 'page', $page);
 | 
	
		
			
				|  |  | +        $paginator = MarketCustomer::with(['consultant' => $fn, 'report' => $fn])->where($where)->orderBy('visit_time', 'desc')->paginate($size, '*', 'page', $page);
 | 
	
		
			
				|  |  |          $total = $paginator->total();
 | 
	
		
			
				|  |  |          $items = $paginator->items();
 | 
	
		
			
				|  |  |          if (!empty($items)) {
 | 
	
	
		
			
				|  | @@ -259,7 +263,9 @@ class CustomService
 | 
	
		
			
				|  |  |          $insertData = [
 | 
	
		
			
				|  |  |              'name' => $params['name'],
 | 
	
		
			
				|  |  |              'mobile' => $mobile,
 | 
	
		
			
				|  |  | -            'consultant_id' => $consultantId,
 | 
	
		
			
				|  |  | +            'consultant_id' => 0,
 | 
	
		
			
				|  |  | +            'report_consultant_id' => $consultantId,
 | 
	
		
			
				|  |  | +            'create_consultant_id' => $consultantId,
 | 
	
		
			
				|  |  |              'dept_id' => $deptId,
 | 
	
		
			
				|  |  |              'gender' => $params['gender'] ?? null,
 | 
	
		
			
				|  |  |              'visit_type' => $params['visit_type'] ?? null,
 | 
	
	
		
			
				|  | @@ -381,15 +387,15 @@ class CustomService
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public static function info($id)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -        $customInfo = MarketCustomer::firstWhere(['id' => $id]);
 | 
	
		
			
				|  |  | +        $fn = function ($query) {
 | 
	
		
			
				|  |  | +            $query->select('name', 'mobile', 'id');
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        $customInfo = MarketCustomer::with(['consultant' => $fn, 'report' => $fn])->firstWhere(['id' => $id]);
 | 
	
		
			
				|  |  |          if (empty($customInfo)) {
 | 
	
		
			
				|  |  |              return json_fail('客户不存在');
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //手机号加密处理
 | 
	
		
			
				|  |  |          $customInfo->mask_mobile = self::handlePhone($customInfo->mobile);
 | 
	
		
			
				|  |  | -        //查询负责顾问
 | 
	
		
			
				|  |  | -        $consultantName = Consultant::where('id', $customInfo->consultant_id)->value('name');
 | 
	
		
			
				|  |  | -        $customInfo->consultant_name = $consultantName;
 | 
	
		
			
				|  |  |          //查询最新的跟进记录
 | 
	
		
			
				|  |  |          $follow = MarketCustomerFollow::where('market_customer_id', $id)->orderBy('created_at', 'desc')->first();
 | 
	
		
			
				|  |  |          $customInfo->follow = $follow;
 | 
	
	
		
			
				|  | @@ -459,6 +465,75 @@ class CustomService
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Notes: 指定顾问
 | 
	
		
			
				|  |  | +     * User: yb
 | 
	
		
			
				|  |  | +     * Date: 2024/9/5
 | 
	
		
			
				|  |  | +     * Time: 12:52
 | 
	
		
			
				|  |  | +     * @param $params
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public static function appoint($params)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (empty($params['id'])) {
 | 
	
		
			
				|  |  | +            return json_fail('请选择客户');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (empty($params['report_consultant_id'])) {
 | 
	
		
			
				|  |  | +            return json_fail('请选择指定顾问');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        $userId = JwtToken::getCurrentId();
 | 
	
		
			
				|  |  | +        //获取绑定的管理信息
 | 
	
		
			
				|  |  | +        $userInfo = Consultant::firstWhere(['id' => $userId]);
 | 
	
		
			
				|  |  | +        if (empty($userInfo)) {
 | 
	
		
			
				|  |  | +            return json_fail('管理员信息不存在');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (!in_array($userInfo->type, [1,3])) {
 | 
	
		
			
				|  |  | +            return json_fail('操作权限不足');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        $relationUserId = $userInfo->relation_user_id;
 | 
	
		
			
				|  |  | +        $customId = $params['id'];
 | 
	
		
			
				|  |  | +        $reportConsultantId = $params['report_consultant_id'];
 | 
	
		
			
				|  |  | +        $customInfo = MarketCustomer::firstWhere(['id' => $customId]);
 | 
	
		
			
				|  |  | +        if (empty($customInfo)) {
 | 
	
		
			
				|  |  | +            return json_fail('客户信息不存在');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        $consultantInfo = Consultant::firstWhere(['id' => $reportConsultantId]);
 | 
	
		
			
				|  |  | +        if (empty($consultantInfo)) {
 | 
	
		
			
				|  |  | +            return json_fail('顾问信息不存在');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        $currentDeptId = $consultantInfo->dept_id; //当前部门
 | 
	
		
			
				|  |  | +        $now = time();
 | 
	
		
			
				|  |  | +        $logData = [
 | 
	
		
			
				|  |  | +            'market_customer_id' => $customId,
 | 
	
		
			
				|  |  | +            'consultant_id' => $reportConsultantId,
 | 
	
		
			
				|  |  | +            'dept_id' => $currentDeptId,
 | 
	
		
			
				|  |  | +            'before_consultant_id' => $customInfo->consultant_id,
 | 
	
		
			
				|  |  | +            'before_dept_id' => $customInfo->dept_id,
 | 
	
		
			
				|  |  | +            'note' => $params['note'] ?? '判客指定顾问',
 | 
	
		
			
				|  |  | +            'change_user_id' => $relationUserId,
 | 
	
		
			
				|  |  | +            'change_consultant_id' => $userId,
 | 
	
		
			
				|  |  | +            'created_at' => $now
 | 
	
		
			
				|  |  | +        ];
 | 
	
		
			
				|  |  | +        Db::beginTransaction();
 | 
	
		
			
				|  |  | +        $result = false;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            $customInfo->report_consultant_id = $reportConsultantId;
 | 
	
		
			
				|  |  | +            $customInfo->dept_id = $currentDeptId;
 | 
	
		
			
				|  |  | +            $result = $customInfo->save();
 | 
	
		
			
				|  |  | +            MarketCustomerLogs::insert($logData);
 | 
	
		
			
				|  |  | +            Db::commit();
 | 
	
		
			
				|  |  | +        }catch (BusinessException|\Exception $e) {
 | 
	
		
			
				|  |  | +            Db::rollBack();
 | 
	
		
			
				|  |  | +            return json_fail($e->getMessage());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if ($result) {
 | 
	
		
			
				|  |  | +            return json_success('指定成功');
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            return json_fail('指定失败');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * Notes: 转移客户
 | 
	
		
			
				|  |  |       * User: yb
 | 
	
	
		
			
				|  | @@ -603,6 +678,7 @@ class CustomService
 | 
	
		
			
				|  |  |                  return json_fail('客户已经存在');
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        $consultantId = $params['consultant_id'];
 | 
	
		
			
				|  |  |          $result = false;
 | 
	
		
			
				|  |  |          Db::beginTransaction();
 | 
	
		
			
				|  |  |          try {
 | 
	
	
		
			
				|  | @@ -611,6 +687,7 @@ class CustomService
 | 
	
		
			
				|  |  |                  //拒绝录入拒绝理由
 | 
	
		
			
				|  |  |                  $info->check_note = $params['note'] ?? '无拒绝理由';
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            $info->consultant_id = $consultantId;
 | 
	
		
			
				|  |  |              $info->current_status = $checkStatus;
 | 
	
		
			
				|  |  |              $info->check_time = time();
 | 
	
		
			
				|  |  |              $info->check_admin_id = $adminId;
 |