Merge branch 'develop'
This commit is contained in:
@@ -325,6 +325,7 @@ class CustomerController extends BaseController
|
||||
'lng' => Util::getParam($request, 'lng', 0),
|
||||
'address' => Util::getParam($request, 'address', ''),
|
||||
'sex' => Util::getParam($request, 'sex', 0),
|
||||
'obtain' => time(),
|
||||
];
|
||||
|
||||
if (Util::isEmpty($id)) {
|
||||
@@ -393,13 +394,31 @@ class CustomerController extends BaseController
|
||||
if(empty($customer)){
|
||||
return $this->error( trans('fail'));
|
||||
}
|
||||
if($force == 'force'){
|
||||
//强制删除
|
||||
$res = $customer->forceDelete();
|
||||
}else{
|
||||
//软删除
|
||||
$res = $customer->delete();
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
if ($force == 'force') {
|
||||
//强制删除
|
||||
$res = $customer->forceDelete();
|
||||
} else {
|
||||
$customer->user_id = 0;
|
||||
$customer->save();
|
||||
|
||||
//记录客户关系变化
|
||||
$his = CustomerHis::create([
|
||||
'customer_id' => $id,
|
||||
'user_his' => $userId,
|
||||
'user_id' => 0,
|
||||
]);
|
||||
|
||||
//软删除
|
||||
$res = $customer->delete();
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
return $this->success($res, trans('success'));
|
||||
} else {
|
||||
@@ -485,10 +504,10 @@ class CustomerController extends BaseController
|
||||
return $this->error(trans('customer_id').trans('not_null'));
|
||||
}
|
||||
$data = [
|
||||
'user_id' => $request->user->uid
|
||||
'user_id' => $request->user->uid,
|
||||
'obtain' => time(),
|
||||
];
|
||||
|
||||
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
$customer= Customer::withTrashed()->find($customerId);
|
||||
@@ -526,8 +545,6 @@ class CustomerController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 批量转让
|
||||
* @param Request $request
|
||||
@@ -543,10 +560,11 @@ class CustomerController extends BaseController
|
||||
return $this->error( trans('user_none'));
|
||||
}
|
||||
|
||||
$query= Customer::whereIn('id',explode(',',$customerId));
|
||||
$query= Customer::withTrashed()->whereIn('id',explode(',',$customerId));
|
||||
try {
|
||||
$customer = $query->get();
|
||||
|
||||
Db::beginTransaction();
|
||||
foreach ($customer as $item) {
|
||||
//记录客户关系变化
|
||||
$his = CustomerHis::create([
|
||||
@@ -561,8 +579,15 @@ class CustomerController extends BaseController
|
||||
$inquiryLog->save();
|
||||
}
|
||||
}
|
||||
|
||||
$item->restore();
|
||||
}
|
||||
$res = $query->update(['user_id' => $user->id]);
|
||||
|
||||
$data = [
|
||||
'user_id' => $user->id,
|
||||
'obtain' => time(),
|
||||
];
|
||||
$res = $query->update($data);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
@@ -79,4 +79,31 @@ class Customer extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::saved(function ($customer) {
|
||||
if (empty($customer->code)) {
|
||||
$customer->code = self::generateCustomerCode($customer);
|
||||
// 使用saveQuietly避免递归调用
|
||||
$customer->saveQuietly();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static function generateCustomerCode($customer)
|
||||
{
|
||||
// 生成唯一16位code,CM+14位
|
||||
$unique = strtoupper(substr(md5($customer->id . microtime(true) . mt_rand(1000, 9999)), 8, 6));
|
||||
$code = 'CM' . date('Ymd') .$unique;
|
||||
return $code;
|
||||
}
|
||||
|
||||
// 静默保存方法,不触发事件
|
||||
public function saveQuietly(array $options = [])
|
||||
{
|
||||
return static::withoutEvents(function () use ($options) {
|
||||
return $this->save($options);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ class CustomerService
|
||||
$follow = $params['follow'] ?? '';
|
||||
$follow_last = $params['follow_last'] ?? '';
|
||||
$tagId = $params['tag_id'] ?? [];
|
||||
$countryId = $params['country_id'] ?? '';
|
||||
$where = [];
|
||||
$user_id =$params['user_id'];
|
||||
|
||||
@@ -49,6 +50,9 @@ class CustomerService
|
||||
}
|
||||
$where[] = ['status', 1];
|
||||
|
||||
if (!empty($countryId)){
|
||||
$where[] = ['country_id', $countryId];
|
||||
}
|
||||
|
||||
$grade = [];
|
||||
if (!Util::isEmpty($follow) && $follow == 0) {
|
||||
@@ -84,7 +88,10 @@ class CustomerService
|
||||
if (!Util::isEmpty($keyword)) {
|
||||
$query->where(function ($query) use ($keyword) {
|
||||
$query->where('contacts', 'like', "%{$keyword}%")
|
||||
->orWhere('phone', 'like', "%{$keyword}%");
|
||||
->orWhere('phone', 'like', "%{$keyword}%")
|
||||
->orWhere('email', 'like', "%{$keyword}%")
|
||||
->orWhere('WhatsApp', 'like', "%{$keyword}%")
|
||||
->orWhere('code', 'like', "%{$keyword}%");
|
||||
});
|
||||
}
|
||||
if (!Util::isEmpty($grade)) {
|
||||
@@ -148,9 +155,16 @@ class CustomerService
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
$config['where']['status'] = 1; // 关键字
|
||||
if (isset($p['user_id']) && $p['user_id']) {
|
||||
$config['where']['user_id'] = $p['user_id'];
|
||||
} // 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
$config['where']['contacts'] = ['like', $k];
|
||||
$config['orWhere'][] = ['contacts','like', $k];
|
||||
$config['orWhere'][] = ['phone','like', $k];
|
||||
$config['orWhere'][] = ['email','like', $k];
|
||||
$config['orWhere'][] = ['WhatsApp','like', $k];
|
||||
$config['orWhere'][] = ['code','like', $k];
|
||||
}
|
||||
$config['order']['id'] = 'desc';
|
||||
$config['dataLimit']['type'] = 'relation';
|
||||
@@ -162,6 +176,11 @@ class CustomerService
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 无用线索举报
|
||||
* @param $params
|
||||
* @return false
|
||||
*/
|
||||
public function report($params)
|
||||
{
|
||||
$id = $params['id'];
|
||||
|
||||
Reference in New Issue
Block a user