Browse Source

积分申报++

sugangqiang 2 năm trước cách đây
mục cha
commit
b419f4cb06
1 tập tin đã thay đổi với 68 bổ sung132 xóa
  1. 68 132
      app/enterprise/controller/Integral.php

+ 68 - 132
app/enterprise/controller/Integral.php

@@ -83,64 +83,22 @@ class Integral extends EnterpriseController {
     private function submitToCheck() {
         $params = $this->request->param();
         $id = $params["id"];
-        $info = TalentApi::chkIsOwner($id, $this->user["uid"]);
+        $info = IntegralRecordApi::chkIsOwner($id, $this->user["uid"]);
         if ($info) {
-            $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
+            $info["real_state"] = TalentLogApi::getLastLog($id, ProjectState::INTEGRAL)["state"];
         }
         $checkState = $info["checkState"];
-        if ($checkState == TalentState::SCND_SAVE || !$id) {
-            $field_dict = \app\common\api\DictApi::getTalentFields(4);
-
-            $no_empty = ["name", "nation", "card_type", "card_number", "sex", "birthday", "politics", "nationality", "province", "city", "county", "talent_type", "experience", "education",
-                "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name",
-                "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"];
-
-            $where = [];
-            $where[] = ["rel", "=", "study_abroad"];
-            $where[] = ["project", "=", 1];
-            $where[] = ["active", "=", 1];
-            $where[] = ["delete", "=", 0];
-            $where[] = ["type", "=", $this->user["type"]];
-            $where[] = ["isConditionFile", "<>", 1];
-            $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
-            $abroad_file_ids = null;
-            if ($abroad_files)
-                $abroad_file_ids = array_column($abroad_files, "id");
-
-            if (in_array($params["talent_type"], [1, 2])) {
-                $no_empty[] = "tax_insurance_month";
-                $no_empty[] = "labor_contract_rangetime";
-            }
-            if ($params["talent_type"] == 3) {
-                $no_empty[] = "pre_import_type";
-            }
-            if ($params["study_abroad"] == 1) {
-                $no_empty[] = "abroad_school";
-                $no_empty[] = "abroad_major";
-            }
-            if (in_array($params["source"], [1, 3])) {
-                $no_empty[] = "source_batch";
-                $no_empty[] = "fujian_highcert_pubtime";
-                $no_empty[] = "fujian_highcert_exptime";
-                if ($params["source"] == 3) {
-                    $no_empty[] = "source_city";
-                }
-            }
-            if (in_array($params["source"], [2, 4])) {
-                $no_empty[] = "source_batch";
-                $no_empty[] = "quanzhou_highcert_pubtime";
-                $no_empty[] = "quanzhou_highcert_exptime";
-                if ($params["source"] == 4) {
-                    $no_empty[] = "source_county";
-                }
-            }
+        if ($checkState == IntegralState::SAVE || !$id) {
+            $field_dict = [
+                "name" => "姓名",
+                "card_type" => "证件类型",
+                "card_number" => "证件号码",
+                "phone" => "手机号码",
+                "email" => "电子邮箱"
+            ];
 
-            $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
+            $no_empty = ["name", "card_type", "card_number", "phone", "email"];
 
-            if ($condition_info["isSalary"] == 1) {
-                $no_empty[] = "annual_salary";
-            }
-            $no_empty = array_filter($no_empty);
             $return = [];
             foreach ($no_empty as $key) {
                 if (!$params[$key]) {
@@ -153,74 +111,52 @@ class Integral extends EnterpriseController {
                 exit;
             }
 
-            if ($condition_info["bindFileTypes"] && $info["source"] == 5) {
-                $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
-                $whr[] = ["must", "=", 1];
-            }
-            $where = [];
-            $where[] = ["project", "=", 1];
-            $where[] = ["type", "=", $this->user["type"]];
-            $where[] = ["must", "=", 1];
-            $where[] = ["active", "=", 1];
-            $where[] = ["delete", "=", 0];
-            $where[] = ["isConditionFile", "<>", 1];
-            if ($whr) {
-                $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
-            } else {
-                $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
-            }
-            $age = 0;
-            if ($params["birthday"]) {
-                $birthday = $params["birthday"];
-                $birthdayYear = substr($birthday, 0, 4);
-                $currentYear = date("Y");
-                $age = $currentYear - $birthdayYear;
-            }
+            $insertDetailList = [];
+            $tmp_item_ids = [];
+            $projectTypes = $params["projectType"];
+            $projectIds = $params["projectId"];
+            $item_ids = $params["item_id"];
+            $amounts = $params["amount"];
+
+            $detailCounts = count($item_ids);
             $ft_ids = [];
-            $deletes = [];
-            foreach ($filetypes as $ft) {
-                if ($ft["option"]) {
-                    if ($ft["rel"] == "birthday") {
-                        if ($age < $ft["option"]) {
-                            $deletes[] = $ft["id"];
-                            continue;
-                        }
-                    } else {
-                        $selectVal = $params[$ft["rel"]];
-                        $conditions = array_filter(explode(",", $ft["option"]));
-                        if (!in_array($selectVal, $conditions)) {
-                            $deletes[] = $ft["id"];
-                            continue;
-                        }
-                    }
+            for ($i = 0; $i < $detailCounts; $i++) {
+                if (!in_array($item_ids[$i], $tmp_item_ids)) {
+                    $tmp_item_ids[] = $item_ids[$i];
                 }
-                $ft_ids[] = $ft["id"];
-            }
-            if ($params["study_abroad"] == 1) {
-                //选中留学,如果存在留学附件变成必传
-                $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids));
-            } else {
-                //没选中,留学附件就算设成必传也不用验证
-                $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids);
+                if (!is_numeric($amounts[$i]) || $amounts[$i] < 0) {
+                    throw new ValidateException(sprintf("第%d个积分标准项的数额填写错误,应填入大于0的数字", $i + 1));
+                }
+                $integralItemInfo = \app\common\api\IntegralItemApi::getOne($item_ids[$i]);
+                if (!$integralItemInfo) {
+                    throw new ValidateException(sprintf("第%d个积分标准项不存在", $i + 1));
+                }
+                $ft_ids = array_filter(array_merge($ft_ids, array(explode(",", $integralItemInfo["fileTypeId"]))));
             }
-            $whr = [];
-            if ($id) {
-                $whr[] = ["mainId", "=", $id];
-            } else {
-                if ($params["uploadFiles"])
-                    $whr[] = ["id", "in", $params["uploadFiles"]];
+            if (count($tmp_item_ids) != $detailCounts) {
+                throw new ValidateException("同一个申报中,同一个积分标准不能申报多次");
             }
-            $whr[] = ["typeId", "in", $ft_ids];
-            $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
-            $upload_type_counts = count($distinct_filetypes);
-            if ($upload_type_counts != count($ft_ids)) {
-                $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
-                echo sprintf("<script>parent.IntegralInfoDlg.submitCallback(%s);</script>", json_encode($res));
-                exit;
+            if ($ft_ids) {
+                $whr = [];
+                if ($id) {
+                    $whr[] = ["mainId", "=", $id];
+                    $whr[] = ["type", "=", ProjectState::INTEGRAL];
+                } else {
+                    if ($params["uploadFiles"])
+                        $whr[] = ["id", "in", $params["uploadFiles"]];
+                }
+                $whr[] = ["typeId", "in", $ft_ids];
+                $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
+                $upload_type_counts = count($distinct_filetypes);
+                if ($upload_type_counts != count($ft_ids)) {
+                    $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
+                    echo sprintf("<script>parent.IntegralInfoDlg.submitCallback(%s);</script>", json_encode($res));
+                    exit;
+                }
             }
 
-            return $this->mixSave($info, $this->request, TalentState::SCND_SUBMIT);
-        } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL, TalentState::ZX_FAIL, TalentState::ANNOUNCED_REVERIFY_FAIL, TalentState::PUBLISH_FAIL])) {
+            return $this->save($info, $this->request, IntegralState::SUBMIT);
+        } else if (in_array($checkState, [IntegralState::VERIFY_FAIL, IntegralState::REVERIFY_FAIL, IntegralState::ZX_FAIL, IntegralState::ANNOUNCED_REVERIFY_FAIL, IntegralState::PUBLISH_FAIL])) {
             $res = ["msg" => "审核失败,不能再提交审核"];
             echo sprintf("<script>parent.IntegralInfoDlg.submitCallback(%s);</script>", json_encode($res));
             exit;
@@ -237,11 +173,12 @@ class Integral extends EnterpriseController {
      */
     private function save($info, \think\Request $request, $checkState) {
         try {
+            $param = $request->param();
             $batch = \app\common\api\BatchApi::getValidBatch(ProjectState::INTEGRAL, $this->user["type"]);
             if (!$batch) {
                 throw new ValidateException("不在人才认定申报申请时间内");
             }
-            $param = $request->param();
+            $data["batch_id"] = $batch["id"];
             validate(IntegralValidator::class)->check($param);
             $id = $param["id"];
             $files = $param["uploadFiles"];
@@ -257,33 +194,22 @@ class Integral extends EnterpriseController {
             }
 
             $insertDetailList = [];
-            $tmp_item_ids = [];
-            $data["batch_id"] = $batch["id"];
-            $projectTypes = $param["projectType"];
-            $projectIds = $param["projectId"];
             $item_ids = $param["item_id"];
             $amounts = $param["amount"];
 
             $detailCounts = count($item_ids);
             for ($i = 0; $i < $detailCounts; $i++) {
-                if (!in_array($item_ids[$i], $tmp_item_ids)) {
-                    $tmp_item_ids[] = $item_ids[$i];
-                }
                 if (!is_numeric($amounts[$i]) || $amounts[$i] < 0) {
                     throw new ValidateException(sprintf("第%d个积分标准项的数额填写错误,应填入大于0的数字", $i + 1));
                 }
                 $insertDetailList[] = [
                     "id" => getStringId(),
                     "record_id" => "",
-                    "item_id" => "",
-                    "amount" => "",
-                    "unit" => "",
-                    "file_id"
+                    "item_id" => $item_ids[$i],
+                    "amount" => $amounts[$i],
+                    "unit" => ""
                 ];
             }
-            if (count($tmp_item_ids) != $detailCounts) {
-                throw new ValidateException("同一个申报中,同一个积分标准不能申报多次");
-            }
 
             if ($info["real_state"] == IntegralState::VERIFY_REJECT) {
                 //真实状态是驳回,需要判断什么字段可以提交                
@@ -294,8 +220,8 @@ class Integral extends EnterpriseController {
                     $data[$field] = $tmp_data[$field];
                 }
                 $tmp_item_ids = [];
-                if ($info["modify_files"]) {
-                    
+                if (!$info["modify_files"]) {
+                    $insertDetailList = []; //不能修改项目,清空
                 }
             }
             $data["checkState"] = $checkState;
@@ -352,6 +278,16 @@ class Integral extends EnterpriseController {
             }
 
             if ($data["id"]) {
+                \app\common\model\IntegralDetail::where("record_id", "=", $data["id"])->delete();
+                if ($insertDetailList) {
+                    foreach ($insertDetailList as $insertItem) {
+                        $integralItemInfo = \app\common\api\IntegralItemApi::getOne($item_ids[$i]);
+                        $insertItem["record_id"] = $data["id"];
+                        $insertItem["unit"] = $integralItemInfo["unit"];
+                        \app\common\model\IntegralDetail::insert($insertItem);
+                    }
+                }
+
                 //删除多余的附件,一般是选择人才类型留下来的
                 $whr = [];
                 $whr[] = ["mainId", "=", $data["id"]];