跟进状态修改、登录返回code、客户统计
This commit is contained in:
@@ -200,6 +200,7 @@ class CustomerController
|
|||||||
if (Util::isEmpty($id)) {
|
if (Util::isEmpty($id)) {
|
||||||
$res = Customer::create($data);
|
$res = Customer::create($data);
|
||||||
} else {
|
} else {
|
||||||
|
unset($data['grade']);
|
||||||
$res = Customer::where('id', $id)
|
$res = Customer::where('id', $id)
|
||||||
->update($data);
|
->update($data);
|
||||||
// Log::info('update', ['res' => $res]);
|
// 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
|
* @param Request $request
|
||||||
@@ -270,22 +299,46 @@ class CustomerController
|
|||||||
$userId = $request->user['id'];
|
$userId = $request->user['id'];
|
||||||
$created_at = $request->user['created_at'];
|
$created_at = $request->user['created_at'];
|
||||||
$day = ceil((time()-$created_at+1)/60/60/24);
|
$day = ceil((time()-$created_at+1)/60/60/24);
|
||||||
$id = Util::getParam($request, 'id');
|
|
||||||
$where[] = ['user_id', '=', $userId];
|
$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();
|
$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 = $where;
|
||||||
$whereVisit[] = ['type', '=', 0];
|
$whereVisit[] = ['type', '=', 0];
|
||||||
$visit = Follow::where($whereVisit)->distinct('customer_id')->count();
|
$visit = Follow::where($whereVisit)->distinct('customer_id')->count();
|
||||||
|
|
||||||
|
//跟进数
|
||||||
$whereVisit = $where;
|
$whereVisit = $where;
|
||||||
$whereVisit[] = ['type', '=', 1];
|
$whereVisit[] = ['type', '=', 1];
|
||||||
$follow = Follow::where($whereVisit)->distinct('customer_id')->count();
|
$follow = Follow::where($whereVisit)->distinct('customer_id')->count();
|
||||||
|
|
||||||
$res = [
|
$res = [
|
||||||
'customer'=>$customer,
|
'customer'=>$customer, //客户数
|
||||||
'visit'=>$visit,
|
'visit'=>$visit, //拜访
|
||||||
'follow'=>$follow,
|
'follow'=>$follow, //跟进
|
||||||
'day'=>$day,
|
'day'=>$day, //注册天数
|
||||||
|
'customer_init'=>$customerInit, //初步接触
|
||||||
|
'customero_fllow'=>$customeroFllow, //跟进中
|
||||||
|
'customer_deal'=>$customerDeal, //已成交
|
||||||
];
|
];
|
||||||
if ($res) {
|
if ($res) {
|
||||||
return Util::success($res, trans('success'));
|
return Util::success($res, trans('success'));
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class AuthMiddleware implements MiddlewareInterface
|
|||||||
|
|
||||||
//需要登录并且未提供token
|
//需要登录并且未提供token
|
||||||
if ($isLogin && (!$token || !str_starts_with($token, 'Bearer '))) {
|
if ($isLogin && (!$token || !str_starts_with($token, 'Bearer '))) {
|
||||||
throw new BusinessException('请先登录', 302);
|
return Util::fail('','请先登录',401);
|
||||||
// throw new BusinessException('未提供 Token'.$isLogin, 401);
|
// throw new BusinessException('未提供 Token'.$isLogin, 401);
|
||||||
}elseif(!$isLogin){
|
}elseif(!$isLogin){
|
||||||
return $handler($request);
|
return $handler($request);
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ class Customer extends Model
|
|||||||
$customer = Util::formatDate($customer,['follow_last']);
|
$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['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['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;
|
// $customer['last_follow'] = $last_follow;
|
||||||
|
|
||||||
return $customer;
|
return $customer;
|
||||||
|
|||||||
@@ -40,11 +40,14 @@ class JwtUtil
|
|||||||
try {
|
try {
|
||||||
return JWT::decode($token, new Key($config['secret'], $config['algorithm']));
|
return JWT::decode($token, new Key($config['secret'], $config['algorithm']));
|
||||||
} catch (ExpiredException $e) {
|
} catch (ExpiredException $e) {
|
||||||
throw new BusinessException('Token 已过期', 401);
|
return Util::fail('','Token 已过期',401);
|
||||||
|
// throw new BusinessException('Token 已过期', 401);
|
||||||
} catch (SignatureInvalidException $e) {
|
} catch (SignatureInvalidException $e) {
|
||||||
throw new BusinessException('Token 无效', 401);
|
return Util::fail('','Token 无效',401);
|
||||||
|
// throw new BusinessException('Token 无效', 401);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new BusinessException('鉴权失败', 401);
|
return Util::fail('','鉴权失败',401);
|
||||||
|
// throw new BusinessException('鉴权失败', 401);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user