瀏覽代碼

申报过程中的短信

sugangqiang 2 年之前
父節點
當前提交
bbfd0f433d
共有 2 個文件被更改,包括 176 次插入33 次删除
  1. 168 33
      app/admin/controller/Talent.php
  2. 8 0
      app/common/api/MenuApi.php

+ 168 - 33
app/admin/controller/Talent.php

@@ -13,6 +13,10 @@ use app\common\api\TalentConditionApi;
 use app\common\api\DictApi;
 use app\common\api\EnterpriseApi;
 use think\facade\Db;
+use app\admin\model\User;
+use app\common\api\MenuApi;
+use app\admin\model\Menu;
+use app\admin\model\SysRelation;
 
 /**
  * Description of Talent
@@ -354,7 +358,8 @@ class Talent extends AdminController {
             }
             if (VerifyApi::setPublic($id, $state, $msg, $publicBatch)) {
                 $success++;
-                $phones[] = $talent_info["phone"];
+                $ep = EnterpriseApi::getOne($talent_info['enterprise_id']);
+                $phones[] = $ep->agentPhone;
             } else {
                 $error++;
             }
@@ -365,7 +370,27 @@ class Talent extends AdminController {
             $tpl_content = sprintf("【晋江市人才服务平台】您好!您提交申请的%s已完成初步审核,现通过%s将审核结果予以公示,公示时间%s至%s。公示期间如有异议,请及时向%s反映。电话%s,电子邮箱%s。",
                     $params["typeName"], $params["address"], $params["publicStartTime"], $params["publicEndTime"], $params["dep"], $params["phone"], $params["email"]);
             while ($phone = array_shift($phones)) {
-                $sms->sendSMS($phone, $tpl_content);
+                $result = $sms->sendSMS($phone, $tpl_content);
+
+                $result = json_decode($result, true);
+
+                $recordId = getStringId();
+
+                $record_data = [
+                    'id' => $recordId,
+                    'bizId' => $recordId,
+                    'type' => 2,
+                    'smsType' => 1,
+                    'phone' => $phone,
+                    'params' => '公示',
+                    'templateCode' => $tpl_content,
+                    '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 json(["code" => 200, "msg" => sprintf("公示完成:共提交%d个人才,通过%d个,失败%d个", $total, $success, $error)]);
@@ -729,6 +754,7 @@ class Talent extends AdminController {
         if (in_array($log["new_state"], [TalentState::BASE_VERIFY_PASS, TalentState::FST_VERIFY_PASS, TalentState::REVERIFY_PASS])) {
             $data["highProcess"] = $nowProcess > $talent_info["highProcess"] ? $nowProcess : $talent_info["highProcess"];
         }
+        $userIds = [];
         if ($log["new_state"] == TalentState::FST_VERIFY_PASS && $talent_info["pass_dept_check"] == 0) {
             $data["first_dept_check_time"] = date("Y-m-d H:i:s");
             $condition = TalentConditionApi::getOne($talent_info["talent_condition"]);
@@ -741,12 +767,25 @@ class Talent extends AdminController {
             } else {
                 sort($unpass_companyIds);
                 TalentLogApi::writeDeptLogs($talent_info["id"], $unpass_companyIds, TalentState::FST_VERIFY_PASS);
+
+                //初审通过发送短信通知并审部门
+                $privs = ["/admin/talent/dept_check"];
+                $menuIds = MenuApi::getMenuIdsByNewUrls($privs);
+                $where[] = ["menuid", "in", $menuIds];
+                $roleIds = SysRelation::where($where)->group("roleid")->having("count(*)=" . count($privs))->column("roleid");
+                $where = [];
+                $where[] = ["status", "=", 1];
+                $where[] = ["companyId","in",$unpass_companyIds];
+                $where[] = ["roleid", "in", $roleIds];
+                $where[] = ["roleid", "<>", 1];
+                $userIds = User::where($where)->column("id");
             }
         }
         $data["id"] = $talent_info["id"];
         $data["checkState"] = $log["new_state"];
         TalentModel::update($data);
         TalentLogApi::setActive($log["id"], 1);
+        $this->sendMsgByState($talent_info, $log["new_state"], $userIds);
         return json(["code" => 200, "msg" => "审核成功"]);
     }
 
@@ -868,6 +907,20 @@ class Talent extends AdminController {
             $data["first_dept_check_time"] = null;
             TalentModel::update($data);
             TalentLogApi::write(1, $talent_info["id"], [$log_checkState, $checkState], "部门审核结束", 1);
+            if ($log_checkState == TalentState::DEPT_VERIFY_REJECT) {
+                //部门驳回发送短信通知
+                $privs = ["admin/talent/fst_check"];
+                $menuIds = MenuApi::getMenuIdsByNewUrls($privs);
+                $where[] = ["menuid", "in", $menuIds];
+                $roleIds = SysRelation::where($where)->group("roleid")->having("count(*)=" . count($privs))->column("roleid");
+                $where = [];
+                $where[] = ["status", "=", 1];
+                $where[] = ["roleid", "in", $roleIds];
+                $where[] = ["roleid", "<>", 1];
+                $userIds = User::where($where)->column("id");
+
+                $this->sendMsgByState($talent_info, $log_checkState, $userIds);
+            }
         }
         TalentLogApi::setActive($dept_log["id"], 1);
         return json(["code" => 200, "msg" => "审核成功"]);
@@ -923,44 +976,126 @@ class Talent extends AdminController {
             $data["highProcess"] = $nowProcess > $talent_info["highProcess"] ? $nowProcess : $talent_info["highProcess"];
         }
 
-        $smsapi = new ChuanglanSmsApi();
-        if ($log['last_state'] == 1) { //TODO 审核结果判断待强哥修复
-            //基础信息审核通过,发送短信
-            $template = "【晋江市人才服务平台】尊敬的用户,您提交的人才基础信息审核通过,请及时登录申报系统并进行人才认定的信息申报填写。";
-        } else {
-            //基础信息审核通过,发送短信
-            $template = "【晋江市人才服务平台】尊敬的用户,您提交的人才基础信息审核驳回,原因是:{$log['description']},请及时登录申报系统修改并重新提交。";
-        }
-        $ep = EnterpriseApi::getOne($talent_info['enterprise_id']);
-        $result = $smsapi->sendSMS($ep->agentPhone, $template);
-
-        $result = json_decode($result, true);
-
-        $id = getStringId();
-
-        $record_data = [
-            'id' => $id,
-            'bizId' => $id,
-            'type' => 2,
-            'smsType' => 1,
-            'phone' => $ep->agentPhone,
-            '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);
-
         $data["id"] = $talent_info["id"];
         $data["checkState"] = $log["new_state"];
         TalentModel::update($data);
         TalentLogApi::setActive($log["id"], 1);
+        $userIds = [];
+        if (in_array($data["checkState"], [TalentState::REVERIFY_PASS, TalentState::REVERIFY_REJECT])) {
+            //复核成功需要发送短信给征信部门,复核的其它状态发送通知给用户,调用此方法的还有基础审核的每个状态都要发送通知给用户
+            //从征信审核权限,逆推征信部门
+            if ($data["checkState"] == TalentState::REVERIFY_PASS) {
+                $privs = ["/admin/talent/hczxReject", "/admin/talent/hczxPass"];
+            } else {
+                $privs = ["admin/talent/fst_check"];
+            }
+            $menuIds = MenuApi::getMenuIdsByNewUrls($privs);
+            $where = [];
+            $where[] = ["menuid", "in", $menuIds];
+            $roleIds = SysRelation::where($where)->group("roleid")->having("count(*)=" . count($privs))->column("roleid");
+            $where = [];
+            $where[] = ["status", "=", 1];
+            $where[] = ["roleid", "in", $roleIds];
+            $where[] = ["roleid", "<>", 1];
+            $userIds = User::where($where)->column("id");
+        }
+        $this->sendMsgByState($talent_info, $data["checkState"], $userIds);
         return json(["code" => 200, "msg" => "审核成功"]);
     }
 
+    private function sendMsgByState($talent_info, $state, $userIds = []) {
+        $phones = [];
+        $template = "";
+        $type = 0;
+        $processName = "";
+        $userId = 0;
+        $name = null;
+        switch ($state) {
+            case TalentState::BASE_VERIFY_PASS://基础信息审核通过发送短信通知用户
+                $type = 2;
+                $processName = "基础信息审核";
+                $template = "【晋江市人才服务平台】尊敬的用户,您提交的人才基础信息审核通过,请及时登录申报系统并进行人才认定的信息申报填写。";
+                break;
+            case TalentState::BASE_REJECT://基础信息审核驳回发送短信通知用户
+                $type = 2;
+                $processName = "基础信息审核";
+                $template = "【晋江市人才服务平台】尊敬的用户,您提交的人才基础信息审核驳回,原因是:{$log['description']},请及时登录申报系统修改并重新提交。";
+                break;
+            case TalentState::BASE_VERIFY_FAIL://基础信息审核不通过发送短信通知用户
+                $type = 2;
+                $processName = "基础信息审核";
+                $template = "【晋江市人才服务平台】尊敬的用户,您提交的人才基础信息审核不通过,原因是:{$log['description']}。";
+                break;
+            case TalentState::FST_VERIFY_PASS://初审通过发送短信通知并审部门
+                $type = 1;
+                $processName = "初级审核";
+                $template = "【晋江市人才服务平台】您的部门有新的人才认定申报需要审批,请及时登录审批系统处理。";
+                break;
+            case TalentState::FST_VERIFY_REJECT; //初审驳回发送短信通知用户
+                $type = 2;
+                $processName = "初级审核";
+                $template = "【晋江市人才服务平台】尊敬的用户,您提交的人才认定申报审核驳回,原因是:{$log['description']},请及时登录申报系统修改并重新提交。";
+                break;
+            case TalentState::FST_VERIFY_FAIL://初审不通过发送短信通知用户
+                $type = 2;
+                $processName = "初级审核";
+                $template = "【晋江市人才服务平台】尊敬的用户,您提交的人才认定申报审核不通过,原因是:{$log['description']}。";
+                break;
+            case TalentState::DEPT_VERIFY_REJECT://并审驳回发送短信通知初审部门
+                $type = 1;
+                $processName = "部门并审";
+                $template = "【晋江市人才服务平台】有人才认定申报在并审阶段被驳回,原因是:{$log['description']},请及时登录审批系统处理。";
+                break;
+            case TalentState::REVERIFY_PASS://复核通过发短信通知征信部门
+                $type = 1;
+                $processName = "复审";
+                $template = "【晋江市人才服务平台】有新的人才认定申报通过复审进入征信阶段,请及时登录审批系统处理。";
+                break;
+            case TalentState::REVERIFY_REJECT://复核驳回发短信通知初审部门
+                $type = 1;
+                $processName = "复审";
+                $template = "【晋江市人才服务平台】有人才认定申报在复审阶段被驳回,原因是:{$log['description']},请及时登录审批系统处理。";
+                break;
+        }
+        if ($type == 1) {
+            $where = [];
+            $where[] = ["id", "in", $userIds];
+            $phones = User::where($where)->column("phone");
+            $phones = array_unique(array_filter($phones));
+        }
+        if ($type == 2) {
+            $ep = EnterpriseApi::getOne($talent_info['enterprise_id']);
+            $phones[] = $ep->agentPhone;
+            $userId = $ep->id;
+            $name = $ep->name;
+        }
+        if ($phones && $template) {
+            while ($phone = array_shift($phones)) {
+                $smsapi = new ChuanglanSmsApi();
+                $result = $smsapi->sendSMS($phone, $template);
+                $result = json_decode($result, true);
+                $id = getStringId();
+                $record_data = [
+                    'id' => $id,
+                    'userId' => $userId,
+                    'bizId' => $id,
+                    'type' => $type,
+                    'smsType' => 2,
+                    'name' => $name,
+                    'phone' => $phone,
+                    'params' => $processName,
+                    '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);
+            }
+        }
+    }
+
     public function check() {
 //公共调度方法
         $request = $this->request;

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

@@ -13,6 +13,14 @@ use app\admin\model\Menu;
  */
 class MenuApi {
 
+    public static function getMenuIdsByNewUrls(array $urls) {
+        $where = [];
+        $where[] = ["new_url", "in", $urls];
+        $where[] = ["status", "=", 1];
+        $where[] = ["delete", "=", 0];
+        return Menu::where($where)->column("id");
+    }
+
     public static function getMenuListByRoleid($roleid) {
         $role = Role::find($roleid);
         $menu_ids = $role->sysRelation->column("menuid");