Merge branch 'develop'
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class CustomerAudit extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'crm_customer_audit';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'customer_id', 'remark', 'img', 'audit', 'report_user_id', 'audit_user_id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -239,6 +239,9 @@ class CustomerController extends BaseController
|
||||
if (Util::isEmpty($param['id'])) {
|
||||
return $this->error(trans('id_empty'));
|
||||
}
|
||||
if (empty($param['remark']) && empty($param['img'])) {
|
||||
return $this->error('举报理由不能为空');
|
||||
}
|
||||
|
||||
$param['user_id'] = $request->user->uid;
|
||||
$param['corp_abbr'] = $request->basic_data['corp_abbr'];
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\crm\service;
|
||||
|
||||
use app\common\model\Corp;
|
||||
use app\common\model\CustomerAudit;
|
||||
use app\common\model\User;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\crm\logic\CustomerLogic;
|
||||
@@ -195,6 +196,14 @@ class CustomerService
|
||||
return false;
|
||||
}
|
||||
|
||||
CustomerAudit::create([
|
||||
'customer_id' => $id,
|
||||
'report_user_id' => $userId,
|
||||
'remark' => $params['remark'],
|
||||
'status' => 1,
|
||||
'img' => implode(',', $params['img']),
|
||||
]);
|
||||
|
||||
CustomerHis::create([
|
||||
'customer_id' => $id,
|
||||
'user_his' => $userId,
|
||||
|
||||
@@ -85,7 +85,7 @@ class CustomerController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户列表
|
||||
* 审核客户
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
@@ -207,4 +207,28 @@ class CustomerController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 离职员工客户分配
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function allocation(Request $request)
|
||||
{
|
||||
try {
|
||||
$param = $request->all();
|
||||
if (empty($param['corp_id'])) {
|
||||
return $this->error('corp_id'.trans('not_null'));
|
||||
}
|
||||
if (empty($param['user_id'])) {
|
||||
return $this->error('user_id'.trans('not_null'));
|
||||
}
|
||||
|
||||
$result = (new CustomerService())->allocation($param);
|
||||
|
||||
return $this->success($result,'成功分配'.$result['userCount'].'位离职用户的'.$result['customerCount'].'位客户');
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ class CustomerLogic
|
||||
$customer->restore();
|
||||
}
|
||||
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\crmAdmin\service;
|
||||
|
||||
use app\common\model\CustomerAudit;
|
||||
use app\common\model\InquiryLog;
|
||||
use app\common\model\User;
|
||||
use app\common\service\OssService;
|
||||
@@ -20,6 +21,8 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
|
||||
class CustomerService
|
||||
{
|
||||
@@ -139,6 +142,15 @@ class CustomerService
|
||||
if ($scene == 'audit') { //审核时查询举报人姓名
|
||||
$customerHis = CustomerHis::where('customer_id', $item->id)->orderBy('id', 'desc')->first(['user_his']);
|
||||
$item['user_name'] = empty($customerHis['user_his']) ? '' : User::where('id',$customerHis['user_his'])->value('name');
|
||||
$item['audit'] = CustomerAudit::where('customer_id', $item->id)->orderBy('id', 'desc')->first();
|
||||
if (!empty($item['audit'])&&!empty($item['audit']['img'])) {
|
||||
$item['audit']['img'] = explode(',', $item['audit']['img']);
|
||||
}
|
||||
|
||||
$ossservice = new OssService();
|
||||
foreach ($item['audit']['img'] as $k => $img) {
|
||||
$item['audit']['img'][$k] = $ossservice->generatePrivateUrl($img);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -287,9 +299,14 @@ class CustomerService
|
||||
$id = $params['id'];
|
||||
|
||||
$logic = new CustomerLogic();
|
||||
$audit = CustomerAudit::where('customer_id', $id)->orderBy('id', 'desc')->first();
|
||||
if ($params['scene'] == 'delete') {
|
||||
$audit->status = 3;
|
||||
$audit->save();
|
||||
return $logic->forceDelete($params['id']);
|
||||
} else {
|
||||
$audit->status = 2;
|
||||
$audit->save();
|
||||
return $logic->status($params['id'], 1);
|
||||
}
|
||||
}
|
||||
@@ -452,4 +469,62 @@ class CustomerService
|
||||
|
||||
return $follow;
|
||||
}
|
||||
|
||||
/**
|
||||
* 离职员工客户分配
|
||||
* @param $params
|
||||
* @return string[]
|
||||
*/
|
||||
public function allocation($params)
|
||||
{
|
||||
$corpId = $params['corp_id'];
|
||||
$userId = explode(',', $params['user_id']);
|
||||
|
||||
log::info('开始分配离职员工客户,corp_id:'.$corpId.' 被分配员工'. implode(',', $userId));
|
||||
|
||||
//查询离职客户
|
||||
$userResign = User::where('status', 2)
|
||||
->where('corp_id', $corpId)
|
||||
->get(['id','name']);
|
||||
|
||||
$resignUerIds = [];
|
||||
$userNames = [];
|
||||
foreach ($userResign as $row) {
|
||||
$resignUerIds[] = (int)$row->id;
|
||||
$userNames[] = $row->name;
|
||||
}
|
||||
if (empty($userResign)) {
|
||||
log::info('未匹配到离职用户');
|
||||
throw new BusinessException('未匹配到离职用户', 500);
|
||||
}
|
||||
log::info('匹配到离职用户数:' . count($resignUerIds) .' '. implode(',',$userNames));
|
||||
|
||||
$customerCount = Customer::whereIn('user_id', $resignUerIds)
|
||||
->orderBy('id', 'asc')
|
||||
->count();
|
||||
|
||||
if ($customerCount === 0) {
|
||||
log::info('未找到离职员工相关的客户记录。');
|
||||
throw new BusinessException('未找到离职员工相关的客户记录', 500);
|
||||
}
|
||||
|
||||
// 初始化 UID 轮询器
|
||||
$uidRotator = new \app\common\utils\RedisUidRotator('allocation_customer_user');
|
||||
$uidRotator->setUids($userId, false);
|
||||
|
||||
Customer::whereIn('user_id',$resignUerIds)->chunk(500, function ($customers) use ($uidRotator){
|
||||
foreach ($customers as $customer) {
|
||||
// 获取下一个分配的UID
|
||||
$newUserId = $uidRotator->next();
|
||||
$customer->user_id = $newUserId;
|
||||
$customer->save();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return [
|
||||
'userCount' => count($resignUerIds),
|
||||
'customerCount' => $customerCount,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -159,6 +159,7 @@ Route::group('/admin', function () {
|
||||
Route::any('/delete', [app\crmAdmin\controller\CustomerController::class, 'delete']);
|
||||
Route::any('/cede', [app\crm\controller\CustomerController::class, 'cede']);
|
||||
Route::any('/follow', [app\crmAdmin\controller\CustomerController::class, 'follow']);
|
||||
Route::any('/allocation', [app\crmAdmin\controller\CustomerController::class, 'allocation']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user