EnterpriseChangeRecord.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\common\AdminController;
  4. use app\common\api\ChuanglanSmsApi;
  5. use app\common\api\CompanyApi;
  6. use app\common\api\DictApi;
  7. use app\common\api\EnterpriseApi;
  8. use app\common\api\TalentState;
  9. use app\common\model\CurrentcyFileType;
  10. use app\common\model\MessageRecord;
  11. use app\common\model\TalentChecklog;
  12. use app\common\model\TalentCommonFile;
  13. class EnterpriseChangeRecord extends AdminController {
  14. public function gotoEnterpriseChangeRecordPage() {
  15. $talentTypeList = DictApi::findChildDictByCode("enterprise_tag");
  16. $industryFieldNewList = DictApi::findChildDictByCode("industry_field");
  17. $streetList = DictApi::findChildDictByCode("street");
  18. return view("", ['enterprise_tag' => $talentTypeList, 'industryFieldNew' => $industryFieldNewList, 'street' => $streetList]);
  19. }
  20. public function findEnterpriseChangeRecordByPage() {
  21. $res = EnterpriseApi::getRecordList($this->request);
  22. return json($res);
  23. }
  24. public function gotoEnterpriseChangeDetailPage() {
  25. $id = trim($this->request['id']);
  26. if (!$id) {
  27. return json(["msg" => 'ID不能为空!']);
  28. }
  29. $ecr = EnterpriseApi::getOneRecord($id);
  30. $ep = EnterpriseApi::getOne($ecr['mainId']);
  31. if (\StrUtil::isNotEmpAndNull($ecr['oldStreet']) || \StrUtil::isNotEmpAndNull($ecr['newStreet'])) {
  32. $streetList = DictApi::selectByParentCode("street");
  33. if (\StrUtil::isNotEmpAndNull($ecr['oldStreet'])) {
  34. $ecr['oldStreetName'] = $streetList[$ecr['oldStreet']];
  35. }
  36. if (\StrUtil::isNotEmpAndNull($ecr['newStreet'])) {
  37. $ecr['newStreetName'] = $streetList[$ecr['newStreet']];
  38. }
  39. }
  40. if ($ep["imgurl"]) {
  41. $ecr["imgurl"] = $ep["imgurl"];
  42. $pathinfo = pathinfo($ecr["imgurl"]);
  43. if (in_array($pathinfo['extension'], ["jpeg", "jpg", "png", "gif"])) {
  44. $ecr['imgurl_is_img'] = 1;
  45. } else {
  46. $ecr['imgurl_is_img'] = 0;
  47. }
  48. }
  49. if ($ep["bankImg"]) {
  50. $ecr["bankImg"] = $ep["bankImg"];
  51. $pathinfo = pathinfo($ecr["bankImg"]);
  52. if (in_array($pathinfo['extension'], ["jpeg", "jpg", "png", "gif"])) {
  53. $ecr['bankImg_is_img'] = 1;
  54. } else {
  55. $ecr['bankImg_is_img'] = 0;
  56. }
  57. }
  58. if ($ep["domainImg"]) {
  59. $ecr["domainImg"] = $ep["domainImg"];
  60. $pathinfo = pathinfo($ecr["domainImg"]);
  61. if (in_array($pathinfo['extension'], ["jpeg", "jpg", "png", "gif"])) {
  62. $ecr['domainImg_is_img'] = 1;
  63. } else {
  64. $ecr['domainImg_is_img'] = 0;
  65. }
  66. }
  67. if ($ep["beian"]) {
  68. $ecr["beian"] = $ep["beian"];
  69. $pathinfo = pathinfo($ecr["beian"]);
  70. if (in_array($pathinfo['extension'], ["jpeg", "jpg", "png", "gif"])) {
  71. $ecr['beian_is_img'] = 1;
  72. } else {
  73. $ecr['beian_is_img'] = 0;
  74. }
  75. }
  76. switch ($ecr['checkState']) {
  77. case 1:
  78. $ecr['checkStateName'] = '保存未提交';
  79. break;
  80. case 2:
  81. $ecr['checkStateName'] = '待审核';
  82. break;
  83. case 3:
  84. $ecr['checkStateName'] = '审核驳回';
  85. break;
  86. case 4:
  87. $ecr['checkStateName'] = '审核通过';
  88. break;
  89. case 5:
  90. $ecr['checkStateName'] = '重新提交';
  91. break;
  92. default:
  93. $ecr['checkStateName'] = '';
  94. break;
  95. }
  96. $where = [];
  97. $where[] = ['tcf.mainId', '=', $id];
  98. $files = TalentCommonFile::alias("tcf")->field("tcf.*,cft.api")->leftJoin("new_currency_filetype cft", "cft.id=tcf.typeId")->where($where)->select();
  99. $_files = [];
  100. foreach ($files as $k => $v) {
  101. $extension = pathinfo($v["url"])["extension"];
  102. if (in_array($extension, ["jpeg", "jpg", "png", "gif"])) {
  103. $v["is_img"] = 1;
  104. } else {
  105. $v["is_img"] = 0;
  106. }
  107. $v['url'] = getStoragePath($v['url']);
  108. $_files[$v["api"]][] = $v;
  109. }
  110. switch ($ep->special) {
  111. case 0:
  112. if (\StrUtil::isNotEmpAndNull($ecr['oldEnterpriseTag']) || \StrUtil::isNotEmpAndNull($ecr['newEnterpriseTag'])) {
  113. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  114. if (\StrUtil::isNotEmpAndNull($ecr['oldEnterpriseTag'])) {
  115. $ecr['oldEnterpriseTagName'] = $talentTypeList[$ecr['oldEnterpriseTag']];
  116. }
  117. if (\StrUtil::isNotEmpAndNull($ecr['newEnterpriseTag'])) {
  118. $ecr['newEnterpriseTagName'] = $talentTypeList[$ecr['newEnterpriseTag']];
  119. }
  120. }
  121. if (\StrUtil::isNotEmpAndNull($ecr['oldIndustryFieldNew']) || \StrUtil::isNotEmpAndNull($ecr['newIndustryFieldNew'])) {
  122. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  123. if (\StrUtil::isNotEmpAndNull($ecr['oldIndustryFieldNew'])) {
  124. $ecr['oldIndustryFieldNewName'] = $industryFieldNewList[$ecr['oldIndustryFieldNew']];
  125. }
  126. if (\StrUtil::isNotEmpAndNull($ecr['newIndustryFieldNew'])) {
  127. $ecr['newIndustryFieldNewName'] = $industryFieldNewList[$ecr['newIndustryFieldNew']];
  128. }
  129. }
  130. if (\StrUtil::isNotEmpAndNull($ecr['oldIndustryFieldOld'])) {
  131. $industry = DictApi::findDictByCode($ecr['oldIndustryFieldOld']);
  132. $ecr['oldIndustryFieldOldName'] = $industry['name'];
  133. }
  134. if (\StrUtil::isNotEmpAndNull($ecr['newIndustryFieldOld'])) {
  135. $industry = DictApi::findDictByCode($ecr['newIndustryFieldOld']);
  136. $ecr['newIndustryFieldOldName'] = $industry['name'];
  137. }
  138. if (\StrUtil::isNotEmpAndNull($ecr['oldEnterpriseType'])) {
  139. $industry = DictApi::findDictByCode($ecr['oldEnterpriseType']);
  140. $ecr['oldEnterpriseTypeName'] = $industry['name'];
  141. }
  142. if (\StrUtil::isNotEmpAndNull($ecr['newEnterpriseType'])) {
  143. $industry = DictApi::findDictByCode($ecr['newEnterpriseType']);
  144. $ecr['newEnterpriseTypeName'] = $industry['name'];
  145. }
  146. return view("", ['ecr' => $ecr, 'files' => $_files]);
  147. break;
  148. case 1:
  149. return view("", ['ecr' => $ecr, 'files' => $_files]);
  150. break;
  151. default:
  152. break;
  153. }
  154. }
  155. public function gotoEnterpriseChangeExaminePage() {
  156. $id = trim($this->request['id']);
  157. if (!$id) {
  158. return json(["msg" => 'ID不能为空!']);
  159. }
  160. $ecr = EnterpriseApi::getOneRecord($id);
  161. $ep = EnterpriseApi::getOne($ecr['mainId']);
  162. $fields = ["Name" => "单位名称", "IdCard" => "统一社会信用代码", "Legal" => "法人代表", "Address" => "单位地址", "Street" => "所属街道", "Ephone" => "单位电话", "BankCard" => "企业银行账号", "Bank" => "企业开户银行", "BankNetwork" => "企业开户银行网点",
  163. "IndustryFieldNew" => "产业领域", "IndustryFieldOld" => "行业领域", "EnterpriseTag" => "单位标签", "EnterpriseType" => "单位类型",
  164. "AgentName" => "人才联络员姓名", "AgentPhone" => "人才联络员电话", "AgentEmail" => "人才联络员邮箱"];
  165. $modify_fields = [];
  166. foreach ($fields as $key => $value) {
  167. $oldFieldName = "old" . $key;
  168. $newFieldName = "new" . $key;
  169. if ($ecr[$oldFieldName] != $ecr[$newFieldName]) {
  170. $modify_fields[$newFieldName] = ["field" => $newFieldName, "name" => $value, "checked" => false];
  171. }
  172. }
  173. if ($ecr["modify_fields"]) {
  174. $_modify_fields = explode(",", $ecr["modify_fields"]);
  175. foreach ($_modify_fields as $_field) {
  176. if ($modify_fields[$_field]) {
  177. $modify_fields[$_field]["checked"] = true;
  178. } else {
  179. $modify_fields[$_field] = ["field" => $_field, "name" => $fields[substr($_field, 3)], "checked" => true];
  180. }
  181. }
  182. }
  183. $currencyType = $ep["special"] == 0 ? "enterpriseChange" : "governmentChange";
  184. $where = [];
  185. $where[] = ["type", "=", $currencyType];
  186. $where[] = ["active", "=", 1];
  187. $fileTypes = \app\admin\model\CurrencyFiletype::where($where)->order("sn asc")->column("name", "id");
  188. $where = [];
  189. $where[] = ['mainId', '=', $id];
  190. $uploadTypeIds = TalentCommonFile::distinct(true)->field("typeId")->where($where)->column("typeId");
  191. $modify_files = [];
  192. foreach ($uploadTypeIds as $typeId) {
  193. $modify_files[$typeId] = ["typeId" => $typeId, "name" => $fileTypes[$typeId], "checked" => false];
  194. }
  195. if ($ecr["modify_files"]) {
  196. $_modify_files = explode(",", $ecr["modify_files"]);
  197. foreach ($_modify_files as $_typeId) {
  198. if ($modify_files[$_typeId]) {
  199. $modify_files[$_typeId]["checked"] = true;
  200. } else {
  201. $modify_files[$_typeId] = ["typeId" => $_typeId, "name" => $fileTypes[$_typeId], "checked" => true];
  202. }
  203. }
  204. }
  205. return view("", ['ecr' => $ecr, 'fields' => $modify_fields, "files" => $modify_files]);
  206. }
  207. public function doExamine() {
  208. $id = trim($this->request['id']);
  209. if (!$id) {
  210. return json(["msg" => 'ID不能为空!', 'code' => 500]);
  211. }
  212. $ecr = EnterpriseApi::getOneRecord($id);
  213. if (!$ecr) {
  214. return json(["msg" => '原始数据不存在!', 'code' => 500]);
  215. }
  216. $checkState = trim($this->request['checkState']);
  217. $files = $this->request["files"];
  218. $fields = $this->request["fields"];
  219. if ($checkState == null || ($checkState != 4 && $checkState != 3)) {
  220. return json(["msg" => '请选择审核状态!', 'code' => 500]);
  221. }
  222. $checkMsg = trim($this->request['checkMsg']);
  223. //如果审核状态为 审核驳回, 需要填写审核意见
  224. if ($checkState == 3 && \StrUtil::isEmpOrNull($checkMsg)) {
  225. return json(["msg" => '审核驳回时,需要填写审核意见!', 'code' => 500]);
  226. }
  227. if ($checkState == 3 && !$files && !$fields) {
  228. return json(["msg" => '审核驳回时,需要选择可修改的字段或者附件!', 'code' => 500]);
  229. }
  230. if (\StrUtil::isNotEmpAndNull($checkMsg) && strlen($checkMsg) > 200) {
  231. return json(["msg" => '审核意见最多200个字符!', 'code' => 500]);
  232. }
  233. if ($ecr['checkState'] != 2 && $ecr['checkState'] != 3 && $ecr['checkState'] != 5) {
  234. return json(["msg" => '不在审核范围内!', 'code' => 500]);
  235. }
  236. //如果为审核驳回,更新表中的审核状态 和 审核意见, 直接返回结果
  237. if ($checkState == 3) {
  238. $ecr->checkState = 3;
  239. $ecr->checkMsg = $checkMsg;
  240. $ecr->updateUser = session('user')['uid'];
  241. $ecr->updateTime = date("Y-m-d H:i:s");
  242. $ecr->modify_fields = $fields ? implode(",", $fields) : null;
  243. $ecr->modify_files = $files ? implode(",", $files) : null;
  244. $ecr->save();
  245. //发送短信
  246. $record_data = [
  247. 'id' => getStringId(),
  248. 'bizId' => getStringId(),
  249. 'userId' => $ecr['mainId'],
  250. 'type' => 2,
  251. 'smsType' => 2,
  252. 'name' => $ecr['newName'],
  253. 'phone' => $ecr['newAgentPhone'],
  254. 'templateCode' => "【晋江市人才服务平台】您好!您提交申请的优秀人才{$checkMsg}因信息填写错误或上传不完整已被退回,请及时登录申报系统查看审核意见并重新提交。",
  255. 'params' => '机构信息变更',
  256. 'state' => 1,
  257. 'sendingDate' => date("Y-m-d H:i:s", time()),
  258. 'createTime' => date("Y-m-d H:i:s", time())
  259. ];
  260. $smsapi = new ChuanglanSmsApi();
  261. $result = $smsapi->sendSMS($ecr['newAgentPhone'], $record_data['templateCode']);
  262. MessageRecord::create($record_data);
  263. $company = CompanyApi::getOne(session('user')['companyId']);
  264. TalentChecklog::create([
  265. 'id' => getStringId(),
  266. 'category' => 'enterprise_change',
  267. 'mainId' => $ecr['id'],
  268. 'type' => 10,
  269. 'typeField' => null,
  270. 'active' => 1,
  271. 'state' => 3,
  272. 'step' => 101,
  273. 'stateChange' => "<span class='label label-info'>审核驳回</span>",
  274. 'description' => $checkMsg,
  275. 'createTime' => date("Y-m-d H:i:s", time()),
  276. 'createUser' => session('user')['name'] . "({$company['name']})"
  277. ]);
  278. return json(["msg" => '操作成功!', "code" => 200]);
  279. } else {
  280. $ecr->checkState = 4;
  281. $ecr->checkMsg = $checkMsg;
  282. $ecr->updateUser = session('user')['uid'];
  283. $ecr->updateTime = date("Y-m-d H:i:s");
  284. $ecr->modify_fields = null;
  285. $ecr->modify_files = null;
  286. $ecr->save();
  287. $ep = EnterpriseApi::getOne($ecr['mainId']);
  288. $ep->name = $ecr['newName'];
  289. $ep->idCard = $ecr['newIdCard'];
  290. $ep->enterpriseTag = $ecr['newEnterpriseTag'];
  291. $ep->street = $ecr['newStreet'];
  292. $ep->address = $ecr['newAddress'];
  293. $ep->legal = $ecr['newLegal'];
  294. $ep->ephone = $ecr['newEphone'];
  295. $ep->agentName = $ecr['newAgentName'];
  296. $ep->agentEmail = $ecr['newAgentEmail'];
  297. $ep->agentPhone = $ecr['newAgentPhone'];
  298. $ep->industryFieldNew = $ecr['newIndustryFieldNew'];
  299. $ep->industryFieldOld = $ecr['newIndustryFieldOld'];
  300. $ep->enterpriseType = $ecr['newEnterpriseType'];
  301. $ep->bankCard = $ecr['newBankCard'];
  302. $ep->bankNetwork = $ecr['newBankNetwork'];
  303. $ep->bank = $ecr['newBank'];
  304. $ep->updateUser = session('user')['uid'];
  305. $ep->updateTime = date("Y-m-d H:i:s");
  306. //查询此次上传的文件
  307. $list = TalentCommonFile::where('mainId', $ecr['id'])->select()->toArray();
  308. if (count($list) > 0) {
  309. foreach ($list as $k => $v) {
  310. $fileInfo = CurrentcyFileType::where('id', $v['typeId'])->select()->toArray();
  311. if (count($fileInfo) > 0) {
  312. foreach ($fileInfo as $item) {
  313. switch ($item['api']) {
  314. case 'businessLicense':
  315. $ep->imgurl = $v['url'];
  316. break;
  317. case 'businessBank':
  318. $ep->bankImg = $v['url'];
  319. break;
  320. case 'businessDomain':
  321. $ep->domainImg = $v['url'];
  322. break;
  323. case 'businessBeian':
  324. $ep->beian = $v['url'];
  325. break;
  326. }
  327. }
  328. }
  329. }
  330. }
  331. //同步人才库与津贴库 TODO
  332. $ep->save();
  333. //发送短信
  334. $record_data = [
  335. 'id' => getStringId(),
  336. 'bizId' => getStringId(),
  337. 'userId' => $ecr['mainId'],
  338. 'type' => 2,
  339. 'smsType' => 2,
  340. 'name' => $ecr['newName'],
  341. 'phone' => $ecr['newAgentPhone'],
  342. 'templateCode' => "【晋江市人才服务平台】您好!您提交申请的优秀人才{$checkMsg}已审核通过,可登录申报系统做相关事宜申报。",
  343. 'params' => '机构信息变更',
  344. 'state' => 1,
  345. 'sendingDate' => date("Y-m-d H:i:s", time()),
  346. 'createTime' => date("Y-m-d H:i:s", time())
  347. ];
  348. $smsapi = new ChuanglanSmsApi();
  349. $result = $smsapi->sendSMS($ecr['newAgentPhone'], $record_data['templateCode']);
  350. MessageRecord::create($record_data);
  351. $company = CompanyApi::getOne(session('user')['companyId']);
  352. TalentChecklog::create([
  353. 'id' => getStringId(),
  354. 'category' => 'enterprise_change',
  355. 'mainId' => $ecr['id'],
  356. 'type' => 10,
  357. 'typeField' => null,
  358. 'active' => 1,
  359. 'state' => 4,
  360. 'step' => 101,
  361. 'stateChange' => "<span class='label label-info'>审核通过</span>",
  362. 'description' => $checkMsg,
  363. 'createTime' => date("Y-m-d H:i:s", time()),
  364. 'createUser' => session('user')['name'] . "({$company['name']})"
  365. ]);
  366. return json(["msg" => '操作成功!', "code" => 200]);
  367. }
  368. }
  369. }