离职客户分配
This commit is contained in:
@@ -228,7 +228,7 @@ class CustomerController extends BaseController
|
|||||||
|
|
||||||
$result = (new CustomerService())->allocation($param);
|
$result = (new CustomerService())->allocation($param);
|
||||||
|
|
||||||
return $this->success($result);
|
return $this->success();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
return $this->error($th->getMessage());
|
return $this->error($th->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|||||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||||
use support\Db;
|
use support\Db;
|
||||||
|
use support\exception\BusinessException;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
|
|
||||||
class CustomerService
|
class CustomerService
|
||||||
@@ -481,28 +482,33 @@ class CustomerService
|
|||||||
$userNames[] = $row->name;
|
$userNames[] = $row->name;
|
||||||
}
|
}
|
||||||
if (empty($userIds)) {
|
if (empty($userIds)) {
|
||||||
log::info('匹配到离职用户数:' . count($resignUerIds) .' '. implode(',',$userNames));
|
log::info('未匹配到离职用户');
|
||||||
|
throw new BusinessException('未找到离职员工相关的客户记录', 500);
|
||||||
}
|
}
|
||||||
|
log::info('匹配到离职用户数:' . count($resignUerIds) .' '. implode(',',$userNames));
|
||||||
|
|
||||||
$customers = Customer::whereIn('user_id', $resignUerIds)
|
$customerCount = Customer::whereIn('user_id', $resignUerIds)
|
||||||
->orderBy('id', 'asc')
|
->orderBy('id', 'asc')
|
||||||
->get(['id','user_id']);
|
->count();
|
||||||
|
|
||||||
if (!$customers || count($customers) === 0) {
|
if ($customerCount === 0) {
|
||||||
$output->writeln('<comment>未找到相关的 crm_customer 记录。</comment>');
|
log::info('未找到离职员工相关的客户记录。');
|
||||||
log::info('未找到相关的离职员工客户记录。' ;
|
throw new BusinessException('未找到离职员工相关的客户记录', 500);
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$follow = Follow::
|
// 初始化 UID 轮询器
|
||||||
where('customer_id', $id)
|
$uidRotator = new \app\common\utils\RedisUidRotator('allocation_customer_user');
|
||||||
->get();
|
$uidRotator->setUids($params, false);
|
||||||
|
|
||||||
$ossservice = new OssService();
|
Customer::chunk(200, function ($customers, $uidRotator) {
|
||||||
foreach ($follow as $item) {
|
foreach ($customers as $customer) {
|
||||||
$item['picture_full'] = empty($item->picture)?'':$ossservice->generatePrivateUrl($item->picture);
|
// 获取下一个分配的UID
|
||||||
}
|
$newUserId = $uidRotator->next();
|
||||||
|
$customer->user_id = $newUserId;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return $follow;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,6 +159,7 @@ Route::group('/admin', function () {
|
|||||||
Route::any('/delete', [app\crmAdmin\controller\CustomerController::class, 'delete']);
|
Route::any('/delete', [app\crmAdmin\controller\CustomerController::class, 'delete']);
|
||||||
Route::any('/cede', [app\crm\controller\CustomerController::class, 'cede']);
|
Route::any('/cede', [app\crm\controller\CustomerController::class, 'cede']);
|
||||||
Route::any('/follow', [app\crmAdmin\controller\CustomerController::class, 'follow']);
|
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