Przeglądaj źródła

定时发送初审提醒短信

sugangqiang 2 lat temu
rodzic
commit
97a0707858

+ 77 - 0
app/command/FstVerifyChecker.php

@@ -0,0 +1,77 @@
+<?php
+
+declare (strict_types=1);
+
+namespace app\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use think\facade\Db;
+use think\facade\Log;
+use app\enterprise\model\Talent;
+use app\common\api\TalentState;
+use app\common\api\MenuApi;
+use app\admin\model\SysRelation;
+use app\admin\model\User;
+
+/**
+ * 人才认定初审待审核检查
+ */
+class FstVerifyChecker extends Command {
+
+    protected function configure() {
+        // 指令配置
+        $this->setName('FstVerifyChecker')
+                ->setDescription('First Verify Checker');
+    }
+
+    protected function execute(Input $input, Output $output) {
+        $where[] = ["e.type", "=", 1];
+        $where[] = ["ti.checkState", "=", TalentState::SCND_SUBMIT];
+        $where[] = ["tl.state", "in", [TalentState::SCND_SUBMIT, TalentState::DEPT_VERIFY_REJECT, TalentState::REVERIFY_REJECT]];
+        $jjrc_count = Talent::alias("ti")
+                        ->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")
+                        ->leftJoin("(select mainId,last_state,new_state,state,createTime from new_talent_checklog where createTime in (select max(createTime) from `new_talent_checklog` where `type`=1 and `step` is null and active=1 and typeFileId is null group by mainId,`type`)) tl", "`tl`.`mainId`=ti.id")
+                        ->where($where)->count();
+
+        $where = [];
+        $where[] = ["e.type", "=", 2];
+        $where[] = ["ti.checkState", "=", TalentState::SCND_SUBMIT];
+        $where[] = ["tl.state", "in", [TalentState::SCND_SUBMIT, TalentState::DEPT_VERIFY_REJECT, TalentState::REVERIFY_REJECT]];
+        $ic_count = Talent::alias("ti")
+                        ->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")
+                        ->leftJoin("(select mainId,last_state,new_state,state,createTime from new_talent_checklog where createTime in (select max(createTime) from `new_talent_checklog` where `type`=1 and `step` is null and active=1 and typeFileId is null group by mainId,`type`)) tl", "`tl`.`mainId`=ti.id")
+                        ->where($where)->count();
+        $codes = ["talentInfo_first"];
+        $menuIds = MenuApi::getMenuIdsByCodes($codes);
+
+        $where = [];
+        $where[] = ["menuid", "in", $menuIds];
+        $roleIds = SysRelation::where($where)->group("roleid")->having("count(*)=" . count($codes))->column("roleid");
+
+        $where = [];
+        $where[] = ["status", "=", 1];
+        $where[] = ["roleid", "<>", 1];
+        $regstr = ",(" . implode("|", $roleIds) . "),";
+        $whereRaw = "concat(',',roleid,',') REGEXP '$regstr'";
+        $users = User::where($where)->whereRaw($whereRaw)->select();
+        foreach ($users as $user) {
+            switch ($user["type"]) {
+                case 1:
+                    if ($jjrc_count > 0 && $user["phone"]) {
+                        queue("app\job\Messenger", ["type" => 2, "userId" => $user["id"], "name" => $user["name"], "phone" => $user["phone"], "count" => $jjrc_count]);
+                    }
+                    break;
+                case 2:
+                    if ($ic_count > 0 && $user["phone"]) {
+                        queue("app\job\Messenger", ["type" => 2, "userId" => $user["id"], "name" => $user["name"], "phone" => $user["phone"], "count" => $ic_count]);
+                    }
+                    break;
+            }
+        }
+    }
+
+}

+ 8 - 0
app/common/api/MenuApi.php

@@ -50,6 +50,14 @@ class MenuApi {
         return Menu::where($where)->column("id");
     }
 
+    public static function getMenuIdsByCodes(array $codes) {
+        $where = [];
+        $where[] = ["code", "in", $codes];
+        $where[] = ["status", "=", 1];
+        $where[] = ["delete", "=", 0];
+        return Menu::where($where)->column("id");
+    }
+
     public static function save($params) {
         $data["name"] = $params["name"];
         $data["new_url"] = $params["url"];

+ 34 - 4
app/job/Messenger.php

@@ -6,6 +6,7 @@ use think\queue\Job;
 use think\facade\Log;
 use think\facade\Db;
 use app\common\api\ChuanglanSmsApi;
+use app\common\model\MessageRecord;
 
 /**
  * Description of Messenger
@@ -38,11 +39,40 @@ class Messenger {
         switch ($type) {
             case 1:
                 //通知单位审核注册
-                $enterprise = $data["info"]; //企业信息
-                $msg["createTime"] = date("Y-m-d H:i:s");
-                $sender = new ChuanglanSmsApi();
-                $sender->sendSMS($mobile, $msg);
+                break;
             case 2:
+                //通知人才申报初审人员
+                try {
+                    $userId = $data["userId"];
+                    $name = $data["name"];
+                    $phone = $data["phone"];
+                    $count = $data["count"];
+                    $template = sprintf("【晋江市人才服务平台】您的部门有%d条人才认定申报记录待初审,请及时登录审批系统处理。", $count);
+                    $smsapi = new ChuanglanSmsApi();
+                    $result = $smsapi->sendSMS($phone, $template);
+                    $result = json_decode($result, true);
+                    $id = getStringId();
+                    $record_data = [
+                        'id' => $id,
+                        'userId' => $userId,
+                        'bizId' => $result["msgId"],
+                        'type' => 1,
+                        'smsType' => 2,
+                        'name' => $name,
+                        'phone' => $phone,
+                        'params' => "初级审核",
+                        'templateCode' => $template,
+                        'state' => $result['code'] == 0 ? 2 : 3,
+                        'sendingDate' => date("Y-m-d H:i:s", time()),
+                        'createTime' => date("Y-m-d H:i:s", time()),
+                        'msg' => $result['errorMsg']
+                    ];
+
+                    MessageRecord::create($record_data);
+                    return true;
+                } catch (\think\Exception $e) {
+                    return false;
+                }
                 break;
         }
         return false;

+ 1 - 0
config/console.php

@@ -7,6 +7,7 @@ return [
     // 指令定义
     'commands' => [
         "Solver" => "app\command\Solver",
+        "FstVerifyChecker" => "app\command\FstVerifyChecker", //人才认定初审阶段检查
         "RegisterMessenger" => "app\command\RegisterMessenger", //注册短信提醒后台审核
         "DeptVerifyChecker" => "app\command\DeptVerifyChecker", //人才认定部门审核阶段检查
     ],