TalentAllowance.php 29 KB

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