Finish mzl_dev
This commit is contained in:
@@ -65,10 +65,10 @@ class PresetController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function users()
|
public function users(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$result = (new UserService())->getList();
|
$result = (new UserService())->getList($request);
|
||||||
return $this->success($result, '获取用户列表');
|
return $this->success($result, '获取用户列表');
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return $this->error($e->getMessage());
|
return $this->error($e->getMessage());
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
namespace app\common\logic;
|
namespace app\common\logic;
|
||||||
|
|
||||||
use app\common\model\User;
|
use app\common\model\User;
|
||||||
|
use app\common\model\UserGroupMembers;
|
||||||
use app\common\traits\crud\CrudLogicTrait;
|
use app\common\traits\crud\CrudLogicTrait;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
|
use support\Request;
|
||||||
|
use app\common\model\UserRoles;
|
||||||
|
|
||||||
class UserLogic
|
class UserLogic
|
||||||
{
|
{
|
||||||
@@ -20,7 +23,7 @@ class UserLogic
|
|||||||
*/
|
*/
|
||||||
public function userInfo(int $uid)
|
public function userInfo(int $uid)
|
||||||
{
|
{
|
||||||
$user = User::find($uid);
|
$user = User::with('reportToInfo')->find($uid);
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
throw new BusinessException('账户不存在', 404);
|
throw new BusinessException('账户不存在', 404);
|
||||||
@@ -38,6 +41,7 @@ class UserLogic
|
|||||||
*/
|
*/
|
||||||
public function edit(int $uid, array $data)
|
public function edit(int $uid, array $data)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
$user = User::find($uid);
|
$user = User::find($uid);
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
@@ -47,6 +51,26 @@ class UserLogic
|
|||||||
$user->fill($data);
|
$user->fill($data);
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
|
// 绑定内勤 10.13 add
|
||||||
|
if (isset($data['office_clerk_id']) && $data['office_clerk_id'] > 0) {
|
||||||
|
$ug = UserGroupMembers::where('user_id', $uid)->where('status', 1)->first();
|
||||||
|
if ($ug) {
|
||||||
|
$ug->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
$group = UserGroupMembers::where('user_id', $data['office_clerk_id'])->where('is_leader', 1)->where('status', 1)->first();
|
||||||
|
if (!$group) {
|
||||||
|
throw new BusinessException('该内勤还未创建分组', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
UserGroupMembers::create([
|
||||||
|
'user_id' => $uid,
|
||||||
|
'group_id' => $group->group_id,
|
||||||
|
'is_leader' => 0,
|
||||||
|
'status' => 1
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,9 +88,16 @@ class UserLogic
|
|||||||
/**
|
/**
|
||||||
* 获取用户列表
|
* 获取用户列表
|
||||||
*/
|
*/
|
||||||
public function getList()
|
public function getList(Request $request)
|
||||||
{
|
{
|
||||||
$list = User::where('status', 1)->orderBy('id', 'desc')->get();
|
$p = $request->all();
|
||||||
|
|
||||||
|
$user = User::where('status', 1);
|
||||||
|
if (isset($p['role_id']) && $p['role_id'] > 0) {
|
||||||
|
$userIds = UserRoles::where('role_id', $p['role_id'])->pluck('user_id');
|
||||||
|
$user->whereIn('id', $userIds);
|
||||||
|
}
|
||||||
|
$list = $user->orderBy('id', 'desc')->get();
|
||||||
$arr = [];
|
$arr = [];
|
||||||
foreach ($list->toArray() as $item) {
|
foreach ($list->toArray() as $item) {
|
||||||
$arr[] = [
|
$arr[] = [
|
||||||
|
|||||||
@@ -98,4 +98,10 @@ class User extends Model
|
|||||||
->orWhere('phone', $account)
|
->orWhere('phone', $account)
|
||||||
->orWhere('email', $account);
|
->orWhere('email', $account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function reportToInfo()
|
||||||
|
{
|
||||||
|
return $this->hasOne(User::class, 'id', 'report_to');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@ namespace app\common\service;
|
|||||||
use app\common\logic\UserLogic;
|
use app\common\logic\UserLogic;
|
||||||
use app\common\model\Corp;
|
use app\common\model\Corp;
|
||||||
use app\common\model\User;
|
use app\common\model\User;
|
||||||
|
use app\common\model\UserGroup;
|
||||||
|
use app\common\model\UserGroupMembers;
|
||||||
use app\common\traits\crud\CrudLogicTrait;
|
use app\common\traits\crud\CrudLogicTrait;
|
||||||
use app\common\traits\crud\CrudServiceTrait;
|
use app\common\traits\crud\CrudServiceTrait;
|
||||||
use app\common\utils\CrudUtil;
|
use app\common\utils\CrudUtil;
|
||||||
@@ -68,6 +70,27 @@ class UserService
|
|||||||
public function getUser(int $uid, $corp_abbr)
|
public function getUser(int $uid, $corp_abbr)
|
||||||
{
|
{
|
||||||
$user = $this->logic->userInfo($uid);
|
$user = $this->logic->userInfo($uid);
|
||||||
|
|
||||||
|
// 查找直属上级 10.13 add
|
||||||
|
$reportToInfo = [];
|
||||||
|
if ($user->reportToInfo) {
|
||||||
|
$reportToInfo = [
|
||||||
|
'id' => $user->reportToInfo->id,
|
||||||
|
'name' => $user->reportToInfo->name
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找绑定内勤 10.13 add
|
||||||
|
$officeClerkInfo = [];
|
||||||
|
$ugm = UserGroupMembers::where('user_id', $uid)->where('status', 1)->first();
|
||||||
|
if ($ugm) {
|
||||||
|
$lugm = UserGroupMembers::where('group_id', $ugm->group_id)->where('is_leader', 1)->first();
|
||||||
|
if ($lugm) {
|
||||||
|
$officeClerkInfo['id'] = $lugm->user_id;
|
||||||
|
$officeClerkInfo['name'] = User::where('id', $lugm->user_id)->value('name');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$corp_name = Corp::where('abbr', $corp_abbr)->value('name');
|
$corp_name = Corp::where('abbr', $corp_abbr)->value('name');
|
||||||
$ossservice = new OssService();
|
$ossservice = new OssService();
|
||||||
return [
|
return [
|
||||||
@@ -90,6 +113,8 @@ class UserService
|
|||||||
'roles' => $user->roles->pluck('name'),
|
'roles' => $user->roles->pluck('name'),
|
||||||
'sign_img' => $user->sign_img,
|
'sign_img' => $user->sign_img,
|
||||||
'sign_img_url' => (!empty($user->sign_img))?$ossservice->generatePrivateUrl($user->sign_img):'',
|
'sign_img_url' => (!empty($user->sign_img))?$ossservice->generatePrivateUrl($user->sign_img):'',
|
||||||
|
'report_to_info' => $reportToInfo,
|
||||||
|
'office_clerk_info' => $officeClerkInfo
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +151,9 @@ class UserService
|
|||||||
/**
|
/**
|
||||||
* 获取用户列表
|
* 获取用户列表
|
||||||
*/
|
*/
|
||||||
public function getList()
|
public function getList(Request $request)
|
||||||
{
|
{
|
||||||
return $this->logic->getList();
|
return $this->logic->getList($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 分页列表 */
|
/** 分页列表 */
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace app\common\utils;
|
|||||||
use GatewayWorker\Lib\Gateway;
|
use GatewayWorker\Lib\Gateway;
|
||||||
use app\common\utils\WsResponse;
|
use app\common\utils\WsResponse;
|
||||||
use app\common\service\MessageNotificationsService;
|
use app\common\service\MessageNotificationsService;
|
||||||
|
use support\Redis;
|
||||||
|
|
||||||
class WsEvents
|
class WsEvents
|
||||||
{
|
{
|
||||||
@@ -158,14 +159,24 @@ class WsEvents
|
|||||||
|
|
||||||
public function systemConnect(?string $traceId)
|
public function systemConnect(?string $traceId)
|
||||||
{
|
{
|
||||||
$num = (new \app\common\utils\approval\service\ApprovalFlowService())->getInitTodoCount($_SESSION['uid']);
|
// 响应
|
||||||
$this->todoCounts($_SESSION['uid'], $num);
|
|
||||||
|
|
||||||
Gateway::sendToClient($this->clientId, WsResponse::success(
|
Gateway::sendToClient($this->clientId, WsResponse::success(
|
||||||
'system.connect.receive',
|
'system.connect.receive',
|
||||||
['time' => time()],
|
['time' => time()],
|
||||||
$traceId
|
$traceId
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// 获取审批待办数量
|
||||||
|
$num = (new \app\common\utils\approval\service\ApprovalFlowService())->getInitTodoCount($_SESSION['uid']);
|
||||||
|
$this->todoCounts($_SESSION['uid'], $num);
|
||||||
|
|
||||||
|
// 绑定检查
|
||||||
|
$initData = $this->initCheck($_SESSION['uid']);
|
||||||
|
Gateway::sendToClient($this->clientId, WsResponse::success(
|
||||||
|
'system.init.check',
|
||||||
|
$initData,
|
||||||
|
$traceId
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================= 消息通知事件 =================
|
// ================= 消息通知事件 =================
|
||||||
@@ -259,7 +270,6 @@ class WsEvents
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
init.pull
|
|
||||||
approval.todo.counts 审批待办数量
|
approval.todo.counts 审批待办数量
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@@ -285,8 +295,44 @@ class WsEvents
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ================= 临时业务处理 =================
|
// ================= 业务处理 =================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化检查
|
||||||
|
*/
|
||||||
|
public function initCheck(int $userId)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'is_report_to' => false,
|
||||||
|
'is_office_clerk' => false,
|
||||||
|
'is_sign' => false
|
||||||
|
];
|
||||||
|
|
||||||
|
$user = \app\common\model\User::find($userId);
|
||||||
|
|
||||||
|
if ($user->report_to > 0) {
|
||||||
|
$data['is_report_to'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->sign_img !== null && $user->sign_img !== '') {
|
||||||
|
$data['is_sign'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ug = \app\common\model\UserGroupMembers::with(['group' => function($query) {
|
||||||
|
$query->where('scenario_code', 'stock_orders');
|
||||||
|
}])->where('user_id', $userId)->first();
|
||||||
|
if ($ug !== null) {
|
||||||
|
$data['is_office_clerk'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data['is_report_to'] && $data['is_office_clerk'] && $data['is_sign']) {
|
||||||
|
Redis::hSet('user:init:check:'.$userId, 'status', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 审批待办数量
|
||||||
public function todoCounts(int $userId, int $num = 0)
|
public function todoCounts(int $userId, int $num = 0)
|
||||||
{
|
{
|
||||||
$ly = [
|
$ly = [
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
namespace app\process;
|
namespace app\process;
|
||||||
|
|
||||||
|
use app\common\model\User;
|
||||||
|
use app\common\model\UserRoles;
|
||||||
|
use app\common\utils\WsEvents;
|
||||||
|
use support\Redis;
|
||||||
use Workerman\Crontab\Crontab;
|
use Workerman\Crontab\Crontab;
|
||||||
|
|
||||||
class CheckWeb
|
class CheckWeb
|
||||||
@@ -18,6 +22,18 @@ class CheckWeb
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new Crontab('*/3 * * * * *', function(){
|
||||||
|
$userIds = UserRoles::where('role_id', 1)->pluck('user_id')->toArray();
|
||||||
|
foreach ($userIds as $userId) {
|
||||||
|
$status = Redis::hGet('user:init:check:'.$userId, 'status');
|
||||||
|
if ($status) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$ws = new WsEvents();
|
||||||
|
$ws->pushWebsocket('system.init.check', $userId, $ws->initCheck($userId));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class EmailMessage implements Consumer
|
|||||||
$inquiryLogService = new InquiryLogService();
|
$inquiryLogService = new InquiryLogService();
|
||||||
$content = $inquiryLogService->getContent($data['id']);
|
$content = $inquiryLogService->getContent($data['id']);
|
||||||
|
|
||||||
MailSend::send($data['email'], '【XYH】新的客户线索', replaceTpl($content));
|
MailSend::send($data['email'], $data['title'], replaceTpl($content));
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
throw $th;
|
throw $th;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,16 @@ class InquiryToCrmNew implements Consumer
|
|||||||
\Webman\RedisQueue\Redis::send('notice', $wsdata);
|
\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)
|
public function syncCustomer(Model $info)
|
||||||
{
|
{
|
||||||
$uInfo = $this->recipientInfo($info);
|
$uInfo = $this->recipientInfo($info);
|
||||||
@@ -87,25 +97,28 @@ class InquiryToCrmNew implements Consumer
|
|||||||
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
$recipient = [$info->recipient];
|
$recipient = [$info->recipient];
|
||||||
$this->pushWs($title, $content, $recipient);
|
// $this->pushWs($title, $content, $recipient);
|
||||||
|
$this->pushEmail($info->id, $title, $uInfo['uinfo']['email']);
|
||||||
} else {
|
} else {
|
||||||
if ($info->status == 2 && $crmCustomerInfo->user_id == $info->recipient) {
|
if ($info->status == 2 && $crmCustomerInfo->user_id == $info->recipient) {
|
||||||
// $notice = '更新';
|
// $notice = '更新';
|
||||||
$title = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理';
|
$title = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理';
|
||||||
$content = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理';
|
$content = '[询单·更新] 客户线索' . $info->order_no . '有新的调整,请及时处理';
|
||||||
$recipient = [$info->recipient];
|
$recipient = [$info->recipient];
|
||||||
$this->pushWs($title, $content, $recipient);
|
// $this->pushWs($title, $content, $recipient);
|
||||||
|
$this->pushEmail($info->id, $title, $uInfo['uinfo']['email']);
|
||||||
} else {
|
} else {
|
||||||
// $notice = '重新分配';
|
// $notice = '重新分配';
|
||||||
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
$recipient = [$info->recipient];
|
$recipient = [$info->recipient];
|
||||||
$this->pushWs($title, $content, $recipient);
|
// $this->pushWs($title, $content, $recipient);
|
||||||
|
$this->pushEmail($info->id, $title, $uInfo['uinfo']['email']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$udata = [
|
$udata = [
|
||||||
'corp_id' => $uInfo['corpId'],
|
'corp_id' => $uInfo['corpId'],
|
||||||
'user_id' => $info->recipient,
|
'user_id' => $info->recipient,
|
||||||
'channel_id' => $info->channel,
|
'channel_id' => $info->channel,
|
||||||
'country_id' => $info->country,
|
'country_id' => $info->country,
|
||||||
@@ -151,7 +164,8 @@ class InquiryToCrmNew implements Consumer
|
|||||||
$title = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布';
|
$title = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布';
|
||||||
$content = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布';
|
$content = '[询单·公海] 新的客户线索【' . $info->order_no . '】发布';
|
||||||
$recipient = [$info->recipient];
|
$recipient = [$info->recipient];
|
||||||
$this->pushWs($title, $content);
|
// $this->pushWs($title, $content);
|
||||||
|
$this->pushEmail($info->id, $title, $uInfo['uinfo']['email']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($info->status == 2) {
|
if ($info->status == 2) {
|
||||||
@@ -159,7 +173,8 @@ class InquiryToCrmNew implements Consumer
|
|||||||
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
$title = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
$content = '[询单·分配] 新的客户线索【' . $info->order_no . '】,请及时处理';
|
||||||
$recipient = [$info->recipient];
|
$recipient = [$info->recipient];
|
||||||
$this->pushWs($title, $content, $recipient);
|
// $this->pushWs($title, $content, $recipient);
|
||||||
|
$this->pushEmail($info->id, $title, $uInfo['uinfo']['email']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -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_bak';
|
||||||
|
|
||||||
|
// 连接名,对应 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
<?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;
|
|
||||||
|
|
||||||
class InquiryToCrmUpdate_bak implements Consumer
|
|
||||||
{
|
|
||||||
// 要消费的队列名
|
|
||||||
public $queue = 'inquiry-to-crm-update';
|
|
||||||
|
|
||||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
|
||||||
public $connection = 'default';
|
|
||||||
|
|
||||||
// 消费
|
|
||||||
public function consume($data)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
// 获取询盘信息
|
|
||||||
$info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
<?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;
|
|
||||||
|
|
||||||
class InquiryToCrm_bak implements Consumer
|
|
||||||
{
|
|
||||||
// 要消费的队列名
|
|
||||||
public $queue = 'inquiry-to-crm';
|
|
||||||
|
|
||||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
|
||||||
public $connection = 'default';
|
|
||||||
|
|
||||||
// 消费
|
|
||||||
public function consume($data)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
// 获取询盘信息
|
|
||||||
$info = InquiryLog::with(['channelInfo', 'countryInfo', 'enter'])->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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user