Merge branch 'hotfix/user' into develop_bm

This commit is contained in:
2025-08-21 10:15:55 +08:00
9 changed files with 86 additions and 22 deletions
+3
View File
@@ -75,6 +75,9 @@ class UserService
$k = '%' . $p['keyword'] . '%';
$config['where']['name'] = ['like', $k];
}
if (isset($p['status']) && $p['status']) {
$config['where']['status'] = $p['status'];
}
if (isset($p['user_id']) && $p['user_id']) {
$config['where']['user_id'] = $p['user_id'];
}
+3 -1
View File
@@ -50,6 +50,7 @@ class CustomerController extends BaseController
: null);
foreach ($data['records'] as &$item) {
$item = $this->service->getCustomer($item);
$item = Util::formatDate($item,['created_at','updated_at']);
}
return $this->success($data);
} catch (\Throwable $e) {
@@ -162,7 +163,7 @@ class CustomerController extends BaseController
$perPage = $request->input('size', 10);
$where = [
['user_id', '=', $userId],
['corp_abbr', '=', $request->basic_data['corp_abbr']],
// ['corp_abbr', '=', $request->basic_data['corp_abbr']],
['follow_next', '<>', 0],
];
@@ -329,6 +330,7 @@ class CustomerController extends BaseController
'address' => Util::getParam($request, 'address', ''),
'sex' => Util::getParam($request, 'sex', 0),
'obtain' => time(),
'company' => Util::getParam($request, 'company', 0),
];
if (Util::isEmpty($id)) {
+36 -4
View File
@@ -10,12 +10,16 @@ use app\crm\logic\CustomerLogic;
use app\crm\model\Channel;
use app\crm\model\Country;
use app\crm\model\Customer;
use app\crm\model\Tag;
use app\crm\model\CustomerHis;
use app\crm\model\Follow;
use app\crm\utils\Util;
use config\constants\Constants;
use support\Request;
/**
* @method mixed complexQuery(array $params)
*/
class CustomerService
{
@@ -37,6 +41,8 @@ class CustomerService
$follow = $params['follow'] ?? '';
$follow_last = $params['follow_last'] ?? '';
$tagId = $params['tag_id'] ?? [];
$sort = $params['sort'] ?? null;
$sortId = $params['sort_id'] ?? null;
$countryId = $params['country_id'] ?? '';
$where = [];
$user_id =$params['user_id'];
@@ -72,7 +78,7 @@ class CustomerService
$where[] = ['follow_last', '>', strtotime('-7 day')];
}
$query = Customer::where($where);
$query = Customer::select('crm_customer.*')->where($where);
if(!empty($tagId)){
//查询有$tagId 里任意一个标签的客户
@@ -115,7 +121,33 @@ class CustomerService
$query->withTrashed();
}
$customer = $query->orderBy('id','desc')->paginate($perPage, ['*'], 'page', $page);
if ($sort == 'tag_group') {
// 排序:按关联的 crm_tag.sort 最小值升序,其次按客户ID倒序
$minSortSub = Tag::selectRaw('MIN(crm_tag.sort) AS min_sort, crm_customer_tag.customer_id')
->join('crm_customer_tag', 'crm_customer_tag.tag_id', '=', 'crm_tag.id')
->whereNull('crm_tag.deleted_at')
->when(!empty($sortId), function ($q) use ($sortId) {
$q->where('crm_tag.group_id', $sortId);
})
->groupBy('crm_customer_tag.customer_id');
$query->leftJoinSub($minSortSub, 'tag_min', function ($join) {
$join->on('crm_customer.id', '=', 'tag_min.customer_id');
});
$query = $query->orderByRaw('tag_min.min_sort IS NULL')
->orderBy('tag_min.min_sort', 'asc')
->orderBy('crm_customer.id', 'desc');
}elseif ($sort == 'follow_last') {
$query = $query->orderBy('crm_customer.follow_last', 'desc');
}elseif ($sort == 'follow_next') {
$query = $query->orderByRaw('crm_customer.follow_next IS NULL, crm_customer.follow_next ASC');
}elseif ($sort == 'id' || empty($sort)) {
$query = $query->orderBy('crm_customer.id', 'desc');
}
$customer = $query->paginate($perPage, ['*'], 'page', $page);
foreach ($customer as &$item) {
$item = $this->getCustomer($item);
if($seas == 'seas'){
@@ -256,7 +288,7 @@ class CustomerService
// $customer['created_at'] = Util::timeTotDate($customer['created_at']);
// $customer['updated_at'] = Util::timeTotDate($customer['updated_at']);
$customer = Util::formatDate($customer,['follow_last']);
$customer = Util::formatDate($customer,['follow_next','follow_last']);
$nameLang = $language=='en'?'name_en':($language=='ru'?'name_ru':'name');
$countryLang = $language=='en'?'en_addr':'cn_addr';
// $customer['car_type_name'] = empty($customer['car_type_id'])?'':CarType::where(['id'=>$customer['car_type_id']])->value($nameLang);
@@ -281,7 +313,7 @@ class CustomerService
public function detail($params)
{
$id =$params['id'];
$customer = Customer::with('tags')->select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'address', 'lat', 'lng', 'follow_next', 'follow_remark', 'sex')
$customer = Customer::with('tags')->select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'address', 'lat', 'lng', 'follow_next', 'follow_remark', 'sex', 'company')
->where('id', $id)
->first();
+7 -1
View File
@@ -100,7 +100,13 @@ class Util
public static function formatDate($value,$key = ['created_at','updated_at'])
{
foreach ($key as $k){
$value[$k]= self::timeTotDate($value[$k]);
// 如果是整数,可能是 UNIX 时间戳
if (is_numeric($value[$k]) && $value[$k] > 0) {
// 检查是否是合理的时间戳范围(1970-2100年)
if ($value[$k] >= 0 && $value[$k] <= 4102444800) {
$value[$k]= self::timeTotDate($value[$k]);
}
}
}
return $value;
}
+1 -2
View File
@@ -135,7 +135,6 @@ class CustomerService
foreach ($customer as &$item) {
$item = $this->getCustomer($item);
$item['desc_collect'] = $item['desc_collect'] ?? '';
$item['follow_next'] = empty($item['follow_next'])?'':date('Y-m-d H:i:s', $item['follow_next']);
if ($seas == 'seas' || $scene == 'seas') {
$item['seas_time'] = time() - (empty($item['deleted_at'])?strtotime($item['updated_at']):strtotime($item['deleted_at']));
}
@@ -427,7 +426,7 @@ class CustomerService
// $customer['created_at'] = Util::timeTotDate($customer['created_at']);
// $customer['updated_at'] = Util::timeTotDate($customer['updated_at']);
$customer = Util::formatDate($customer, ['follow_last']);
$customer = Util::formatDate($customer, ['follow_next','follow_last']);
$nameLang = $language == 'en' ? 'name_en' : ($language == 'ru' ? 'name_ru' : 'name');
$countryLang = $language == 'en' ? 'en_addr' : 'cn_addr';
// $customer['car_type_name'] = empty($customer['car_type_id'])?'':CarType::where(['id'=>$customer['car_type_id']])->value($nameLang);
+1 -5
View File
@@ -20,11 +20,7 @@ class Conversation extends Model
protected $primaryKey = 'id';
public $timestamps = true;
protected $dateFormat = 'U';
protected $dates = ['created_at', 'updated_at'];
protected $casts = [
'updated_at' => 'datetime:Y-m-d H:i:s',
'created_at' => 'datetime:Y-m-d H:i:s',
];
protected $fillable = [
'ticket_id',
'user_id',
+24 -6
View File
@@ -47,16 +47,34 @@ class Ticket extends Model
*
* @var bool
*/
public $timestamps = true;
public $timestamps = false;
protected $dateFormat = 'U';
protected $dates = ['created_at', 'updated_at'];
/**
* 在保存时手动设置时间戳
*/
protected static function boot()
{
parent::boot();
protected $casts = [
'updated_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式
'created_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式
];
static::creating(function ($model) {
$model->created_at = time();
$model->updated_at = time();
});
static::updating(function ($model) {
$model->updated_at = time();
});
}
/**
* 指定哪些字段自动转换为 Carbon 实例
*/
public function getDates()
{
return [];
}
protected $fillable = [
'code',
+9 -3
View File
@@ -35,6 +35,8 @@ class ConversationService
$user = User::where('id', $value['user_id'])->first();
$value['user_name'] = $user?->name;
$value['user_avatar'] = $user?->avatar;
$value['created_at'] = date('Y-m-d H:i:s', strtotime($value['created_at']));
$value['updated_at'] = date('Y-m-d H:i:s', strtotime($value['updated_at']));
$result[$key] = $value;
}
return $result;
@@ -60,7 +62,8 @@ class ConversationService
'reply' => '',
];
//$emailDefault = 'app@hnxinyouhe.com'; //公共邮箱
$emailDefault = 'tuotuo@hnxinyouhe.com'; //范彩凤
//$emailDefault = 'support@hnxinyouhe.com'; //公共邮箱
$emailDefault = env('TICKET_EMAIL_DEFAULT');
if (empty($conversation)) {
$email = $emailDefault;
}else{
@@ -84,7 +87,9 @@ class ConversationService
$notice['reply'] = '<li>最新回复:' . $content . '</li>';
}
\app\common\utils\email\MailSend::send($email, '【XYH】新的工单提醒', replaceTpl($notice, 'work_order'));
if(!empty($emailDefault)){
\app\common\utils\email\MailSend::send($email, '【XYH】新的工单提醒', replaceTpl($notice, 'work_order'));
}
unset($data['categorie_id']);
unset($data['code']);
@@ -108,7 +113,8 @@ class ConversationService
'reply' => '',
];
//$emailDefault = 'app@hnxinyouhe.com'; //公共邮箱
$emailDefault = 'tuotuo@hnxinyouhe.com'; //范彩凤
//$emailDefault = 'support@hnxinyouhe.com'; //公共邮箱
$emailDefault = env('ticket_email_default');
if (empty($conversation)) {
$email = $emailDefault;
}else{
+2
View File
@@ -33,6 +33,8 @@ class TicketService
$user = User::where('id', $v['user_id'])->first();
$res[$k]['user_name'] = $user?->name;
$res[$k]['user_avatar'] = $user?->avatar;
$res[$k]['created_at'] = date('Y-m-d H:i:s', $v['created_at']);
$res[$k]['updated_at'] = date('Y-m-d H:i:s', $v['updated_at']);
}
unset($v);
unset($attachments);