组员客户数
This commit is contained in:
@@ -44,7 +44,8 @@ class CustomerCodeCommand extends SymfonyCommand
|
|||||||
$code = 'CM' . $unique;
|
$code = 'CM' . $unique;
|
||||||
}
|
}
|
||||||
|
|
||||||
$obtain = $customer->created_at>strtotime('2025-07-29')?$customer->created_at:strtotime('2025-07-29');
|
$created_at = $customer->created_at->getTimestamp();
|
||||||
|
$obtain = $created_at > strtotime('2025-07-29')?$created_at:strtotime('2025-07-29');
|
||||||
|
|
||||||
$customer->code = $code;
|
$customer->code = $code;
|
||||||
$customer->obtain = $obtain;
|
$customer->obtain = $obtain;
|
||||||
|
|||||||
@@ -46,4 +46,31 @@ class CrmCustomer extends Model
|
|||||||
* 不允许自动填充模型字段
|
* 不允许自动填充模型字段
|
||||||
*/
|
*/
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
|
||||||
|
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, 14));
|
||||||
|
$code = 'CM' . date('Ymd') .$unique;
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 静默保存方法,不触发事件
|
||||||
|
public function saveQuietly(array $options = [])
|
||||||
|
{
|
||||||
|
return static::withoutEvents(function () use ($options) {
|
||||||
|
return $this->save($options);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ use app\common\traits\crud\CrudLogicTrait;
|
|||||||
use app\common\traits\crud\CrudServiceTrait;
|
use app\common\traits\crud\CrudServiceTrait;
|
||||||
use app\common\utils\CrudUtil;
|
use app\common\utils\CrudUtil;
|
||||||
use app\crm\model\Country;
|
use app\crm\model\Country;
|
||||||
|
use app\crm\model\Customer;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
|
|
||||||
@@ -136,6 +137,11 @@ class UserService
|
|||||||
$page = (int)$request->get('current', 1);
|
$page = (int)$request->get('current', 1);
|
||||||
$result = $this->logicList($config, $limit, $page);
|
$result = $this->logicList($config, $limit, $page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($result as &$data){
|
||||||
|
$data['customer_count'] = Customer::where('user_id', $data['id'])->count();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->postProcess('List', $result);
|
return $this->postProcess('List', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,9 @@ class CustomerService
|
|||||||
if (!Util::isEmpty($keyword)) {
|
if (!Util::isEmpty($keyword)) {
|
||||||
$query->where(function ($query) use ($keyword) {
|
$query->where(function ($query) use ($keyword) {
|
||||||
$query->where('contacts', 'like', "%{$keyword}%")
|
$query->where('contacts', 'like', "%{$keyword}%")
|
||||||
->orWhere('phone', 'like', "%{$keyword}%");
|
->orWhere('phone', 'like', "%{$keyword}%")
|
||||||
|
->orWhere('WhatsApp', 'like', "%{$keyword}%")
|
||||||
|
->orWhere('code', 'like', "%{$keyword}%");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!Util::isEmpty($grade)) {
|
if (!Util::isEmpty($grade)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user