LivingAllowance.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\common\AdminController;
  4. use app\common\api\ChuanglanSmsApi;
  5. use app\common\api\EnterpriseApi;
  6. use app\common\api\LivingAllowanceApi;
  7. use app\common\state\LivingAllowanceState as LaState;
  8. use app\common\state\CommonConst;
  9. use app\common\model\TalentLog;
  10. use app\common\state\ProjectState;
  11. use app\common\model\LivingAllowance as LaModel;
  12. use app\common\api\DictApi;
  13. use think\facade\Db;
  14. /**
  15. * Description of LivingAllowance
  16. *
  17. * @author sgq
  18. */
  19. class LivingAllowance extends AdminController {
  20. public function index() {
  21. $enterpriseList = EnterpriseApi::getSimpleList();
  22. $provinceList = \app\common\api\LocationApi::findProvinceSelect();
  23. $process = $this->request->param("process");
  24. $message = [];
  25. if ($this->user["type"] == 1) {
  26. $message["typeName"] = "晋江市硕博人才生活补贴申报";
  27. $message["address"] = "聚才网/人才晋江微信公众号";
  28. $message["dep"] = "中共晋江市委人才办、晋江市纪委监委驻市人力资源和社会保障局纪检监察组或晋江市公共就业和人才服务中心";
  29. $message["phone"] = "0595-85633128";
  30. $message["email"] = "jjrc85661234@163.com";
  31. } else if ($this->user["type"] == 2) {
  32. $message["typeName"] = "晋江市硕博人才生活补贴申报";
  33. $message["address"] = "福建(晋江)集成电路产业园官方网站及微信公众号";
  34. $message["dep"] = "集成电路产业园区";
  35. $message["phone"] = "0595-82250007、0595-82250001";
  36. $message["email"] = "jjjcdr@163.com";
  37. }
  38. return view("", ["enterpriseList" => $enterpriseList, "provinceList" => $provinceList, "process" => $process, "message" => $message]);
  39. }
  40. public function list() {
  41. $res = LivingAllowanceApi::getList($this->request->param());
  42. return json($res);
  43. }
  44. public function detail() {
  45. $id = $this->request->param("id");
  46. $process = $this->request->param("process");
  47. $info = LivingAllowanceApi::getInfoById($id);
  48. $info = $this->translateToChinese($info);
  49. return view("", ["row" => $info, "process" => $process]);
  50. }
  51. private function translateToChinese($obj) {
  52. if ($obj["industryFieldNew"]) {
  53. $obj["industryFieldNewName"] = DictApi::findByParentCodeAndCode("industry_field", $obj["industryFieldNew"])["name"];
  54. }
  55. if ($obj["industryField"]) {
  56. $industry_field_type = $obj["industryFieldNew"] ? $obj["industryFieldNew"] . "_field" : "un_industryField";
  57. $obj["industryFieldName"] = DictApi::findByParentCodeAndCode($industry_field_type, $obj["industryField"])["name"];
  58. }
  59. if ($obj["address"]) {
  60. $obj["streetName"] = DictApi::findByParentCodeAndCode("street", $obj["address"])["name"];
  61. }
  62. if ($obj["nationality"]) {
  63. $obj["nationalityName"] = DictApi::findByParentCodeAndCode("nationality", $obj["nationality"])["name"];
  64. }
  65. if ($obj["nation"]) {
  66. $obj["nationName"] = DictApi::findByParentCodeAndCode("nation", $obj["nation"])["name"];
  67. }
  68. if ($obj["politics"]) {
  69. $obj["politicsName"] = DictApi::findByParentCodeAndCode("politics", $obj["politics"])["name"];
  70. }
  71. if ($obj["highEducation"]) {
  72. $obj["educationName"] = DictApi::findByParentCodeAndCode("highest_degree", $obj["highEducation"])["name"];
  73. }
  74. if ($obj["introductionMode"]) {
  75. $obj["introductionModeName"] = DictApi::findByParentCodeAndCode("un_introduction_mode", $obj["introductionMode"])["name"];
  76. }
  77. if ($obj["declareType"]) {
  78. $obj["declareTypeName"] = DictApi::findByParentCodeAndCode("un_master_education", $obj["declareType"])["name"];
  79. }
  80. if ($obj["cardType"] == 1) {
  81. $obj["cardTypeName"] = "身份证";
  82. } else if ($obj["cardType"] == 2) {
  83. $obj["cardTypeName"] = "通行证";
  84. } else if ($obj["cardType"] == 3) {
  85. $obj["cardTypeName"] = "护照";
  86. } else {
  87. $obj["cardTypeName"] = "未知";
  88. }
  89. return $obj;
  90. }
  91. /**
  92. * 校验是否在审核范围内
  93. * @param type $id
  94. * @param type $process
  95. * @return type
  96. */
  97. public function validateIsCheck($id, $process) {
  98. $oldInfo = \app\common\api\LivingAllowanceApi::getInfoById($id);
  99. $responseObj = new \stdClass();
  100. $responseObj->code = 500;
  101. switch ($process) {
  102. case 1:
  103. if ($oldInfo["checkState"] != LaState::LA_NEED_FIRST_CHECK && $oldInfo["checkState"] != LaState::LA_DEP_REJECT) {
  104. $responseObj->msg = "该申报不在审核范围内,无法审核";
  105. } else {
  106. $responseObj->code = 200;
  107. $responseObj->msg = "";
  108. }
  109. break;
  110. case 2:
  111. $company = getCacheById("Company", $this->user["companyId"]);
  112. if ($oldInfo["checkState"] != LaState::LA_NEED_DEP_CHECK && $oldInfo["checkState"] != LaState::LA_THIRD_REJECT) {
  113. $responseObj->msg = "该申报不在审核范围内,无法审核";
  114. } else if ($company["code"] != CommonConst::JYJ) {
  115. $responseObj->msg = "部门审核仅教育局能够审核!";
  116. } else {
  117. $responseObj->code = 200;
  118. $responseObj->msg = "";
  119. }
  120. break;
  121. case 3:
  122. if ($oldInfo["checkState"] != LaState::LA_NEED_THIRD) {
  123. $responseObj->msg = "该申报不在审核范围内,无法审核";
  124. } else if ($oldInfo["reditStatus"] == 1) {
  125. $responseObj->msg = "当前申报数据未导入核查数据,无法审核";
  126. } else {
  127. $responseObj->code = 200;
  128. $responseObj->msg = "";
  129. }
  130. break;
  131. case 4:
  132. break;
  133. }
  134. if ($responseObj->code == 500) {
  135. return json($responseObj);
  136. }
  137. $where = [];
  138. $where[] = ["mainId", "=", $id];
  139. $where[] = ["active", "=", 2];
  140. $where[] = ["step", "=", $process];
  141. $log = TalentLog::where($where)->order("createTime desc")->find();
  142. if ($log) {
  143. $oldInfo["checkState"] = $log["state"];
  144. $oldInfo["checkMsg"] = $log["description"];
  145. } else {
  146. $oldInfo["checkState"] = null;
  147. $oldInfo["checkMsg"] = "";
  148. }
  149. $res = [];
  150. $res["obj"] = $oldInfo;
  151. if ($responseObj->code == 200) {
  152. $where = [];
  153. $where[] = ["project", "=", ProjectState::LIVINGALLOWANCE];
  154. $where[] = ["active", "=", 1];
  155. $where[] = ["type", "=", $oldInfo["type"]];
  156. $fileTypeList = \app\common\model\FileType::where($where)->order("sn")->select()->toArray();
  157. $res["fileList"] = $fileTypeList;
  158. }
  159. $responseObj->obj = $res;
  160. return json($responseObj);
  161. }
  162. /**
  163. * 审核
  164. * @return type
  165. */
  166. public function check() {
  167. $responseObj = new \stdClass();
  168. $responseObj->code = 500;
  169. $obj = $this->request->param();
  170. if (!$obj) {
  171. $responseObj->msg = "系统错误,请联系管理员";
  172. return json($responseObj);
  173. }
  174. if (!$obj["checkState"]) {
  175. $responseObj->msg = "请选择审核状态";
  176. return json($responseObj);
  177. }
  178. Db::startTrans();
  179. try {
  180. //保存驳回字段
  181. $updData["id"] = $obj["id"];
  182. $updData["fields"] = $obj["fields"];
  183. $updData["files"] = $obj["files"];
  184. Db::table("md_living_allowance_info")->save($updData);
  185. //加入日志
  186. $newLog["id"] = getStringId();
  187. $newLog["type"] = ProjectState::LIVINGALLOWANCE;
  188. $newLog["mainId"] = $obj["id"];
  189. $newLog["active"] = 2;
  190. $newLog["state"] = $obj["checkState"];
  191. $newLog["step"] = $obj["process"];
  192. $newLog["stateChange"] = "保存未提交";
  193. $newLog["description"] = $obj["checkMsg"];
  194. $newLog["createTime"] = date("Y-m-d H:i:s");
  195. $newLog["createUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"]);
  196. Db::table("new_talent_checklog")->insert($newLog);
  197. $responseObj->code = 200;
  198. $responseObj->msg = "审核成功";
  199. Db::commit();
  200. return json($responseObj);
  201. } catch (\Exception $e) {
  202. Db::rollback();
  203. $responseObj->msg = $e->getMessage();
  204. return json($responseObj);
  205. }
  206. }
  207. /**
  208. * 审核不通过
  209. * @return type
  210. */
  211. public function setNotPass() {
  212. $responseObj = new \stdClass();
  213. $responseObj->code = 500;
  214. $ids = trim($this->request->param("ids"));
  215. $msg = trim($this->request->param("msg"));
  216. $ids = array_filter(explode(",", $ids));
  217. if (!$ids) {
  218. $responseObj->msg = "请选择需要设置审核不通过的数据";
  219. return json($responseObj);
  220. }
  221. if (!$msg) {
  222. $responseObj->msg = "请填写审核不通过的原因";
  223. return json($responseObj);
  224. }
  225. $where = [];
  226. $where[] = ["id", "in", $ids];
  227. $list = LaModel::where($where)->select()->toArray();
  228. $updates = [];
  229. $newLogs = [];
  230. $sb = [];
  231. Db::startTrans();
  232. try {
  233. foreach ($list as $obj) {
  234. if ($obj["checkState"] != LaState::LA_SAVE && $obj["checkState"] != LaState::LA_FIRST_REJECT) {
  235. $sb[] = $obj["name"];
  236. }
  237. $oldState = $obj["checkState"];
  238. $newState = LaState::LA_NOTPASS;
  239. $updates[] = [
  240. "id" => $obj["id"],
  241. "checkState" => $newState,
  242. "checkMsg" => $msg
  243. ];
  244. $newLog["id"] = getStringId();
  245. $newLog["type"] = ProjectState::LIVINGALLOWANCE;
  246. $newLog["mainId"] = $obj["id"];
  247. $newLog["active"] = 2;
  248. $newLog["state"] = $newState;
  249. $newLog["step"] = 70; //审核不通过
  250. $newLog["stateChange"] = LaState::getStateDesc($oldState) . "->" . LaState::getStateDesc($newState);
  251. $newLog["description"] = $msg;
  252. $newLog["createTime"] = date("Y-m-d H:i:s");
  253. $newLog["createUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"]);
  254. $newLogs[] = $newLog;
  255. }
  256. if ($sb) {
  257. $responseObj->msg = implode(",", $sb) . "的审核状态既不是待提交,也不是初审驳回";
  258. return json($responseObj);
  259. }
  260. if (!$updates || !$newLogs) {
  261. $responseObj->msg = "没有待审核项";
  262. return json($responseObj);
  263. }
  264. Db::table("md_living_allowance_info")->saveAll($updates);
  265. Db::table("new_talent_checklog")->insertAll($newLogs);
  266. Db::commit();
  267. $responseObj->code = 200;
  268. $responseObj->msg = "设置审核不通过成功";
  269. return json($responseObj);
  270. } catch (\Exception $e) {
  271. Db::rollback();
  272. return json(["msg" => "设置审核不通过失败:" . $e->getMessage()]);
  273. }
  274. }
  275. public function submitCheck() {
  276. $id = $this->request->param("id");
  277. $process = $this->request->param("process");
  278. $responseObj = new \stdClass();
  279. $responseObj->code = 500;
  280. if (!$id) {
  281. $responseObj->msg = "系统错误,请联系管理员!";
  282. return json($responseObj);
  283. }
  284. $oldInfo = \app\common\api\LivingAllowanceApi::getInfoById($id);
  285. $oldState = $oldInfo["checkState"];
  286. $where = [];
  287. $where[] = ["mainId", "=", $id];
  288. $where[] = ["active", "=", 2];
  289. $where[] = ["step", "=", $process];
  290. $oldLog = TalentLog::where($where)->order("createTime desc")->find();
  291. if (!$oldLog) {
  292. $responseObj->msg = "请先审核后再提交";
  293. return json($responseObj);
  294. }
  295. $company = getCacheById("Company", $this->user["companyId"]);
  296. if ($process == 2 && $company["code"] != CommonConst::JYJ) {
  297. $responseObj->msg = "部门审核仅教育局能够审核!";
  298. return $responseObj;
  299. }
  300. $updData = [];
  301. $updData["id"] = $id;
  302. if (!$oldInfo["highProcess"]) {
  303. $updData["highProcess"] = $process;
  304. } else {
  305. $updData["highProcess"] = $oldInfo["process"] < $process ? $process : $oldInfo["highProcess"];
  306. }
  307. switch ($process) {
  308. case 1:
  309. if ($oldLog["state"] == -1) {
  310. $updData["checkState"] = LaState::LA_NOTPASS;
  311. $updData["recommendAmount"] = 0;
  312. $updData["isPay"] = -1;
  313. $updData["recommendAmountDesc"] = "审核不通过,不予兑现";
  314. $updData["recommendJudgmentDetails"] = "审核不通过,不予兑现";
  315. }
  316. if ($oldLog["state"] == 2) {
  317. $updData["checkState"] = LaState::LA_FIRST_REJECT;
  318. //MessageRecord record = new MessageRecord(old.getId(), 2, 2, old.getName(), old.getPhone(), null, SmsProperties.MASTER_ALLOWANCE_REJECT);
  319. //Sms253Util.sendMessage(record);
  320. }
  321. //审核通过
  322. if ($oldLog["state"] == 3) {
  323. $updData["checkState"] = LaState::LA_NEED_DEP_CHECK;
  324. $updData["firstPassTime"] = date("Y-m-d H:i:s");
  325. }
  326. break;
  327. case 2:
  328. if ($oldLog["state"] == -1) {
  329. $updData["checkState"] = LaState::LA_NOTPASS;
  330. $updData["recommendAmount"] = 0;
  331. $updData["recommendAmountDesc"] = "审核不通过,不予兑现";
  332. $updData["recommendJudgmentDetails"] = "审核不通过,不予兑现";
  333. $updData["recommendIsPay"] = -1;
  334. }
  335. if ($oldLog["state"] == 2) {
  336. $updData["checkState"] = LaState::LA_DEP_REJECT;
  337. $updData["creditStatus"] = 1;
  338. $updData["recommendAmount"] = null;
  339. $updData["recommendAmountDesc"] = "";
  340. $updData["recommendJudgmentDetails"] = "";
  341. $updData["recommendIsPay"] = 0;
  342. }
  343. if ($oldLog["state"] == 3) {
  344. $updData["checkState"] = LaState::LA_NEED_THIRD;
  345. $updData["firstDepPassTime"] = date("Y-m-d H:i:s");
  346. $_updData = $this->calculateAmount($oldInfo);
  347. $updData = array_merge($updData, $_updData);
  348. }
  349. break;
  350. case 3:
  351. if ($oldLog["state"] == -1) {
  352. $updData["checkState"] = LaState::LA_NOTPASS;
  353. $updData["recommendAmount"] = 0;
  354. $updData["recommendAmountDesc"] = "审核不通过,不予兑现";
  355. $updData["recommendJudgmentDetails"] = "审核不通过,不予兑现";
  356. $updData["recommendIsPay"] = -1;
  357. }
  358. if ($oldLog["state"] == 2) {
  359. $updData["checkState"] = LaState::LA_DEP_REJECT;
  360. $updData["creditStatus"] = 1;
  361. $updData["recommendAmount"] = null;
  362. $updData["recommendAmountDesc"] = "";
  363. $updData["recommendJudgmentDetails"] = "";
  364. $updData["recommendIsPay"] = 0;
  365. }
  366. if ($oldLog["state"] == 3) {
  367. $updData["checkState"] = LaState::LA_PASS;
  368. $updData["isPublic"] = 2;
  369. }
  370. break;
  371. }
  372. $newLog["id"] = getStringId();
  373. $newLog["type"] = ProjectState::LIVINGALLOWANCE;
  374. $newLog["mainId"] = $id;
  375. $newLog["active"] = 1;
  376. $newLog["state"] = $oldLog["state"];
  377. $newLog["step"] = $process;
  378. $newLog["stateChange"] = LaState::getStateDesc($oldState) . "->" . LaState::getStateDesc($updData["checkState"]);
  379. $newLog["description"] = $oldLog["description"];
  380. $newLog["createTime"] = date("Y-m-d H:i:s");
  381. $newLog["createUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"]);
  382. Db::startTrans();
  383. try {
  384. $where = [];
  385. $where[] = ["mainId", "=", $id];
  386. $where[] = ["type", "=", ProjectState::LIVINGALLOWANCE];
  387. $where[] = ["active", "=", 2];
  388. Db::table("new_talent_checklog")->where($where)->delete();
  389. Db::table("new_talent_checklog")->insert($newLog);
  390. Db::table("md_living_allowance_info")->save($updData);
  391. Db::commit();
  392. $responseObj->code = 200;
  393. $responseObj->msg = "提交审核成功";
  394. return json($responseObj);
  395. } catch (\think\db\exception\DbException $e) {
  396. Db::rollback();
  397. $responseObj->msg = $e->getMessage();
  398. return json($responseObj);
  399. }
  400. }
  401. /**
  402. * 计算兑现额度
  403. * @param type $oldInfo
  404. * @return string
  405. */
  406. private function calculateAmount($oldInfo) {
  407. $return = [];
  408. /* * 硕士研究生补贴 */
  409. if ($oldInfo["declareType"] == 1) {
  410. //硕士 master_living_allowance_ss_money
  411. $moneyInfo = DictApi::findByParentCodeAndCode("master_living_allowance_ss_money", $oldInfo["applyCount"]);
  412. } else {
  413. //博士 master_living_allowance_bs_money
  414. $moneyInfo = DictApi::findByParentCodeAndCode("master_living_allowance_bs_money", $oldInfo["applyCount"]);
  415. }
  416. $moneyStanard = $moneyInfo ? $moneyInfo["name"] : 0;
  417. $return["recommendAmount"] = $moneyStanard;
  418. $where = [];
  419. $where[] = ["cardType", "=", $oldInfo["cardType"]];
  420. $where[] = ["idCard", "=", $oldInfo["idCard"]];
  421. $where[] = ["year", "=", substr($oldInfo["year"], 0, 4)];
  422. $where[] = ["checkState", "=", 30];
  423. $where[] = ["publicState", ">=", 4];
  424. $talentAllowanceInfo = \app\common\model\TalentAllowance::where($where)->findOrEmpty();
  425. if ($talentAllowanceInfo) {
  426. $balanceMoney = $oldInfo["amount"] - $talentAllowanceInfo["money"];
  427. if (round($balanceMoney, 2) == round(0, 2)) {
  428. $return["recommendAmountDesc"] = "当年度存在享受津补贴的记录,津补贴额度为:" . $talentAllowanceInfo["money"] . ",生活补贴额度为:" . $oldInfo["amount"] . ",根据就高原则生活补贴享受额度为0元,因此不予兑现;\n";
  429. $return["recommendAmount"] = 0;
  430. $return["recommendIsPay"] = -1;
  431. } else {
  432. $return["recommendAmountDesc"] = "当年度存在享受津补贴的记录,津补贴额度为:" . $talentAllowanceInfo["money"] . ",生活补贴额度为:" . $oldInfo["amount"] . ",需要补充生活补贴额度为:" . round($balanceMoney, 2) . "元,予以兑现;\n";
  433. $return["recommendAmount"] = $balanceMoney;
  434. }
  435. } else {
  436. $return["recommendAmountDesc"] = "当年度无享受津补贴的记录,可全额享受,予以兑现;\n";
  437. }
  438. return $return;
  439. }
  440. }