sugangqiang 2 years ago
parent
commit
892602fea9
6 changed files with 108 additions and 11 deletions
  1. 10 1
      app/command/Solver.php
  2. 8 6
      app/common/api/CompanyApi.php
  3. 46 0
      app/job/Messenger.php
  4. 2 1
      composer.json
  5. 39 0
      config/queue.php
  6. 3 3
      public/static/js/common/Feng.js

+ 10 - 1
app/command/Solver.php

@@ -29,11 +29,20 @@ class Solver extends Command {
         if (flock($lockFile, LOCK_EX | LOCK_NB)) {//文件锁(独占)
             set_time_limit(0);
             $schedules = Db::table("new_schedule")->select();
-            var_dump($info);
+            foreach ($schedules as $schedule) {
+                //检查时间到了没
+                if ($this->checkTime($schedule["time"])) {
+                    queue("app\job\Messenger", []); //任务加入队列待执行
+                }
+            }
             flock($lockFile, LOCK_UN);
         } else {
             $output->writeln('每分钟执行一次,执行时间超过1分钟下个1分钟跳过等待再下1分钟');
         }
     }
 
+    private function checkTime() {
+        return false;
+    }
+
 }

+ 8 - 6
app/common/api/CompanyApi.php

@@ -38,20 +38,22 @@ class CompanyApi {
     }
 
     public static function edit($params) {
+        $data["name"] = $params["name"];
+        $data["shortName"] = $params["shortName"];
+        $data["code"] = $params["code"];
+        $data["sn"] = $params["sn"];
+        $data["description"] = $params["description"];
         if ($params["id"]) {
             $data["id"] = $params["id"];
             $data["updateTime"] = date("Y-m-d H:i:s");
             $data["updateUser"] = session("user")["uid"];
+            return Company::update($data);
         } else {
+            $data["id"] = getStringId();
             $data["createTime"] = date("Y-m-d H:i:s");
             $data["createUser"] = session("user")["uid"];
+            return Company::insert($data);
         }
-        $data["name"] = $params["name"];
-        $data["shortName"] = $params["shortName"];
-        $data["code"] = $params["code"];
-        $data["sn"] = $params["sn"];
-        $data["description"] = $params["description"];
-        return Company::update($data);
     }
 
     public static function delete($id) {

+ 46 - 0
app/job/Messenger.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace app\job;
+
+use think\queue\Job;
+use think\facade\Log;
+
+/**
+ * Description of Messenger
+ *
+ * @author sgq
+ */
+class Messenger {
+
+    public function fire(Job $job, $data) {
+        if ($this->deal($data)) {
+            Log::record(json_encode($data));
+            $job->delete();
+            return true;
+        }
+        Log::error(json_encode($data));
+        if ($job->attempts() >= 3) {
+            $job->delete();
+            return false;
+        }
+        $job->release(10); //10秒后重试
+    }
+
+    /**
+     * 处理业务逻辑
+     * @param type $data
+     * @return bool
+     */
+    public function deal($data): bool {
+        $type = $data["type"];
+        switch ($data) {
+            case 1:
+                //通知单位审核注册
+                break;
+            case 2:
+                break;
+        }
+        return false;
+    }
+
+}

+ 2 - 1
composer.json

@@ -27,7 +27,8 @@
         "topthink/think-multi-app": "^1.0",
         "phpoffice/phpexcel": "^1.8",
         "topthink/think-captcha": "^3.0",
-        "phpoffice/phpspreadsheet": "^1.24"
+        "phpoffice/phpspreadsheet": "^1.24",
+        "topthink/think-queue": "^3.0"
     },
     "require-dev": {
         "symfony/var-dumper": "^4.2",

+ 39 - 0
config/queue.php

@@ -0,0 +1,39 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: yunwuxin <448901948@qq.com>
+// +----------------------------------------------------------------------
+
+return [
+    'default'     => 'redis',
+    'connections' => [
+        'sync'     => [
+            'type' => 'sync',
+        ],
+        'database' => [
+            'type'       => 'database',
+            'queue'      => 'default',
+            'table'      => 'jobs',
+            'connection' => null,
+        ],
+        'redis'    => [
+            'type'       => 'redis',
+            'queue'      => 'default',
+            'host'       => '127.0.0.1',
+            'port'       => 6379,
+            'password'   => '',
+            'select'     => 0,
+            'timeout'    => 0,
+            'persistent' => false,
+        ],
+    ],
+    'failed'      => [
+        'type'  => 'none',
+        'table' => 'failed_jobs',
+    ],
+];

+ 3 - 3
public/static/js/common/Feng.js

@@ -609,15 +609,15 @@ var Feng = {
             $("#"+target).val('');
         }
     },
-    chkFileInvalid:function(file,maxImageSize,maxFileSize,fileType = null,msg = null){
+    chkFileInvalid:function(file,maxImageSize,maxFileSize,fileType,msg){
         var size = 0;
-        if(fileType != null){
+        if(typeof fileType != "undefined" && fileType != null){
             if(fileType.indexOf(file.type)<0){
+                msg = typeof msg !="undefined"?msg:"不支持的文件类型";
                 Feng.error(msg)
                 return false;
             }
         }
-        console.log(file.type)
         switch(file.type){
             case "image/jpeg":
             case "image/gif":