Quellcode durchsuchen

格式化事件代码

liaofei vor 6 Jahren
Ursprung
Commit
d236a9da93

+ 3 - 1
crmeb/crmeb/subscribes/MaterialSubscribe.php

@@ -1,7 +1,9 @@
 <?php
+
 namespace crmeb\subscribes;
 
 use think\facade\Db;
+
 /**
  * 素材消息事件
  * Class MaterialSubscribe
@@ -21,7 +23,7 @@ class MaterialSubscribe
      */
     public function onWechatMaterialAfter($event)
     {
-        list($data,$type) = $event;
+        list($data, $type) = $event;
         $data['type'] = $type;
         $data['add_time'] = time();
         $data['temporary'] = 0;

+ 59 - 55
crmeb/crmeb/subscribes/MessageSubscribe.php

@@ -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);
             }
         }
     }

+ 16 - 14
crmeb/crmeb/subscribes/OrderSubscribe.php

@@ -41,8 +41,8 @@ class OrderSubscribe
      */
     public function onStoreProductOrderDeliveryAfter($event)
     {
-        list($data,$oid) = $event;
-        AdminStoreOrder::orderPostageAfter($oid,$data);
+        list($data, $oid) = $event;
+        AdminStoreOrder::orderPostageAfter($oid, $data);
     }
 
     /**
@@ -54,8 +54,8 @@ class OrderSubscribe
      */
     public function onStoreProductOrderDeliveryGoodsAfter($event)
     {
-        list($data,$oid) = $event;
-        AdminStoreOrder::orderPostageAfter($oid,$data);
+        list($data, $oid) = $event;
+        AdminStoreOrder::orderPostageAfter($oid, $data);
     }
 
     /**
@@ -64,8 +64,8 @@ class OrderSubscribe
      */
     public function onStoreProductOrderRefundNAfter($event)
     {
-        list($data,$id) = $event;
-        AdminStoreOrder::refundNoPrieTemplate($id,$data);
+        list($data, $id) = $event;
+        AdminStoreOrder::refundNoPrieTemplate($id, $data);
     }
 
     /**
@@ -84,7 +84,7 @@ class OrderSubscribe
      */
     public function onStoreProductOrderEditAfter($event)
     {
-        list($data,$id) = $event;
+        list($data, $id) = $event;
         //$data  total_price 商品总价   pay_price 实际支付
         //订单编号  $id
     }
@@ -95,7 +95,7 @@ class OrderSubscribe
      */
     public function onStoreProductOrderDistributionAfter($event)
     {
-        list($data,$id) = $event;
+        list($data, $id) = $event;
         //$data   送货人姓名/快递公司   送货人电话/快递单号
         //订单编号  $id
     }
@@ -113,7 +113,7 @@ class OrderSubscribe
      * 回退所有  未支付和已退款的状态下才可以退积分退库存退优惠券
      * @param $event
      */
-    public  function onStoreOrderRegressionAllAfter($event)
+    public function onStoreOrderRegressionAllAfter($event)
     {
         list($order) = $event;
         StoreOrder::RegressionStock($order) && StoreOrder::RegressionIntegral($order) && StoreOrder::RegressionCoupon($order);
@@ -125,16 +125,18 @@ class OrderSubscribe
      */
     public function onOrderPaySuccess($event)
     {
-        list($order,$formId) = $event;
+        list($order, $formId) = $event;
         //更新用户支付订单数量
         User::bcInc($order['uid'], 'pay_count', 1, 'uid');
         //发送模版消息、客服消息、短信、小票打印给客户和管理员
-        NoticeRepositories::noticeOrderPaySuccess($order,$formId);
+        NoticeRepositories::noticeOrderPaySuccess($order, $formId);
         //检测会员等级
         event('UserLevelAfter', [$order['uid']]);
 
-
-        //向后台发送新订单消息
-        ChannelService::instance()->send('NEW_ORDER', ['order_id'=>$order['order_id']]);
+        try {
+            //向后台发送新订单消息
+            ChannelService::instance()->send('NEW_ORDER', ['order_id' => $order['order_id']]);
+        } catch (\Throwable $e) {
+        }
     }
 }

+ 13 - 10
crmeb/crmeb/subscribes/ProductSubscribe.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace crmeb\subscribes;
 
 /**
@@ -21,28 +22,30 @@ class ProductSubscribe
      */
     public function onStoreProductSetCartAfter($event)
     {
-       list($cartInfo, $userInfo) = $event;
-       //$cartInfo 购物车信息
-       //$userInfo 用户信息
+        list($cartInfo, $userInfo) = $event;
+        //$cartInfo 购物车信息
+        //$userInfo 用户信息
     }
 
     /**
      * 用户操作产品添加事件  用户点赞产品  用户收藏产品
      * @param $event
      */
