审核
This commit is contained in:
@@ -195,6 +195,29 @@ class CustomerController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户恢复
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function report(Request $request)
|
||||
{
|
||||
$param = $request->all();
|
||||
if (Util::isEmpty($param['id'])) {
|
||||
return $this->error(trans('id_empty'));
|
||||
}
|
||||
|
||||
$param['user_id'] = $request->user->uid;
|
||||
$param['corp_abbr'] = $request->basic_data['corp_abbr'];
|
||||
$res = (new CustomerService())->report($param);
|
||||
|
||||
if($res){
|
||||
return $this->success($res, trans('success'));
|
||||
}else{
|
||||
return $this->error(trans('fail'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 客户详情
|
||||
@@ -337,8 +360,10 @@ class CustomerController extends BaseController
|
||||
return $this->error( trans('fail'));
|
||||
}
|
||||
if($force == 'force'){
|
||||
//强制删除
|
||||
$res = $customer->forceDelete();
|
||||
}else{
|
||||
//软删除
|
||||
$res = $customer->delete();
|
||||
}
|
||||
if ($res) {
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
|
||||
namespace app\crm\service;
|
||||
|
||||
use app\crm\logic\CustomerLogic;
|
||||
use app\crmAdmin\logic\CustomerLogic;
|
||||
use app\crm\model\CarType;
|
||||
use app\crm\model\Channel;
|
||||
use app\crm\model\Country;
|
||||
use app\crm\model\Customer;
|
||||
use app\crm\model\CustomerHis;
|
||||
use app\crm\model\Follow;
|
||||
use app\crm\utils\Util;
|
||||
use config\constants\Constants;
|
||||
@@ -35,6 +36,7 @@ class CustomerService
|
||||
}else{
|
||||
$where[] = ['user_id', $user_id];
|
||||
}
|
||||
$where[] = ['status', 1];
|
||||
|
||||
|
||||
$grade = [];
|
||||
@@ -100,6 +102,34 @@ class CustomerService
|
||||
return $customer;
|
||||
}
|
||||
|
||||
public function report($params)
|
||||
{
|
||||
$id = $params['id'];
|
||||
$userId = $params['user_id'];
|
||||
|
||||
$where = [
|
||||
'id' => $id,
|
||||
'user_id' => $userId,
|
||||
];
|
||||
$customer = Customer::where($where)->withTrashed()->first();
|
||||
if(empty($customer)){
|
||||
return false;
|
||||
}
|
||||
|
||||
CustomerHis::create([
|
||||
'customer_id' => $id,
|
||||
'user_his' => $userId,
|
||||
'user_id' => 0,
|
||||
]);
|
||||
|
||||
$customer->status = 2;
|
||||
$res = $customer->save();
|
||||
|
||||
//软删除
|
||||
$customer->delete();
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $customer
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace app\crmAdmin\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,83 @@
|
||||
<?php
|
||||
|
||||
namespace app\crmAdmin\controller;
|
||||
|
||||
use app\common\model\Corp;
|
||||
use app\crmAdmin\service\CustomerService;
|
||||
use support\Request;
|
||||
|
||||
class CustomerController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要头信息的方法
|
||||
*/
|
||||
protected $noNeedHeader = [];
|
||||
|
||||
protected $noNeedLogin = [];
|
||||
|
||||
/**
|
||||
* 客户列表
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function list(Request $request)
|
||||
{
|
||||
try {
|
||||
$param = $request->all();
|
||||
$corp = Corp::where(['abbr' => $request->basic_data['corp_abbr']])->first();
|
||||
$param['corp_abbr'] = $corp->id;
|
||||
// $param['corp_abbr'] = $request->basic_data['corp_abbr'];
|
||||
$result = (new CustomerService())->list($param);
|
||||
|
||||
return $this->success($this->page($result));
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getFile().$e->getLine().$e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户导出
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function export(Request $request)
|
||||
{
|
||||
try {
|
||||
$param = $request->all();
|
||||
$corp = Corp::where(['abbr' => $request->basic_data['corp_abbr']])->first();
|
||||
$param['corp_abbr'] = $corp->id;
|
||||
// $param['corp_abbr'] = $request->basic_data['corp_abbr'];
|
||||
$result = (new CustomerService())->export($param);
|
||||
|
||||
return $this->success($this->page($result));
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getFile().$e->getLine().$e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户列表
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function audit(Request $request)
|
||||
{
|
||||
try {
|
||||
$param = $request->all();
|
||||
if (empty($param['id'])) {
|
||||
return $this->error('ID'.trans('not_null'));
|
||||
}
|
||||
if (in_array($param['scene'],['delete','report'])) {
|
||||
return $this->error('scene 不合法');
|
||||
}
|
||||
$result = (new CustomerService())->audit($param);
|
||||
|
||||
return $this->success($result);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getFile().$e->getLine().$e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\crmAdmin\logic;
|
||||
|
||||
use app\crm\model\Customer;
|
||||
|
||||
class CustomerLogic
|
||||
{
|
||||
|
||||
public function status(int $id,int $status)
|
||||
{
|
||||
$customer = Customer::find($id);
|
||||
$customer->status = $status;
|
||||
$res = $customer->save();
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
$customer = Customer::find($id);
|
||||
$res = $customer->forceDelete();
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace app\crmAdmin\service;
|
||||
|
||||
use app\common\model\User;
|
||||
use app\crmAdmin\logic\CustomerLogic;
|
||||
use app\crm\model\CarType;
|
||||
use app\crm\model\Channel;
|
||||
use app\crm\model\Country;
|
||||
use app\crm\model\Customer;
|
||||
use app\crm\model\Follow;
|
||||
use app\crm\utils\Util;
|
||||
use config\constants\Constants;
|
||||
|
||||
class CustomerService
|
||||
{
|
||||
public function list($params)
|
||||
{
|
||||
// $page = $request->input('page', 1);
|
||||
// $perPage = $request->input('per_page', 10);
|
||||
$perPage = $params['size'] ?? 10;
|
||||
$page = $params['current'] ?? 1;
|
||||
$keyword = $params['keyword'] ?? '';
|
||||
$recycle = $params['recycle'] ?? '';
|
||||
$follow = $params['follow'] ?? '';
|
||||
$follow_last = $params['follow_last'] ?? '';
|
||||
$tagId = $params['tag_id'] ?? [];
|
||||
$user_id = $params['user_id'] ?? '';
|
||||
$seas = $params['seas'] ?? '';
|
||||
$scene = $params['scene'] ?? '';
|
||||
$where = [];
|
||||
|
||||
if ($scene == 'audit') {
|
||||
$where = ['status', 2];
|
||||
}else {
|
||||
$where = ['status', 1];
|
||||
}
|
||||
if($seas == 'seas' || $scene == 'seas'){
|
||||
$where[] = ['user_id', 0];
|
||||
}
|
||||
// if($recycle == 'recycle'){
|
||||
// $where[] = ['user_id', $user_id];
|
||||
// }
|
||||
|
||||
|
||||
$grade = [];
|
||||
if (!Util::isEmpty($follow) && $follow == 0) {
|
||||
$where[] = ['grade', '<=', 2];
|
||||
} elseif (!Util::isEmpty($follow) && $follow == 1) {
|
||||
$grade = [3, 4];
|
||||
} elseif (!Util::isEmpty($follow) && $follow == 2) {
|
||||
$where[] = ['grade', '=', 5];
|
||||
}
|
||||
|
||||
if (!Util::isEmpty($follow_last) && $follow_last == 0) {
|
||||
$where[] = ['follow_last', '>', strtotime('-1 day')];
|
||||
} elseif (!Util::isEmpty($follow_last) && $follow_last == 1) {
|
||||
$where[] = ['follow_last', '>', strtotime('-3 day')];
|
||||
} elseif (!Util::isEmpty($follow_last) && $follow_last == 2) {
|
||||
$where[] = ['follow_last', '>', strtotime('-7 day')];
|
||||
}
|
||||
|
||||
$query = Customer::where($where);
|
||||
|
||||
if(!empty($user_id)){
|
||||
$query->whereIn('user_id', explode(',',$user_id));
|
||||
}
|
||||
|
||||
if(!empty($tagId)){
|
||||
//查询有$tagId 里任意一个标签的客户
|
||||
//$query->whereHas('tags', function($query) use ($tagId){
|
||||
// $query->whereIn ('tag.id', $tagId);
|
||||
//});
|
||||
//查询有$tagId 里所有标签的客户
|
||||
foreach ($tagId as $id) {
|
||||
$query->whereHas('tags', function($query) use ($id){
|
||||
$query->where('tag.id', $id);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!Util::isEmpty($keyword)) {
|
||||
$query->where(function ($query) use ($keyword) {
|
||||
$query->where('contacts', 'like', "%{$keyword}%")
|
||||
->orWhere('phone', 'like', "%{$keyword}%");
|
||||
});
|
||||
}
|
||||
if (!Util::isEmpty($grade)) {
|
||||
$query->whereIn('grade', $grade);
|
||||
}
|
||||
|
||||
if ($recycle == 'recycle' || $scene == 'recycle' || $seas == 'seas' || $scene == 'seas') {
|
||||
$query->onlyTrashed();
|
||||
}
|
||||
|
||||
$customer = $query->paginate($perPage, ['*'], 'page', $page);
|
||||
foreach ($customer as &$item) {
|
||||
$item = $this->getCustomer($item);
|
||||
if($seas == 'seas' || $scene == 'seas'){
|
||||
$item['seas_time'] = time()-strtotime($item['deleted_at']);
|
||||
}
|
||||
}
|
||||
unset($item);
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
* @return bool
|
||||
*/
|
||||
public function audit($params){
|
||||
|
||||
$id = $params['id'];
|
||||
|
||||
$where = [
|
||||
'id' => $id,
|
||||
];
|
||||
|
||||
$logic = new CustomerLogic();
|
||||
if($params['scene'] == 'delete'){
|
||||
return $logic->delete($params['id']);
|
||||
}else{
|
||||
return $logic->status($params['id'], 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $customer
|
||||
* @param $request
|
||||
* @param $tag 是否返回客户标签
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getCustomer($customer, $language = 'zh_CN', $tag = false)
|
||||
{
|
||||
$customer['grade_txt'] = Util::language($language, Constants::GRADE_EN[$customer['grade']], Constants::GRADE_ZH[$customer['grade']], Constants::GRADE_RU[$customer['grade']]);
|
||||
$customer['magnitude_txt'] = Util::language($language, Constants::MAGNITUDE_EN[$customer['magnitude']], Constants::MAGNITUDE[$customer['magnitude']], Constants::MAGNITUDE_RU[$customer['magnitude']]);
|
||||
$customer['sex_txt'] = Util::language($language, Constants::SEX_EN[$customer['sex']], Constants::SEX[$customer['sex']], Constants::SEX_RU[$customer['sex']]);
|
||||
|
||||
if ($customer['grade']<=2) {
|
||||
$customer['follow'] = 0;
|
||||
$customer['follow_txt'] = Util::language($language,'Following','跟进中','Продолжение');
|
||||
}elseif ($customer['grade']<5) {
|
||||
$customer['follow'] = 1;
|
||||
$customer['follow_txt'] = Util::language($language,'transacted','已成交','Транзакция завершена');
|
||||
}else{
|
||||
$customer['follow'] = 2;
|
||||
$customer['follow_txt'] = Util::language($language,'lost','已流失','Потерянный');
|
||||
}
|
||||
|
||||
$where = [
|
||||
'customer_id' => $customer['id']
|
||||
];
|
||||
$begin_follow = Follow::select('id','created_at','updated_at')
|
||||
->where($where)
|
||||
->min('created_at');
|
||||
|
||||
|
||||
$customer['begin_follow'] = Util::timeTotDate($begin_follow);
|
||||
// $customer['created_at'] = Util::timeTotDate($customer['created_at']);
|
||||
// $customer['updated_at'] = Util::timeTotDate($customer['updated_at']);
|
||||
|
||||
$customer = Util::formatDate($customer,['follow_last']);
|
||||
$nameLang = $language=='en'?'name_en':($language=='ru'?'name_ru':'name');
|
||||
$countryLang = $language=='en'?'en_addr':'cn_addr';
|
||||
// $customer['car_type_name'] = empty($customer['car_type_id'])?'':CarType::where(['id'=>$customer['car_type_id']])->value($nameLang);
|
||||
$customer['country_name'] = empty($customer['country_id'])?'':Country::where(['id'=>$customer['country_id']])->value($countryLang);
|
||||
$customer['channel_name'] = empty($customer['channel_id'])?'':Channel::where(['id'=>$customer['channel_id']])->value($nameLang);
|
||||
// $customer['last_follow'] = $last_follow;
|
||||
|
||||
if ($tag) {
|
||||
foreach ($customer['tags'] as &$tag) {
|
||||
$tag['names'] = unserialize($tag['names']);
|
||||
$tag['name'] = $tag['names'][$language];
|
||||
}
|
||||
}
|
||||
|
||||
$customer['enter_user_name'] = empty($customer['enter_user_id']) ? '' : User::find($customer['enter_user_id'])->value('name');
|
||||
$customer['user_name'] = empty($customer['user_id']) ? '公海' : User::find($customer['user_id'])->value('name');
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
|
||||
public function detail($params)
|
||||
{
|
||||
$id =$params['id'];
|
||||
$customer = Customer::with('tags')->select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'address', 'lat', 'lng', 'follow_next', 'follow_remark', 'sex')
|
||||
->where('id', $id)
|
||||
->first();
|
||||
|
||||
return $customer;
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,15 @@ Route::group('/admin', function () {
|
||||
Route::any('/release', [app\inquiry\controller\InquiryLogController::class, 'release']);
|
||||
Route::any('/allocation', [app\inquiry\controller\InquiryLogController::class, 'allocation']);
|
||||
});
|
||||
|
||||
// crm
|
||||
Route::group('/crm', function () {
|
||||
Route::group('/customer', function () {
|
||||
Route::any('/list', [app\crmAdmin\controller\CustomerController::class, 'list']);
|
||||
Route::any('/export', [app\crmAdmin\controller\CustomerController::class, 'export']);
|
||||
Route::any('/audit', [app\crmAdmin\controller\CustomerController::class, 'audit']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user