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');
|
2025-07-17 09:36:46 +08:00
|
|
|
$request->setGet('corp_abbr', $request->basic_data['corp_abbr']);
|
|
|
|
|
$result = (new FollowService())->list($request->all(), $request->user->uid);
|
2025-07-10 14:27:56 +08:00
|
|
|
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
|
2025-07-17 09:36:46 +08:00
|
|
|
$id = Util::getParam($request, 'id');
|
|
|
|
|
if (Util::isEmpty($id)) {
|
|
|
|
|
return $this->error('id' . trans('not_null'));
|
2025-07-09 15:10:14 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-17 09:36:46 +08:00
|
|
|
$res = Follow::select('id', 'user_id', 'customer_id', 'type', 'picture', 'remark', 'audio', 'audio_text', 'lat', 'lng', 'address')
|
|
|
|
|
->where('id', $id)
|
2025-07-09 15:10:14 +08:00
|
|
|
->first();
|
2025-07-17 09:36:46 +08:00
|
|
|
if ($res) {
|
2025-07-09 15:10:14 +08:00
|
|
|
$res->toArray();
|
2025-07-17 09:36:46 +08:00
|
|
|
} else {
|
2025-07-09 15:10:14 +08:00
|
|
|
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)
|
|
|
|
|
{
|
2025-07-17 09:36:46 +08:00
|
|
|
$customer_id = Util::getParam($request, 'customer_id');
|
2025-07-09 15:10:14 +08:00
|
|
|
|
2025-07-17 09:36:46 +08:00
|
|
|
if (Util::isEmpty($customer_id)) {
|
|
|
|
|
return $this->error('customer_id' . trans('not_null'));
|
2025-07-09 15:10:14 +08:00
|
|
|
}
|
2025-07-17 09:36:46 +08:00
|
|
|
$type = Util::getParam($request, 'type');
|
|
|
|
|
if (Util::isEmpty($type)) {
|
|
|
|
|
return $this->error('type' . trans('not_null'));
|
2025-07-09 15:10:14 +08:00
|
|
|
}
|
2025-07-17 09:36:46 +08:00
|
|
|
$picture = Util::getParam($request, 'picture');
|
|
|
|
|
if (Util::isEmpty($picture)) {
|
2025-07-09 15:10:14 +08:00
|
|
|
return $this->error(trans('picture_not_null'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = [
|
2025-07-17 09:36:46 +08:00
|
|
|
'user_id' => $request->user->uid,
|
|
|
|
|
'corp_abbr' => $request->basic_data['corp_abbr'],
|
|
|
|
|
'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)),
|
2025-07-09 15:10:14 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$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);
|
2025-07-17 09:36:46 +08:00
|
|
|
if ($res && (!empty($follow_next))) {
|
2025-07-10 14:27:56 +08:00
|
|
|
$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) {
|
2025-07-17 09:36:46 +08:00
|
|
|
return $this->success($res, trans('save_success'));
|
2025-07-09 15:10:14 +08:00
|
|
|
} else {
|
|
|
|
|
return $this->error(trans('save_fail'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|