TalentAllowance.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace app\enterprise\controller;
  8. use app\enterprise\common\EnterpriseController;
  9. use app\common\state\CommonConst;
  10. use app\common\api\BatchApi;
  11. use app\common\api\TalentAllowanceApi;
  12. use app\common\api\EnterpriseApi;
  13. use app\common\state\ProjectState;
  14. use app\common\api\DictApi;
  15. use app\common\state\MainState;
  16. use app\common\model\TalentAllowance as TaModel;
  17. use app\common\state\AllowanceProjectEnum;
  18. use app\common\model\TalentChecklog;
  19. /**
  20. * Description of TalentAllowance
  21. *
  22. * @author sgq
  23. */
  24. class TalentAllowance extends EnterpriseController {
  25. public function index() {
  26. $tpl = "";
  27. switch ($this->user["type"]) {
  28. case CommonConst::ENTERPRISE_JC:
  29. $tpl = "indexIC";
  30. break;
  31. }
  32. return view($tpl, ['type' => $this->user["type"]]);
  33. }
  34. public function list() {
  35. $res = TalentAllowanceApi::getList($this->request);
  36. return json($res);
  37. }
  38. /**
  39. * 申请
  40. */
  41. public function apply(\think\Request $request) {
  42. $param = $request->param();
  43. $id = isset($param["id"]) ? $param["id"] : 0;
  44. $info = null;
  45. if ($id) {
  46. $info = TalentAllowanceApi::getInfoById($id);
  47. $this->translateToChinese($info);
  48. }
  49. if ($request->isPost()) {
  50. return $this->save($info, $request);
  51. }
  52. $batch = $info["year"] ?: BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  53. return view("", ["year" => $batch, "type" => $this->user["type"], "row" => $info]);
  54. }
  55. private function save($talentAllowance, \think\Request $request) {
  56. $response = new \stdClass();
  57. $response->code = 500;
  58. $param = $request->param();
  59. if (!$param) {
  60. $response->msg = "请填写信息后在提交";
  61. return $response;
  62. }
  63. if (\StrUtil::isEmpOrNull($param["talentId"])) {
  64. $response->msg = "请选择申报对象";
  65. return $response;
  66. }
  67. if (!$param["id"]) {
  68. $where = [];
  69. $where[] = ["year", "=", $param["year"]];
  70. $where[] = ["idCard", "=", $param["idCard"]];
  71. $where[] = ["checkState", "not in", [MainState::NOTPASS, MainState::PASS]];
  72. $exists = TaModel::where($where)->find();
  73. if ($exists) {
  74. $response->msg = "当前申请对象在当前批次中存在申请中的记录,请等待申请结束后再操作";
  75. return $response;
  76. }
  77. $user = $this->user;
  78. $ti = \app\common\api\VerifyApi::getTalentInfoById($param["talentId"]);
  79. $data = [
  80. "talentId" => $param["talentId"],
  81. "enterpriseId" => $ti["enterprise_id"],
  82. "enterpriseName" => $user["name"],
  83. "year" => $param["year"],
  84. "source" => $ti["source"],
  85. "qzgccrcActiveTime" => $ti["certificateExpireTime"],
  86. "talentType" => $ti["enterpriseTag"],
  87. "address" => $ti["street"],
  88. "name" => $ti["name"],
  89. "sex" => $ti["sex"],
  90. "cardType" => $ti["card_type"],
  91. "idCard" => $ti["card_number"],
  92. "firstInJJTime" => $ti["fst_work_time"],
  93. "entryTime" => $ti["cur_entry_time"],
  94. "post" => $ti["position"],
  95. "phone" => $ti["phone"],
  96. "talentArrange" => $ti["talent_arrange"],
  97. "identifyCondition" => $ti["talent_condition"],
  98. "identifyGetTime" => $ti["identifyGetTime"],
  99. "identifyOutTime" => $ti["identifyExpireTime"],
  100. "identifyConditionName" => $ti["identifyConditionName"],
  101. "identifyMonth" => $ti["identifyMonth"],
  102. "bank" => $ti["bank"],
  103. "bankNetwork" => $ti["bank_branch_name"],
  104. "bankAccount" => $ti["bank_account"],
  105. "bankNumber" => $ti["bank_number"],
  106. "checkState" => 1,
  107. "type" => $user["type"],
  108. "provinceCode" => $ti["province"],
  109. "provinceName" => \app\common\api\LocationApi::getNameByCode($ti["province"]),
  110. "cityCode" => $ti["city"],
  111. "cityName" => \app\common\api\LocationApi::getNameByCode($ti["city"]),
  112. "countyCode" => $ti["county"],
  113. "countyName" => \app\common\api\LocationApi::getNameByCode($ti["county"]),
  114. "isSupple" => 2,
  115. "createTime" => date("Y-m-d H:i:s"),
  116. "createUser" => $user["uid"],
  117. "id" => getStringId(),
  118. "wage" => $param["wage"]
  119. ];
  120. /* * 1.获取上一年度的人才层次 */
  121. $arrangeList = $this->getLastYearTalentType($data, $ti);
  122. if (!$arrangeList) {
  123. $response->msg = "上一年度暂无有效的人才层次";
  124. return $response;
  125. }
  126. /* * 2.获取上一年度所在单位* */
  127. $contractDetailList = $this->getConcatList($ti, $data, $param["year"]); //保存上一年度的工作单位
  128. if (!$contractDetailList) {
  129. $response->msg = "申报失败,原因为:申报年度不存在有效的工作单位";
  130. return $response;
  131. }
  132. TaModel::insert($data);
  133. \app\common\model\TalentAllowancecontractDetail::insertAll($contractDetailList);
  134. /**
  135. * 4.添加津补贴核查项目
  136. */
  137. //核查项目详情表
  138. $this->createAllowanceProject($data, $contractDetailList);
  139. \app\common\model\TalentAllowanceArrange::insertAll($arrangeList);
  140. //添加日志
  141. TalentChecklog::create([
  142. 'id' => getStringId(),
  143. 'mainId' => $data['id'],
  144. 'type' => intval(ProjectState::JBT),
  145. 'typeFileId' => null,
  146. 'active' => 1,
  147. 'state' => 1,
  148. 'step' => 0,
  149. 'stateChange' => "保存未提交",
  150. 'description' => "添加津补贴申报",
  151. 'createTime' => date("Y-m-d H:i:s", time()),
  152. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  153. ]);
  154. $response->msg = "保存成功";
  155. $response->code = 200;
  156. $response->obj = $data;
  157. return $response;
  158. } else {
  159. TaModel::update($param);
  160. $response->msg = "修改成功";
  161. $response->code = 200;
  162. return $response;
  163. }
  164. }
  165. /**
  166. * 删除优秀人才津补贴
  167. */
  168. public function delete() {
  169. $id = $this->request["id"];
  170. $response = new \stdClass();
  171. $response->code = 500;
  172. $info = TalentAllowanceApi::getInfoById($id);
  173. if ($info["checkState"] != 1) {
  174. $response->msg = "删除失败!此数据已提交审核,无法删除!";
  175. return $response;
  176. }
  177. Db::startTrans();
  178. try {
  179. //删除核查项目表
  180. Db::table("un_talent_allowance_project")->where("mainId", $id)->delete();
  181. //删除合同情况表
  182. Db::table("un_talent_allowancecontract_detail")->where("mainId", $id)->delete();
  183. //删除人才层次变更表
  184. Db::table("un_talent_allowance_arrange")->where("mainId", $id)->delete();
  185. //删除日志
  186. $where[] = ["mainId", "=", $id];
  187. $where[] = ["type", "=", ProjectState::JBT];
  188. Db::table("new_talent_checklog")->where($where)->delete();
  189. //删除主表
  190. Db::table("un_talent_allowance_info")->delete($id);
  191. Db::commit();
  192. $response->code = 200;
  193. $response->msg = "删除成功";
  194. return $response;
  195. } catch (think\db\exception\DbException $e) {
  196. Db::rollback();
  197. $response->msg = $e->getMessage();
  198. return $response;
  199. }
  200. }
  201. public function detail(\think\Request $request) {
  202. $param = $request->param();
  203. $id = $param["id"];
  204. $info = TalentAllowanceApi::getInfoById($id);
  205. $this->translateToChinese($info);
  206. return view("", ["row" => $info]);
  207. }
  208. private function translateToChinese(&$obj) {
  209. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  210. $obj["addressName"] = DictApi::findByParentCodeAndCode("street", $obj["address"])["name"];
  211. }
  212. if (\StrUtil::isNotEmpAndNull($obj["talentType"])) {
  213. $obj["talentTypeName"] = DictApi::findByParentCodeAndCode("enterprise_tag", $obj["talentType"])["name"];
  214. }
  215. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  216. $obj["talentArrangeName"] = DictApi::findByParentCodeAndCode("talent_arrange", $obj["talentArrange"])["name"];
  217. }
  218. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  219. $obj["identifyConditionText"] = \app\common\api\TalentConditionApi::getOne($obj["identifyCondition"])["name"];
  220. }
  221. if (\StrUtil::isNotEmpAndNull($obj["introductionMode"])) {
  222. $obj["introductionModeName"] = DictApi::findByParentCodeAndCode("import_way", $obj["introductionMode"])["name"];
  223. }
  224. }
  225. /* * 获取上一年度的人才层次变更信息 */
  226. private function getLastYearTalentType($info, $talentInfo) {
  227. $arrangeList = [];
  228. /* * * 添加人才层次记录 */
  229. $where = [];
  230. $where[] = ["talentId", "=", $info["talentId"]];
  231. $where[] = ["checkState", "=", MainState::PASS];
  232. $where[] = ["isPublic", ">=", 5];
  233. $where[] = ["oldIdentifyMonth", "<=", $info["year"] . "-12-31"];
  234. $typeList = \app\enterprise\model\TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth")->order("createTime desc")->select()->toArray();
  235. $typeList[] = [
  236. "oldTalentArrange" => $talentInfo["talent_arrange"],
  237. "oldIdentifyCondition" => $talentInfo["talent_condition"],
  238. "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
  239. "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
  240. "oldIdentifyMonth" => $talentInfo["identifyMonth"],
  241. "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
  242. "oldCertificateOutTime" => $talentInfo["certificateExpireTime"],
  243. "newIdentifyMonth" => $info["year"] . "-12-31"
  244. ];
  245. $totalMonth = \DateUtil::getMonthBetweenDates($info["year"] . "-01-01", $info["year"] . "-12-31");
  246. /* * 获取上一年度有效的人才层次 */
  247. usort($typeList, function($a, $b) {
  248. return (int) $b["oldTalentArrange"] - (int) $a["oldTalentArrange"];
  249. });
  250. $commonMonth = [];
  251. foreach ($typeList as $talentTypeChange) {
  252. $startTime = $talentTypeChange["oldIdentifyMonth"];
  253. $endTime = $talentTypeChange["newIdentifyMonth"];
  254. $monthList = \DateUtil::getMonthBetweenDatesNotEnd($startTime, $endTime);
  255. if ($monthList) {
  256. $monthList = array_intersect($monthList, $totalMonth);
  257. }
  258. if ($monthList) {
  259. $months = implode(",", $monthList);
  260. $monthList = array_filter($monthList, function($value) use ($commonMonth) {
  261. return !in_array($value, $commonMonth);
  262. });
  263. $commonMonth = array_filter(array_merge($commonMonth, $monthList));
  264. if (count($monthList) > 0) {
  265. $arrange = [
  266. "id" => getStringId(),
  267. "mainId" => $info["id"],
  268. "talentArrange" => $talentTypeChange["oldTalentArrange"],
  269. "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
  270. "startTime" => $startTime,
  271. "endTime" => $endTime,
  272. "prepareMonths" => null,
  273. "description" => "申报年度有效月份:" . $months,
  274. "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
  275. "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
  276. ];
  277. $sb = '';
  278. foreach ($monthList as $month) {
  279. $sb .= substr($month, 5, 2) . ",";
  280. }
  281. $arrange["prepareMonths"] = rtrim($sb, ",");
  282. $arrangeList[] = $arrange;
  283. }
  284. }
  285. }
  286. return $arrangeList;
  287. }
  288. /**
  289. * @param
  290. * @returns void
  291. * @author Liu
  292. * @date 2020/4/26
  293. * @description 获取上一年度所在单位
  294. * */
  295. private function getConcatList($talentInfo, $info, $year) {
  296. $totalMonth = \DateUtil::getMonthBetweenDates($year + "-01-01", $year + "-12-31");
  297. /** 添加申报人才上一年度工作单位记录 */
  298. $where = [];
  299. $where[] = ["talentId", "=", $talentInfo["id"]];
  300. $where[] = ["checkState", "=", 3];
  301. $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
  302. /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
  303. if ($talentInfo["active"] == 1) {
  304. $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
  305. $starttime = $labor_contract_rangetime[0];
  306. $endtime = $labor_contract_rangetime[1];
  307. $quitList[] = [
  308. "enterpriseId" => $talentInfo["enterprise_id"],
  309. "enterpriseName" => $talentInfo["enterpriseName"],
  310. "talentType" => $talentInfo["enterpriseTag"],
  311. "identifyGetTime" => $talentInfo["identifyGetTime"],
  312. "starttime" => $starttime,
  313. "endtime" => $endtime,
  314. "entryTime" => $talentInfo["cur_entry_time"],
  315. "quitTime" => null,
  316. "post" => $talentInfo["position"]
  317. ];
  318. }
  319. $count = 0;
  320. $list = [];
  321. foreach ($quitList as $quit) {
  322. $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
  323. $monthList = array_intersect($monthList, $totalMonth);
  324. if (!$monthList) {
  325. $list[] = [
  326. "id" => getStringId(),
  327. "mainId" => $info["id"],
  328. "enterpriseId" => $quit["enterpriseId"],
  329. "talentType" => $quit["talentType"],
  330. "startTime" => $quit["starttime"],
  331. "endTime" => $quit["endtime"],
  332. "entryTime" => $quit["entryTime"],
  333. "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
  334. "letterTime" => $quit["letterTime"],
  335. "gygb" => $quit["gygb"],
  336. "identifyGetTime" => $quit["identifyGetTime"],
  337. "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
  338. "post" => $quit["post"]
  339. ];
  340. $count++;
  341. }
  342. }
  343. return $list;
  344. }
  345. private function createAllowanceProject($info, $contractList) {
  346. foreach ($contractList as $detail) {
  347. $projects = [
  348. AllowanceProjectEnum::PROJECT_CONTRACT,
  349. AllowanceProjectEnum::PROJECT_TAX,
  350. AllowanceProjectEnum::PROJECT_WAGES,
  351. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  352. AllowanceProjectEnum::PROJECT_SB_PENSION,
  353. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  354. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  355. AllowanceProjectEnum::PROJECT_WORKDAY,
  356. ];
  357. $list = [];
  358. foreach ($projects as $project) {
  359. $list[] = [
  360. "mainId" => $info["id"],
  361. "baseId" => $detail["id"],
  362. "enterpriseId" => $detail["enterpriseId"],
  363. "project" => $project,
  364. "isLock" => 1,
  365. "createTime" => date("Y-m-d H:i:s")
  366. ];
  367. }
  368. \app\common\model\TalentAllowanceProject::insertAll($list);
  369. }
  370. }
  371. /**
  372. * 查询工作单位
  373. */
  374. public function findAllowanceContractDetail() {
  375. $mainId = $this->request["mainId"];
  376. $offset = $this->request["offset"] ?: 0;
  377. $limit = $this->request["limit"] ?: 1000;
  378. $count = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->count();
  379. $list = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->limit($offset, $limit)->select()->toArray();
  380. $enterpriseMap = \app\common\model\Enterprise::column("name", "id");
  381. foreach ($list as &$row) {
  382. $row["enterpriseName"] = $enterpriseMap[$row["enterpriseId"]];
  383. }unset($row);
  384. return json(["rows" => $list, "total" => $count]);
  385. }
  386. /**
  387. * 查询核查项目情况
  388. */
  389. public function findAllowanceProject() {
  390. $mainId = $this->request["mainId"];
  391. $baseId = $this->request["baseId"];
  392. $offset = $this->request["offset"] ?: 0;
  393. $limit = $this->request["limit"] ?: 1000;
  394. $where = [];
  395. $where[] = ["mainId", "=", $mainId];
  396. $where[] = ["baseId", "=", $baseId];
  397. $count = \app\common\model\TalentAllowanceProject::where($where)->count();
  398. $list = \app\common\model\TalentAllowanceProject::where($where)->limit($offset, $limit)->select()->toArray();
  399. $info = TalentAllowanceApi::getInfoById($mainId);
  400. foreach ($list as &$project) {
  401. $project["projectName"] = AllowanceProjectEnum::getProjectName($project["project"]);
  402. if ($info["checkState"] == 1) {
  403. $project["isEdit"] = in_array($project["project"], [
  404. AllowanceProjectEnum::PROJECT_CONTRACT,
  405. AllowanceProjectEnum::PROJECT_TAX,
  406. AllowanceProjectEnum::PROJECT_WAGES,
  407. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  408. AllowanceProjectEnum::PROJECT_SB_PENSION,
  409. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  410. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  411. AllowanceProjectEnum::PROJECT_WORKDAY
  412. ]) ? 1 : 2;
  413. } else if ($info["checkState"] == 10) {
  414. $projects = explode(",", $info["projects"]);
  415. if (in_array($project["id"], $projects)) {
  416. $project["isEdit"] = 1;
  417. } else {
  418. $project["isEdit"] = 2;
  419. }
  420. } else {
  421. $project["isEdit"] = 2;
  422. }
  423. }unset($project);
  424. return json(["rows" => $list, "total" => $count]);
  425. }
  426. /**
  427. * 查询人才层次变更记录
  428. */
  429. public function findAllowanceArrange() {
  430. $mainId = $this->request["mainId"];
  431. $offset = $this->request["offset"] ?: 0;
  432. $limit = $this->request["limit"] ?: 1000;
  433. $where = [];
  434. $where[] = ["mainId", "=", $mainId];
  435. $count = \app\common\model\TalentAllowanceArrange::where($where)->count();
  436. $list = \app\common\model\TalentAllowanceArrange::where($where)->limit($offset, $limit)->select()->toArray();
  437. foreach ($list as &$arrange) {
  438. $condition = \app\common\api\TalentConditionApi::getOne($arrange["identifyCondition"]);
  439. $arrange["identifyConditionText"] = $condition["name"];
  440. $arrange["talentArrangeName"] = app\common\state\CommonConst::getLayerNameByLayer($arrange["talentArrange"]);
  441. }unset($arrange);
  442. return json(["rows" => $list, "total" => $count]);
  443. }
  444. /**
  445. * 修改合同起止时间
  446. */
  447. public function editContract() {
  448. $response = new \stdClass();
  449. $response->code = 500;
  450. $param = $this->request->param();
  451. if (!$param["id"]) {
  452. $response->msg = "系统错误,请联系管理员";
  453. return $response;
  454. }
  455. $detail = \app\common\model\TalentAllowancecontractDetail::find($param["id"]);
  456. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  457. if (\StrUtil::isEmpOrNull($param["startTime"])) {
  458. $response->msg = "请选择合同起始时间";
  459. return $response;
  460. }
  461. if (\StrUtil::isEmpOrNull($param["endTime"])) {
  462. $response->msg = "请选择合同截止时间";
  463. return $response;
  464. }
  465. \app\common\model\TalentAllowancecontractDetail::update($param);
  466. //添加日志
  467. TalentChecklog::create([
  468. 'id' => getStringId(),
  469. 'mainId' => $info['id'],
  470. 'type' => intval(ProjectState::JBT),
  471. 'typeFileId' => $param["id"],
  472. 'active' => 1,
  473. 'state' => null,
  474. 'step' => 0,
  475. 'stateChange' => null,
  476. 'description' => "修改工作单位合同时间为:" . $param["startTime"] . "至" . $param["endTime"],
  477. 'createTime' => date("Y-m-d H:i:s", time()),
  478. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  479. ]);
  480. $response->msg = "修改成功";
  481. $response->code = 200;
  482. return $response;
  483. }
  484. /**
  485. * 修改项目
  486. */
  487. public function editProject() {
  488. $response = new \stdClass();
  489. $response->code = 500;
  490. $param = $this->request->param();
  491. if (!$param["id"]) {
  492. $response->msg = "系统错误,请联系管理员";
  493. return $response;
  494. }
  495. $detail = \app\common\model\TalentAllowanceProject::find($param["id"]);
  496. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  497. \app\common\model\TalentAllowanceProject::update($param);
  498. //添加日志
  499. TalentChecklog::create([
  500. 'id' => getStringId(),
  501. 'mainId' => $info['id'],
  502. 'type' => intval(ProjectState::JBT),
  503. 'typeFileId' => $param["id"],
  504. 'active' => 1,
  505. 'state' => null,
  506. 'step' => 0,
  507. 'stateChange' => null,
  508. 'description' => "修改项目名:" . AllowanceProjectEnum::getProjectName($detail["project"]) . "的值为:" . $param["months"] . ";备注为:" . $param["description"],
  509. 'createTime' => date("Y-m-d H:i:s", time()),
  510. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  511. ]);
  512. $response->msg = "修改成功";
  513. $response->code = 200;
  514. return $response;
  515. }
  516. /**
  517. * 判断是否可以修改
  518. */
  519. public function validateIsEdit() {
  520. $id = $this->request["id"];
  521. $type = $this->request["type"];
  522. $response = new \stdClass();
  523. $response->code = 500;
  524. $info = null;
  525. if ($type == 1) { //编辑合同
  526. $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
  527. } else if ($type == 2) { //编辑项目
  528. $detail = \app\common\model\TalentAllowanceProject::find($id);
  529. }
  530. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  531. if ($info["checkState"] != 1 && $info["checkState"] != 10) {
  532. if ($info["checkState"] == -1) {
  533. $response->msg = "您的申报审核不通过,无法操作";
  534. return $response;
  535. } else if ($info["checkState"] == 30) {
  536. $response->msg = "您的申报已审核通过,无法操作";
  537. return $response;
  538. } else {
  539. $response->msg = "您的申报正在审核中,请耐心等待";
  540. return $response;
  541. }
  542. }
  543. $response->code = 200;
  544. return $response;
  545. }
  546. /**
  547. * 提交审核
  548. */
  549. public function submitToCheck() {
  550. $data = $this->request->param();
  551. $response = new \stdClass();
  552. $response->code = 500;
  553. if (!$data || !$data["id"]) {
  554. $response->msg = "提交审核失败,请先填写基础信息";
  555. return $response;
  556. }
  557. $old = TalentAllowanceApi::getInfoById($data["id"]);
  558. $batch = BatchApi::checkBatchValid(["type" => ProjectState::JBT, "year" => $old["year"], "first_submit_time" => $old["firstSubmitTime"]], $this->user["type"]);
  559. if ($batch["code"] != 200) {
  560. $response->msg = $batch["msg"];
  561. return $response;
  562. }
  563. if ($old["checkState"] != 1 && $old["checkState"] != 10) {
  564. $response->msg = "不能重复提交审核";
  565. return $response;
  566. }
  567. $where = [];
  568. $where[] = ["type", "=", $old["type"]];
  569. $where[] = ["project", "=", ProjectState::JBT];
  570. $where[] = ["active", "=", 1];
  571. $where[] = ["delete", "=", 0];
  572. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  573. $sb = [];
  574. $sb[] = "以下为必传附件:";
  575. foreach ($filetypes as $filetype) {
  576. if ($filetype["must"] == 1) {
  577. $where = [];
  578. $where[] = ["mainId", "=", $id];
  579. $where[] = ["typeId", "=", $filetype["id"]];
  580. $count = Db::table("new_talent_file")->where($where)->count();
  581. if ($count == 0) {
  582. $sb[] = $filetype["name"] . ";";
  583. }
  584. }
  585. }
  586. if (count($sb) > 1) {
  587. $response->msg = implode("<br>", $sb);
  588. return $response;
  589. }
  590. /**
  591. * 初步判断合同是否满两年
  592. */
  593. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $old["id"])->select()->toArray();
  594. foreach ($detailList as $detail) {
  595. if (\StrUtil::isEmpOrNull($detail["startTime"]) || \StrUtil::isEmpOrNull($detail["endTime"])) {
  596. $response->msg = "合同起止时间不能为空";
  597. return $response;
  598. }
  599. }
  600. foreach ($detailList as $detail) {
  601. $contractEndTime = strtotime($detail["endTime"]);
  602. $contractStartTimeAdd2Years = strtotime("+2 years -1 day {$detail['startTime']}");
  603. $where = [];
  604. $where[] = ["mainId", "=", $data["id"]];
  605. $where[] = ["baseId", "=", $detail["id"]];
  606. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_CONTRACT];
  607. $updProject["months"] = $contractEndTime >= $contractStartTimeAdd2Years ? "是" : "否";
  608. \app\common\model\TalentAllowanceProject::where($where)->update($updProject);
  609. }
  610. $data["checkMsg"] = "";
  611. $data["checkState"] = 5;
  612. $data["files"] = "";
  613. $data["projects"] = "";
  614. $data["concats"] = "";
  615. $data["fields"] = "";
  616. $data["toDep"] = "";
  617. $data["process"] = null;
  618. if (!$old["firstSubmitTime"]) {
  619. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  620. }
  621. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  622. TaModel::update($data);
  623. //添加日志
  624. TalentChecklog::create([
  625. 'id' => getStringId(),
  626. 'mainId' => $data['id'],
  627. 'type' => intval(ProjectState::JBT),
  628. 'typeFileId' => null,
  629. 'active' => 1,
  630. 'state' => 1,
  631. 'step' => 0,
  632. 'stateChange' => sprintf("%s->%s", MainState::getStateDesc(1), MainState::getStateDesc(7)),
  633. 'description' => "确认提交审核",
  634. 'createTime' => date("Y-m-d H:i:s", time()),
  635. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  636. ]);
  637. $response->msg = "提交审核成功";
  638. $response->code = 200;
  639. $response->obj = 5;
  640. return $response;
  641. }
  642. public function updateSuppleState() {
  643. $id = $this->request["id"];
  644. $response = new \stdClass();
  645. $response->code = 500;
  646. if (\StrUtil::isEmpOrNull($id)) {
  647. $response->msg = "系统错误,请联系管理员";
  648. return $response;
  649. }
  650. $data["id"] = $id;
  651. $data["isSupple"] = 1;
  652. TaModel::update($data);
  653. $response->msg = "状态更新成功";
  654. $response->code = 200;
  655. return $response;
  656. }
  657. }