-    public function onStoreProductUserOperationConfirmAfter($event){
-       list($category, $productId, $relationType, $uid) = $event;
-       //$category 产品类型
-       //$productId 产品编号
-       //$relationType 操作类型   like  点赞  collect 收藏
-       //$uid 用户编号
+    public function onStoreProductUserOperationConfirmAfter($event)
+    {
+        list($category, $productId, $relationType, $uid) = $event;
+        //$category 产品类型
+        //$productId 产品编号
+        //$relationType 操作类型   like  点赞  collect 收藏
+        //$uid 用户编号
     }
 
     /**
      * 用户操作产品取消事件    用户取消点赞产品  用户取消收藏产品
      * @param $event
      */
-    public function onStoreProductUserOperationCancelAfter($event){
+    public function onStoreProductUserOperationCancelAfter($event)
+    {
         list($category, $productId, $relationType, $uid) = $event;
         //$category 产品类型
         //$productId 产品编号

+ 6 - 4
crmeb/crmeb/subscribes/SystemSubscribe.php

@@ -1,8 +1,10 @@
 <?php
+
 namespace crmeb\subscribes;
 
 use app\admin\model\system\SystemAdmin;
 use app\admin\model\system\SystemLog;
+
 /**
  * 后台系统事件
  * Class SystemSubscribe
@@ -22,8 +24,8 @@ class SystemSubscribe
      */
     public function onAdminVisit($event)
     {
-        list($adminInfo,$type) = $event;
-        if(strtolower(app('request')->controller()) != 'index') SystemLog::adminVisit($adminInfo->id,$adminInfo->account,$type);
+        list($adminInfo, $type) = $event;
+        if (strtolower(app('request')->controller()) != 'index') SystemLog::adminVisit($adminInfo->id, $adminInfo->account, $type);
     }
 
     /**
@@ -33,7 +35,7 @@ class SystemSubscribe
     public function onSystemAdminLoginAfter($event)
     {
         list($adminInfo) = $event;
-        SystemAdmin::edit(['last_ip'=>app('request')->ip(),'last_time'=>time()],$adminInfo['id']);
+        SystemAdmin::edit(['last_ip' => app('request')->ip(), 'last_time' => time()], $adminInfo['id']);
     }
 
     /**
@@ -42,7 +44,7 @@ class SystemSubscribe
      */
     public function onMerchantRegisterAfter($event)
     {
-      list($merchantInfo) = $event;
+        list($merchantInfo) = $event;
     }
 
 }

+ 4 - 2
crmeb/crmeb/subscribes/TaskSubscribe.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace crmeb\subscribes;
 
 use app\admin\model\system\SystemAttachment;
@@ -26,6 +27,7 @@ class TaskSubscribe
     public function onTask_2()
     {
     }
+
     /**
      * 6秒钟执行的方法
      */
@@ -45,14 +47,14 @@ class TaskSubscribe
      */
     public function onTask_30()
     {
-        try{
+        try {
             Db::startTrans();
             StoreBargainUser::startBargainUserStatus();//批量修改砍价状态为 砍价失败
             StoreOrder::orderUnpaidCancel();//订单未支付默认取消
             StoreOrder::startTakeOrder();//7天自动收货
             StorePink::statusPink();//拼团到期修改状态
             Db::commit();
-        }catch (\Exception $e){
+        } catch (\Exception $e) {
             Db::rollback();
         }
     }

+ 6 - 6
crmeb/crmeb/subscribes/UserSubscribe.php

@@ -41,24 +41,24 @@ class UserSubscribe
      */
     public function onWechatOauthAfter($event)
     {
-        list($openid, $wechatInfo, $spreadId,$login_type) = $event;
+        list($openid, $wechatInfo, $spreadId, $login_type) = $event;
 
         if (!User::be(['uid' => $spreadId])) $spreadId = 0;
 
         $wechatInfo['nickname'] = filterEmoji($wechatInfo['nickname']);
         Cookie::set('is_login', 1);
-        if (isset($wechatInfo['unionid']) && $wechatInfo['unionid'] != '' && ($uid = WechatUser::where('unionid', $wechatInfo['unionid'])->where('user_type','<>','h5')->value('uid'))) {
+        if (isset($wechatInfo['unionid']) && $wechatInfo['unionid'] != '' && ($uid = WechatUser::where('unionid', $wechatInfo['unionid'])->where('user_type', '<>', 'h5')->value('uid'))) {
             WechatUser::edit($wechatInfo, $uid, 'uid');
             if (!User::be(['uid' => $uid])) {
                 $wechatInfo = WechatUser::where('uid', $uid)->find();
                 User::setWechatUser($wechatInfo, $spreadId);
             } else {
-                if($login_type) $wechatInfo['login_type'] = $login_type;
+                if ($login_type) $wechatInfo['login_type'] = $login_type;
                 User::updateWechatUser($wechatInfo, $uid);
             }
-        } else if ($uid = WechatUser::where(['openid' => $wechatInfo['openid']])->where('user_type','<>','h5')->value('uid')) {
+        } else if ($uid = WechatUser::where(['openid' => $wechatInfo['openid']])->where('user_type', '<>', 'h5')->value('uid')) {
             WechatUser::edit($wechatInfo, $uid, 'uid');
-            if($login_type) $wechatInfo['login_type'] = $login_type;
+            if ($login_type) $wechatInfo['login_type'] = $login_type;
             User::updateWechatUser($wechatInfo, $uid);
         } else {
             if (isset($wechatInfo['subscribe_scene'])) unset($wechatInfo['subscribe_scene']);
@@ -80,7 +80,7 @@ class UserSubscribe
 //                User::where('uid', $wechatInfo['uid'])
 //                    ->limit(1)->update(['openid' => $wechatInfo['openid']]);
 //            else
-                User::setWechatUser($wechatInfo, $spreadId);
+            User::setWechatUser($wechatInfo, $spreadId);
         }
         $uid = WechatUser::openidToUid($openid, 'openid');
         // 设置推广关系