EnterpriseChangeRecord.php 16 KB

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