diff --git a/app/common/utils/WsEvents.php b/app/common/utils/WsEvents.php index 12f1a2c..96596b8 100644 --- a/app/common/utils/WsEvents.php +++ b/app/common/utils/WsEvents.php @@ -314,7 +314,7 @@ class WsEvents $data['is_report_to'] = true; } - if ($user->sign_img !== null || $user->is_sign !== '') { + if ($user->sign_img !== null && $user->sign_img !== '') { $data['is_sign'] = true; } diff --git a/app/queue/redis/EmailMessage.php b/app/queue/redis/EmailMessage.php index 7291868..f170a78 100644 --- a/app/queue/redis/EmailMessage.php +++ b/app/queue/redis/EmailMessage.php @@ -22,7 +22,7 @@ class EmailMessage implements Consumer $inquiryLogService = new InquiryLogService(); $content = $inquiryLogService->getContent($data['id']); - MailSend::send($data['email'], '【XYH】新的客户线索', replaceTpl($content)); + MailSend::send($data['email'], $data['title'], replaceTpl($content)); } catch (\Throwable $th) { throw $th; } diff --git a/app/queue/redis/InquiryToCrmNew.php b/app/queue/redis/InquiryToCrmNew.php index 297359a..2ad666f 100644 --- a/app/queue/redis/InquiryToCrmNew.php +++ b/app/queue/redis/InquiryToCrmNew.php @@ -75,6 +75,16 @@ class InquiryToCrmNew implements Consumer \Webman\RedisQueue\Redis::send('notice', $wsdata); } + public function pushEmail($id, $title, $email) + { + $options = [ + 'id' => $id, + 'email' => $email, + 'title' => $title, + ]; + \Webman\RedisQueue\Redis::send('email-message', $options); + } + public function syncCustomer(Model $info) { $uInfo = $this->recipientInfo($info); @@ -87,25 +97,28 @@ class InquiryToCrmNew implements Consumer $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); + // $this->pushWs($title, $content, $recipient); + $this->pushEmail($info->id, $title, $uInfo['uinfo']['email']); } 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); + // $this->pushWs($title, $content, $recipient); + $this->pushEmail($info->id, $title, $uInfo['uinfo']['email']); } else { // $notice = '重新分配'; $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); + // $this->pushWs($title, $content, $recipient); + $this->pushEmail($info->id, $title, $uInfo['uinfo']['email']); } } $udata = [ - 'corp_id' => $uInfo['corpId'], + 'corp_id' => $uInfo['corpId'], 'user_id' => $info->recipient, 'channel_id' => $info->channel, 'country_id' => $info->country, @@ -151,7 +164,8 @@ class InquiryToCrmNew implements Consumer $title = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布'; $content = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布'; $recipient = [$info->recipient]; - $this->pushWs($title, $content); + // $this->pushWs($title, $content); + $this->pushEmail($info->id, $title, $uInfo['uinfo']['email']); } if ($info->status == 2) { @@ -159,7 +173,8 @@ class InquiryToCrmNew implements Consumer $title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; $content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理'; $recipient = [$info->recipient]; - $this->pushWs($title, $content, $recipient); + // $this->pushWs($title, $content, $recipient); + $this->pushEmail($info->id, $title, $uInfo['uinfo']['email']); } } return true; diff --git a/app/queue/redis/InquiryToCrmNew_bak.php b/app/queue/redis/InquiryToCrmNew_bak.php new file mode 100644 index 0000000..23dc724 --- /dev/null +++ b/app/queue/redis/InquiryToCrmNew_bak.php @@ -0,0 +1,207 @@ +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 diff --git a/app/queue/redis/InquiryToCrmUpdate_bak.php b/app/queue/redis/InquiryToCrmUpdate_bak.php deleted file mode 100644 index 8dc3140..0000000 --- a/app/queue/redis/InquiryToCrmUpdate_bak.php +++ /dev/null @@ -1,113 +0,0 @@ -where('id', $data['id'])->first(); - - $corpId = 0; - if ($info->recipient) { - $uinfo = User::where('id', $info->recipient)->where('status', 1)->first(); - if ($uinfo) { - $corpId = $uinfo->corp_id; - } - } - - // 获取客户信息 - $crmCustomerInfo = CrmCustomer::where('sn', $info->order_no)->first(); - if ($crmCustomerInfo) { - $udata = [ - 'corp_id' => $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, - ]; - $crmCustomerInfo->update($udata); - } else { - // 同步客户数据 - $crmCustomer = new CrmCustomer(); - $crmCustomer->sn = $info->order_no; - $crmCustomer->corp_id = $corpId; - $crmCustomer->user_id = $info->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; - if(empty($info->recipient)){ - $crmCustomer->deleted_at = time(); - } - // 修改同步CRM状态 - $info->sync_crm = 1; - // 保存 - if (!$crmCustomer->save() || !$info->save()) { - throw new BusinessException('同步失败~'); - } - - // 发送邮件消息 - if ($uinfo && $uinfo->email) { - $options = [ - 'id' => $info->id, - 'email' => $uinfo->email - ]; - \Webman\RedisQueue\Redis::send('email-message', $options); - } - } - } catch (\Throwable $th) { - throw $th; - } - } - - // 消费失败回调 - /* - $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/InquiryToCrm_bak.php b/app/queue/redis/InquiryToCrm_bak.php deleted file mode 100644 index c6f3b15..0000000 --- a/app/queue/redis/InquiryToCrm_bak.php +++ /dev/null @@ -1,113 +0,0 @@ -where('id', $data['id'])->where('sync_crm', 0)->first(); - - if ($info) { - // 获取用户信息 - $recipient = 0; - $corpId = 0; - $uinfo = null; - if ($info->recipient) { - $recipient = $info->recipient; - $uinfo = User::where('id', $info->recipient)->first(); - if ($uinfo) { - $corpId = $uinfo->corp_id; - } - } - // 同步客户数据 - $crmCustomer = new CrmCustomer(); - $crmCustomer->sn = $info->order_no; - $crmCustomer->corp_id = $corpId; - $crmCustomer->user_id = $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($recipient)){ - $crmCustomer->deleted_at = time(); - } - // 修改同步CRM状态 - $info->sync_crm = 1; - // 保存 - if (!$crmCustomer->save() || !$info->save()) { - throw new BusinessException('同步失败~'); - } - - // // 发送邮件消息 - // if ($uinfo && $uinfo->email) { - // $options = [ - // 'id' => $info->id, - // 'email' => $uinfo->email - // ]; - // // Log::info('发送邮件消息:' . json_encode($options)); - // \Webman\RedisQueue\Redis::send('email-message', $options); - // } - - $wsdata = [ - 'sender_id' => 0, - 'sender_type' => 'system', - 'title' => '有新的客户线索,' . $info->order_no . ',请及时处理', - 'content' => '有新的客户线索,' . $info->order_no . ',请及时处理', - 'scene' => 1, - 'recipient' => [$info->recipient] - ]; - // 异步推送 - \Webman\RedisQueue\Redis::send('notice', $wsdata); - } - } catch (\Throwable $th) { - throw $th; - } - } - - // 消费失败回调 - /* - $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