142 lines
5.1 KiB
PHP
142 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace app\http\service;
|
|
|
|
use app\facade\AppConstant;
|
|
use app\facade\RedisCache;
|
|
use think\captcha\Captcha;
|
|
use think\Db;
|
|
use think\facade\Cache;
|
|
use think\facade\Config;
|
|
use think\facade\Log;
|
|
|
|
class MessageQueueService extends CommonService
|
|
{
|
|
protected $fd=0;
|
|
protected $message_data=[];
|
|
protected $server=null;
|
|
protected $fd_store='';
|
|
|
|
public function __construct($server,$msgs)
|
|
{
|
|
$this->server=$server;
|
|
$this->message_data = json_decode($msgs[1],true);
|
|
Log::info('数组数据:'.json_encode($this->message_data));
|
|
}
|
|
public function deal() {
|
|
//处理具体的消息推送
|
|
switch ($this->message_data['type']) {
|
|
case 'noticeOrder' ://通知打开控制台的管理员,订单的情况
|
|
Log::info('处理noticeOrder');
|
|
if ($this->csInit()) { $this->noticeOrder(); }
|
|
break;
|
|
case 'workRmind' ://通知打开控制台的普通工作人员
|
|
Log::info('处理workRmind');
|
|
if ($this->csInit()) { $this->workRmind(); }
|
|
break;
|
|
case 'verifyRmind' ://通知打开控制台的普通工作人员
|
|
Log::info('处理verifyRmind');
|
|
if ($this->csInit()) { $this->verifyRmind(); }
|
|
break;
|
|
case 'adminLogout' ://通知管理用户已退出
|
|
if ($this->csInit()) { $this->adminLogout(); }
|
|
break;
|
|
case 'logout' ://通知用户已退出
|
|
if ($this->userInit()) { $this->logout(); }
|
|
break;
|
|
default:
|
|
break;
|
|
/*$result['message_type']='error';
|
|
$result['data']=['错误消息类型'];*/
|
|
}
|
|
}
|
|
|
|
protected function csInit() {
|
|
//客服初始化
|
|
//读出fd所对应的客服
|
|
$cs_fd = RedisCache::hget('CHAT_CS_FD', $this->message_data['admin_user_id']);
|
|
if ($cs_fd) {
|
|
$this->fd = $cs_fd;
|
|
return true;
|
|
}
|
|
|
|
$admin_fd = RedisCache::hget('CHAT_ADMIN_FD', $this->message_data['admin_user_id']);
|
|
if ($admin_fd) {
|
|
$this->fd = $admin_fd;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
protected function userInit() {
|
|
//用户初始化
|
|
//读出fd所对应的用户
|
|
$user_fd = RedisCache::hget('CHAT_USER_FD', $this->message_data['user_id']);
|
|
if ($user_fd) {
|
|
$this->fd = $user_fd;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected function noticeOrder() {
|
|
$message_type='noticeOrder';
|
|
$push_data['message']=$this->message_data['message'];
|
|
$push_data['phone']=$this->message_data['phone'];
|
|
$push_data['name']=$this->message_data['name'];
|
|
$push_data['time']=$this->message_data['time'];
|
|
$push_data['goods_amount']=$this->message_data['goods_amount'];
|
|
$push_data['order_id']=$this->message_data['order_id'];
|
|
$push_data['order_sn']=$this->message_data['order_sn'];
|
|
if ($this->server->exist($this->fd)) {
|
|
$this->server->push($this->fd,myResult($message_type,$push_data));
|
|
}
|
|
}
|
|
|
|
protected function workRmind() {
|
|
$message_type='workRmind';
|
|
$push_data['message']=$this->message_data['message'];
|
|
$push_data['phone']=$this->message_data['phone'];
|
|
$push_data['name']=$this->message_data['name'];
|
|
$push_data['time']=$this->message_data['time'];
|
|
$push_data['goods_amount']=$this->message_data['goods_amount'];
|
|
$push_data['shipping_fee']=$this->message_data['shipping_fee'];
|
|
$push_data['total_amount']=$this->message_data['total_amount'];
|
|
$push_data['deal_url']=$this->message_data['deal_url'];
|
|
$push_data['order_id']=$this->message_data['order_id'];
|
|
$push_data['order_sn']=$this->message_data['order_sn'];
|
|
if ($this->server->exist($this->fd)) {
|
|
$this->server->push($this->fd,myResult($message_type,$push_data));
|
|
}
|
|
}
|
|
|
|
protected function verifyRmind() {
|
|
$message_type='verifyRmind';
|
|
$push_data['message']=$this->message_data['message'];
|
|
$push_data['phone']=$this->message_data['phone'];
|
|
$push_data['name']=$this->message_data['name'];
|
|
$push_data['time']=$this->message_data['time'];
|
|
$push_data['offline_deadline']=$this->message_data['offline_deadline'];
|
|
$push_data['deal_url']=$this->message_data['deal_url'];
|
|
if ($this->server->exist($this->fd)) {
|
|
$this->server->push($this->fd,myResult($message_type,$push_data));
|
|
}
|
|
}
|
|
|
|
protected function adminLogout() {
|
|
$message_type='initError';
|
|
$push_data['content']='您已退出登录';
|
|
if ($this->server->exist($this->fd)) {
|
|
$this->server->push($this->fd,myResult($message_type,$push_data));
|
|
}
|
|
}
|
|
|
|
protected function logout() {
|
|
$message_type='initError';
|
|
$push_data['content']='您已退出登录';
|
|
if ($this->server->exist($this->fd)) {
|
|
$this->server->push($this->fd,myResult($message_type,$push_data));
|
|
}
|
|
}
|
|
} |