登录
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\common\model\CorpFeishuApp;
|
||||
use app\common\model\CrmCustomer;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
use app\common\model\User;
|
||||
use app\common\utils\FeishuMessage as FeishuMsg;
|
||||
use support\exception\BusinessException;
|
||||
use app\inquiry\service\InquiryLogService;
|
||||
|
||||
class FeishuMessage implements Consumer
|
||||
{
|
||||
// 要消费的队列名
|
||||
public $queue = 'feishu-message';
|
||||
|
||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||
public $connection = 'default';
|
||||
|
||||
// 消费
|
||||
|
||||
/**
|
||||
* @param string $category 分类:crm | inquiry
|
||||
* @param string $scene 场景:group-send | group-update | person-send | person-update
|
||||
* @param string $id 数据ID:询单ID | 客户ID
|
||||
* @param string $receive_type 接收者类型:group | person
|
||||
*/
|
||||
public function consume($data)
|
||||
{
|
||||
try {
|
||||
if ($data['category'] === 'crm') {
|
||||
// 客户线索
|
||||
$crmCustomer = new CrmCustomer();
|
||||
$info = $crmCustomer->where('id', $data['id'])->first();
|
||||
|
||||
// 跟单人
|
||||
$reInfo = User::where('id', $info->user_id)->first();
|
||||
|
||||
// 飞书应用
|
||||
$feishuApp = new CorpFeishuApp();
|
||||
$feishuAppInfo = $feishuApp->where('corp_id', $reInfo->corp_id)->where('system_id', 1)->first();
|
||||
|
||||
// 推送数据
|
||||
$options = [
|
||||
'contacts' => $info->contacts,
|
||||
'follow_last' => $info->follow_last ? date('Y-m-d H:i', $info->follow_last) : '',
|
||||
'follow_next' => $info->follow_next ? date('Y-m-d H:i', $info->follow_next) : '',
|
||||
|
||||
'app_id' => $feishuAppInfo->app_id,
|
||||
'app_secret' => $feishuAppInfo->app_secret,
|
||||
'state' => $feishuAppInfo->state,
|
||||
'msg_type' => 'interactive',
|
||||
'receive_id_type' => 'open_id',
|
||||
'receive_id' => $reInfo->open_id
|
||||
];
|
||||
}
|
||||
|
||||
if ($data['category'] === 'inquiry') {
|
||||
// 询单信息
|
||||
$inquiryLogService = new InquiryLogService();
|
||||
$info = $inquiryLogService->getInquiryLogBy($data['id']);
|
||||
|
||||
// 接受者处理
|
||||
if ($data['receive_type'] == 'group') {
|
||||
$appId = 'cli_a6183b882cb8500d';
|
||||
$appSecret = 'VqYib48u4EtDIa6nG9qH3f0fYCA1bCvs';
|
||||
$state = 'hesu';
|
||||
$receiveId = 'oc_a52d9f89ad76735279088c78beade8dc';
|
||||
$receiveIdType = 'chat_id';
|
||||
} else {
|
||||
// 跟单人
|
||||
$reInfo = User::where('id', $info->recipient)->first();
|
||||
// 飞书应用
|
||||
$feishuApp = new CorpFeishuApp();
|
||||
$feishuAppInfo = $feishuApp->where('corp_id', $reInfo->corp_id)->where('system_id', 1)->first();
|
||||
// 推送信息
|
||||
$appId = $feishuAppInfo->app_id;
|
||||
$appSecret = $feishuAppInfo->app_secret;
|
||||
$state = $feishuAppInfo->state;
|
||||
$receiveId = $reInfo->open_id;
|
||||
$receiveIdType = 'open_id';
|
||||
}
|
||||
|
||||
// 推送数据
|
||||
$options = [
|
||||
'order_no' => $info->order_no,
|
||||
'quality' => $inquiryLogService->qualityName($info->quality),
|
||||
'channel' => $info->channelInfo ? $info->channelInfo->name : '',
|
||||
'country' => $info->countryInfo ? $info->countryInfo->cn_addr : '',
|
||||
'enter_user' => $info->enter ? $info->enter->name : '',
|
||||
'r_time' => $info->r_time ? date('Y-m-d H:i:s', $info->r_time) : '',
|
||||
't_time' => $info->t_time ? date('Y-m-d H:i:s', $info->t_time) : '',
|
||||
|
||||
'app_id' => $appId,
|
||||
'app_secret' => $appSecret,
|
||||
'state' => $state,
|
||||
'msg_type' => 'interactive',
|
||||
'receive_id_type' => $receiveIdType,
|
||||
'receive_id' => $receiveId
|
||||
];
|
||||
}
|
||||
|
||||
$feishuMsg = new FeishuMsg($options);
|
||||
$feishuMsg->messageSend($data['scene'], $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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user