diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index 87bc1bb..a2f97a6 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -200,6 +200,7 @@ class CustomerController if (Util::isEmpty($id)) { $res = Customer::create($data); } else { + unset($data['grade']); $res = Customer::where('id', $id) ->update($data); // Log::info('update', ['res' => $res]); @@ -213,6 +214,34 @@ class CustomerController } } + /** + * 跟进状态 + * @param Request $request + * @return \support\Response + */ + public function grade(Request $request) + { + $id = Util::getParam($request, 'id'); + $id = Util::getParam($request, 'grade'); + if (Util::isEmpty($id)) { + return Util::fail('', 'id' . trans('not_null')); + } + if (Util::isEmpty($id)) { + return Util::fail('', 'grade' . trans('not_null')); + } + $data = [ + 'grade' => Util::getParam($request, 'grade', 0), + ]; + $res = Customer::where('id', $id) + ->update($data); + + if ($res) { + return Util::success($res, trans('save_success')); + } else { + return Util::fail($res, trans('save_fail')); + } + } + /** * 更新下次跟进时间 * @param Request $request @@ -270,22 +299,46 @@ class CustomerController $userId = $request->user['id']; $created_at = $request->user['created_at']; $day = ceil((time()-$created_at+1)/60/60/24); - $id = Util::getParam($request, 'id'); $where[] = ['user_id', '=', $userId]; - $where[] = ['created_at', '>', strtotime($created.'-01')]; + $start = strtotime($created.'-01'); + $year = date('Y', $start); + $month = date('n',$start); //获取月份 + $end = mktime(00, 00, 00, $month+1, 1, $year); + $where[] = ['created_at', '>=', $start]; + $where[] = ['created_at', '<', $end]; $customer = Customer::where($where)->count(); + + //初步接触 + $whereGrade = $where; + $whereGrade[] = ['grade','<=', 2]; + $customerInit = Customer::where($whereGrade)->count(); + + //跟进中 + $customeroFllow = Customer::where($where)->whereIn('grade', [3, 4])->count(); + + //已成交 + $whereGrade = $where; + $whereGrade[] = ['grade','=', 5]; + $customerDeal = Customer::where($whereGrade)->count(); + + //拜访数 $whereVisit = $where; $whereVisit[] = ['type', '=', 0]; $visit = Follow::where($whereVisit)->distinct('customer_id')->count(); + + //跟进数 $whereVisit = $where; $whereVisit[] = ['type', '=', 1]; $follow = Follow::where($whereVisit)->distinct('customer_id')->count(); $res = [ - 'customer'=>$customer, - 'visit'=>$visit, - 'follow'=>$follow, - 'day'=>$day, + 'customer'=>$customer, //客户数 + 'visit'=>$visit, //拜访 + 'follow'=>$follow, //跟进 + 'day'=>$day, //注册天数 + 'customer_init'=>$customerInit, //初步接触 + 'customero_fllow'=>$customeroFllow, //跟进中 + 'customer_deal'=>$customerDeal, //已成交 ]; if ($res) { return Util::success($res, trans('success')); diff --git a/app/middleware/AuthMiddleware.php b/app/middleware/AuthMiddleware.php index 8bb6693..8c96a0d 100644 --- a/app/middleware/AuthMiddleware.php +++ b/app/middleware/AuthMiddleware.php @@ -56,7 +56,7 @@ class AuthMiddleware implements MiddlewareInterface //需要登录并且未提供token if ($isLogin && (!$token || !str_starts_with($token, 'Bearer '))) { - throw new BusinessException('请先登录', 302); + return Util::fail('','请先登录',401); // throw new BusinessException('未提供 Token'.$isLogin, 401); }elseif(!$isLogin){ return $handler($request); diff --git a/app/model/Customer.php b/app/model/Customer.php index a8d01ef..92dc5e6 100644 --- a/app/model/Customer.php +++ b/app/model/Customer.php @@ -91,6 +91,7 @@ class Customer extends Model $customer = Util::formatDate($customer,['follow_last']); $customer['car_type_name'] = empty($customer['car_type_id'])?'':CarType::where(['id'=>$customer['car_type_id']])->value('name'); $customer['country_name'] = empty($customer['country_id'])?'':Country::where(['id'=>$customer['country_id']])->value('cn_addr'); + $customer['channel_name'] = empty($customer['channel_id'])?'':Channel::where(['id'=>$customer['channel_id']])->value('name'); // $customer['last_follow'] = $last_follow; return $customer; diff --git a/app/util/JwtUtil.php b/app/util/JwtUtil.php index f28f5da..bf4c860 100644 --- a/app/util/JwtUtil.php +++ b/app/util/JwtUtil.php @@ -40,11 +40,14 @@ class JwtUtil try { return JWT::decode($token, new Key($config['secret'], $config['algorithm'])); } catch (ExpiredException $e) { - throw new BusinessException('Token 已过期', 401); + return Util::fail('','Token 已过期',401); +// throw new BusinessException('Token 已过期', 401); } catch (SignatureInvalidException $e) { - throw new BusinessException('Token 无效', 401); + return Util::fail('','Token 无效',401); +// throw new BusinessException('Token 无效', 401); } catch (\Exception $e) { - throw new BusinessException('鉴权失败', 401); + return Util::fail('','鉴权失败',401); +// throw new BusinessException('鉴权失败', 401); } } } \ No newline at end of file