diff --git a/app/admin/controller/SysAccountController.php b/app/admin/controller/SysAccountController.php index 64398bb..aa4b132 100644 --- a/app/admin/controller/SysAccountController.php +++ b/app/admin/controller/SysAccountController.php @@ -30,7 +30,8 @@ class SysAccountController extends BaseController $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); - $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name'); + if (isset($data['currency_name'])) + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name'); return $data; } @@ -46,7 +47,8 @@ class SysAccountController extends BaseController $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); - $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name'); + if (isset($data['currency_name'])) + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name'); return $data; } } \ No newline at end of file diff --git a/app/admin/controller/SysCurrencyController.php b/app/admin/controller/SysCurrencyController.php index 0e96169..db9d589 100644 --- a/app/admin/controller/SysCurrencyController.php +++ b/app/admin/controller/SysCurrencyController.php @@ -2,6 +2,7 @@ namespace app\admin\controller; use app\common\controller\BaseController; +use app\common\model\Country; use app\common\traits\crud\CrudControllerTrait; use app\admin\service\SysCurrencyService; @@ -30,6 +31,11 @@ class SysCurrencyController extends BaseController $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); if (isset($data['last_updated'])) $data['last_updated'] = date('Y-m-d H:i:s', $data['last_updated']); + if (isset($data['country_id'])){ + $data['country_name'] = Country::where('id',$data['country_id'])->value('item_label'); + } else { + $data['country_name'] = ''; + } return $data; } @@ -47,6 +53,11 @@ class SysCurrencyController extends BaseController $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); if (isset($data['last_updated'])) $data['last_updated'] = date('Y-m-d H:i:s', $data['last_updated']); + if (isset($data['country_id'])){ + $data['country_name'] = Country::where('id',$data['country_id'])->value('item_label'); + } else { + $data['country_name'] = ''; + } return $data; } } \ No newline at end of file diff --git a/app/admin/controller/SysDictCategoryController.php b/app/admin/controller/SysDictCategoryController.php new file mode 100644 index 0000000..c0c2593 --- /dev/null +++ b/app/admin/controller/SysDictCategoryController.php @@ -0,0 +1,60 @@ +service = new SysDictCategoryService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } + + public function preset(Request $request) + { + try { + $params = $request->all(); + $result = (new SysDictCategoryService)->getList($params); + return $this->success($result, '获取字典项列表'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/admin/controller/SysDictController.php b/app/admin/controller/SysDictController.php index 34be3e1..b75f923 100644 --- a/app/admin/controller/SysDictController.php +++ b/app/admin/controller/SysDictController.php @@ -32,7 +32,11 @@ class SysDictController extends BaseController $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); - + if (isset($data['category_id'])){ + $data['category'] = SysDictItem::where('id',$data['category_id'])->value('item_label'); + } else { + $data['category'] = ''; + } return $data; } @@ -75,4 +79,17 @@ class SysDictController extends BaseController return $this->error($e->getMessage()); } } + + public function group(Request $request) + { + try { + $raw = $this->service->group($request); + $data = $this->transformData($raw, method_exists($this, 'groupFormat') + ? [$this, 'groupFormat'] + : null); + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/admin/controller/VehColorController.php b/app/admin/controller/VehColorController.php index 0d208ae..9f17c7c 100644 --- a/app/admin/controller/VehColorController.php +++ b/app/admin/controller/VehColorController.php @@ -22,12 +22,27 @@ class VehColorController extends BaseController * @param array $data * @return array */ - // protected function indexFormat($data) - // { - // if (isset($data['created_at'])) - // $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); - // if (isset($data['updated_at'])) - // $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); - // return $data; - // } + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } } \ No newline at end of file diff --git a/app/admin/logic/SysDictCategoryLogic.php b/app/admin/logic/SysDictCategoryLogic.php new file mode 100644 index 0000000..6d8c413 --- /dev/null +++ b/app/admin/logic/SysDictCategoryLogic.php @@ -0,0 +1,21 @@ +orderBy('sort','desc')->get(['id', 'category_name']); + } +} \ No newline at end of file diff --git a/app/admin/service/SysDictCategoryService.php b/app/admin/service/SysDictCategoryService.php new file mode 100644 index 0000000..28e7be6 --- /dev/null +++ b/app/admin/service/SysDictCategoryService.php @@ -0,0 +1,40 @@ +validator; + } + /** + * 获取系统list + */ + public function getList($params) + { + return (new SysDictCategoryLogic)->getList(); + } +} \ No newline at end of file diff --git a/app/admin/service/SysDictService.php b/app/admin/service/SysDictService.php index 1261c30..859628c 100644 --- a/app/admin/service/SysDictService.php +++ b/app/admin/service/SysDictService.php @@ -50,6 +50,10 @@ class SysDictService if (isset($p['status']) && in_array($p['status'], [0,1])) { $config['where']['status'] = $p['status']; } + // 分类筛选 + if (isset($p['category_id']) && !empty($p['category_id'])) { + $config['where']['category_id'] = $p['category_id']; + } // 关键字 if (isset($p['keyword']) && $p['keyword']) { $k = '%' . $p['keyword'] . '%'; @@ -83,11 +87,25 @@ class SysDictService $config['with']['sysDictItem'][] = 'item_label'; $config['with']['sysDictItem'][] = 'item_value'; break; + case 'group': + $config['order']['id'] = 'desc'; + $config['where']['id'] = 1; + $config['with']['sysDictItem'][] = 'dict_id'; + $config['with']['sysDictItem'][] = 'item_label'; + $config['with']['sysDictItem'][] = 'item_value'; + break; } return $config; } + public function group(Request $request) + { + $config = $this->buildQueryConfig($request, 'group'); + $result = $this->logicShow($config); + return $this->postProcess('group', $result); + } + public function serviceListAllScope(Request $request) { diff --git a/app/admin/service/SysPortService.php b/app/admin/service/SysPortService.php index 7a2dfd0..6e8774c 100644 --- a/app/admin/service/SysPortService.php +++ b/app/admin/service/SysPortService.php @@ -58,6 +58,14 @@ class SysPortService $config['orWhere'][] = [$col, 'like', $k]; } } + // 场景 + if (isset($p['scene']) && $p['scene']) { + if($p['country_id'] == 'domestic'){ + $config['where']['country_id'] = 45; + }else{ + $config['where']['country_id'] = ['<>', 45]; + } + } //$config['where']['status'] = 1; break; case 'show': diff --git a/app/admin/validate/SysDictCategoryValidate.php b/app/admin/validate/SysDictCategoryValidate.php new file mode 100644 index 0000000..f494854 --- /dev/null +++ b/app/admin/validate/SysDictCategoryValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/common/controller/PresetController.php b/app/common/controller/PresetController.php index 0d3ebf1..1abe3de 100644 --- a/app/common/controller/PresetController.php +++ b/app/common/controller/PresetController.php @@ -147,10 +147,11 @@ class PresetController extends BaseController } } - public function port() + public function port(Request $request) { try { - $result = (new SysPortService)->getList(); + $params = $request->all(); + $result = (new SysPortService)->getList($params); return $this->success($result, '获取港口列表'); } catch (\Throwable $e) { return $this->error($e->getMessage()); diff --git a/app/common/logic/SysCurrencyLogic.php b/app/common/logic/SysCurrencyLogic.php index 206efa2..4de7559 100644 --- a/app/common/logic/SysCurrencyLogic.php +++ b/app/common/logic/SysCurrencyLogic.php @@ -16,6 +16,6 @@ class SysCurrencyLogic public function getList() { - return SysCurrency::where('status', 1)->get(['id', 'currency_code', 'currency_name', 'currency_symbol', 'exchange_rate', 'float_percent']); + return SysCurrency::where('status', 1)->get(['id', 'country_id', 'currency_code', 'currency_name', 'currency_symbol', 'exchange_rate', 'float_percent_up', 'float_percent_down']); } } \ No newline at end of file diff --git a/app/common/logic/SysPortLogic.php b/app/common/logic/SysPortLogic.php index a2e78a8..e12c260 100644 --- a/app/common/logic/SysPortLogic.php +++ b/app/common/logic/SysPortLogic.php @@ -14,9 +14,9 @@ class SysPortLogic */ protected string $modelClass = SysPort::class; - public function getList() + public function getList($where) { - return SysPort::where('status', 1)->orderBy('sort','desc')->get(['id', 'port_code', 'port_name', 'country_id', 'description']); + return SysPort::where('status', 1)->where($where)->orderBy('sort','desc')->get(['id', 'port_code', 'port_name', 'country_id', 'description']); } } \ No newline at end of file diff --git a/app/common/model/SysAccount.php b/app/common/model/SysAccount.php index def900f..693e823 100644 --- a/app/common/model/SysAccount.php +++ b/app/common/model/SysAccount.php @@ -40,7 +40,7 @@ class SysAccount extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'account_name', 'account_type', 'account_number', 'account_holder', 'bank_name', 'bank_branch', 'daily_limit', 'single_limit', 'description', 'status', 'sort', 'created_at', 'updated_at']; + protected $fillable = ['id', 'currency_id', 'account_name', 'account_number', 'account_holder', 'bank_name', 'bank_branch', 'daily_limit', 'single_limit', 'description', 'status', 'sort', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 diff --git a/app/common/model/SysCurrency.php b/app/common/model/SysCurrency.php index 200a23b..57b4339 100644 --- a/app/common/model/SysCurrency.php +++ b/app/common/model/SysCurrency.php @@ -40,7 +40,7 @@ class SysCurrency extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'currency_code', 'currency_name', 'currency_symbol', 'exchange_rate', 'base_currency', 'float_percent', 'status', 'last_updated', 'created_at', 'updated_at']; + protected $fillable = ['id', 'country_id', 'currency_code', 'currency_name', 'currency_symbol', 'exchange_rate', 'base_currency', 'float_percent_up', 'float_percent_down', 'status', 'last_updated', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 diff --git a/app/common/model/SysDict.php b/app/common/model/SysDict.php index 7ef5a62..ad7cf5c 100644 --- a/app/common/model/SysDict.php +++ b/app/common/model/SysDict.php @@ -43,7 +43,7 @@ class SysDict extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'dict_name', 'dict_code', 'description', 'status', 'created_at', 'updated_at', 'deleted_at']; + protected $fillable = ['id', 'category_id', 'dict_name', 'dict_code', 'description', 'status', 'created_at', 'updated_at', 'deleted_at']; /** * 不允许自动填充模型字段 diff --git a/app/common/model/SysDictCategory.php b/app/common/model/SysDictCategory.php new file mode 100644 index 0000000..fef0219 --- /dev/null +++ b/app/common/model/SysDictCategory.php @@ -0,0 +1,49 @@ +logic->getList(); + $where = []; + if(isset($params['scene']) && $params['scene']) { + if($params['scene'] == 'domestic'){ + $where['country_id'] = 45; + }else{ + $where['country_id'] = ['<>', 45]; + } + } + return $this->logic->getList($where); } } \ No newline at end of file diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index 0860af8..b2e125e 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -205,6 +205,25 @@ class CustomerController extends BaseController } } + /** + * 客户下拉 + * @param Request $request + * @return \support\Response + */ + public function preset(Request $request) + { + try { + $param = $request->all(); + $param['user_id'] = $request->user->uid; + $param['corp_abbr'] = $request->basic_data['corp_abbr']; + $result = (new CustomerService())->preset($param); + + return $this->success($result); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 客户恢复 * @param Request $request diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index c20ceab..c08b21d 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -164,6 +164,39 @@ class CustomerService return $customer; } + public function preset($params) + { + $keyword = $params['keyword'] ?? ''; + $where = []; + $user_id =$params['user_id']; + + $where[] = ['status', 1]; + $where[] = ['user_id', $user_id]; + + if (!empty($countryId)){ + $where[] = ['country_id', $countryId]; + } + + $query = Customer::select('id','code','sn','corp_id','email','phone','WhatsApp','contacts','company')->where($where); + + if (!Util::isEmpty($keyword)) { + $query->where(function ($query) use ($keyword) { + $query->where('contacts', 'like', "%{$keyword}%") + ->orWhere('phone', 'like', "%{$keyword}%") + ->orWhere('email', 'like', "%{$keyword}%") + ->orWhere('WhatsApp', 'like', "%{$keyword}%") + ->orWhere('code', 'like', "%{$keyword}%"); + }); + } + $customer = $query->orderBy('follow_last','desc')->get(); + + foreach ($customer as &$item) { + } + unset($item); + + return $customer; + } + /** 分页列表 */ public function serviceList(Request $request) diff --git a/app/queue/redis/InquiryToCrmNew_BACKUP_5243.php b/app/queue/redis/InquiryToCrmNew_BACKUP_5243.php new file mode 100644 index 0000000..d63b683 --- /dev/null +++ b/app/queue/redis/InquiryToCrmNew_BACKUP_5243.php @@ -0,0 +1,218 @@ +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 new file mode 100644 index 0000000..e69de29 diff --git a/app/queue/redis/InquiryToCrmNew_LOCAL_5243.php b/app/queue/redis/InquiryToCrmNew_LOCAL_5243.php new file mode 100644 index 0000000..a350c7e --- /dev/null +++ b/app/queue/redis/InquiryToCrmNew_LOCAL_5243.php @@ -0,0 +1,204 @@ +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 new file mode 100644 index 0000000..075deda --- /dev/null +++ b/app/queue/redis/InquiryToCrmNew_REMOTE_5243.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/config/route.php b/config/route.php index 586a191..018d437 100644 --- a/config/route.php +++ b/config/route.php @@ -212,6 +212,8 @@ Route::group('/admin', function () { Route::any('/update', [app\admin\controller\SysDictController::class, 'update']); Route::any('/destroy', [app\admin\controller\SysDictController::class, 'destroy']); Route::any('/scope', [app\admin\controller\SysDictController::class, 'listScope']); + // 字典分类 + Route::any('/group', [app\admin\controller\SysDictController::class, 'group']); Route::group('/item', function () { Route::any('/list', [app\admin\controller\SysDictItemController::class, 'index']); @@ -220,6 +222,7 @@ Route::group('/admin', function () { Route::any('/update', [app\admin\controller\SysDictItemController::class, 'update']); Route::any('/destroy', [app\admin\controller\SysDictItemController::class, 'destroy']); }); + }); // 货币 @@ -337,6 +340,7 @@ Route::group('/crm', function () { Route::any('/customer/followNext', [app\crm\controller\CustomerController::class, 'followNext']); Route::any('/customer/report', [app\crm\controller\CustomerController::class, 'report']); Route::any('/customer/distinctNotice', [app\crm\controller\CustomerController::class, 'distinctNotice']); + Route::any('/customer/preset', [app\crm\controller\CustomerController::class, 'preset']); Route::any('/tagGroup/list', [app\crm\controller\TagGroupController::class, 'list']); Route::any('/tagGroup/updatePivot', [app\crm\controller\TagGroupController::class, 'updatePivot']);