TalentAllowance.php 52 KB

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