跟进状态修改、登录返回code、客户统计

This commit is contained in:
2025-03-21 11:42:25 +08:00
parent 196a4a2001
commit 8b23f26dce
4 changed files with 67 additions and 10 deletions
+59 -6
View File
@@ -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'));