|  | @@ -5,11 +5,12 @@ namespace app\enterprise\controller;
 | 
	
		
			
				|  |  |  use app\enterprise\common\EnterpriseController;
 | 
	
		
			
				|  |  |  use think\facade\Db;
 | 
	
		
			
				|  |  |  use app\common\api\EnterpriseApi;
 | 
	
		
			
				|  |  | -use app\enterprise\validate\TalentInfo;
 | 
	
		
			
				|  |  | -use app\common\api\IntegralState;
 | 
	
		
			
				|  |  | +use app\common\state\IntegralState;
 | 
	
		
			
				|  |  |  use app\common\api\IntegralRecordApi;
 | 
	
		
			
				|  |  |  use app\common\api\TalentLogApi;
 | 
	
		
			
				|  |  | -use app\common\api\Project;
 | 
	
		
			
				|  |  | +use app\common\state\ProjectState;
 | 
	
		
			
				|  |  | +use app\enterprise\validate\IntegralValidator;
 | 
	
		
			
				|  |  | +use think\exception\ValidateException;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * Description of 积分申报
 | 
	
	
		
			
				|  | @@ -23,7 +24,7 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public function list() {
 | 
	
		
			
				|  |  | -        $res = IntegralRecordApi::getList($this->request, $step);
 | 
	
		
			
				|  |  | +        $res = IntegralRecordApi::getList($this->request->param());
 | 
	
		
			
				|  |  |          return json($res);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -37,7 +38,7 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |          $info = IntegralRecordApi::getOne($id);
 | 
	
		
			
				|  |  |          $ep = EnterpriseApi::getOne($this->user["uid"]);
 | 
	
		
			
				|  |  |          if ($info) {
 | 
	
		
			
				|  |  | -            $info["real_state"] = TalentLogApi::getLastLog($id, Project::INTEGRAL)["state"];
 | 
	
		
			
				|  |  | +            $info["real_state"] = TalentLogApi::getLastLog($id, ProjectState::INTEGRAL)["state"];
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if ($info && in_array($info["checkState"], [IntegralState::VERIFY_PASS, IntegralState::REVERIFY_PASS, IntegralState::REVERIFY_FAIL])) {
 | 
	
		
			
				|  |  |              return $this->view($request);
 | 
	
	
		
			
				|  | @@ -236,7 +237,7 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      private function save($info, \think\Request $request, $checkState) {
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  | -            $batch = \app\common\api\BatchApi::getValidBatch(Project::INTEGRAL, $this->user["type"]);
 | 
	
		
			
				|  |  | +            $batch = \app\common\api\BatchApi::getValidBatch(ProjectState::INTEGRAL, $this->user["type"]);
 | 
	
		
			
				|  |  |              if (!$batch) {
 | 
	
		
			
				|  |  |                  throw new ValidateException("不在人才认定申报申请时间内");
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -255,14 +256,35 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |                  $data[$key] = trim($param[$key]);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            $updateDetailList = [];
 | 
	
		
			
				|  |  |              $insertDetailList = [];
 | 
	
		
			
				|  |  | +            $tmp_item_ids = [];
 | 
	
		
			
				|  |  |              $data["batch_id"] = $batch["id"];
 | 
	
		
			
				|  |  | -            $detail_ids = $param["detail_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"
 | 
	
		
			
				|  |  | +                ];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (count($tmp_item_ids) != $detailCounts) {
 | 
	
		
			
				|  |  | +                throw new ValidateException("同一个申报中,同一个积分标准不能申报多次");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              if ($info["real_state"] == IntegralState::VERIFY_REJECT) {
 | 
	
		
			
				|  |  |                  //真实状态是驳回,需要判断什么字段可以提交                
 | 
	
		
			
				|  |  |                  $modify_fields = array_filter(explode(",", $info["modify_fields"]));
 | 
	
	
		
			
				|  | @@ -273,31 +295,7 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  $tmp_item_ids = [];
 | 
	
		
			
				|  |  |                  if ($info["modify_files"]) {
 | 
	
		
			
				|  |  | -                    $detailCounts = count($detail_ids);
 | 
	
		
			
				|  |  | -                    for ($i = 0; $i < $detailCounts; $i++) {
 | 
	
		
			
				|  |  | -                        if (!in_array($item_ids[$i], $tmp_item_ids)) {
 | 
	
		
			
				|  |  | -                            $tmp_item_ids[] = $item_ids[$i];
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        if ($detail_ids[$i]) {
 | 
	
		
			
				|  |  | -                            $updateDetailList[] = [
 | 
	
		
			
				|  |  | -                                "id" => $detail_ids[$i],
 | 
	
		
			
				|  |  | -                                "record_id" => "",
 | 
	
		
			
				|  |  | -                                "item_id" => "",
 | 
	
		
			
				|  |  | -                                "amount" => "",
 | 
	
		
			
				|  |  | -                                "unit" => "",
 | 
	
		
			
				|  |  | -                                "file_id"
 | 
	
		
			
				|  |  | -                            ];
 | 
	
		
			
				|  |  | -                        } else {
 | 
	
		
			
				|  |  | -                            $insertDetailList[] = [
 | 
	
		
			
				|  |  | -                                "id" => getStringId(),
 | 
	
		
			
				|  |  | -                                "record_id" => "",
 | 
	
		
			
				|  |  | -                                "item_id" => "",
 | 
	
		
			
				|  |  | -                                "amount" => "",
 | 
	
		
			
				|  |  | -                                "unit" => "",
 | 
	
		
			
				|  |  | -                                "file_id"
 | 
	
		
			
				|  |  | -                            ];
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | +                    
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              $data["checkState"] = $checkState;
 | 
	
	
		
			
				|  | @@ -308,8 +306,9 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |                  $success_msg = "保存成功";
 | 
	
		
			
				|  |  |                  if ($data["id"]) {
 | 
	
		
			
				|  |  |                      //编辑
 | 
	
		
			
				|  |  | -                    TalentModel::update($data);
 | 
	
		
			
				|  |  | -                    $last_log = TalentLogApi::getLastLog($data["id"], Project::INTEGRAL);
 | 
	
		
			
				|  |  | +                    $data["updateTime"] = date("Y-m-d H:i:s");
 | 
	
		
			
				|  |  | +                    \app\common\model\IntegralRecord::update($data);
 | 
	
		
			
				|  |  | +                    $last_log = TalentLogApi::getLastLog($data["id"], ProjectState::INTEGRAL);
 | 
	
		
			
				|  |  |                      if ($last_log["new_state"] != IntegralState::SAVE) {
 | 
	
		
			
				|  |  |                          TalentLogApi::write(1, $data["id"], $checkState, "保存未提交", 1);
 | 
	
		
			
				|  |  |                      } else {
 | 
	
	
		
			
				|  | @@ -317,10 +316,11 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  } else {
 | 
	
		
			
				|  |  |                      //新增
 | 
	
		
			
				|  |  | -                    $data["enterprise_id"] = $this->user["uid"];
 | 
	
		
			
				|  |  |                      $data["id"] = getStringId();
 | 
	
		
			
				|  |  | +                    $data["enterprise_id"] = $this->user["uid"];
 | 
	
		
			
				|  |  | +                    $data["createTime"] = date("Y-m-d H:i:s");
 | 
	
		
			
				|  |  |                      \app\common\model\IntegralRecord::insert($data);
 | 
	
		
			
				|  |  | -                    TalentLogApi::write(Project::INTEGRAL, $data["id"], $checkState, "保存未提交", 1);
 | 
	
		
			
				|  |  | +                    TalentLogApi::write(ProjectState::INTEGRAL, $data["id"], $checkState, "保存未提交", 1);
 | 
	
		
			
				|  |  |                      $whr = [];
 | 
	
		
			
				|  |  |                      $whr[] = ["fileId", "in", $files];
 | 
	
		
			
				|  |  |                      $upd_checklog["mainId"] = $data["id"];
 | 
	
	
		
			
				|  | @@ -333,18 +333,20 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |                      $data["new_submit_time"] = date("Y-m-d H:i:s");
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  if ($data["id"]) {
 | 
	
		
			
				|  |  | +                    $data["updateTime"] = date("Y-m-d H:i:s");
 | 
	
		
			
				|  |  |                      \app\common\model\IntegralRecord::update($data);
 | 
	
		
			
				|  |  |                  } else {
 | 
	
		
			
				|  |  |                      //新增
 | 
	
		
			
				|  |  | -                    $data["enterprise_id"] = $this->user["uid"];
 | 
	
		
			
				|  |  |                      $data["id"] = getStringId();
 | 
	
		
			
				|  |  | +                    $data["enterprise_id"] = $this->user["uid"];
 | 
	
		
			
				|  |  | +                    $data["createTime"] = date("Y-m-d H:i:s");
 | 
	
		
			
				|  |  |                      \app\common\model\IntegralRecord::insert($data);
 | 
	
		
			
				|  |  |                      $whr = [];
 | 
	
		
			
				|  |  |                      $whr[] = ["fileId", "in", $files];
 | 
	
		
			
				|  |  |                      $upd_checklog["mainId"] = $data["id"];
 | 
	
		
			
				|  |  |                      Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                TalentLogApi::write(Project::INTEGRAL, $id, $checkState, "确认提交审核", 1);
 | 
	
		
			
				|  |  | +                TalentLogApi::write(ProjectState::INTEGRAL, $data["id"], $checkState, "确认提交审核", 1);
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  throw new ValidateException($error_msg);
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -353,7 +355,7 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |                  //删除多余的附件,一般是选择人才类型留下来的
 | 
	
		
			
				|  |  |                  $whr = [];
 | 
	
		
			
				|  |  |                  $whr[] = ["mainId", "=", $data["id"]];
 | 
	
		
			
				|  |  | -                $whr[] = ["type", "=", Project::INTEGRAL];
 | 
	
		
			
				|  |  | +                $whr[] = ["type", "=", ProjectState::INTEGRAL];
 | 
	
		
			
				|  |  |                  $whr[] = ["id", "not in", $files];
 | 
	
		
			
				|  |  |                  $_wait_del_files = Db::table("new_talent_file")->where($whr)->select()->toArray();
 | 
	
		
			
				|  |  |                  $_logfileIds[] = [];
 | 
	
	
		
			
				|  | @@ -373,8 +375,8 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  $whr = [];
 | 
	
		
			
				|  |  |                  $whr[] = ["id", "in", $files];
 | 
	
		
			
				|  |  | -                Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
 | 
	
		
			
				|  |  | -                $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $id, "checkState" => $checkState]];
 | 
	
		
			
				|  |  | +                Db::table("new_talent_file")->where($whr)->save(["mainId" => $data["id"]]);
 | 
	
		
			
				|  |  | +                $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $data["id"], "checkState" => $checkState]];
 | 
	
		
			
				|  |  |                  $callback = $checkState == IntegralState::SAVE ? "infoCallback" : "submitCallback";
 | 
	
		
			
				|  |  |                  echo sprintf("<script>parent.IntegralInfoDlg.{$callback}(%s);</script>", json_encode($res));
 | 
	
		
			
				|  |  |                  exit();
 | 
	
	
		
			
				|  | @@ -397,7 +399,7 @@ class Integral extends EnterpriseController {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          $checkState = $info["checkState"];
 | 
	
		
			
				|  |  |          if (in_array($checkState, [0, 1])) {
 | 
	
		
			
				|  |  | -            $log = TalentLogApi::getLastLog($id, Project::INTEGRAL);
 | 
	
		
			
				|  |  | +            $log = TalentLogApi::getLastLog($id, ProjectState::INTEGRAL);
 | 
	
		
			
				|  |  |              if ($log["state"] > 1) {
 | 
	
		
			
				|  |  |                  //有提交审核记录
 | 
	
		
			
				|  |  |                  return json(["msg" => "该申报已提交审核,无法删除"]);
 |