2025-07-09 15:10:14 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\crm\controller;
|
|
|
|
|
|
|
|
|
|
use app\crm\model\Customer;
|
|
|
|
|
use app\crm\model\Follow;
|
|
|
|
|
use app\crm\service\CustomerService;
|
|
|
|
|
use app\crm\service\FollowService;
|
|
|
|
|
use app\crm\utils\Util;
|
|
|
|
|
use app\crm\validate\FollowValidate;
|
|
|
|
|
use config\constants\Constants;
|
|
|
|
|
use support\Request;
|
|
|
|
|
|
|
|
|
|
class FollowController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 客户分级
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
*/
|
|
|
|
|
public function getFollowType(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$grade = [];
|
|
|
|
|
foreach (Constants::FOLLOW as $key => $value) {
|
|
|
|
|
$grade[] = [
|
|
|
|
|
'status' => $key,
|
|
|
|
|
'text' => $value,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
return $this->success($grade);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 跟进列表
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
*/
|
|
|
|
|
public function list(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-07-10 14:27:56 +08:00
|
|
|
$data = $this->validate(new FollowValidate(), $request->get(), 'list');
|
|
|
|
|
$result = (new FollowService())->list($request->all(),$request->user->uid);
|
|
|
|
|
return $this->success($result);
|
2025-07-09 15:10:14 +08:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 跟进详情
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
*/
|
|
|
|
|
public function detail(Request $request)
|
|
|
|
|
{
|
|
|
|
|
//跟进id
|
|
|
|
|
$id = Util::getParam($request,'id');
|
|
|
|
|
if(Util::isEmpty($id)){
|
|
|
|
|
return $this->error('id'.trans('not_null'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$res = Follow::select('id','user_id','customer_id','type','picture','remark','audio','audio_text','lat','lng','address')
|
|
|
|
|
->where('id',$id)
|
|
|
|
|
->first();
|
|
|
|
|
if($res){
|
|
|
|
|
$res->toArray();
|
|
|
|
|
}else{
|
|
|
|
|
return $this->error('记录不存在');
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-10 14:27:56 +08:00
|
|
|
$res = FollowService::getFollow($res);
|
2025-07-09 15:10:14 +08:00
|
|
|
|
|
|
|
|
return $this->success($res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 客户录入
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
*/
|
|
|
|
|
public function save(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$customer_id = Util::getParam($request,'customer_id');
|
|
|
|
|
|
|
|
|
|
if(Util::isEmpty($customer_id)){
|
|
|
|
|
return $this->error('customer_id'.trans('not_null'));
|
|
|
|
|
}
|
|
|
|
|
$type = Util::getParam($request,'type');
|
|
|
|
|
if(Util::isEmpty($type)){
|
|
|
|
|
return $this->error('type'.trans('not_null'));
|
|
|
|
|
}
|
|
|
|
|
$picture = Util::getParam($request,'picture');
|
|
|
|
|
if(Util::isEmpty($picture)){
|
|
|
|
|
return $this->error(trans('picture_not_null'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = [
|
2025-07-10 14:27:56 +08:00
|
|
|
'user_id'=>$request->user->uid,
|
2025-07-09 15:10:14 +08:00
|
|
|
'customer_id'=>$customer_id,
|
|
|
|
|
'type'=>$type,
|
|
|
|
|
'picture'=>$picture,
|
|
|
|
|
'remark'=>Util::getParam($request,'remark',''),
|
|
|
|
|
'audio'=>Util::getParam($request,'audio',''),
|
|
|
|
|
'audio_text'=>Util::getParam($request,'audio_text',''),
|
|
|
|
|
'lat'=>Util::getParam($request,'lat',0),
|
|
|
|
|
'lng'=>Util::getParam($request,'lng',0),
|
|
|
|
|
'address'=>Util::getParam($request,'address'),
|
|
|
|
|
'follow_time'=>strtotime(Util::getParam($request,'firstFollowtime',0)),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = Follow::create($data);
|
|
|
|
|
|
|
|
|
|
$customer = Customer::find($customer_id);
|
|
|
|
|
$customer->follow_last = strtotime($res->created_at);
|
|
|
|
|
$customer->follow_next = null;
|
|
|
|
|
$customer->warn = 0;
|
|
|
|
|
$customer->save();
|
|
|
|
|
|
2025-07-10 14:27:56 +08:00
|
|
|
$follow_next = Util::getParam($request, 'follow_next', 0);
|
|
|
|
|
$follow_remark = Util::getParam($request, 'follow_remark', 0);
|
|
|
|
|
if($res && (!empty($follow_next))){
|
|
|
|
|
$data = [
|
|
|
|
|
'follow_next' => $follow_next,
|
|
|
|
|
'follow_remark' => $follow_remark,
|
|
|
|
|
'warn' => 0,
|
|
|
|
|
];
|
|
|
|
|
$res = Customer::where('id', $customer_id)
|
|
|
|
|
->update($data);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-09 15:10:14 +08:00
|
|
|
if ($res) {
|
|
|
|
|
return $this->success($res,trans('save_success'));
|
|
|
|
|
} else {
|
|
|
|
|
return $this->error(trans('save_fail'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|