跟单人修改
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user