跟单人修改
This commit is contained in:
@@ -58,7 +58,7 @@ class UserService
|
||||
$config['where']['id'] = $p['id'];
|
||||
}
|
||||
|
||||
$config['fields'] = ['id', 'name', 'email', 'sex', 'phone', 'avatar', 'corp_id', 'country_id', 'position', 'status', 'created_at'];
|
||||
$config['fields'] = ['id','sn', 'name', 'email', 'sex', 'phone', 'avatar', 'corp_id', 'country_id', 'position', 'status', 'created_at'];
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\crm\model\Customer;
|
||||
use support\Log;
|
||||
use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
||||
use Webman\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class CustomerCodeCommand extends SymfonyCommand
|
||||
{
|
||||
protected static $defaultName = 'customer:generate-code';
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setDescription('为crm_customer表所有记录生成唯一code码,分批处理');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$batchSize = 1000;
|
||||
$total = Customer::withTrashed()->where('code','')->count();
|
||||
$output->writeln("总计需处理:$total 条记录");
|
||||
|
||||
$processed = 0;
|
||||
do {
|
||||
// 查询一批未生成code的记录
|
||||
$customers = Customer::withTrashed()->where('code','')->limit($batchSize)->get();
|
||||
if ($customers->isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Eloquent 批量处理
|
||||
foreach ($customers as $customer) {
|
||||
// 生成唯一16位code,CM+14位
|
||||
$unique = strtoupper(substr(md5($customer->id . microtime(true) . mt_rand(1000, 9999)), 0, 14));
|
||||
$code = 'CM' . $unique;
|
||||
|
||||
// 防止极小概率重复
|
||||
while (Customer::where('code', $code)->exists()) {
|
||||
$unique = strtoupper(substr(md5($customer->id . microtime(true) . mt_rand(1000, 9999)), 0, 14));
|
||||
$code = 'CM' . $unique;
|
||||
}
|
||||
|
||||
$obtain = $customer->created_at>strtotime('2025-07-29')?$customer->created_at:strtotime('2025-07-29');
|
||||
|
||||
$customer->code = $code;
|
||||
$customer->obtain = $obtain;
|
||||
$customer->save();
|
||||
$processed++;
|
||||
}
|
||||
|
||||
$output->writeln("已处理:$processed / $total");
|
||||
} while (true);
|
||||
|
||||
$output->writeln('<info>全部处理完成!</info>');
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\crm\controller;
|
||||
|
||||
use app\common\model\Corp;
|
||||
use app\common\model\InquiryLog;
|
||||
use app\common\model\User;
|
||||
use app\crm\model\Channel;
|
||||
use app\crm\model\Country;
|
||||
@@ -12,6 +13,7 @@ use app\crm\model\Follow;
|
||||
use app\crm\service\CustomerService;
|
||||
use app\crm\utils\Util;
|
||||
use config\constants\Constants;
|
||||
use support\Db;
|
||||
use support\Request;
|
||||
|
||||
class CustomerController extends BaseController
|
||||
@@ -454,22 +456,38 @@ class CustomerController extends BaseController
|
||||
$data = [
|
||||
'user_id' => $request->user->uid
|
||||
];
|
||||
$customer= Customer::withTrashed()->find($customerId);
|
||||
|
||||
if(empty($customer) || $customer->user_id != 0){
|
||||
return $this->error( trans('claim_fail'));
|
||||
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
$customer= Customer::withTrashed()->find($customerId);
|
||||
|
||||
if(empty($customer) || $customer->user_id != 0){
|
||||
return $this->error( trans('claim_fail'));
|
||||
}
|
||||
|
||||
$customer->restore();
|
||||
$res = $customer->update($data);
|
||||
|
||||
//记录客户关系变化
|
||||
$his = CustomerHis::create([
|
||||
'customer_id' => $customerId,
|
||||
'user_his' => 0,
|
||||
'user_id' => $userId,
|
||||
]);
|
||||
if (!empty($customer->sn) && $customer->type==1){
|
||||
$inquiryLog = InquiryLog::where('order_no', $customer->sn)->first();
|
||||
if (!empty($inquiryLog)) {
|
||||
$inquiryLog->recipient = $userId;
|
||||
$inquiryLog->save();
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$customer->restore();
|
||||
$res = $customer->update($data);
|
||||
|
||||
//记录客户关系变化
|
||||
$his = CustomerHis::create([
|
||||
'customer_id' => $customerId,
|
||||
'user_his' => 0,
|
||||
'user_id' => $userId,
|
||||
]);
|
||||
|
||||
if ($res) {
|
||||
return $this->success($res, trans('success'));
|
||||
} else {
|
||||
@@ -506,17 +524,44 @@ class CustomerController extends BaseController
|
||||
}else{
|
||||
$query= Customer::whereIn('id',explode(',',$customerId));
|
||||
}
|
||||
$customer = $query->get();
|
||||
// $customer = $query->get();
|
||||
//
|
||||
// foreach ($customer as $item) {
|
||||
// //记录客户关系变化
|
||||
// $his = CustomerHis::create([
|
||||
// 'customer_id' => $item->id,
|
||||
// 'user_his' => $item->user_id,
|
||||
// 'user_id' => $user['id'],
|
||||
// ]);
|
||||
// }
|
||||
// $res = $query->update(['user_id' => $user->id]);
|
||||
|
||||
foreach ($customer as $item) {
|
||||
//记录客户关系变化
|
||||
$his = CustomerHis::create([
|
||||
'customer_id' => $item->id,
|
||||
'user_his' => $item->user_id,
|
||||
'user_id' => $user['id'],
|
||||
]);
|
||||
try {
|
||||
$customer = $query->get();
|
||||
|
||||
foreach ($customer as $item) {
|
||||
//记录客户关系变化
|
||||
$his = CustomerHis::create([
|
||||
'customer_id' => $item->id,
|
||||
'user_his' => $item->user_id,
|
||||
'user_id' => $user['id'],
|
||||
]);
|
||||
if (!empty($customer->sn) && $customer->type==1){
|
||||
$inquiryLog = InquiryLog::where('order_no', $customer->sn)->first();
|
||||
if (!empty($inquiryLog)) {
|
||||
$inquiryLog->recipient = $userId;
|
||||
$inquiryLog->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
$res = $query->update(['user_id' => $user->id]);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
$res = $query->update(['user_id' => $user->id]);
|
||||
|
||||
|
||||
|
||||
if ($res) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\crmAdmin\service;
|
||||
|
||||
use app\common\model\InquiryLog;
|
||||
use app\common\model\User;
|
||||
use app\crm\model\CustomerHis;
|
||||
use app\crmAdmin\logic\CustomerLogic;
|
||||
@@ -306,6 +307,13 @@ class CustomerService
|
||||
'user_his' => $item->user_id,
|
||||
'user_id' => $userId,
|
||||
]);
|
||||
if (!empty($item->sn) && $item->type==1){
|
||||
$inquiryLog = InquiryLog::where('order_no', $item->sn)->first();
|
||||
if (!empty($inquiryLog)) {
|
||||
$inquiryLog->recipient = $userId;
|
||||
$inquiryLog->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
$res = $query->update(['user_id' => $userId]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user