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