From dac360ec65d9afd5d52504feab19daa5fb075d04 Mon Sep 17 00:00:00 2001 From: mzl Date: Tue, 19 Aug 2025 13:54:19 +0800 Subject: [PATCH 01/16] Merge branch 'develop' --- app/common/model/CustomerAudit.php | 49 ++++++++++++ app/crm/controller/CustomerController.php | 3 + app/crm/service/CustomerService.php | 9 +++ .../controller/CustomerController.php | 26 ++++++- app/crmAdmin/logic/CustomerLogic.php | 1 + app/crmAdmin/service/CustomerService.php | 75 +++++++++++++++++++ config/route.php | 1 + 7 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 app/common/model/CustomerAudit.php diff --git a/app/common/model/CustomerAudit.php b/app/common/model/CustomerAudit.php new file mode 100644 index 0000000..4e52267 --- /dev/null +++ b/app/common/model/CustomerAudit.php @@ -0,0 +1,49 @@ +error(trans('id_empty')); } + if (empty($param['remark']) && empty($param['img'])) { + return $this->error('举报理由不能为空'); + } $param['user_id'] = $request->user->uid; $param['corp_abbr'] = $request->basic_data['corp_abbr']; diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index 0573972..b7654f0 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -3,6 +3,7 @@ namespace app\crm\service; use app\common\model\Corp; +use app\common\model\CustomerAudit; use app\common\model\User; use app\common\traits\crud\CrudServiceTrait; use app\crm\logic\CustomerLogic; @@ -195,6 +196,14 @@ class CustomerService return false; } + CustomerAudit::create([ + 'customer_id' => $id, + 'report_user_id' => $userId, + 'remark' => $params['remark'], + 'status' => 1, + 'img' => implode(',', $params['img']), + ]); + CustomerHis::create([ 'customer_id' => $id, 'user_his' => $userId, diff --git a/app/crmAdmin/controller/CustomerController.php b/app/crmAdmin/controller/CustomerController.php index a3dc0e2..2f3ba2e 100644 --- a/app/crmAdmin/controller/CustomerController.php +++ b/app/crmAdmin/controller/CustomerController.php @@ -85,7 +85,7 @@ class CustomerController extends BaseController } /** - * 客户列表 + * 审核客户 * @param Request $request * @return \support\Response */ @@ -207,4 +207,28 @@ class CustomerController extends BaseController } } + /** + * 离职员工客户分配 + * @param Request $request + * @return \support\Response + */ + public function allocation(Request $request) + { + try { + $param = $request->all(); + if (empty($param['corp_id'])) { + return $this->error('corp_id'.trans('not_null')); + } + if (empty($param['user_id'])) { + return $this->error('user_id'.trans('not_null')); + } + + $result = (new CustomerService())->allocation($param); + + return $this->success($result,'成功分配'.$result['userCount'].'位离职用户的'.$result['customerCount'].'位客户'); + } catch (\Throwable $th) { + return $this->error($th->getMessage()); + } + } + } \ No newline at end of file diff --git a/app/crmAdmin/logic/CustomerLogic.php b/app/crmAdmin/logic/CustomerLogic.php index 83ba426..13efe9c 100644 --- a/app/crmAdmin/logic/CustomerLogic.php +++ b/app/crmAdmin/logic/CustomerLogic.php @@ -17,6 +17,7 @@ class CustomerLogic $customer->restore(); } + return $res; } diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index 074f341..2ded7cb 100644 --- a/app/crmAdmin/service/CustomerService.php +++ b/app/crmAdmin/service/CustomerService.php @@ -2,6 +2,7 @@ namespace app\crmAdmin\service; +use app\common\model\CustomerAudit; use app\common\model\InquiryLog; use app\common\model\User; use app\common\service\OssService; @@ -20,6 +21,8 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Fill; use support\Db; +use support\exception\BusinessException; +use support\Log; class CustomerService { @@ -139,6 +142,15 @@ class CustomerService if ($scene == 'audit') { //审核时查询举报人姓名 $customerHis = CustomerHis::where('customer_id', $item->id)->orderBy('id', 'desc')->first(['user_his']); $item['user_name'] = empty($customerHis['user_his']) ? '' : User::where('id',$customerHis['user_his'])->value('name'); + $item['audit'] = CustomerAudit::where('customer_id', $item->id)->orderBy('id', 'desc')->first(); + if (!empty($item['audit'])&&!empty($item['audit']['img'])) { + $item['audit']['img'] = explode(',', $item['audit']['img']); + } + + $ossservice = new OssService(); + foreach ($item['audit']['img'] as $k => $img) { + $item['audit']['img'][$k] = $ossservice->generatePrivateUrl($img); + } } } } @@ -287,9 +299,14 @@ class CustomerService $id = $params['id']; $logic = new CustomerLogic(); + $audit = CustomerAudit::where('customer_id', $id)->orderBy('id', 'desc')->first(); if ($params['scene'] == 'delete') { + $audit->status = 3; + $audit->save(); return $logic->forceDelete($params['id']); } else { + $audit->status = 2; + $audit->save(); return $logic->status($params['id'], 1); } } @@ -452,4 +469,62 @@ class CustomerService return $follow; } + + /** + * 离职员工客户分配 + * @param $params + * @return string[] + */ + public function allocation($params) + { + $corpId = $params['corp_id']; + $userId = explode(',', $params['user_id']); + + log::info('开始分配离职员工客户,corp_id:'.$corpId.' 被分配员工'. implode(',', $userId)); + + //查询离职客户 + $userResign = User::where('status', 2) + ->where('corp_id', $corpId) + ->get(['id','name']); + + $resignUerIds = []; + $userNames = []; + foreach ($userResign as $row) { + $resignUerIds[] = (int)$row->id; + $userNames[] = $row->name; + } + if (empty($userResign)) { + log::info('未匹配到离职用户'); + throw new BusinessException('未匹配到离职用户', 500); + } + log::info('匹配到离职用户数:' . count($resignUerIds) .' '. implode(',',$userNames)); + + $customerCount = Customer::whereIn('user_id', $resignUerIds) + ->orderBy('id', 'asc') + ->count(); + + if ($customerCount === 0) { + log::info('未找到离职员工相关的客户记录。'); + throw new BusinessException('未找到离职员工相关的客户记录', 500); + } + + // 初始化 UID 轮询器 + $uidRotator = new \app\common\utils\RedisUidRotator('allocation_customer_user'); + $uidRotator->setUids($userId, false); + + Customer::whereIn('user_id',$resignUerIds)->chunk(500, function ($customers) use ($uidRotator){ + foreach ($customers as $customer) { + // 获取下一个分配的UID + $newUserId = $uidRotator->next(); + $customer->user_id = $newUserId; + $customer->save(); + } + }); + + + return [ + 'userCount' => count($resignUerIds), + 'customerCount' => $customerCount, + ]; + } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index fd117b2..2abd88a 100644 --- a/config/route.php +++ b/config/route.php @@ -159,6 +159,7 @@ Route::group('/admin', function () { Route::any('/delete', [app\crmAdmin\controller\CustomerController::class, 'delete']); Route::any('/cede', [app\crm\controller\CustomerController::class, 'cede']); Route::any('/follow', [app\crmAdmin\controller\CustomerController::class, 'follow']); + Route::any('/allocation', [app\crmAdmin\controller\CustomerController::class, 'allocation']); }); }); }); From e7cf1dce94954b2b75c23c01aa9dccc0f9c36eb4 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 09:40:52 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/service/UserService.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/admin/service/UserService.php b/app/admin/service/UserService.php index 4d23710..3354e88 100644 --- a/app/admin/service/UserService.php +++ b/app/admin/service/UserService.php @@ -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']; } From 2d2e30faa98b58891c2bdf6e4b2d99c1ce5a1996 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 11:29:05 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/service/CustomerService.php | 2 +- app/crm/utils/Util.php | 8 +++++++- app/ticket/service/ConversationService.php | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index b7654f0..ef5aa71 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -256,7 +256,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); diff --git a/app/crm/utils/Util.php b/app/crm/utils/Util.php index e6ac4d0..586ee45 100644 --- a/app/crm/utils/Util.php +++ b/app/crm/utils/Util.php @@ -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; } diff --git a/app/ticket/service/ConversationService.php b/app/ticket/service/ConversationService.php index e80704a..22da6fb 100644 --- a/app/ticket/service/ConversationService.php +++ b/app/ticket/service/ConversationService.php @@ -60,7 +60,7 @@ class ConversationService 'reply' => '', ]; //$emailDefault = 'app@hnxinyouhe.com'; //公共邮箱 - $emailDefault = 'tuotuo@hnxinyouhe.com'; //范彩凤 + $emailDefault = 'support@hnxinyouhe.com'; //范彩凤 if (empty($conversation)) { $email = $emailDefault; }else{ @@ -108,7 +108,7 @@ class ConversationService 'reply' => '', ]; //$emailDefault = 'app@hnxinyouhe.com'; //公共邮箱 - $emailDefault = 'tuotuo@hnxinyouhe.com'; //范彩凤 + $emailDefault = 'support@hnxinyouhe.com'; //范彩凤 if (empty($conversation)) { $email = $emailDefault; }else{ From 9f8bab618d96fbda81dc112e4a07642398e51445 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 11:37:41 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crmAdmin/service/CustomerService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index a3ee935..ce4dda1 100644 --- a/app/crmAdmin/service/CustomerService.php +++ b/app/crmAdmin/service/CustomerService.php @@ -427,7 +427,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); From c7c25381ccdd0ba0e4669e7c35f1adea441af7d3 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 11:41:15 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crmAdmin/service/CustomerService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index ce4dda1..038a5e0 100644 --- a/app/crmAdmin/service/CustomerService.php +++ b/app/crmAdmin/service/CustomerService.php @@ -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'])); } From bba9c294f4b5750a6680091ca4e044803b7bf10e Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 13:37:25 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/controller/CustomerController.php | 1 + app/ticket/model/Conversation.php | 6 +----- app/ticket/service/ConversationService.php | 2 ++ 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index f391abd..7d05d44 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -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) { diff --git a/app/ticket/model/Conversation.php b/app/ticket/model/Conversation.php index f275f2b..641ff35 100644 --- a/app/ticket/model/Conversation.php +++ b/app/ticket/model/Conversation.php @@ -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', diff --git a/app/ticket/service/ConversationService.php b/app/ticket/service/ConversationService.php index 22da6fb..05158c8 100644 --- a/app/ticket/service/ConversationService.php +++ b/app/ticket/service/ConversationService.php @@ -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; From dbebaa9805ac12d691aa6bc6618576a22f0f5164 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 14:20:54 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/controller/CustomerController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index 7d05d44..a2296cd 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -163,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], ]; From 3c731594d2dafef67ea4fdcf836b20cea88d9ccd Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 14:38:20 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E5=B7=A5=E5=8D=95=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ticket/model/Ticket.php | 7 ------- app/ticket/service/TicketService.php | 2 ++ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/ticket/model/Ticket.php b/app/ticket/model/Ticket.php index cf71b2a..737482c 100644 --- a/app/ticket/model/Ticket.php +++ b/app/ticket/model/Ticket.php @@ -51,13 +51,6 @@ class Ticket extends Model 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 = [ 'code', 'categorie_id', diff --git a/app/ticket/service/TicketService.php b/app/ticket/service/TicketService.php index d12c4e7..ce772df 100644 --- a/app/ticket/service/TicketService.php +++ b/app/ticket/service/TicketService.php @@ -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); From 5cede502e38b7d2a3657d030cf67a2b8ec547de2 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 14:40:19 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E5=B7=A5=E5=8D=95=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ticket/service/TicketService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/ticket/service/TicketService.php b/app/ticket/service/TicketService.php index ce772df..4be052f 100644 --- a/app/ticket/service/TicketService.php +++ b/app/ticket/service/TicketService.php @@ -33,8 +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']); + $res[$k]['created_at'] = date('Y-m-d H:i:s', strtotime($v['created_at'])); + $res[$k]['updated_at'] = date('Y-m-d H:i:s', strtotime($v['updated_at'])); } unset($v); unset($attachments); From f83824c46255c70680ffbf441ec118998094eef8 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 15:16:16 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E5=B7=A5=E5=8D=95=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ticket/model/Ticket.php | 8 ++++++++ app/ticket/service/TicketService.php | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/ticket/model/Ticket.php b/app/ticket/model/Ticket.php index 737482c..41b3794 100644 --- a/app/ticket/model/Ticket.php +++ b/app/ticket/model/Ticket.php @@ -51,6 +51,14 @@ class Ticket extends Model protected $dateFormat = 'U'; + /** + * 指定哪些字段自动转换为 Carbon 实例 + */ + public function getDates() + { + return []; + } + protected $fillable = [ 'code', 'categorie_id', diff --git a/app/ticket/service/TicketService.php b/app/ticket/service/TicketService.php index 4be052f..ce772df 100644 --- a/app/ticket/service/TicketService.php +++ b/app/ticket/service/TicketService.php @@ -33,8 +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', strtotime($v['created_at'])); - $res[$k]['updated_at'] = date('Y-m-d H:i:s', strtotime($v['updated_at'])); + $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); From 08a7a10392e91a774581f9fe66527f73eec0ab88 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 15:24:36 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E5=B7=A5=E5=8D=95=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ticket/model/Ticket.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/ticket/model/Ticket.php b/app/ticket/model/Ticket.php index 41b3794..d1bbe9e 100644 --- a/app/ticket/model/Ticket.php +++ b/app/ticket/model/Ticket.php @@ -47,10 +47,27 @@ class Ticket extends Model * * @var bool */ - public $timestamps = true; + public $timestamps = false; protected $dateFormat = 'U'; + /** + * 在保存时手动设置时间戳 + */ + protected static function boot() + { + parent::boot(); + + static::creating(function ($model) { + $model->created_at = time(); + $model->updated_at = time(); + }); + + static::updating(function ($model) { + $model->updated_at = time(); + }); + } + /** * 指定哪些字段自动转换为 Carbon 实例 */ From 691cb5421abac61b1ee082cef31317b428691fea Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 17:52:44 +0800 Subject: [PATCH 12/16] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/service/CustomerService.php | 37 +++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index ef5aa71..64e0ce8 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -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,34 @@ 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->orderBy('crm_customer.follow_next', 'asc'); + $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'){ From 8b61923692119f673dfb28a0102a7fd6c62f486c Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 17:57:50 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E5=85=AC=E5=8F=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/controller/CustomerController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index a2296cd..3d03c9e 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -330,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)) { From 19082ea6c82fbb1c5dd0001086190833dc4c311b Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 18:19:41 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E6=8E=92=E5=BA=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/service/CustomerService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index 64e0ce8..9cc5ca1 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -141,7 +141,6 @@ class CustomerService }elseif ($sort == 'follow_last') { $query = $query->orderBy('crm_customer.follow_last', 'desc'); }elseif ($sort == 'follow_next') { - $query = $query->orderBy('crm_customer.follow_next', 'asc'); $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'); From ba69b2c2c0d46b9d6eb423a1a95ab3db607e2739 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 20 Aug 2025 18:27:38 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/service/CustomerService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index 9cc5ca1..a3559d5 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -313,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(); From bf0e385a592a4204817ef13317be3ba2b843a592 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 21 Aug 2025 10:12:06 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=82=AE=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ticket/service/ConversationService.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/ticket/service/ConversationService.php b/app/ticket/service/ConversationService.php index 05158c8..ea97cef 100644 --- a/app/ticket/service/ConversationService.php +++ b/app/ticket/service/ConversationService.php @@ -62,7 +62,8 @@ class ConversationService 'reply' => '', ]; //$emailDefault = 'app@hnxinyouhe.com'; //公共邮箱 - $emailDefault = 'support@hnxinyouhe.com'; //范彩凤 + //$emailDefault = 'support@hnxinyouhe.com'; //公共邮箱 + $emailDefault = env('TICKET_EMAIL_DEFAULT'); if (empty($conversation)) { $email = $emailDefault; }else{ @@ -86,7 +87,9 @@ class ConversationService $notice['reply'] = '
  • 最新回复:' . $content . '
  • '; } - \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']); @@ -110,7 +113,8 @@ class ConversationService 'reply' => '', ]; //$emailDefault = 'app@hnxinyouhe.com'; //公共邮箱 - $emailDefault = 'support@hnxinyouhe.com'; //范彩凤 + //$emailDefault = 'support@hnxinyouhe.com'; //公共邮箱 + $emailDefault = env('ticket_email_default'); if (empty($conversation)) { $email = $emailDefault; }else{