TalentAllowance.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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. use app\common\api\UploadApi;
  21. use app\enterprise\model\TalentTypeChange;
  22. /**
  23. * Description of TalentAllowance
  24. *
  25. * @author sgq
  26. */
  27. class TalentAllowance extends EnterpriseController {
  28. public function index() {
  29. $tpl = "";
  30. switch ($this->user["type"]) {
  31. case CommonConst::ENTERPRISE_JC:
  32. $tpl = "indexIC";
  33. break;
  34. }
  35. return view($tpl, ['type' => $this->user["type"]]);
  36. }
  37. public function list() {
  38. $res = TalentAllowanceApi::getList($this->request);
  39. return json($res);
  40. }
  41. /**
  42. * 申请
  43. */
  44. public function apply(\think\Request $request) {
  45. $param = $request->param();
  46. $id = isset($param["id"]) ? $param["id"] : 0;
  47. $info = null;
  48. if ($id) {
  49. $info = TalentAllowanceApi::getInfoById($id);
  50. $this->translateToChinese($info);
  51. }
  52. if ($request->isPost()) {
  53. return $this->save($info, $request);
  54. }
  55. $batch = $info["year"] ?: BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  56. return view("", ["year" => $batch, "type" => $this->user["type"], "row" => $info]);
  57. }
  58. public function batchApply() {
  59. $ids = $this->request["ids"];
  60. $ids = array_filter(explode(",", $ids));
  61. $allowanceType = $this->request["allowanceType"];
  62. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  63. if (!$batch) {
  64. return new Response(Response::ERROR, "当前并无有效的申报批次进行中");
  65. }
  66. for ($i = 0; $i < count($ids); $i++) {
  67. queue("app\job\TalentAllowance", ["type" => 1, "talentId" => $ids[$i], "enterprise" => $this->user, "year" => $batch, "allowanceType" => $allowanceType]);
  68. }
  69. return new Response(Response::SUCCESS, "已经成功添加到计划任务,请稍候查看申报列表进行确认");
  70. }
  71. private function save($talentAllowance, \think\Request $request) {
  72. $response = new \stdClass();
  73. $response->code = 500;
  74. $param = $request->param();
  75. if (!$param) {
  76. $response->msg = "请填写信息后在提交";
  77. return $response;
  78. }
  79. if (\StrUtil::isEmpOrNull($param["talentId"])) {
  80. $response->msg = "请选择申报对象";
  81. return $response;
  82. }
  83. if (!$param["id"]) {
  84. $where = [];
  85. $where[] = ["year", "=", $param["year"]];
  86. $where[] = ["idCard", "=", $param["idCard"]];
  87. $where[] = ["checkState", "not in", [MainState::NOTPASS, MainState::PASS]];
  88. $exists = TaModel::where($where)->find();
  89. if ($exists) {
  90. $response->msg = "当前申请对象在当前批次中存在申请中的记录,请等待申请结束后再操作";
  91. return $response;
  92. }
  93. $user = $this->user;
  94. $ti = \app\common\api\VerifyApi::getTalentInfoById($param["talentId"]);
  95. $data = [
  96. "talentId" => $param["talentId"],
  97. "enterpriseId" => $ti["enterprise_id"],
  98. "enterpriseName" => $user["name"],
  99. "year" => $param["year"],
  100. "source" => $ti["source"],
  101. "qzgccrcActiveTime" => $ti["certificateExpireTime"],
  102. "talentType" => $ti["enterpriseTag"],
  103. "address" => $ti["street"],
  104. "name" => $ti["name"],
  105. "sex" => $ti["sex"],
  106. "cardType" => $ti["card_type"],
  107. "idCard" => $ti["card_number"],
  108. "firstInJJTime" => $ti["fst_work_time"],
  109. "entryTime" => $ti["cur_entry_time"],
  110. "post" => $ti["position"],
  111. "phone" => $ti["phone"],
  112. "talentArrange" => $ti["talent_arrange"],
  113. "identifyCondition" => $ti["talent_condition"],
  114. "identifyGetTime" => $ti["identifyGetTime"],
  115. "identifyOutTime" => $ti["identifyExpireTime"],
  116. "identifyConditionName" => $ti["identifyConditionName"],
  117. "identifyMonth" => $ti["identifyMonth"],
  118. "bank" => $ti["bank"],
  119. "bankNetwork" => $ti["bank_branch_name"],
  120. "bankAccount" => $ti["bank_account"],
  121. "bankNumber" => $ti["bank_number"],
  122. "checkState" => 1,
  123. "type" => $user["type"],
  124. "provinceCode" => $ti["province"],
  125. "provinceName" => \app\common\api\LocationApi::getNameByCode($ti["province"]),
  126. "cityCode" => $ti["city"],
  127. "cityName" => \app\common\api\LocationApi::getNameByCode($ti["city"]),
  128. "countyCode" => $ti["county"],
  129. "countyName" => \app\common\api\LocationApi::getNameByCode($ti["county"]),
  130. "isSupple" => 2,
  131. "createTime" => date("Y-m-d H:i:s"),
  132. "createUser" => $user["uid"],
  133. "id" => getStringId(),
  134. "wage" => $param["wage"],
  135. "allowanceType" => $param["allowanceType"]
  136. ];
  137. /* * 1.获取上一年度的人才层次 */
  138. $arrangeList = $this->getLastYearTalentType($data, $ti);
  139. if (!$arrangeList) {
  140. $response->msg = "上一年度暂无有效的人才层次";
  141. return $response;
  142. }
  143. /* * 2.获取上一年度所在单位* */
  144. $contractDetailList = $this->getConcatList($ti, $data, $param["year"]); //保存上一年度的工作单位
  145. if (!$contractDetailList) {
  146. $response->msg = "申报失败,原因为:申报年度不存在有效的工作单位";
  147. return $response;
  148. }
  149. TaModel::insert($data);
  150. \app\common\model\TalentAllowancecontractDetail::insertAll($contractDetailList);
  151. /**
  152. * 4.添加津补贴核查项目
  153. */
  154. //核查项目详情表
  155. $this->createAllowanceProject($data, $contractDetailList);
  156. \app\common\model\TalentAllowanceArrange::insertAll($arrangeList);
  157. //添加日志
  158. TalentChecklog::create([
  159. 'id' => getStringId(),
  160. 'mainId' => $data['id'],
  161. 'type' => intval(ProjectState::JBT),
  162. 'typeFileId' => null,
  163. 'active' => 1,
  164. 'state' => 1,
  165. 'step' => 0,
  166. 'stateChange' => "保存未提交",
  167. 'description' => "添加津补贴申报",
  168. 'createTime' => date("Y-m-d H:i:s", time()),
  169. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  170. ]);
  171. $response->msg = "保存成功";
  172. $response->code = 200;
  173. $response->obj = $data;
  174. return $response;
  175. } else {
  176. TaModel::update($param);
  177. $response->msg = "修改成功";
  178. $response->code = 200;
  179. return $response;
  180. }
  181. }
  182. public function getInfoByIdAndYear($id, $year) {
  183. $ti = \app\common\api\VerifyApi::getTalentInfoById($id);
  184. $data = [
  185. "talentId" => $id,
  186. "year" => $year,
  187. "idCard" => $ti["card_number"],
  188. "id" => getStringId()
  189. ];
  190. /* * 1.获取上一年度的人才层次 */
  191. $arrangeList = $this->getLastYearTalentType($data, $ti);
  192. if (!$arrangeList) {
  193. return new Response(Response::ERROR, "该人员上一年度暂无有效的人才层次");
  194. }
  195. /* * 2.获取上一年度所在单位* */
  196. $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
  197. if (!$contractDetailList) {
  198. return new Response(Response::ERROR, "该人员申报年度不存在有效的工作单位");
  199. }
  200. return new Response(Response::SUCCESS, "", $ti);
  201. }
  202. /**
  203. * 删除优秀人才津补贴
  204. */
  205. public function delete() {
  206. $id = $this->request["id"];
  207. $response = new \stdClass();
  208. $response->code = 500;
  209. $info = TalentAllowanceApi::getInfoById($id);
  210. if ($info["checkState"] != 1) {
  211. $response->msg = "删除失败!此数据已提交审核,无法删除!";
  212. return $response;
  213. }
  214. Db::startTrans();
  215. try {
  216. //删除核查项目表
  217. Db::table("un_talent_allowance_project")->where("mainId", $id)->delete();
  218. //删除合同情况表
  219. Db::table("un_talent_allowancecontract_detail")->where("mainId", $id)->delete();
  220. //删除人才层次变更表
  221. Db::table("un_talent_allowance_arrange")->where("mainId", $id)->delete();
  222. //删除日志
  223. $where[] = ["mainId", "=", $id];
  224. $where[] = ["type", "=", ProjectState::JBT];
  225. Db::table("new_talent_checklog")->where($where)->delete();
  226. //删除主表
  227. Db::table("un_talent_allowance_info")->delete($id);
  228. Db::commit();
  229. $response->code = 200;
  230. $response->msg = "删除成功";
  231. return $response;
  232. } catch (think\db\exception\DbException $e) {
  233. Db::rollback();
  234. $response->msg = $e->getMessage();
  235. return $response;
  236. }
  237. }
  238. public function detail(\think\Request $request) {
  239. $param = $request->param();
  240. $id = $param["id"];
  241. $info = TalentAllowanceApi::getInfoById($id);
  242. $this->translateToChinese($info);
  243. return view("", ["row" => $info]);
  244. }
  245. private function translateToChinese(&$obj) {
  246. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  247. $obj["addressName"] = DictApi::findByParentCodeAndCode("street", $obj["address"])["name"];
  248. }
  249. if (\StrUtil::isNotEmpAndNull($obj["talentType"])) {
  250. $obj["talentTypeName"] = DictApi::findByParentCodeAndCode("enterprise_tag", $obj["talentType"])["name"];
  251. }
  252. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  253. $obj["talentArrangeName"] = DictApi::findByParentCodeAndCode("talent_arrange", $obj["talentArrange"])["name"];
  254. }
  255. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  256. $obj["identifyConditionText"] = \app\common\api\TalentConditionApi::getOne($obj["identifyCondition"])["name"];
  257. }
  258. if (\StrUtil::isNotEmpAndNull($obj["introductionMode"])) {
  259. $obj["introductionModeName"] = DictApi::findByParentCodeAndCode("import_way", $obj["introductionMode"])["name"];
  260. }
  261. }
  262. /* * 获取上一年度的人才层次变更信息 */
  263. private function getLastYearTalentType($info, $talentInfo) {
  264. $arrangeList = [];
  265. /* * * 添加人才层次记录 */
  266. $where = [];
  267. $where[] = ["idCard", "=", $info["idCard"]];
  268. $where[] = ["checkState", "=", MainState::PASS];
  269. $where[] = ["isPublic", ">=", 5];
  270. $where[] = ["oldIdentifyMonth", "<=", $info["year"] . "-12-31"];
  271. $typeList = TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth")->order("createTime desc")->select()->toArray();
  272. $typeList[] = [
  273. "oldTalentArrange" => $talentInfo["talent_arrange"],
  274. "oldIdentifyCondition" => $talentInfo["talent_condition"],
  275. "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
  276. "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
  277. "oldIdentifyMonth" => $talentInfo["identifyMonth"],
  278. "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
  279. "oldCertificateOutTime" => $talentInfo["certificateExpireTime"],
  280. "newIdentifyMonth" => $info["year"] . "-12-31"
  281. ];
  282. $totalMonth = \DateUtil::getMonthBetweenDates($info["year"] . "-01-01", $info["year"] . "-12-31");
  283. /* * 获取上一年度有效的人才层次 */
  284. usort($typeList, function($a, $b) {
  285. return (int) $b["oldTalentArrange"] - (int) $a["oldTalentArrange"];
  286. });
  287. $commonMonth = [];
  288. foreach ($typeList as $talentTypeChange) {
  289. $startTime = $talentTypeChange["oldIdentifyMonth"];
  290. $endTime = $talentTypeChange["newIdentifyMonth"];
  291. $monthList = \DateUtil::getMonthBetweenDatesNotBegin($startTime, $endTime);
  292. if ($monthList) {
  293. $monthList = array_intersect($monthList, $totalMonth);
  294. }
  295. if ($monthList) {
  296. $months = implode(",", $monthList);
  297. $monthList = array_filter($monthList, function($value) use ($commonMonth) {
  298. return !in_array($value, $commonMonth);
  299. });
  300. $commonMonth = array_filter(array_merge($commonMonth, $monthList));
  301. if (count($monthList) > 0) {
  302. $arrange = [
  303. "id" => getStringId(),
  304. "mainId" => $info["id"],
  305. "talentArrange" => $talentTypeChange["oldTalentArrange"],
  306. "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
  307. "startTime" => $startTime,
  308. "endTime" => $endTime,
  309. "prepareMonths" => null,
  310. "description" => "申报年度有效月份:" . $months,
  311. "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
  312. "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
  313. ];
  314. $sb = '';
  315. foreach ($monthList as $month) {
  316. $sb .= substr($month, 5, 2) . ",";
  317. }
  318. $arrange["prepareMonths"] = rtrim($sb, ",");
  319. $arrangeList[] = $arrange;
  320. }
  321. }
  322. }
  323. return $arrangeList;
  324. }
  325. /**
  326. * @param
  327. * @returns void
  328. * @author Liu
  329. * @date 2020/4/26
  330. * @description 获取上一年度所在单位
  331. * */
  332. private function getConcatList($talentInfo, $info, $year) {
  333. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  334. /** 添加申报人才上一年度工作单位记录 */
  335. $where = [];
  336. $where[] = ["idCard", "=", $talentInfo["card_number"]];
  337. $where[] = ["checkState", "=", 3];
  338. $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
  339. /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
  340. if ($talentInfo["active"] == 1) {
  341. $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
  342. $starttime = $labor_contract_rangetime[0];
  343. $endtime = $labor_contract_rangetime[1];
  344. $quitList[] = [
  345. "enterpriseId" => $talentInfo["enterprise_id"],
  346. "enterpriseName" => $talentInfo["enterpriseName"],
  347. "talentType" => $talentInfo["enterpriseTag"],
  348. "identifyGetTime" => $talentInfo["identifyGetTime"],
  349. "starttime" => $starttime,
  350. "endtime" => $endtime,
  351. "entryTime" => $talentInfo["cur_entry_time"],
  352. "quitTime" => null,
  353. "post" => $talentInfo["position"]
  354. ];
  355. }
  356. $list = [];
  357. foreach ($quitList as $quit) {
  358. $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
  359. $monthList = array_intersect($monthList, $totalMonth);
  360. if ($monthList) {
  361. $sb = '';
  362. foreach ($monthList as $month) {
  363. $sb .= substr($month, 5, 2) . ",";
  364. }
  365. $list[] = [
  366. "id" => getStringId(),
  367. "mainId" => $info["id"],
  368. "enterpriseId" => $quit["enterpriseId"],
  369. "talentType" => $quit["talentType"],
  370. "startTime" => $quit["starttime"],
  371. "endTime" => $quit["endtime"],
  372. "entryTime" => $quit["entryTime"],
  373. "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
  374. "letterTime" => $quit["letterTime"],
  375. "gygb" => $quit["gygb"],
  376. "identifyGetTime" => $quit["identifyGetTime"],
  377. "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
  378. "post" => $quit["post"],
  379. "months" => rtrim($sb, ",")
  380. ];
  381. }
  382. }
  383. return $list;
  384. }
  385. private function createAllowanceProject($info, $contractList) {
  386. foreach ($contractList as $detail) {
  387. $projects = [
  388. //AllowanceProjectEnum::PROJECT_CONTRACT,
  389. AllowanceProjectEnum::PROJECT_TAX,
  390. AllowanceProjectEnum::PROJECT_WAGES,
  391. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  392. AllowanceProjectEnum::PROJECT_SB_PENSION,
  393. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  394. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  395. //AllowanceProjectEnum::PROJECT_WORKDAY,
  396. ];
  397. $list = [];
  398. foreach ($projects as $project) {
  399. $list[] = [
  400. "mainId" => $info["id"],
  401. "baseId" => $detail["id"],
  402. "enterpriseId" => $detail["enterpriseId"],
  403. "project" => $project,
  404. "isLock" => 1,
  405. "createTime" => date("Y-m-d H:i:s")
  406. ];
  407. }
  408. \app\common\model\TalentAllowanceProject::insertAll($list);
  409. }
  410. }
  411. /**
  412. * 查询工作单位
  413. */
  414. public function findAllowanceContractDetail() {
  415. $mainId = $this->request["mainId"];
  416. $offset = $this->request["offset"] ?: 0;
  417. $limit = $this->request["limit"] ?: 1000;
  418. $count = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->count();
  419. $list = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->limit($offset, $limit)->select()->toArray();
  420. $enterpriseMap = \app\common\model\Enterprise::column("name", "id");
  421. foreach ($list as &$row) {
  422. $row["enterpriseName"] = $enterpriseMap[$row["enterpriseId"]];
  423. }unset($row);
  424. return json(["rows" => $list, "total" => $count]);
  425. }
  426. /**
  427. * 查询核查项目情况
  428. */
  429. public function findAllowanceProject() {
  430. $mainId = $this->request["mainId"];
  431. $baseId = $this->request["baseId"];
  432. $offset = $this->request["offset"] ?: 0;
  433. $limit = $this->request["limit"] ?: 1000;
  434. $where = [];
  435. $where[] = ["mainId", "=", $mainId];
  436. $where[] = ["baseId", "=", $baseId];
  437. $count = \app\common\model\TalentAllowanceProject::where($where)->count();
  438. $list = \app\common\model\TalentAllowanceProject::where($where)->limit($offset, $limit)->select()->toArray();
  439. $info = TalentAllowanceApi::getInfoById($mainId);
  440. foreach ($list as &$project) {
  441. $project["projectName"] = AllowanceProjectEnum::getProjectName($project["project"]);
  442. if ($info["checkState"] == 1) {
  443. $project["isEdit"] = in_array($project["project"], [
  444. //AllowanceProjectEnum::PROJECT_CONTRACT,
  445. AllowanceProjectEnum::PROJECT_TAX,
  446. AllowanceProjectEnum::PROJECT_WAGES,
  447. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  448. AllowanceProjectEnum::PROJECT_SB_PENSION,
  449. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  450. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  451. //AllowanceProjectEnum::PROJECT_WORKDAY
  452. ]) ? 1 : 2;
  453. } else if ($info["checkState"] == 10) {
  454. $projects = explode(",", $info["projects"]);
  455. if (in_array($project["id"], $projects)) {
  456. $project["isEdit"] = 1;
  457. } else {
  458. $project["isEdit"] = 2;
  459. }
  460. } else {
  461. $project["isEdit"] = 2;
  462. }
  463. }unset($project);
  464. return json(["rows" => $list, "total" => $count]);
  465. }
  466. /**
  467. * 查询人才层次变更记录
  468. */
  469. public function findAllowanceArrange() {
  470. $mainId = $this->request["mainId"];
  471. $offset = $this->request["offset"] ?: 0;
  472. $limit = $this->request["limit"] ?: 1000;
  473. $where = [];
  474. $where[] = ["mainId", "=", $mainId];
  475. $count = \app\common\model\TalentAllowanceArrange::where($where)->count();
  476. $list = \app\common\model\TalentAllowanceArrange::where($where)->limit($offset, $limit)->select()->toArray();
  477. foreach ($list as &$arrange) {
  478. $condition = \app\common\api\TalentConditionApi::getOne($arrange["identifyCondition"]);
  479. $arrange["identifyConditionText"] = $condition["name"];
  480. $arrange["talentArrangeName"] = app\common\state\CommonConst::getLayerNameByLayer($arrange["talentArrange"]);
  481. }unset($arrange);
  482. return json(["rows" => $list, "total" => $count]);
  483. }
  484. /**
  485. * 修改合同起止时间
  486. */
  487. public function editContract() {
  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\TalentAllowancecontractDetail::find($param["id"]);
  496. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  497. if (\StrUtil::isEmpOrNull($param["startTime"])) {
  498. $response->msg = "请选择合同起始时间";
  499. return $response;
  500. }
  501. if (\StrUtil::isEmpOrNull($param["endTime"])) {
  502. $response->msg = "请选择合同截止时间";
  503. return $response;
  504. }
  505. \app\common\model\TalentAllowancecontractDetail::update($param);
  506. //添加日志
  507. TalentChecklog::create([
  508. 'id' => getStringId(),
  509. 'mainId' => $info['id'],
  510. 'type' => intval(ProjectState::JBT),
  511. 'typeFileId' => $param["id"],
  512. 'active' => 1,
  513. 'state' => null,
  514. 'step' => 0,
  515. 'stateChange' => null,
  516. 'description' => "修改工作单位合同时间为:" . $param["startTime"] . "至" . $param["endTime"],
  517. 'createTime' => date("Y-m-d H:i:s", time()),
  518. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  519. ]);
  520. $response->msg = "修改成功";
  521. $response->code = 200;
  522. return $response;
  523. }
  524. /**
  525. * 修改项目
  526. */
  527. public function editProject() {
  528. $response = new \stdClass();
  529. $response->code = 500;
  530. $param = $this->request->param();
  531. if (!$param["id"]) {
  532. $response->msg = "系统错误,请联系管理员";
  533. return $response;
  534. }
  535. $detail = \app\common\model\TalentAllowanceProject::find($param["id"]);
  536. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  537. \app\common\model\TalentAllowanceProject::update($param);
  538. //添加日志
  539. TalentChecklog::create([
  540. 'id' => getStringId(),
  541. 'mainId' => $info['id'],
  542. 'type' => intval(ProjectState::JBT),
  543. 'typeFileId' => $param["id"],
  544. 'active' => 1,
  545. 'state' => null,
  546. 'step' => 0,
  547. 'stateChange' => null,
  548. 'description' => "修改项目名:" . AllowanceProjectEnum::getProjectName($detail["project"]) . "的值为:" . $param["months"] . ";备注为:" . $param["description"],
  549. 'createTime' => date("Y-m-d H:i:s", time()),
  550. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  551. ]);
  552. $response->msg = "修改成功";
  553. $response->code = 200;
  554. return $response;
  555. }
  556. /**
  557. * 判断是否可以修改
  558. */
  559. public function validateIsEdit() {
  560. $id = $this->request["id"];
  561. $type = $this->request["type"];
  562. $info = null;
  563. if ($type == 1) { //编辑合同
  564. $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
  565. } else if ($type == 2) { //编辑项目
  566. $detail = \app\common\model\TalentAllowanceProject::find($id);
  567. }
  568. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  569. if ($info["checkState"] != 1 && $info["checkState"] != 10) {
  570. if ($info["checkState"] == -1) {
  571. return new Response(Response::ERROR, "您的申报审核不通过,无法操作");
  572. } else if ($info["checkState"] == 30) {
  573. return new Response(Response::ERROR, "您的申报已审核通过,无法操作");
  574. } else {
  575. return new Response(Response::ERROR, "您的申报正在审核中,请耐心等待");
  576. }
  577. }
  578. return new Response(Response::SUCCESS, "");
  579. }
  580. /**
  581. * 提交审核
  582. */
  583. public function submitToCheck() {
  584. $data = $this->request->param();
  585. $response = new \stdClass();
  586. $response->code = 500;
  587. if (!$data || !$data["id"]) {
  588. $response->msg = "提交审核失败,请先填写基础信息";
  589. return $response;
  590. }
  591. $old = TalentAllowanceApi::getInfoById($data["id"]);
  592. $batch = BatchApi::checkBatchValid(["type" => ProjectState::JBT, "year" => $old["year"], "first_submit_time" => $old["firstSubmitTime"]], $this->user["type"]);
  593. if ($batch["code"] != 200) {
  594. $response->msg = $batch["msg"];
  595. return $response;
  596. }
  597. if ($old["checkState"] != 1 && $old["checkState"] != 10) {
  598. $response->msg = "不能重复提交审核";
  599. return $response;
  600. }
  601. if (!$old["allowanceType"]) {
  602. $response->msg = "没有明确津贴类型";
  603. return $response;
  604. }
  605. //因为工作津贴和交通补贴两者的考勤分别记录的是月份和天数,如果没有手动修改值会导致数据不对口,如修改类型却未修改考勤记录,则手动改为空。
  606. $where = [];
  607. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_ATTENDANCE];
  608. $where[] = ["mainId", "=", $data["id"]];
  609. $attendanceList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  610. if ($old["allowanceType"] == \app\common\state\AllowanceTypeEnum::JBT_JT) {
  611. //因为天数保存格式为 月份=天数 如 01=31,02=20,03=15,月份保存格式为01,02,03,所以可以从有没有=号判断是否有进行考勤的修改保存操作
  612. foreach ($attendanceList as $a) {
  613. //$a["months"]有值但是没有包含=号则一般可认为是类型修改为交通补贴而未修改考勤,此时的months字段数据是错误的,修改为空。
  614. if ($a["months"] && strpos($a["months"], "=") === false) {
  615. $_updProject["id"] = $a["id"];
  616. $_updProject["months"] = "";
  617. \app\common\model\TalentAllowanceProject::update($_updProject);
  618. }
  619. }
  620. } else {
  621. foreach ($attendanceList as $a) {
  622. //$a["months"]有值但是包含了=号则一般可认为是类型修改为工作津贴而未修改考勤,此时的months字段数据是错误的,修改为空。
  623. if ($a["months"] && strpos($a["months"], "=") !== false) {
  624. $_updProject["id"] = $a["id"];
  625. $_updProject["months"] = "";
  626. \app\common\model\TalentAllowanceProject::update($_updProject);
  627. }
  628. }
  629. }
  630. $where = [];
  631. $where[] = ["type", "=", $old["type"]];
  632. $where[] = ["project", "=", ProjectState::JBT];
  633. $where[] = ["isConditionFile", "in", [0, $old["allowanceType"]]];
  634. $where[] = ["active", "=", 1];
  635. $where[] = ["delete", "=", 0];
  636. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  637. $sb = [];
  638. $sb[] = "以下为必传附件:";
  639. foreach ($filetypes as $filetype) {
  640. if ($filetype["must"] == 1) {
  641. $where = [];
  642. $where[] = ["mainId", "=", $data["id"]];
  643. $where[] = ["typeId", "=", $filetype["id"]];
  644. $count = Db::table("new_talent_file")->where($where)->count();
  645. if ($count == 0) {
  646. $sb[] = $filetype["name"] . ";";
  647. }
  648. }
  649. }
  650. if (count($sb) > 1) {
  651. $response->msg = implode("<br>", $sb);
  652. return $response;
  653. }
  654. /**
  655. * 初步判断合同是否满两年
  656. */
  657. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $old["id"])->select()->toArray();
  658. foreach ($detailList as $detail) {
  659. if (\StrUtil::isEmpOrNull($detail["startTime"]) || \StrUtil::isEmpOrNull($detail["endTime"])) {
  660. $response->msg = "合同起止时间不能为空";
  661. return $response;
  662. }
  663. }
  664. foreach ($detailList as $detail) {
  665. $contractEndTime = strtotime($detail["endTime"]);
  666. $contractStartTimeAdd2Years = strtotime("+2 years -1 day {$detail['startTime']}");
  667. $where = [];
  668. $where[] = ["mainId", "=", $data["id"]];
  669. $where[] = ["baseId", "=", $detail["id"]];
  670. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_CONTRACT];
  671. $updProject["months"] = $contractEndTime >= $contractStartTimeAdd2Years ? "是" : "否";
  672. \app\common\model\TalentAllowanceProject::where($where)->update($updProject);
  673. }
  674. $data["checkMsg"] = "";
  675. $data["checkState"] = 5;
  676. $data["files"] = "";
  677. $data["projects"] = "";
  678. $data["concats"] = "";
  679. $data["fields"] = "";
  680. $data["toDep"] = "";
  681. $data["process"] = null;
  682. if (!$old["firstSubmitTime"]) {
  683. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  684. }
  685. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  686. TaModel::update($data);
  687. //添加日志
  688. TalentChecklog::create([
  689. 'id' => getStringId(),
  690. 'mainId' => $data['id'],
  691. 'type' => intval(ProjectState::JBT),
  692. 'typeFileId' => null,
  693. 'active' => 1,
  694. 'state' => 1,
  695. 'step' => 0,
  696. 'stateChange' => sprintf("%s->%s", MainState::getStateDesc(1), MainState::getStateDesc(7)),
  697. 'description' => "确认提交审核",
  698. 'createTime' => date("Y-m-d H:i:s", time()),
  699. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  700. ]);
  701. $response->msg = "提交审核成功";
  702. $response->code = 200;
  703. $response->obj = 5;
  704. return $response;
  705. }
  706. public function updateSuppleState() {
  707. $id = $this->request["id"];
  708. $response = new \stdClass();
  709. $response->code = 500;
  710. if (\StrUtil::isEmpOrNull($id)) {
  711. $response->msg = "系统错误,请联系管理员";
  712. return $response;
  713. }
  714. $data["id"] = $id;
  715. $data["isSupple"] = 1;
  716. TaModel::update($data);
  717. $response->msg = "状态更新成功";
  718. $response->code = 200;
  719. return $response;
  720. }
  721. public function uploadCommonFile() {
  722. $batchId = $this->request["batch"];
  723. if (!$batchId) {
  724. return json(new Response(Response::ERROR, "没有提交批次信息,无法按批次归档,上传被中止"));
  725. }
  726. $batchInfo = BatchApi::getOne($batchId);
  727. if (!$batchInfo) {
  728. return json(new Response(Response::ERROR, "批次信息不存在,无法按批次归档,上传被中止"));
  729. }
  730. if (!$this->request->file()) {
  731. return json(new Response(Response::ERROR, "没有上传任何材料"));
  732. }
  733. $file = $this->request->file("file");
  734. $upload = new UploadApi();
  735. $result = $upload->uploadOne($file, "system", "talent/TalentAllowanceCommonFile");
  736. if ($result->code != 200) {
  737. return json(new Response(Response::ERROR, $result->msg));
  738. }
  739. $data["id"] = getStringId();
  740. $data["enterpriseId"] = $this->user["uid"];
  741. $data["batchId"] = $batchId;
  742. $data["batch"] = $batchInfo["batch"];
  743. $data["url"] = $result->filepath;
  744. $data["originalName"] = $file->getOriginalName();
  745. $data["createTime"] = date("Y-m-d H:i:s");
  746. $data["createUser"] = $this->user["uid"];
  747. $res = Db::table("un_talent_allowance_common_file")->insert($data);
  748. return json(new Response(Response::SUCCESS, "上传成功"));
  749. }
  750. public function listCommonFile() {
  751. $param = $this->request->param();
  752. $batchId = $param["batch"];
  753. $where = [["batchId", "=", $batchId], ["enterpriseId", "=", $this->user["uid"]]];
  754. $list = Db::table("un_talent_allowance_common_file")->where($where)->select()->toArray();
  755. foreach ($list as $key => $item) {
  756. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  757. $list[$key]["url"] = getStoragePath($item["url"]);
  758. }
  759. return json(["rows" => $list]);
  760. }
  761. public function deleteCommonFile() {
  762. $id = $this->request["id"];
  763. $where = [];
  764. $where[] = ["id", "=", $id];
  765. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  766. $file = Db::table("un_talent_allowance_common_file")->where($where)->find();
  767. if (!$file) {
  768. return json(new Response(Response::ERROR, "不存在的文件,删除失败"));
  769. }
  770. if (Db::table("un_talent_allowance_common_file")->where($where)->delete()) {
  771. if (!empty($file["url"])) {
  772. $filepath = "storage/" . $file["url"];
  773. if (file_exists($filepath)) {
  774. unlink($filepath);
  775. }
  776. }
  777. return json(new Response(Response::SUCCESS, "删除成功"));
  778. }
  779. }
  780. public function findTalentAllowance() {
  781. $res = [];
  782. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"]);
  783. $year = $batch["batch"];
  784. if ($year) {
  785. $ids = null;
  786. //根据申报年度查询当前企业已申报的人才
  787. $where = [];
  788. $where[] = ["year", "=", $year];
  789. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  790. $talentAllowances = TaModel::where($where)->select()->toArray();
  791. $ids = array_unique(array_column($talentAllowances, "talentId"));
  792. $whr = [];
  793. $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  794. $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
  795. $whr[] = ["e.type", "=", $this->user["type"]];
  796. $whr[] = ["ti.id", "not in", $ids];
  797. $list = \app\enterprise\model\Talent::alias("ti")->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")->field("ti.id,ti.name,ti.card_number as idCard")->where($whr)->select()->toArray();
  798. foreach ($list as $info) {
  799. if (strtotime($year . "-12-31") >= strtotime($info["identifyMonth"])) {
  800. $res[] = $info;
  801. } else {
  802. $whereTypeChange = [];
  803. $whereTypeChange[] = ["idCard", "=", $info["idCard"]];
  804. $whereTypeChange[] = ["checkState", "=", MainState::PASS];
  805. $whereTypeChange[] = ["isPublic", "=", 6];
  806. $typeChanges = TalentTypeChange::where($whereTypeChange)->select()->toArray();
  807. foreach ($typeChanges as $typeChange) {
  808. if (strtotime($year . "-12-31") >= strtotime($typeChange["oldIdentifyMonth"])) {
  809. $res[] = $info;
  810. break;
  811. }
  812. }
  813. }
  814. }
  815. }
  816. return new Response(Response::SUCCESS, "", ["rows" => $res, "total" => count($res)]);
  817. }
  818. public function export() {
  819. $obj["year"] = \StrUtil::getRequestDecodeParam($this->request, "year");
  820. $obj["name"] = \StrUtil::getRequestDecodeParam($this->request, "name");
  821. $obj["talentArrange"] = \StrUtil::getRequestDecodeParam($this->request, "talentArrange");
  822. $obj["address"] = \StrUtil::getRequestDecodeParam($this->request, "address");
  823. $obj["identifyCondition"] = \StrUtil::getRequestDecodeParam($this->request, "identifyCondition");
  824. $where = [];
  825. $where[] = ["ta.enterpriseId", "=", $this->user["uid"]];
  826. if (\StrUtil::isNotEmpAndNull($obj["year"])) {
  827. $where[] = ["ta.year", "like", "%" . $obj["year"] . "%"];
  828. }
  829. if (\StrUtil::isNotEmpAndNull($obj["name"])) {
  830. $where[] = ["ta.name", "like", "%" . $obj["name"] . "%"];
  831. }
  832. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  833. $where[] = ["ta.talentArrange", "=", $obj["talentArrange"]];
  834. }
  835. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  836. $where[] = ["ta.address", "=", $obj["address"]];
  837. }
  838. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  839. $where[] = ["ta.identifyCondition", "=", $obj["identifyCondition"]];
  840. }
  841. $projects = [
  842. AllowanceProjectEnum::PROJECT_TAX,
  843. AllowanceProjectEnum::PROJECT_WAGES,
  844. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  845. AllowanceProjectEnum::PROJECT_SB_PENSION,
  846. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  847. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  848. ];
  849. $months = [];
  850. for ($m = 1; $m <= 12; $m++) {
  851. $months[] = $m . "月";
  852. }
  853. $columns = [["年度", [1, 2]], ["所属镇街", [1, 2]], ["姓名", [1, 2]], ["性别", [1, 2]], ["证件号码", [1, 2]], ["人才层次", [1, 2]], ["认定条件", [1, 2]], ["认定条件取得时间", [1, 2]], ["认定条件名称", [1, 2]], ["公布入选月份", [1, 2]], ["津补贴类型", [1, 2]], ["兑现月份", [1, 2]], ["兑现金额", [1, 2]], ["金额说明", [1, 2]], ["审核状态", [1, 2]], ["缴纳单位", [1, 2]]];
  854. $infoCols = count($columns);
  855. for ($i = 0; $i < count($projects); $i++) {
  856. $columns[] = [AllowanceProjectEnum::getProjectName($projects[$i]), $months];
  857. }
  858. $list = \app\common\model\TalentAllowanceProject::alias("pro")
  859. ->field("ta.id,ta.year,ta.enterpriseId as curEnterpriseId,ta.address,ta.name,ta.sex,ta.idCard,ta.talentArrange,ta.identifyCondition,ta.identifyConditionName,ta.identifyMonth,ta.allowanceType,ta.months,ta.money,ta.moneyDesc,ta.checkState,pro.months as pre_months,con.enterpriseId,con.startTime,con.endTime,con.entryTime,con.quitTime,con.isQuit")
  860. ->leftJoin("un_talent_allowance_info ta", "ta.id=pro.mainId")
  861. ->leftJoin("un_talent_allowancecontract_detail con", "pro.baseId=con.id")
  862. ->where($where)
  863. ->order("ta.year desc,ta.createTime desc,pro.project asc")
  864. ->select()->toArray();
  865. $tmpList = [];
  866. foreach ($list as $item) {
  867. }
  868. $cols = $infoCols + count($projects) * 12 - 1;
  869. $settings = [
  870. "background-color" => [[sprintf("A1:%s1", getExcelColumnByIndex($cols)), "0066CC"]],
  871. "color" => [[sprintf("A1:%s1", getExcelColumnByIndex($cols)), "FFFFFF"]],
  872. "border" => sprintf("A1:%s%d", getExcelColumnByIndex($cols), 2),
  873. "wrap" => [sprintf("A2:%s%d", getExcelColumnByIndex($cols), 2)],
  874. "align" => [[sprintf("A1:%s%d", getExcelColumnByIndex($cols), 2), "hCenter"], [sprintf("A1:%s%d", getExcelColumnByIndex($cols - 1), 2), "vCenter"]],
  875. "height" => [18],
  876. "freeze" => "D1"
  877. ];
  878. for ($i = 0; $i < count($projects) * 12; $i++) {
  879. $settings["width"][] = [getExcelColumnByIndex($infoCols + $i), 6]; //批设置项目的宽度
  880. }
  881. $settings["background-color"][] = [sprintf("%s2:%s2", getExcelColumnByIndex($infoCols), getExcelColumnByIndex($cols)), "E1F1DE"];
  882. export($columns, [], "津补贴申报名单", $settings);
  883. }
  884. }