Api.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\admin\model\Enterprise;
  4. use app\common\api\DictApi;
  5. use app\common\model\CurrentcyFileType;
  6. use app\common\model\TalentChecklog;
  7. use app\common\model\TalentCommonFile;
  8. use app\enterprise\model\EnterpriseRecord;
  9. use app\enterprise\common\EnterpriseController;
  10. use app\Request;
  11. use think\exception\ValidateException;
  12. class Api extends EnterpriseController {
  13. public function findEnterpriseChangeByPage()
  14. {
  15. $order = trim($this->request->param("order")) ?: "desc";
  16. $offset = trim($this->request->param("offset")) ?: 0;
  17. $limit = trim($this->request->param("limit")) ?: 10;
  18. $list = EnterpriseRecord::where('mainId',session("user")["uid"])->limit($offset, $limit)->order('createTime ' . $order)->select()->toArray();
  19. $count = count($list);
  20. if($count > 0){
  21. $streetList = DictApi::selectByParentCode('street');
  22. $typeList = DictApi::selectByParentCode('enterprise_type');
  23. $industryFieldNew = DictApi::selectByParentCode('industry_field');
  24. foreach ($list as $k => &$v){
  25. $v['newIndustryFieldNewName'] = $industryFieldNew[$v['newIndustryFieldNew']];
  26. $v['newEnterpriseType'] = $typeList[$v['newEnterpriseType']];
  27. $v['newStreetName'] = $streetList[$v['newStreet']];
  28. }
  29. }
  30. return json(["total" => $count, "rows" => $list]);
  31. }
  32. public function findUnfinishedChangeRecord(){
  33. return EnterpriseRecord::where('mainId',session("user")["uid"])->where('checkState','<>', 4)->select()->toArray();
  34. }
  35. public function toAdd()
  36. {
  37. $ep = Enterprise::where('id',session("user")["uid"])->find();
  38. $ecr = [
  39. 'enterprise_id' => $ep['id'],
  40. 'newName' => $ep['name'],
  41. 'newIdCard' => $ep['idCard'],
  42. 'newStreet' => $ep['street'],
  43. 'newAddress' => $ep['address'],
  44. 'newLegal' => $ep['legal'],
  45. 'newEphone' => $ep['ephone'],
  46. 'newAgentName' => $ep['agentName'],
  47. 'newAgentEmail' => $ep['agentEmail'],
  48. 'newAgentPhone' => $ep['agentPhone'],
  49. 'type' => $ep['type'],
  50. 'newEnterpriseTag' => $ep['enterpriseTag'],
  51. 'newEnterpriseType' => $ep['enterpriseType'],
  52. 'newIndustryFieldNew' => $ep['industryFieldNew'],
  53. 'newIndustryFieldOld' => $ep['industryFieldOld'],
  54. 'newBankCard' => $ep['bankCard'],
  55. 'newBank' => $ep['bank'],
  56. 'newBankNetwork' => $ep['bankNetwork']
  57. ];
  58. switch ($ep['checkState']){
  59. case 1:
  60. $ecr['checkStateName'] = '保存未提交审核';
  61. break;
  62. case 2:
  63. $ecr['checkStateName'] = '待审核';
  64. break;
  65. case 3:
  66. $ecr['checkStateName'] = '审核驳回';
  67. break;
  68. case 4:
  69. $ecr['checkStateName'] = '审核通过';
  70. break;
  71. case 5:
  72. $ecr['checkStateName'] = '重新提交';
  73. break;
  74. default:
  75. $ecr['checkStateName'] = '';
  76. }
  77. return view("", ['ecr' => $ecr]);
  78. }
  79. public function upsert(){
  80. $data = [
  81. 'id' => \StrUtil::getRequestDecodeParam($this->request,'enterprise_id'),
  82. 'name' => \StrUtil::getRequestDecodeParam($this->request,'newName'),//单位名称
  83. 'idCard' => \StrUtil::getRequestDecodeParam($this->request,'newIdCard'),//社会信用代码
  84. 'agentName' => \StrUtil::getRequestDecodeParam($this->request,'newAgentName'),//人才联络员
  85. 'agentPhone' => \StrUtil::getRequestDecodeParam($this->request,'newAgentPhone'),//人才联络员电话
  86. 'legal' => \StrUtil::getRequestDecodeParam($this->request,'newLegal'),//法人
  87. 'street' => \StrUtil::getRequestDecodeParam($this->request,'newStreet'),//镇街
  88. 'address' => \StrUtil::getRequestDecodeParam($this->request,'newAddress'),//地址
  89. 'type' => intval($this->request['type']),
  90. 'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request,'newEnterpriseTag'),//单位标签
  91. 'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request,'newEnterpriseType'),//单位类型
  92. 'agentEmail' => \StrUtil::getRequestDecodeParam($this->request,'newAgentEmail'),//邮箱
  93. 'ephone' => \StrUtil::getRequestDecodeParam($this->request,'newEphone'),//单位电话
  94. 'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request,'newIndustryFieldNew'),//产业领域
  95. 'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request,'newIndustryFieldOld'),//行业领域
  96. 'bankCard' => \StrUtil::getRequestDecodeParam($this->request,'newBankCard'),//银行
  97. 'bank' => \StrUtil::getRequestDecodeParam($this->request,'newBank'),//开户行
  98. 'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request,'newBankNetwork')//网点
  99. ];
  100. try {
  101. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('change')->check($data);
  102. $ep = Enterprise::where('id',session("user")["uid"])->find();
  103. $record_id = \StrUtil::getRequestDecodeParam($this->request,'id');
  104. if(!$record_id){
  105. $record_data = [
  106. 'id' => getStringId(),
  107. 'mainId' => $data['id'],
  108. 'type' => $data['type'],
  109. 'oldName' => $ep['name'],
  110. 'oldIdCard' => $ep['idCard'],
  111. 'oldIndustryFieldNew' => $ep['industryFieldNew'],
  112. 'oldIndustryFieldOld' => $ep['industryFieldOld'],
  113. 'oldStreet' => $ep['street'],
  114. 'oldAddress' => $ep['address'],
  115. 'oldLegal' => $ep['legal'],
  116. 'oldEphone' => $ep['ephone'],
  117. 'oldAgentName' => $ep['agentName'],
  118. 'oldAgentEmail' => $ep['agentEmail'],
  119. 'oldAgentPhone' => $ep['agentPhone'],
  120. 'oldEnterpriseTag' => $ep['enterpriseTag'],
  121. 'oldEnterpriseType' => $ep['enterpriseType'],
  122. 'oldBankCard' => $ep['bankCard'],
  123. 'oldBank' => $ep['bank'],
  124. 'oldBankNetwork' => $ep['bankNetwork'],
  125. 'newName' => htmlspecialchars($data['name']),
  126. 'newIdCard' => htmlspecialchars($data['idCard']),
  127. 'newIndustryFieldNew' => $data['industryFieldNew'],
  128. 'newIndustryFieldOld' => $data['industryFieldOld'],
  129. 'newStreet' => $data['street'],
  130. 'newAddress' => $data['address'],
  131. 'newLegal' => $data['legal'],
  132. 'newEphone' => $data['ephone'],
  133. 'newAgentName' => $data['agentName'],
  134. 'newAgentEmail' => $data['agentEmail'],
  135. 'newAgentPhone' => $data['agentPhone'],
  136. 'newEnterpriseTag' => $data['enterpriseTag'],
  137. 'newEnterpriseType' => $data['enterpriseType'],
  138. 'newBankCard' => $data['bankCard'],
  139. 'newBank' => $data['bank'],
  140. 'newBankNetwork' => $data['bankNetwork'],
  141. 'checkState' => 1,
  142. 'createTime' => date("Y-m-d H:i:s",time()),
  143. 'createUser' => session("user")["uid"]
  144. ];
  145. EnterpriseRecord::create($record_data);
  146. $log = [
  147. 'id' => getStringId(),
  148. 'mainId' => $record_data['id'],
  149. 'category' => 'enterprise_change',
  150. 'type' => 10,
  151. 'active' => 1,
  152. 'state' => 1,
  153. 'step' => 100,
  154. 'stateChange' => '保存未提交',
  155. 'description' => '企业信息变更记录添加成功',
  156. 'createTime' => date("Y-m-d H:i:s",time()),
  157. 'createUser' => '用户'
  158. ];
  159. $res = ['msg' => '添加成功', 'code' => 200, 'obj' => $record_data];
  160. } else {
  161. $record = EnterpriseRecord::find($record_id);
  162. $ep = Enterprise::where('id',session("user")["uid"])->find();
  163. $record->oldName = $ep['name'];
  164. $record->oldIdCard = $ep['idCard'];
  165. $record->oldIndustryFieldNew = $ep['industryFieldNew'];
  166. $record->oldIndustryFieldOld = $ep['industryFieldOld'];
  167. $record->oldStreet = $ep['street'];
  168. $record->oldAddress = $ep['address'];
  169. $record->oldLegal = $ep['legal'];
  170. $record->oldEphone = $ep['ephone'];
  171. $record->oldAgentName = $ep['agentName'];
  172. $record->oldAgentEmail = $ep['agentEmail'];
  173. $record->oldAgentPhone = $ep['agentPhone'];
  174. $record->oldEnterpriseTag = $ep['enterpriseTag'];
  175. $record->oldEnterpriseType = $ep['enterpriseType'];
  176. $record->oldBankCard = $ep['bankCard'];
  177. $record->oldBank = $ep['bank'];
  178. $record->oldBankNetwork = $ep['bankNetwork'];
  179. $record->newName = htmlspecialchars($data['name']);
  180. $record->newIdCard = htmlspecialchars($data['idCard']);
  181. $record->newIndustryFieldNew = $data['industryFieldNew'];
  182. $record->newIndustryFieldOld = $data['industryFieldOld'];
  183. $record->newStreet = $data['street'];
  184. $record->newAddress = $data['address'];
  185. $record->newLegal = $data['legal'];
  186. $record->newEphone = $data['ephone'];
  187. $record->newAgentName = $data['agentName'];
  188. $record->newAgentEmail = $data['agentEmail'];
  189. $record->newAgentPhone = $data['agentPhone'];
  190. $record->newEnterpriseTag = $data['enterpriseTag'];
  191. $record->newEnterpriseType = $data['enterpriseType'];
  192. $record->newBankCard = $data['bankCard'];
  193. $record->newBank = $data['bank'];
  194. $record->newBankNetwork = $data['bankNetwork'];
  195. $record->updateTime = date("Y-m-d H:i:s");
  196. $record->updateUser = session("user")["uid"];
  197. $record->save();
  198. $log = [
  199. 'id' => getStringId(),
  200. 'category' => 'enterprise_change',
  201. 'mainId' => '',
  202. 'type' => 10,
  203. 'active' => 1,
  204. 'state' => 1,
  205. 'step' => 100,
  206. 'stateChange' => '保存未提交',
  207. 'description' => '企业信息变更记录修改成功',
  208. 'createTime' => date("Y-m-d H:i:s",time()),
  209. 'createUser' => '用户'
  210. ];
  211. $res = ['msg' => '修改成功', 'code' => 200, 'obj' => $record];
  212. }
  213. TalentChecklog::create($log);
  214. return json($res);
  215. } catch (ValidateException $e){
  216. $error = $e->getError();
  217. return json(["msg" => array_pop($error)],500);
  218. }
  219. }
  220. public function toUpdate(){
  221. $id = trim($this->request['id']);
  222. $ecr = EnterpriseRecord::findOrEmpty($id);
  223. return view("", ['ecr' => $ecr]);
  224. }
  225. public function submitToCheck(){
  226. $id = trim($this->request->post('id'));
  227. if(!$id){
  228. return json(['msg' => '记录为空', 'code' => 500]);
  229. }
  230. $obj = EnterpriseRecord::find($id);
  231. if(!$obj){
  232. return json(['msg' => '提交审核失败,请先填写基础信息', 'code' => 500]);
  233. }
  234. if($obj['checkState'] != 1 && $obj['checkState'] != 3){
  235. return json(['msg' => '不能重复提交审核', 'code' => 500]);
  236. }
  237. $list = CurrentcyFileType::where('type','enterpriseChange')->where('active',1)->select();
  238. if(!$list || count($list) <= 0){
  239. return json(['msg' => '缺少附件', 'code' => 500]);
  240. }
  241. $error_msg = "";
  242. foreach ($list as $k => $v){
  243. if($v['must'] == 1){
  244. $count = TalentCommonFile::where('mainId',$id)->where('typeId',$v['id'])->count();
  245. if($count == 0){
  246. if(strlen($error_msg) == 0){
  247. $error_msg = "以下为必传附件:";
  248. }
  249. $error_msg .= $v['name'] . ";";
  250. }
  251. }
  252. }
  253. if(strlen($error_msg) > 0){
  254. return json(['msg' => $error_msg, 'code' => 500]);
  255. }
  256. if($obj['checkState'] == 3){
  257. $obj['checkState'] = 5;
  258. $state = 5;
  259. }else{
  260. $obj['checkState'] = 2;
  261. $state = 2;
  262. }
  263. $obj->save();
  264. $log = [
  265. 'id' => getStringId(),
  266. 'category' => 'enterprise_change',
  267. 'mainId' => $id,
  268. 'type' => 10,
  269. 'active' => 1,
  270. 'state' => $state,
  271. 'step' => 100,
  272. 'stateChange' => "<span class='label'>待提交</span>-><span class='label label-success'>待审核</span>" ,
  273. 'description' => '提交审核',
  274. 'createTime' => date("Y-m-d H:i:s",time()),
  275. 'createUser' => '用户'
  276. ];
  277. TalentChecklog::create($log);
  278. return json(['msg' => '提交审核成功', 'code' => 200, 'obj' => 1]);
  279. }
  280. public function toDetail(){
  281. $id = trim($this->request['id']);
  282. if(!$id){
  283. return json(['msg' => '记录为空', 'code' => 500]);
  284. }
  285. $ecr = EnterpriseRecord::find($id);
  286. $streetList = DictApi::selectByParentCode('street');
  287. $tagList = DictApi::selectByParentCode('enterprise_tag');
  288. $typeList = DictApi::selectByParentCode('enterprise_type');
  289. $industryFieldNew = DictApi::selectByParentCode('industry_field');
  290. $ecr['oldStreetName'] = $streetList[$ecr['oldStreet']];
  291. $ecr['newStreetName'] = $streetList[$ecr['newStreet']];
  292. $ecr['oldEnterpriseTagName'] = $tagList[$ecr['oldEnterpriseTag']];
  293. $ecr['newEnterpriseTagName'] = $tagList[$ecr['newEnterpriseTag']];
  294. $ecr['oldEnterpriseTypeName'] = $typeList[$ecr['oldEnterpriseType']];
  295. $ecr['newEnterpriseTypeName'] = $typeList[$ecr['newEnterpriseType']];
  296. $ecr['oldIndustryFieldNewName'] = $industryFieldNew[$ecr['oldIndustryFieldNew']];
  297. $ecr['newIndustryFieldNewName'] = $industryFieldNew[$ecr['newIndustryFieldNew']];
  298. return view("",['ecr' => $ecr]);
  299. }
  300. }