1
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\SysDictService;
|
||||
|
||||
class SysDictController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new SysDictService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @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;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\SysDictItemService;
|
||||
|
||||
class SysDictItemController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new SysDictItemService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @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;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\SysDictItem;
|
||||
|
||||
class SysDictItemLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysDictItem::class;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\SysDict;
|
||||
|
||||
class SysDictLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysDict::class;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\SysDictItemValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysDictItem;
|
||||
|
||||
class SysDictItemService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysDictItem::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = SysDictItemValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\SysDictValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysDict;
|
||||
use support\Request;
|
||||
|
||||
class SysDictService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysDict::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = SysDictValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
// ====== ====== 排序 ====== ======
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
// 状态
|
||||
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
||||
$config['where']['status'] = $p['status'];
|
||||
}
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['dict_name','dict_code','description','whatsapp','contacts'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
|
||||
// ====== ====== 关联 ====== ======
|
||||
$config['with']['sysDictItem'][] = 'item_label';
|
||||
$config['with']['sysDictItem'][] = 'item_value';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
// ====== ====== 关联 ====== ======
|
||||
$config['with']['sysDictItem'][] = 'item_label';
|
||||
$config['with']['sysDictItem'][] = 'item_value';
|
||||
break;
|
||||
case 'update':
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class SysDictItemValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class SysDictValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use support\Model;
|
||||
|
||||
class SysDict extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sys_dict';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'dict_name', 'dict_code', 'description', 'status', 'created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
// 定义与 SysDictItem 的一对多关系
|
||||
public function sysDictItem()
|
||||
{
|
||||
return $this->hasMany(SysDictItem::class, 'dict_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use support\Model;
|
||||
|
||||
class SysDictItem extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sys_dict_item';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'dict_id', 'item_label', 'item_value', 'sort', 'status', 'remark', 'created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
// 定义反向多对一关联
|
||||
public function sysDict()
|
||||
{
|
||||
return $this->belongsTo(SysDict::class, 'dict_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -77,26 +77,26 @@ class IndexController
|
||||
{
|
||||
$options = [
|
||||
'controller' => [
|
||||
'module' => 'common',
|
||||
'name' => 'message_notifications'
|
||||
'module' => 'admin',
|
||||
'name' => 'sys_dict_item'
|
||||
],
|
||||
'model' => [
|
||||
'module' => 'common',
|
||||
'name' => 'message_notifications'
|
||||
'name' => 'sys_dict_item'
|
||||
],
|
||||
'service' => [
|
||||
'module' => 'common',
|
||||
'name' => 'message_notifications'
|
||||
'module' => 'admin',
|
||||
'name' => 'sys_dict_item'
|
||||
],
|
||||
'logic' => [
|
||||
'module' => 'common',
|
||||
'name' => 'message_notifications'
|
||||
'module' => 'admin',
|
||||
'name' => 'sys_dict_item'
|
||||
],
|
||||
'validate' => [
|
||||
'module' => 'common',
|
||||
'name' => 'message_notifications'
|
||||
'module' => 'admin',
|
||||
'name' => 'sys_dict_item'
|
||||
],
|
||||
'table' => 'message_notifications'
|
||||
'table' => 'sys_dict_item'
|
||||
];
|
||||
|
||||
$result = (new Generate($options))->doGenerate();
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\inquiry\service\InquiryLogService;
|
||||
use app\common\model\CrmCustomer;
|
||||
use app\common\model\InquiryLog;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
use app\common\model\User;
|
||||
use app\common\utils\FeishuMessage;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use support\Model;
|
||||
|
||||
class InquiryToCrmNew implements Consumer
|
||||
{
|
||||
// 要消费的队列名
|
||||
public $queue = 'inquiry-to-crm-new';
|
||||
|
||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||
public $connection = 'default';
|
||||
|
||||
// 消费
|
||||
public function consume($data)
|
||||
{
|
||||
|
||||
/*
|
||||
询单 与 CRM 之间的同步场景描述
|
||||
|
||||
添加(询单)
|
||||
添加 不发 不分 (不同步)1
|
||||
添加 发了 不分 (要同步)2
|
||||
添加 不发 分了 (要同步)3
|
||||
添加 不发 直分 (要同步)4
|
||||
|
||||
更新(询单)
|
||||
没发 没分 更新 (不同步)5
|
||||
没发 分过 更新 (要同步)6
|
||||
发过 没分 更新 (要同步)7
|
||||
发过 分过 更新 (要同步)8
|
||||
*/
|
||||
|
||||
try {
|
||||
// 获取询盘信息
|
||||
$info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\inquiry\service\InquiryLogService;
|
||||
use app\common\model\CrmCustomer;
|
||||
use app\common\model\InquiryLog;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
use app\common\model\User;
|
||||
use app\common\utils\FeishuMessage;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use support\Model;
|
||||
|
||||
class InquiryToCrmNew implements Consumer
|
||||
{
|
||||
// 要消费的队列名
|
||||
public $queue = 'inquiry-to-crm-new';
|
||||
|
||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||
public $connection = 'default';
|
||||
|
||||
// 消费
|
||||
public function consume($data)
|
||||
{
|
||||
|
||||
/*
|
||||
询单 与 CRM 之间的同步场景描述
|
||||
|
||||
添加(询单)
|
||||
添加 不发 不分 (不同步)1
|
||||
添加 发了 不分 (要同步)2
|
||||
添加 不发 分了 (要同步)3
|
||||
添加 不发 直分 (要同步)4
|
||||
|
||||
更新(询单)
|
||||
没发 没分 更新 (不同步)5
|
||||
没发 分过 更新 (要同步)6
|
||||
发过 没分 更新 (要同步)7
|
||||
发过 分过 更新 (要同步)8
|
||||
*/
|
||||
|
||||
try {
|
||||
// 获取询盘信息
|
||||
$info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\inquiry\service\InquiryLogService;
|
||||
use app\common\model\CrmCustomer;
|
||||
use app\common\model\InquiryLog;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
use app\common\model\User;
|
||||
use app\common\utils\FeishuMessage;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use support\Model;
|
||||
|
||||
class InquiryToCrmNew implements Consumer
|
||||
{
|
||||
// 要消费的队列名
|
||||
public $queue = 'inquiry-to-crm-new';
|
||||
|
||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||
public $connection = 'default';
|
||||
|
||||
// 消费
|
||||
public function consume($data)
|
||||
{
|
||||
|
||||
/*
|
||||
询单 与 CRM 之间的同步场景描述
|
||||
|
||||
添加(询单)
|
||||
添加 不发 不分 (不同步)1
|
||||
添加 发了 不分 (要同步)2
|
||||
添加 不发 分了 (要同步)3
|
||||
添加 不发 直分 (要同步)4
|
||||
|
||||
更新(询单)
|
||||
没发 没分 更新 (不同步)5
|
||||
没发 分过 更新 (要同步)6
|
||||
发过 没分 更新 (要同步)7
|
||||
发过 分过 更新 (要同步)8
|
||||
*/
|
||||
|
||||
try {
|
||||
// 获取询盘信息
|
||||
$info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->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);
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,23 @@ Route::group('/admin', function () {
|
||||
Route::any('/allocation', [app\crmAdmin\controller\CustomerController::class, 'allocation']);
|
||||
});
|
||||
});
|
||||
|
||||
// 字典
|
||||
Route::group('/dict', function () {
|
||||
Route::any('/list', [app\admin\controller\SysDictController::class, 'index']);
|
||||
Route::any('/show', [app\admin\controller\SysDictController::class, 'show']);
|
||||
Route::any('/store', [app\admin\controller\SysDictController::class, 'store']);
|
||||
Route::any('/update', [app\admin\controller\SysDictController::class, 'update']);
|
||||
Route::any('/destroy', [app\admin\controller\SysDictController::class, 'destroy']);
|
||||
|
||||
Route::group('/item', function () {
|
||||
Route::any('/list', [app\admin\controller\SysDictItemController::class, 'index']);
|
||||
Route::any('/show', [app\admin\controller\SysDictItemController::class, 'show']);
|
||||
Route::any('/store', [app\admin\controller\SysDictItemController::class, 'store']);
|
||||
Route::any('/update', [app\admin\controller\SysDictItemController::class, 'update']);
|
||||
Route::any('/destroy', [app\admin\controller\SysDictItemController::class, 'destroy']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user