Merge branch 'develop'
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace app\crm\controller;
|
||||
|
||||
use app\common\model\Corp;
|
||||
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 {
|
||||
$data = $this->validate(new FollowValidate(), $request->get(), 'list');
|
||||
$request->setGet('corp_abbr', $request->basic_data['corp_abbr']);
|
||||
$result = (new FollowService())->list($request->all(), $request->user->uid);
|
||||
return $this->success($result);
|
||||
} 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('记录不存在');
|
||||
}
|
||||
|
||||
$res = FollowService::getFollow($res);
|
||||
|
||||
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'));
|
||||
}
|
||||
$audio_text = Util::getParam($request, 'audio_text', '');
|
||||
$picture = Util::getParam($request, 'picture');
|
||||
$remark = Util::getParam($request,'remark');
|
||||
if(Util::isEmpty($picture) && Util::isEmpty($audio_text) && Util::isEmpty($remark)){
|
||||
return $this->error(trans('follow_not_null'));
|
||||
}
|
||||
|
||||
$corpInfo = Corp::where('abbr', $request->basic_data['corp_abbr'])->first();
|
||||
$corpId = $corpInfo->id;
|
||||
$data = [
|
||||
'user_id' => $request->user->uid,
|
||||
'corp_abbr' => $corpId,
|
||||
'customer_id' => $customer_id,
|
||||
'type' => $type,
|
||||
'picture' => $picture,
|
||||
'remark' => Util::getParam($request, 'remark', ''),
|
||||
'audio' => Util::getParam($request, 'audio', ''),
|
||||
'audio_text' => $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();
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
return $this->success($res, trans('save_success'));
|
||||
} else {
|
||||
return $this->error(trans('save_fail'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user