1
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace app\crm\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use support\exception\BusinessException;
|
||||
use app\common\traits\ResponseTrait;
|
||||
use think\Validate;
|
||||
|
||||
abstract class BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected mixed $validator = null;
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
*
|
||||
* @param Validate $validator 验证器实例
|
||||
* @param array $data 待验证的数据
|
||||
* @param string $scene 验证场景
|
||||
* @return array 验证后的数据
|
||||
* @throws BusinessException 验证失败时抛出业务异常
|
||||
*/
|
||||
public function validate(Validate $validator, array $data, string $scene = ''): array
|
||||
{
|
||||
// 如果指定了验证场景,并且验证器支持场景方法,则设置验证场景
|
||||
if ($scene && method_exists($validator, 'scene')) {
|
||||
$validator->scene($scene);
|
||||
}
|
||||
// 执行数据验证
|
||||
if (!$validator->check($data)) {
|
||||
// 验证失败,抛出业务异常,异常信息为验证器返回的错误信息
|
||||
throw new BusinessException($validator->getError());
|
||||
}
|
||||
// 验证成功,返回原始数据
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function page($result){
|
||||
$current = $result->currentPage();
|
||||
$total = $result->total();
|
||||
$size = $result->perPage();
|
||||
$result = $result->toArray();
|
||||
$result['current'] = $current;
|
||||
$result['total'] = $total;
|
||||
$result['size'] = $size;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\crm\controller\BaseController;
|
||||
use app\crm\model\CarType;
|
||||
use app\crm\model\Customer;
|
||||
use app\crm\utils\Util;
|
||||
use PDO;
|
||||
use support\Db;
|
||||
use support\Redis;
|
||||
use support\Request;
|
||||
|
||||
class CarTypeController extends BaseController
|
||||
{
|
||||
|
||||
public function getAll(Request $request)
|
||||
{
|
||||
$list = CarType::getAll();
|
||||
|
||||
if($request->user['language'] != 'zh_CN'){
|
||||
foreach ($list as &$value) {
|
||||
$value['name'] = $value['name_en'];
|
||||
}
|
||||
}elseif ($request->user['language'] == 'ru'){
|
||||
foreach ($list as &$value) {
|
||||
$value['name'] = $value['name_ru'];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\crm\controller;
|
||||
|
||||
use app\crm\model\Customer;
|
||||
use app\crm\model\User;
|
||||
use app\crm\service\CustomerService;
|
||||
use app\crm\utils\Util;
|
||||
use support\Request;
|
||||
|
||||
class CustomerController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 客户列表
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function list(Request $request)
|
||||
{
|
||||
try {
|
||||
$result = (new CustomerService())->list($request->all());
|
||||
return $this->success($this->page($result));
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function follow(Request $request)
|
||||
{
|
||||
// try {
|
||||
// $result = (new CustomerService())->follow($request->all());
|
||||
// return $this->success($this->page($result));
|
||||
// } catch (\Throwable $e) {
|
||||
// return $this->error($e->getMessage());
|
||||
// }
|
||||
$page = $request->input('page', 1);
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$where = [];
|
||||
if($request->input('user_id')){
|
||||
$where[] = ['user_id', '=', $request->input('user_id')];
|
||||
}
|
||||
$user = Customer::with('user')->where($where)->paginate($perPage, ['*'], 'page', $page);
|
||||
$user = $user->toArray();
|
||||
foreach ($user['data'] as &$item) {
|
||||
unset($item['password']);
|
||||
}
|
||||
return $this->success($user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?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 {
|
||||
$data = $this->validate(new FollowValidate(), $request->get(), 'upwd_list');
|
||||
$result = (new FollowService())->list($request->all());
|
||||
return $this->success($this->page($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 = Follow::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'));
|
||||
}
|
||||
$picture = Util::getParam($request,'picture');
|
||||
if(Util::isEmpty($picture)){
|
||||
return $this->error(trans('picture_not_null'));
|
||||
}
|
||||
|
||||
$data = [
|
||||
'user_id'=>$request->user['id'],
|
||||
'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();
|
||||
|
||||
if ($res) {
|
||||
return $this->success($res,trans('save_success'));
|
||||
} else {
|
||||
return $this->error(trans('save_fail'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace app\crm\controller;
|
||||
|
||||
use app\crm\controller\BaseController;
|
||||
use app\crm\model\CustomerTag;
|
||||
use app\crm\model\TagGroup;
|
||||
use app\crm\utils\Util;
|
||||
use config\constants\Constants;
|
||||
use support\Request;
|
||||
|
||||
class TagGroupController extends BaseController
|
||||
{
|
||||
|
||||
// 列表
|
||||
public function list(Request $request)
|
||||
{
|
||||
$list = TagGroup::with('tags')->get();
|
||||
$languageArr = Constants::LANGUAGE;
|
||||
$language = $request->user['language'];
|
||||
foreach ($list as &$item) {
|
||||
$item['names'] = unserialize($item['names']);
|
||||
if (in_array($language, $languageArr)) {
|
||||
$item['name'] = $item['names'][$language];
|
||||
}
|
||||
foreach ($item['tags'] as &$tag) {
|
||||
$tag['names'] = unserialize($tag['names']);
|
||||
if (in_array($language, $languageArr)) {
|
||||
$tag['name'] = $tag['names'][$language];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新客户标签关系
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function updatePivot(Request $request)
|
||||
{
|
||||
$customerId = Util::getParam($request, 'customer_id');
|
||||
$groupId = Util::getParam($request, 'group_id');
|
||||
$tagId = Util::getParam($request, 'tag_id');
|
||||
if (Util::isEmpty($customerId)) {
|
||||
return $this->error( trans('customer_id') . trans('not_null'));
|
||||
}
|
||||
if (Util::isEmpty($groupId)) {
|
||||
return $this->error( trans('tag_group_id') . trans('not_null'));
|
||||
}
|
||||
|
||||
if(empty($tagId)){
|
||||
$res = CustomerTag::where(['customer_id' => $customerId, 'group_id' => $groupId])->delete();
|
||||
}else{
|
||||
$res = CustomerTag::updateOrCreate(['customer_id' => $customerId, 'group_id' => $groupId], ['tag_id' => $tagId]);
|
||||
}
|
||||
|
||||
if($res){
|
||||
return $this->success($res, trans('success'));
|
||||
}else{
|
||||
return $this->error( trans('fail'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user