|
|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace crmeb\subscribes;
|
|
|
|
|
|
use app\admin\model\wechat\WechatMessage;
|
|
|
@@ -31,18 +32,19 @@ class MessageSubscribe
|
|
|
*/
|
|
|
public function onAdminNewPush($event)
|
|
|
{
|
|
|
- try{
|
|
|
- $data['ordernum'] = StoreOrder::where('paid',1)->where('status',0)
|
|
|
- ->where('shipping_type',1)->where('refund_status',0)
|
|
|
- ->where('is_del',0)->count();
|
|
|
+ try {
|
|
|
+ $data['ordernum'] = StoreOrder::where('paid', 1)->where('status', 0)
|
|
|
+ ->where('shipping_type', 1)->where('refund_status', 0)
|
|
|
+ ->where('is_del', 0)->count();
|
|
|
$store_stock = sysConfig('store_stock');
|
|
|
- if($store_stock < 0) $store_stock = 2;
|
|
|
- $data['inventory'] = StoreProduct::where('stock','<=',$store_stock)->where('is_show',1)->where('is_del',0)->count();//库存
|
|
|
- $data['commentnum'] = StoreProductReply::where('is_reply',0)->count();
|
|
|
- $data['reflectnum'] = UserExtract::where('status',0)->count();//提现
|
|
|
+ if ($store_stock < 0) $store_stock = 2;
|
|
|
+ $data['inventory'] = StoreProduct::where('stock', '<=', $store_stock)->where('is_show', 1)->where('is_del', 0)->count();//库存
|
|
|
+ $data['commentnum'] = StoreProductReply::where('is_reply', 0)->count();
|
|
|
+ $data['reflectnum'] = UserExtract::where('status', 0)->count();//提现
|
|
|
$data['msgcount'] = intval($data['ordernum']) + intval($data['inventory']) + intval($data['commentnum']) + intval($data['reflectnum']);
|
|
|
- ChannelService::instance()->send('ADMIN_NEW_PUSH',$data);
|
|
|
- }catch (\Exception $e){}
|
|
|
+ ChannelService::instance()->send('ADMIN_NEW_PUSH', $data);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -55,10 +57,10 @@ class MessageSubscribe
|
|
|
WechatUser::saveUser($message->FromUserName);
|
|
|
|
|
|
$event = isset($message->Event) ?
|
|
|
- $message->MsgType.(
|
|
|
+ $message->MsgType . (
|
|
|
$message->Event == 'subscribe' && isset($message->EventKey) ? '_scan' : ''
|
|
|
- ).'_'.$message->Event : $message->MsgType;
|
|
|
- WechatMessage::setMessage(json_encode($message),$message->FromUserName,strtolower($event));
|
|
|
+ ) . '_' . $message->Event : $message->MsgType;
|
|
|
+ WechatMessage::setMessage(json_encode($message), $message->FromUserName, strtolower($event));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -86,21 +88,22 @@ class MessageSubscribe
|
|
|
public function onShortMssageSend($event)
|
|
|
{
|
|
|
//$actions 可为数组
|
|
|
- list($order_id,$actions) = $event;
|
|
|
- try{
|
|
|
- if(is_array($actions)){
|
|
|
- foreach ($actions as $action){
|
|
|
- $actionName = 'MssageSend'.$action;
|
|
|
- if(method_exists($this,$actionName)) $this->$actionName($order_id);
|
|
|
+ list($order_id, $actions) = $event;
|
|
|
+ try {
|
|
|
+ if (is_array($actions)) {
|
|
|
+ foreach ($actions as $action) {
|
|
|
+ $actionName = 'MssageSend' . $action;
|
|
|
+ if (method_exists($this, $actionName)) $this->$actionName($order_id);
|
|
|
}
|
|
|
- }else{
|
|
|
- $actionName = 'MssageSend'.$actions;
|
|
|
- if(method_exists($this,$actionName)) $this->$actionName($order_id);
|
|
|
+ } else {
|
|
|
+ $actionName = 'MssageSend' . $actions;
|
|
|
+ if (method_exists($this, $actionName)) $this->$actionName($order_id);
|
|
|
}
|
|
|
- }catch (\Exception $e){
|
|
|
- Log::error('短信下发事件发生系统错误,错误原因:'.$e->getMessage());
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::error('短信下发事件发生系统错误,错误原因:' . $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 发送短信
|
|
|
* @param boolean $switch 发送开关
|
|
|
@@ -109,9 +112,9 @@ class MessageSubscribe
|
|
|
* @param int $template 模板编号
|
|
|
* @param string $logMsg 错误日志记录
|
|
|
*/
|
|
|
- public function send($switch,$phone,array $data,$template,$logMsg='')
|
|
|
+ public function send($switch, $phone, array $data, $template, $logMsg = '')
|
|
|
{
|
|
|
- if($switch && $phone){
|
|
|
+ if ($switch && $phone) {
|
|
|
$template = SMSService::getConstants($template);
|
|
|
$res = SMSService::send($phone, $template, $data);
|
|
|
if ($res['status'] == 400) Log::info($logMsg);
|
|
|
@@ -124,12 +127,12 @@ class MessageSubscribe
|
|
|
*/
|
|
|
public function MssageSendPaySuccess($order_id)
|
|
|
{
|
|
|
- $storeInfo = StoreOrder::where(['order_id'=>$order_id,'paid'=>1,'refund_status'=>0])->find();
|
|
|
- if(!$storeInfo) return;
|
|
|
+ $storeInfo = StoreOrder::where(['order_id' => $order_id, 'paid' => 1, 'refund_status' => 0])->find();
|
|
|
+ if (!$storeInfo) return;
|
|
|
$switch = sysConfig('lower_order_switch') ? true : false;
|
|
|
//模板变量
|
|
|
$pay_price = $storeInfo->pay_price;
|
|
|
- $this->send($switch,$storeInfo->user_phone,compact('order_id','pay_price'),'PAY_SUCCESS_CODE','用户支付成功发送短信失败,订单号为:'.$order_id);
|
|
|
+ $this->send($switch, $storeInfo->user_phone, compact('order_id', 'pay_price'), 'PAY_SUCCESS_CODE', '用户支付成功发送短信失败,订单号为:' . $order_id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -138,13 +141,13 @@ class MessageSubscribe
|
|
|
*/
|
|
|
public function MssageSendDeliver($order_id)
|
|
|
{
|
|
|
- $storeInfo = StoreOrder::where(['order_id'=>$order_id,'paid'=>1,'refund_status'=>0,'status'=>1])->find();
|
|
|
- if(!$storeInfo) return;
|
|
|
+ $storeInfo = StoreOrder::where(['order_id' => $order_id, 'paid' => 1, 'refund_status' => 0, 'status' => 1])->find();
|
|
|
+ if (!$storeInfo) return;
|
|
|
$switch = sysConfig('deliver_goods_switch') ? true : false;
|
|
|
//模板变量
|
|
|
- $nickname = User::where('uid',$storeInfo->uid)->value('nickname');
|
|
|
+ $nickname = User::where('uid', $storeInfo->uid)->value('nickname');
|
|
|
$store_name = StoreOrder::getProductTitle($storeInfo->cart_id);
|
|
|
- $this->send($switch,$storeInfo->user_phone,compact('order_id','store_name','nickname'),'DELIVER_GOODS_CODE','用户发货发送短信失败,订单号为:'.$order_id);
|
|
|
+ $this->send($switch, $storeInfo->user_phone, compact('order_id', 'store_name', 'nickname'), 'DELIVER_GOODS_CODE', '用户发货发送短信失败,订单号为:' . $order_id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -153,12 +156,12 @@ class MessageSubscribe
|
|
|
*/
|
|
|
public function MssageSendReceiving($order_id)
|
|
|
{
|
|
|
- $storeInfo = StoreOrder::where(['order_id'=>$order_id,'paid'=>1,'refund_status'=>0,'status'=>2])->find();
|
|
|
- if(!$storeInfo) return;
|
|
|
+ $storeInfo = StoreOrder::where(['order_id' => $order_id, 'paid' => 1, 'refund_status' => 0, 'status' => 2])->find();
|
|
|
+ if (!$storeInfo) return;
|
|
|
$switch = sysConfig('confirm_take_over_switch') ? true : false;
|
|
|
//模板变量
|
|
|
$store_name = StoreOrder::getProductTitle($storeInfo->cart_id);
|
|
|
- $this->send($switch,$storeInfo->user_phone,compact('store_name','order_id'),'TAKE_DELIVERY_CODE','用户确认收货发送短信失败,订单号为:'.$order_id);
|
|
|
+ $this->send($switch, $storeInfo->user_phone, compact('store_name', 'order_id'), 'TAKE_DELIVERY_CODE', '用户确认收货发送短信失败,订单号为:' . $order_id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -167,14 +170,14 @@ class MessageSubscribe
|
|
|
*/
|
|
|
public function MssageSendAdminPlaceAnOrder($order_id)
|
|
|
{
|
|
|
- $storeInfo = StoreOrder::where(['order_id'=>$order_id,'paid'=>0,'refund_status'=>0,'status'=>0])->find();
|
|
|
- if(!$storeInfo) return;
|
|
|
+ $storeInfo = StoreOrder::where(['order_id' => $order_id, 'paid' => 0, 'refund_status' => 0, 'status' => 0])->find();
|
|
|
+ if (!$storeInfo) return;
|
|
|
$switch = sysConfig('admin_lower_order_switch') ? true : false;
|
|
|
- $switch && $this->getAdminNoticeAuth(function ($userInfo) use($storeInfo) {
|
|
|
+ $switch && $this->getAdminNoticeAuth(function ($userInfo) use ($storeInfo) {
|
|
|
//模板变量
|
|
|
$admin_name = $userInfo->nickname;
|
|
|
$order_id = $storeInfo->order_id;
|
|
|
- $this->send(true,$userInfo->phone,compact('admin_name','order_id'),'ADMIN_PLACE_ORDER_CODE','用户下单成功管理员发送短信通知失败,订单号为:'.$storeInfo->order_id);
|
|
|
+ $this->send(true, $userInfo->phone, compact('admin_name', 'order_id'), 'ADMIN_PLACE_ORDER_CODE', '用户下单成功管理员发送短信通知失败,订单号为:' . $storeInfo->order_id);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -184,14 +187,14 @@ class MessageSubscribe
|
|
|
*/
|
|
|
public function MssageSendAdminPaySuccess($order_id)
|
|
|
{
|
|
|
- $storeInfo = StoreOrder::where(['order_id'=>$order_id,'paid'=>1,'refund_status'=>0,'status'=>0])->find();
|
|
|
- if(!$storeInfo) return;
|
|
|
+ $storeInfo = StoreOrder::where(['order_id' => $order_id, 'paid' => 1, 'refund_status' => 0, 'status' => 0])->find();
|
|
|
+ if (!$storeInfo) return;
|
|
|
$switch = sysConfig('admin_pay_success_switch') ? true : false;
|
|
|
- $switch && $this->getAdminNoticeAuth(function ($userInfo) use($storeInfo) {
|
|
|
+ $switch && $this->getAdminNoticeAuth(function ($userInfo) use ($storeInfo) {
|
|
|
//模板变量
|
|
|
$admin_name = $userInfo->nickname;
|
|
|
$order_id = $storeInfo->order_id;
|
|
|
- $this->send(true,$userInfo->phone,compact('admin_name','order_id'),'ADMIN_PAY_SUCCESS_CODE','用户支付成功管理员发送短信通知失败,订单号为:'.$storeInfo->order_id);
|
|
|
+ $this->send(true, $userInfo->phone, compact('admin_name', 'order_id'), 'ADMIN_PAY_SUCCESS_CODE', '用户支付成功管理员发送短信通知失败,订单号为:' . $storeInfo->order_id);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -201,14 +204,14 @@ class MessageSubscribe
|
|
|
*/
|
|
|
public function MssageSendAdminConfirmTakeOver($order_id)
|
|
|
{
|
|
|
- $storeInfo = StoreOrder::where(['order_id'=>$order_id,'paid'=>1,'refund_status'=>0,'status'=>2])->find();
|
|
|
- if(!$storeInfo) return;
|
|
|
+ $storeInfo = StoreOrder::where(['order_id' => $order_id, 'paid' => 1, 'refund_status' => 0, 'status' => 2])->find();
|
|
|
+ if (!$storeInfo) return;
|
|
|
$switch = sysConfig('admin_confirm_take_over_switch') ? true : false;
|
|
|
- $switch && $this->getAdminNoticeAuth(function ($userInfo) use($storeInfo) {
|
|
|
+ $switch && $this->getAdminNoticeAuth(function ($userInfo) use ($storeInfo) {
|
|
|
//模板变量
|
|
|
$admin_name = $userInfo->nickname;
|
|
|
$order_id = $storeInfo->order_id;
|
|
|
- $this->send(true,$userInfo->phone,compact('admin_name','order_id'),'ADMIN_TAKE_DELIVERY_CODE','用户确认收货成功管理员发送短信通知失败,订单号为:'.$storeInfo->order_id);
|
|
|
+ $this->send(true, $userInfo->phone, compact('admin_name', 'order_id'), 'ADMIN_TAKE_DELIVERY_CODE', '用户确认收货成功管理员发送短信通知失败,订单号为:' . $storeInfo->order_id);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -218,16 +221,17 @@ class MessageSubscribe
|
|
|
*/
|
|
|
public function MssageSendAdminRefund($order_id)
|
|
|
{
|
|
|
- $storeInfo = StoreOrder::where(['order_id'=>$order_id,'paid'=>1,'refund_status'=>1])->find();
|
|
|
- if(!$storeInfo) return;
|
|
|
+ $storeInfo = StoreOrder::where(['order_id' => $order_id, 'paid' => 1, 'refund_status' => 1])->find();
|
|
|
+ if (!$storeInfo) return;
|
|
|
$switch = sysConfig('admin_refund_switch') ? true : false;
|
|
|
- $switch && $this->getAdminNoticeAuth(function ($userInfo) use($storeInfo) {
|
|
|
+ $switch && $this->getAdminNoticeAuth(function ($userInfo) use ($storeInfo) {
|
|
|
//模板变量
|
|
|
$admin_name = $userInfo->nickname;
|
|
|
$order_id = $storeInfo->order_id;
|
|
|
- $this->send(true,$userInfo->phone,compact('admin_name','order_id'),'ADMIN_RETURN_GOODS_CODE','用户退款管理员发送短信通知失败,订单号为:'.$storeInfo->order_id);
|
|
|
+ $this->send(true, $userInfo->phone, compact('admin_name', 'order_id'), 'ADMIN_RETURN_GOODS_CODE', '用户退款管理员发送短信通知失败,订单号为:' . $storeInfo->order_id);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 提取管理员权限
|
|
|
* @param callable $callable 回调函数
|
|
|
@@ -235,10 +239,10 @@ class MessageSubscribe
|
|
|
public function getAdminNoticeAuth(callable $callable)
|
|
|
{
|
|
|
$serviceOrderNotice = StoreService::getStoreServiceOrderNotice();
|
|
|
- if(count($serviceOrderNotice)) {
|
|
|
+ if (count($serviceOrderNotice)) {
|
|
|
foreach ($serviceOrderNotice as $uid) {
|
|
|
- $userInfo= User::where('uid',$uid)->field('phone,nickname')->find();
|
|
|
- if($userInfo && is_callable($callable)) $callable($userInfo);
|
|
|
+ $userInfo = User::where('uid', $uid)->field('phone,nickname')->find();
|
|
|
+ if ($userInfo && is_callable($callable)) $callable($userInfo);
|
|
|
}
|
|
|
}
|
|
|
}
|