From ced046aa189c49b0aac18f97d4d095605c43c4d0 Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 4 Sep 2025 11:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B3=E8=81=94=E5=85=B3?= =?UTF-8?q?=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/StockOrderAccounts.php | 9 + app/common/model/StockOrderItemOptions.php | 9 + app/common/model/StockOrderItems.php | 27 +++ app/common/model/StockOrders.php | 25 ++ app/common/model/VehMoneyValue.php | 25 ++ app/common/service/StockOrdersService.php | 74 +++--- app/common/service/VehVehicleSkuService.php | 2 + .../redis/InquiryToCrmNew_BACKUP_5243.php | 218 ------------------ app/queue/redis/InquiryToCrmNew_BASE_5243.php | 0 .../redis/InquiryToCrmNew_LOCAL_5243.php | 204 ---------------- .../redis/InquiryToCrmNew_REMOTE_5243.php | 207 ----------------- 11 files changed, 140 insertions(+), 660 deletions(-) delete mode 100644 app/queue/redis/InquiryToCrmNew_BACKUP_5243.php delete mode 100644 app/queue/redis/InquiryToCrmNew_BASE_5243.php delete mode 100644 app/queue/redis/InquiryToCrmNew_LOCAL_5243.php delete mode 100644 app/queue/redis/InquiryToCrmNew_REMOTE_5243.php diff --git a/app/common/model/StockOrderAccounts.php b/app/common/model/StockOrderAccounts.php index dabc02e..53c2beb 100644 --- a/app/common/model/StockOrderAccounts.php +++ b/app/common/model/StockOrderAccounts.php @@ -46,4 +46,13 @@ class StockOrderAccounts extends Model * 不允许自动填充模型字段 */ protected $guarded = []; + + + /** + * 关联主订单 + */ + public function order() + { + return $this->belongsTo(StockOrders::class, 'order_id', 'id'); + } } \ No newline at end of file diff --git a/app/common/model/StockOrderItemOptions.php b/app/common/model/StockOrderItemOptions.php index 417a927..e6f8122 100644 --- a/app/common/model/StockOrderItemOptions.php +++ b/app/common/model/StockOrderItemOptions.php @@ -46,4 +46,13 @@ class StockOrderItemOptions extends Model * 不允许自动填充模型字段 */ protected $guarded = []; + + + /** + * 关联订单项 + */ + public function item() + { + return $this->belongsTo(StockOrderItems::class, 'order_item_id', 'id'); + } } \ No newline at end of file diff --git a/app/common/model/StockOrderItems.php b/app/common/model/StockOrderItems.php index 847fec7..610f694 100644 --- a/app/common/model/StockOrderItems.php +++ b/app/common/model/StockOrderItems.php @@ -81,4 +81,31 @@ class StockOrderItems extends Model public function getPortMiscFeeAmountAttribute() { return $this->moneyLatest('port_misc_fee')?->amount; } public function getRetrofitFeeAmountAttribute() { return $this->moneyLatest('retrofit_fee')?->amount; } public function getTotalPriceAmountAttribute() { return $this->moneyLatest('total_price')?->amount; } + + + /** + * 关联主订单 + */ + public function order() + { + return $this->belongsTo(StockOrders::class, 'order_id', 'id'); + } + + /** + * 关联订单项选项 + */ + public function options() + { + return $this->hasMany(StockOrderItemOptions::class, 'order_item_id', 'id'); + } + + + /** + * 关联货币价值信息(一个订单项可以有多个货币价值记录) + */ + public function moneyValues() + { + return $this->hasMany(VehMoneyValue::class, 'object_id', 'id') + ->where('object_scene', 'stock_order_items'); // 场景标识区分不同对象类型 + } } \ No newline at end of file diff --git a/app/common/model/StockOrders.php b/app/common/model/StockOrders.php index 2814f39..123eb66 100644 --- a/app/common/model/StockOrders.php +++ b/app/common/model/StockOrders.php @@ -56,4 +56,29 @@ class StockOrders extends Model * 不允许自动填充模型字段 */ protected $guarded = []; + + + /** + * 关联订单项 + */ + public function items() + { + return $this->hasMany(StockOrderItems::class, 'order_id', 'id'); + } + + /** + * 关联订单账户信息 + */ + public function accounts() + { + return $this->hasMany(StockOrderAccounts::class, 'order_id', 'id'); + } + + /** + * 关联货币价值信息(一个订单可以有多个货币价值记录) + */ + public function moneyValues() + { + return $this->hasMany(VehMoneyValue::class, 'object_id', 'id')->where('object_scene', 'stock_orders'); + } } \ No newline at end of file diff --git a/app/common/model/VehMoneyValue.php b/app/common/model/VehMoneyValue.php index e4c9d58..38c1458 100644 --- a/app/common/model/VehMoneyValue.php +++ b/app/common/model/VehMoneyValue.php @@ -59,4 +59,29 @@ class VehMoneyValue extends Model if ($this->exchange_rate === null) return null; return (string) bcmul((string)$this->amount, (string)$this->exchange_rate, $scale); } + + + /** + * 关联订单 + */ + public function order() + { + return $this->belongsTo(StockOrders::class, 'object_id', 'id'); + } + + /** + * 关联订单项(一个货币价值记录可能关联到订单项) + */ + public function orderItem() + { + return $this->belongsTo(StockOrderItems::class, 'object_id', 'id'); + } + + /** + * 限定查询特定对象类型的货币价值记录 + */ + public function scopeOfScene($query, $scene) + { + return $query->where('object_scene', $scene); + } } \ No newline at end of file diff --git a/app/common/service/StockOrdersService.php b/app/common/service/StockOrdersService.php index 55e8dd3..c694177 100644 --- a/app/common/service/StockOrdersService.php +++ b/app/common/service/StockOrdersService.php @@ -11,6 +11,7 @@ use app\common\model\StockOrders; use support\Request; use app\common\model\User; use support\exception\BusinessException; +use support\Db; class StockOrdersService { @@ -48,6 +49,12 @@ class StockOrdersService break; case 'show': $config['where']['id'] = $p['id']; + + $config['with'][] = 'items'; + $config['with'][] = 'items.options'; + $config['with'][] = 'items.moneyValues'; + $config['with'][] = 'accounts'; + $config['with'][] = 'moneyValues'; break; case 'store': break; @@ -65,38 +72,47 @@ class StockOrdersService public function serviceStore(Request $request, array $data = []) { - $data = $this->preProcess('Store', $data, $request); - $dl = $this->getDataLimitFromRequest($request); - $created = $this->logicCreate($data, $dl); // 表1 + // 关联表较多,增加事务处理 + return Db::transaction(function () use ($request, $data) { + $data = $this->preProcess('Store', $data, $request); + $dl = $this->getDataLimitFromRequest($request); + $created = $this->logicCreate($data, $dl); // 表1 - // 车辆 - foreach ($data['veh_list'] as $veh) { - $veh['order_id'] = $created->id; - $item = StockOrderItems::create($veh); // 表2 + // 车辆 + foreach ($data['veh_list'] as $veh) { + $veh['order_id'] = $created->id; + $item = StockOrderItems::create($veh); // 表2 - // 金额 // 表3 - $item->addMoney('official_price', $veh['currency'], $veh['amount'], $veh['rate'], '官方指导价'); - $item->addMoney('discount_price', $veh['currency'], $veh['amount'], $veh['rate'], '优惠价'); - $item->addMoney('unit_price', $veh['currency'], $veh['amount'], $veh['rate'], '单价'); - $item->addMoney('total_price', $veh['currency'], $veh['amount'], $veh['rate'], '总价'); - $item->addMoney('handling_fee', $veh['currency'], $veh['amount'], $veh['rate'], '手续费'); - $item->addMoney('fob_transport_fee', $veh['currency'], $veh['amount'], $veh['rate'], 'FOB运输费'); - $item->addMoney('port_misc_fee', $veh['currency'], $veh['amount'], $veh['rate'], '港杂'); - $item->addMoney('retrofit_fee', $veh['currency'], $veh['amount'], $veh['rate'], '改装费'); + // 金额 // 表3 + $item->addMoney('official_price', $veh['official_price']['currency'], $veh['official_price']['amount'], $veh['official_price']['rate'], '官方指导价'); + $item->addMoney('discount_price', $veh['discount_price']['currency'], $veh['discount_price']['amount'], $veh['discount_price']['rate'], '优惠价'); + $item->addMoney('unit_price', $veh['unit_price']['currency'], $veh['unit_price']['amount'], $veh['unit_price']['rate'], '单价'); + $item->addMoney('total_price', $veh['total_price']['currency'], $veh['total_price']['amount'], $veh['total_price']['rate'], '总价'); + $item->addMoney('handling_fee', $veh['handling_fee']['currency'], $veh['handling_fee']['amount'], $veh['handling_fee']['rate'], '手续费'); + $item->addMoney('fob_transport_fee', $veh['fob_transport_fee']['currency'], $veh['fob_transport_fee']['amount'], $veh['fob_transport_fee']['rate'], 'FOB运输费'); + $item->addMoney('port_misc_fee', $veh['port_misc_fee']['currency'], $veh['port_misc_fee']['amount'], $veh['port_misc_fee']['rate'], '港杂'); + $item->addMoney('retrofit_fee', $veh['retrofit_fee']['currency'], $veh['retrofit_fee']['amount'], $veh['retrofit_fee']['rate'], '改装费'); - // 改装 - foreach ($data['veh_list']['modify_list'] as $modify) { - $modify['order_item_id'] = $item->id; - StockOrderItemOptions::create($modify); // 表4 + // 改装 + if (count($veh['modify_list']) > 0) { + foreach ($veh['modify_list'] as $modify) { + $modify['order_item_id'] = $item->id; + StockOrderItemOptions::create($modify); // 表4 + } + } } - } - // 账户 - foreach ($data['account_list'] as $account) { - $account['order_id'] = $created->id; - StockOrderAccounts::create($account); // 表5 - } - return $this->postProcess('Store', $created); + // 账户 + if (count($data['account_list']) > 0) { + foreach ($data['account_list'] as $account) { + $account['order_id'] = $created->id; + $account['remit_date'] = strtotime($account['remit_date']); + StockOrderAccounts::create($account); // 表5 + } + } + + return $this->postProcess('Store', $created); + }); } public function beforeServiceStore($data, Request $request) @@ -110,10 +126,6 @@ class StockOrdersService $data['salesperson_id'] = $userId; $data['salesperson_snapshot'] = User::where('id', $userId)->value('name') ?? ''; - var_dump($data); - - throw new BusinessException('测试异常'); - return $data; } diff --git a/app/common/service/VehVehicleSkuService.php b/app/common/service/VehVehicleSkuService.php index d2679ab..0fa8649 100644 --- a/app/common/service/VehVehicleSkuService.php +++ b/app/common/service/VehVehicleSkuService.php @@ -140,6 +140,8 @@ class VehVehicleSkuService public function beforeServiceUpdate($data, Request $request) { + unset($data['created_at']); + unset($data['updated_at']); // $data = $this->backfill($data); if (empty($data['model_code'])) { $data['model_code'] = ModelNaming::buildModelCode($data); diff --git a/app/queue/redis/InquiryToCrmNew_BACKUP_5243.php b/app/queue/redis/InquiryToCrmNew_BACKUP_5243.php deleted file mode 100644 index d63b683..0000000 --- a/app/queue/redis/InquiryToCrmNew_BACKUP_5243.php +++ /dev/null @@ -1,218 +0,0 @@ -where('id', $data['id'])->first(); - - // 无论添加 或 更新,询单必然要存在 - if (!$info) { - throw new BusinessException('询盘不存在:' . $data['id']); - } - - if ($info->status == 0 && $info->recipient == 0) { - // 如果询单未发、未分,则不与crm同步,不做任何处理 - return true; - } - - // 更改库信息 - $this->syncCustomer($info); - } catch (\Throwable $th) { - throw $th; - } - } - - public function pushWs($title, $content, $recipient = []) - { - $wsdata = [ - 'sender_id' => 0, - 'sender_type' => 'system', - 'title' => $title, - 'content' => $content, - 'scene' => 1, - 'recipient' => $recipient - ]; - // 异步推送 - \Webman\RedisQueue\Redis::send('notice', $wsdata); - } - - public function syncCustomer(Model $info) - { - $uInfo = $this->recipientInfo($info); - $crmCustomerInfo = CrmCustomer::where('sn', $info->order_no)->first(); - if ($crmCustomerInfo) { - - // 消息推送 - if ($info->status == 2 && empty($crmCustomerInfo->user_id)) { - // $notice = '分配'; - $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } else { - if ($info->status == 2 && $crmCustomerInfo->user_id == $info->recipient) { - // $notice = '更新'; - $title = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理'; - $content = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } else { - // $notice = '重新分配'; - $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } - } - - $udata = [ -<<<<<<< HEAD - 'corp_abbr' => $uInfo['corpId'], -======= - 'corp_id' => $uInfo['corpId'], ->>>>>>> feature/distinct - 'user_id' => $info->recipient, - 'channel_id' => $info->channel, - 'country_id' => $info->country, - 'magnitude' => $info->quality, - 'email' => $info->email, - 'phone' => $info->tel, - 'WhatsApp' => $info->whatsapp, - 'contacts' => $info->contacts, - 'desc_collect' => $info->content, - ]; - if (!$crmCustomerInfo->update($udata)) { - throw new BusinessException('同步失败,更新客户线索失败'); - } - } else { - $crmCustomer = new CrmCustomer(); - $crmCustomer->sn = $info->order_no; -<<<<<<< HEAD - $crmCustomer->corp_abbr = $uInfo['corpId']; -======= - $crmCustomer->corp_id = $uInfo['corpId']; ->>>>>>> feature/distinct - $crmCustomer->user_id = $uInfo['recipient']; - $crmCustomer->type = 1; - $crmCustomer->channel_id = $info->channel; - $crmCustomer->country_id = $info->country; - $crmCustomer->magnitude = $info->quality; - $crmCustomer->email = $info->email; - $crmCustomer->phone = $info->tel; - $crmCustomer->WhatsApp = $info->whatsapp; - $crmCustomer->contacts = $info->contacts; - $crmCustomer->desc_collect = $info->content; - $crmCustomer->enter_user_id = $info->enter_user_id; - $crmCustomer->obtain = time(); -<<<<<<< HEAD -======= - if(empty($uInfo['recipient'])){ - $crmCustomer->deleted_at = time(); - } ->>>>>>> feature/distinct - // 修改同步CRM状态 - $info->sync_crm = 1; - // 保存 - if (!$crmCustomer->save() || !$info->save()) { - throw new BusinessException('同步失败,创建客户线索失败'); - } - - // 消息推送 - if ($info->status == 1) { - // $notice = '发布'; - $title = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布'; - $content = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content); - } - - if ($info->status == 2) { - // $notice = '分配'; - $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } - } - return true; - } - - public function recipientInfo(Model $info) - { - $recipient = 0; - $corpId = 0; - $uinfo = null; - if (!empty($info->recipient)) { - $recipient = $info->recipient; - $uinfo = User::where('id', $info->recipient)->first(); - if ($uinfo) { - $corpId = $uinfo->corp_id; - } - } - return [ - 'recipient' => $recipient, - 'corpId' => $corpId, - 'uinfo' => $uinfo - ]; - } - - // 消费失败回调 - /* - $package = [ - 'id' => 1357277951, // 消息ID - 'time' => 1709170510, // 消息时间 - 'delay' => 0, // 延迟时间 - 'attempts' => 2, // 消费次数 - 'queue' => 'send-mail', // 队列名 - 'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容 - 'max_attempts' => 5, // 最大重试次数 - 'error' => '错误信息' // 错误信息 - ] - */ - public function onConsumeFailure(\Throwable $e, $package) - { - echo "consume failure\n"; - echo $e->getMessage() . "\n"; - // 无需反序列化 - var_export($package); - } -} \ No newline at end of file diff --git a/app/queue/redis/InquiryToCrmNew_BASE_5243.php b/app/queue/redis/InquiryToCrmNew_BASE_5243.php deleted file mode 100644 index e69de29..0000000 diff --git a/app/queue/redis/InquiryToCrmNew_LOCAL_5243.php b/app/queue/redis/InquiryToCrmNew_LOCAL_5243.php deleted file mode 100644 index a350c7e..0000000 --- a/app/queue/redis/InquiryToCrmNew_LOCAL_5243.php +++ /dev/null @@ -1,204 +0,0 @@ -where('id', $data['id'])->first(); - - // 无论添加 或 更新,询单必然要存在 - if (!$info) { - throw new BusinessException('询盘不存在:' . $data['id']); - } - - if ($info->status == 0 && $info->recipient == 0) { - // 如果询单未发、未分,则不与crm同步,不做任何处理 - return true; - } - - // 更改库信息 - $this->syncCustomer($info); - } catch (\Throwable $th) { - throw $th; - } - } - - public function pushWs($title, $content, $recipient = []) - { - $wsdata = [ - 'sender_id' => 0, - 'sender_type' => 'system', - 'title' => $title, - 'content' => $content, - 'scene' => 1, - 'recipient' => $recipient - ]; - // 异步推送 - \Webman\RedisQueue\Redis::send('notice', $wsdata); - } - - public function syncCustomer(Model $info) - { - $uInfo = $this->recipientInfo($info); - $crmCustomerInfo = CrmCustomer::where('sn', $info->order_no)->first(); - if ($crmCustomerInfo) { - - // 消息推送 - if ($info->status == 2 && empty($crmCustomerInfo->user_id)) { - // $notice = '分配'; - $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } else { - if ($info->status == 2 && $crmCustomerInfo->user_id == $info->recipient) { - // $notice = '更新'; - $title = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理'; - $content = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } else { - // $notice = '重新分配'; - $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } - } - - $udata = [ - 'corp_abbr' => $uInfo['corpId'], - 'user_id' => $info->recipient, - 'channel_id' => $info->channel, - 'country_id' => $info->country, - 'magnitude' => $info->quality, - 'email' => $info->email, - 'phone' => $info->tel, - 'WhatsApp' => $info->whatsapp, - 'contacts' => $info->contacts, - 'desc_collect' => $info->content, - ]; - if (!$crmCustomerInfo->update($udata)) { - throw new BusinessException('同步失败,更新客户线索失败'); - } - } else { - $crmCustomer = new CrmCustomer(); - $crmCustomer->sn = $info->order_no; - $crmCustomer->corp_abbr = $uInfo['corpId']; - $crmCustomer->user_id = $uInfo['recipient']; - $crmCustomer->type = 1; - $crmCustomer->channel_id = $info->channel; - $crmCustomer->country_id = $info->country; - $crmCustomer->magnitude = $info->quality; - $crmCustomer->email = $info->email; - $crmCustomer->phone = $info->tel; - $crmCustomer->WhatsApp = $info->whatsapp; - $crmCustomer->contacts = $info->contacts; - $crmCustomer->desc_collect = $info->content; - $crmCustomer->enter_user_id = $info->enter_user_id; - $crmCustomer->obtain = time(); - // 修改同步CRM状态 - $info->sync_crm = 1; - // 保存 - if (!$crmCustomer->save() || !$info->save()) { - throw new BusinessException('同步失败,创建客户线索失败'); - } - - // 消息推送 - if ($info->status == 1) { - // $notice = '发布'; - $title = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布'; - $content = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content); - } - - if ($info->status == 2) { - // $notice = '分配'; - $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } - } - return true; - } - - public function recipientInfo(Model $info) - { - $recipient = 0; - $corpId = 0; - $uinfo = null; - if (!empty($info->recipient)) { - $recipient = $info->recipient; - $uinfo = User::where('id', $info->recipient)->first(); - if ($uinfo) { - $corpId = $uinfo->corp_id; - } - } - return [ - 'recipient' => $recipient, - 'corpId' => $corpId, - 'uinfo' => $uinfo - ]; - } - - // 消费失败回调 - /* - $package = [ - 'id' => 1357277951, // 消息ID - 'time' => 1709170510, // 消息时间 - 'delay' => 0, // 延迟时间 - 'attempts' => 2, // 消费次数 - 'queue' => 'send-mail', // 队列名 - 'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容 - 'max_attempts' => 5, // 最大重试次数 - 'error' => '错误信息' // 错误信息 - ] - */ - public function onConsumeFailure(\Throwable $e, $package) - { - echo "consume failure\n"; - echo $e->getMessage() . "\n"; - // 无需反序列化 - var_export($package); - } -} \ No newline at end of file diff --git a/app/queue/redis/InquiryToCrmNew_REMOTE_5243.php b/app/queue/redis/InquiryToCrmNew_REMOTE_5243.php deleted file mode 100644 index 075deda..0000000 --- a/app/queue/redis/InquiryToCrmNew_REMOTE_5243.php +++ /dev/null @@ -1,207 +0,0 @@ -where('id', $data['id'])->first(); - - // 无论添加 或 更新,询单必然要存在 - if (!$info) { - throw new BusinessException('询盘不存在:' . $data['id']); - } - - if ($info->status == 0 && $info->recipient == 0) { - // 如果询单未发、未分,则不与crm同步,不做任何处理 - return true; - } - - // 更改库信息 - $this->syncCustomer($info); - } catch (\Throwable $th) { - throw $th; - } - } - - public function pushWs($title, $content, $recipient = []) - { - $wsdata = [ - 'sender_id' => 0, - 'sender_type' => 'system', - 'title' => $title, - 'content' => $content, - 'scene' => 1, - 'recipient' => $recipient - ]; - // 异步推送 - \Webman\RedisQueue\Redis::send('notice', $wsdata); - } - - public function syncCustomer(Model $info) - { - $uInfo = $this->recipientInfo($info); - $crmCustomerInfo = CrmCustomer::where('sn', $info->order_no)->first(); - if ($crmCustomerInfo) { - - // 消息推送 - if ($info->status == 2 && empty($crmCustomerInfo->user_id)) { - // $notice = '分配'; - $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } else { - if ($info->status == 2 && $crmCustomerInfo->user_id == $info->recipient) { - // $notice = '更新'; - $title = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理'; - $content = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } else { - // $notice = '重新分配'; - $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } - } - - $udata = [ - 'corp_id' => $uInfo['corpId'], - 'user_id' => $info->recipient, - 'channel_id' => $info->channel, - 'country_id' => $info->country, - 'magnitude' => $info->quality, - 'email' => $info->email, - 'phone' => $info->tel, - 'WhatsApp' => $info->whatsapp, - 'contacts' => $info->contacts, - 'desc_collect' => $info->content, - ]; - if (!$crmCustomerInfo->update($udata)) { - throw new BusinessException('同步失败,更新客户线索失败'); - } - } else { - $crmCustomer = new CrmCustomer(); - $crmCustomer->sn = $info->order_no; - $crmCustomer->corp_id = $uInfo['corpId']; - $crmCustomer->user_id = $uInfo['recipient']; - $crmCustomer->type = 1; - $crmCustomer->channel_id = $info->channel; - $crmCustomer->country_id = $info->country; - $crmCustomer->magnitude = $info->quality; - $crmCustomer->email = $info->email; - $crmCustomer->phone = $info->tel; - $crmCustomer->WhatsApp = $info->whatsapp; - $crmCustomer->contacts = $info->contacts; - $crmCustomer->desc_collect = $info->content; - $crmCustomer->enter_user_id = $info->enter_user_id; - $crmCustomer->obtain = time(); - if(empty($uInfo['recipient'])){ - $crmCustomer->deleted_at = time(); - } - // 修改同步CRM状态 - $info->sync_crm = 1; - // 保存 - if (!$crmCustomer->save() || !$info->save()) { - throw new BusinessException('同步失败,创建客户线索失败'); - } - - // 消息推送 - if ($info->status == 1) { - // $notice = '发布'; - $title = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布'; - $content = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content); - } - - if ($info->status == 2) { - // $notice = '分配'; - $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; - $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); - } - } - return true; - } - - public function recipientInfo(Model $info) - { - $recipient = 0; - $corpId = 0; - $uinfo = null; - if (!empty($info->recipient)) { - $recipient = $info->recipient; - $uinfo = User::where('id', $info->recipient)->first(); - if ($uinfo) { - $corpId = $uinfo->corp_id; - } - } - return [ - 'recipient' => $recipient, - 'corpId' => $corpId, - 'uinfo' => $uinfo - ]; - } - - // 消费失败回调 - /* - $package = [ - 'id' => 1357277951, // 消息ID - 'time' => 1709170510, // 消息时间 - 'delay' => 0, // 延迟时间 - 'attempts' => 2, // 消费次数 - 'queue' => 'send-mail', // 队列名 - 'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容 - 'max_attempts' => 5, // 最大重试次数 - 'error' => '错误信息' // 错误信息 - ] - */ - public function onConsumeFailure(\Throwable $e, $package) - { - echo "consume failure\n"; - echo $e->getMessage() . "\n"; - // 无需反序列化 - var_export($package); - } -} \ No newline at end of file