wugg 7 月之前
父节点
当前提交
389558639e
共有 2 个文件被更改,包括 19 次插入14 次删除
  1. 1 2
      app/bug/controller/Note.php
  2. 18 12
      app/command/WxPush.php

+ 1 - 2
app/bug/controller/Note.php

@@ -204,8 +204,7 @@ class Note extends Base
 
     public function wxpushList(){
 	    $param = $this->request->param(["start"=>"","end"=>"","bugNo"=>"","push_id"=>"","template_name"=>"",
-	    "template_id"=>"","status"=>"",'belong'=>'','action_name'=>'',
-	    "page"=>1,"size"=>10],'post','trim');
+	    "template_id"=>"","status"=>"",'belong'=>'','action_name'=>'',"page"=>1,"size"=>10],'post','trim');
 	    $where=[];
 	    if($param['start']!==""){
 	        $where[]=['createTime',">",startTime($param['start'])];

+ 18 - 12
app/command/WxPush.php

@@ -20,13 +20,14 @@ class WxPush extends Command
 
     protected function execute(Input $input, Output $output)
     {
-        $appid = env('WECHAT.APPID');
-        $appsecret = env('WECHAT.APPSECRET');
-        $wechat = new \Wechat(['appid' => $appid, 'appsecret' => $appsecret]);
-       $bool=True;
-       while ($bool){
-            $que= Cache::store('redis')->handler()->lpop('wxpush_queue');
-            if ($que){
+        $lockKey= Cache::set('wxpush_lock',1,600);
+        try{
+            $appid = env('WECHAT.APPID');
+            $appsecret = env('WECHAT.APPSECRET');
+            $wechat = new \Wechat(['appid' => $appid, 'appsecret' => $appsecret]);
+           $que= Cache::store('redis')->handler()->lpop('wxpush_queue');
+           $output->writeln($que);
+            while ($que){
                 $data=json_decode($que,true);
                 $temp=[];
                 $res=false;
@@ -43,7 +44,7 @@ class WxPush extends Command
 
                 $add= [
                     'bugNo'=>$data['code'],
-                    "belong"=>$data['belong'],
+                    'belong'=>$data['belong'],
                     'action_name'=>$data['action_name'],
                     'template_id'=>$data['template_id'],
                     'template_name'=>$data['template_name'],
@@ -54,11 +55,16 @@ class WxPush extends Command
                     'remark'=>$res?'':$wechat->errMsg
                     ];
                  WeChatPush::create($add);
-                Log::write('data:'.json_encode($temp,JSON_UNESCAPED_UNICODE),'info');
-            }else{
-                $bool=false;
-            }
+                Log::write('data:'.json_encode($add,JSON_UNESCAPED_UNICODE),'info');
+                 $output->writeln(json_encode($add,JSON_UNESCAPED_UNICODE));
+                 $que= Cache::store('redis')->handler()->lpop('wxpush_queue');
+                 $output->writeln($que);
        }
 
+        }catch (\Exception $e){
+            Log::write('wxpush:'.$e->getMessage(),'error');
+            $output->writeln($e->getMessage());
+        }
+       Cache::delete('wxpush_lock');
     }
 }