Human.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\AdminBaseController;
  4. use app\common\model\HumanEnterpriseApplyModel;
  5. use app\common\model\HumanEnterpriseModel;
  6. use app\common\model\HumanInstitutionApplyModel;
  7. use app\common\model\HumanInstitutionModel;
  8. use app\common\validate\HumanEnterpriseValidate;
  9. use app\common\validate\HumanInstitutionValidate;
  10. use think\exception\ValidateException;
  11. class Human extends AdminBaseController
  12. {
  13. /**
  14. * 机构报名
  15. */
  16. public function institutionApply()
  17. {
  18. return view('', [
  19. 'status_list' => HumanInstitutionApplyModel::STATUS,
  20. ]);
  21. }
  22. public function listInstitutionApply()
  23. {
  24. $map = $this->dealEqualInput(['status'], $this->dealLikeInput(['name']));
  25. $list = HumanInstitutionApplyModel::where($map)
  26. ->order(['status' => 'asc'])
  27. ->limit(input('limit'))
  28. ->page(input('page'))
  29. ->append(['status_text'])
  30. ->select();
  31. $count = HumanInstitutionApplyModel::where($map)->count();
  32. if ($count == 0) {
  33. ajax_return(1, '未查询到数据');
  34. }
  35. list_return($list, $count);
  36. }
  37. public function statusInstitutionApply()
  38. {
  39. $id_arr = input('id_arr/a');
  40. $status = input('status', 1);
  41. HumanInstitutionApplyModel::update(['status' => $status], ['id' => $id_arr]);
  42. ajax_return();
  43. }
  44. public function institutionDetail()
  45. {
  46. $id = input('id/d');
  47. $info = HumanInstitutionApplyModel::find($id);
  48. return view('', [
  49. 'info' => $info,
  50. ]);
  51. }
  52. /**
  53. * 企业报名
  54. */
  55. public function enterpriseApply()
  56. {
  57. return view('', [
  58. 'status_list' => HumanEnterpriseApplyModel::STATUS,
  59. ]);
  60. }
  61. public function listEnterpriseApply()
  62. {
  63. $map = $this->dealEqualInput(['status'], $this->dealLikeInput(['name']));
  64. $list = HumanEnterpriseApplyModel::where($map)
  65. ->order(['status' => 'asc'])
  66. ->limit(input('limit'))
  67. ->page(input('page'))
  68. ->append(['status_text'])
  69. ->select();
  70. $count = HumanEnterpriseApplyModel::where($map)->count();
  71. if ($count == 0) {
  72. ajax_return(1, '未查询到数据');
  73. }
  74. list_return($list, $count);
  75. }
  76. public function statusEnterpriseApply()
  77. {
  78. $id_arr = input('id_arr/a');
  79. $status = input('status', 1);
  80. HumanEnterpriseApplyModel::update(['status' => $status], ['id' => $id_arr]);
  81. ajax_return();
  82. }
  83. public function enterpriseDetail()
  84. {
  85. $id = input('id/d');
  86. $info = HumanEnterpriseApplyModel::find($id);
  87. return view('', [
  88. 'info' => $info,
  89. ]);
  90. }
  91. /**
  92. * 机构列表
  93. */
  94. public function institutionList()
  95. {
  96. return view('', [
  97. 'status_list' => HumanInstitutionModel::STATUS,
  98. ]);
  99. }
  100. public function listInstitution()
  101. {
  102. $map = $this->dealEqualInput(['status'], $this->dealLikeInput(['name']));
  103. $list = HumanInstitutionModel::where($map)
  104. ->order(['priority' => 'desc', 'update_time' => 'desc'])
  105. ->limit(input('limit'))
  106. ->page(input('page'))
  107. ->append(['status_text'])
  108. ->select();
  109. $count = HumanInstitutionModel::where($map)->count();
  110. if ($count == 0) {
  111. ajax_return(1, '未查询到数据');
  112. }
  113. list_return($list, $count);
  114. }
  115. public function delInstitution()
  116. {
  117. $id_arr = input('id_arr/a');
  118. HumanInstitutionModel::destroy($id_arr);
  119. ajax_return();
  120. }
  121. /**
  122. * 编辑
  123. */
  124. public function institutionForm()
  125. {
  126. $id = input('id/d, 0');
  127. $info = HumanInstitutionModel::find($id);
  128. return view('', [
  129. 'info' => $info,
  130. 'status_list' => HumanInstitutionModel::STATUS,
  131. 'cooperate_list' => HumanInstitutionModel::COOPERATE,
  132. ]);
  133. }
  134. public function editInstitution()
  135. {
  136. $data = input('post.');
  137. try {
  138. validate(HumanInstitutionValidate::class)->check($data);
  139. } catch (ValidateException $e) {
  140. ajax_return(1, $e->getError());
  141. }
  142. if (empty($data['cooperate'])) {
  143. $data['cooperate'] = [];
  144. } else {
  145. $data['cooperate'] = array_values($data['cooperate']);
  146. }
  147. if (empty($data['id'])) {
  148. HumanInstitutionModel::create($data);
  149. } else {
  150. HumanInstitutionModel::update($data, ['id' => $data['id']]);
  151. }
  152. ajax_return();
  153. }
  154. public function importInstitution()
  155. {
  156. return view('public/import', [
  157. 'url' => url('human/importInstitutionPost'),
  158. 'last_table' => 'lay-human-institutionList-table',
  159. 'template_file' => '/static/common/exl/human_institution.xls',
  160. ]);
  161. }
  162. public function importInstitutionPost()
  163. {
  164. $file_url = input('file_url/s', "");
  165. if (!file_exists($file_url)) {
  166. ajax_return(1, '文件不存在');
  167. }
  168. //初始化数据
  169. $data = ['name', 'tel', 'address', 'introduction', 'cooperate', 'join', 'join_mobile'];
  170. $list = import_exl($file_url, $data, 1);
  171. if (empty($list)) {
  172. ajax_return(1, '请上传有数据的文件');
  173. }
  174. $empty_check = [
  175. 'name' => '企业名称',
  176. 'tel' => '联系电话',
  177. 'address' => '企业地址',
  178. ];
  179. //错误判断
  180. $time = time();
  181. foreach ($list as $k => $v) {
  182. foreach ($empty_check as $key => $value) {
  183. if (empty($v[$key])) {
  184. ajax_return(1, '第' . ($k + 2) . '行的' . $value . '不能为空');
  185. }
  186. }
  187. $cooperate = explode(',', $v['cooperate']);
  188. if (!empty($cooperate)) {
  189. foreach ($cooperate as $c) {
  190. if (!in_array($c, HumanInstitutionModel::COOPERATE)) {
  191. ajax_return(1, '第' . ($k + 2) . '行的业务范围(' . $c . ')不在业务范围列表中');
  192. }
  193. }
  194. }
  195. $list[$k]['cooperate'] = $cooperate;
  196. $list[$k]['priority'] = 255;
  197. $list[$k]['create_time'] = $list[$k]['update_time'] = $time;
  198. }
  199. HumanInstitutionModel::insertAll($list);
  200. ajax_return(0);
  201. }
  202. /**
  203. * 企业列表
  204. */
  205. public function enterpriseList()
  206. {
  207. return view('', [
  208. 'status_list' => HumanEnterpriseModel::STATUS,
  209. ]);
  210. }
  211. public function listEnterprise()
  212. {
  213. $map = $this->dealEqualInput(['status'], $this->dealLikeInput(['name']));
  214. $list = HumanEnterpriseModel::where($map)
  215. ->order(['priority' => 'desc', 'update_time' => 'desc'])
  216. ->limit(input('limit'))
  217. ->page(input('page'))
  218. ->append(['status_text'])
  219. ->select();
  220. $count = HumanEnterpriseModel::where($map)->count();
  221. if ($count == 0) {
  222. ajax_return(1, '未查询到数据');
  223. }
  224. list_return($list, $count);
  225. }
  226. public function delEnterprise()
  227. {
  228. $id_arr = input('id_arr/a');
  229. HumanEnterpriseModel::destroy($id_arr);
  230. ajax_return();
  231. }
  232. /**
  233. * 编辑
  234. */
  235. public function enterpriseForm()
  236. {
  237. $id = input('id/d, 0');
  238. $info = HumanEnterpriseModel::find($id);
  239. return view('', [
  240. 'info' => $info,
  241. 'status_list' => HumanEnterpriseModel::STATUS,
  242. ]);
  243. }
  244. public function editEnterprise()
  245. {
  246. $data = input('post.');
  247. try {
  248. validate(HumanEnterpriseValidate::class)->check($data);
  249. } catch (ValidateException $e) {
  250. ajax_return(1, $e->getError());
  251. }
  252. if (empty($data['id'])) {
  253. HumanEnterpriseModel::create($data);
  254. } else {
  255. HumanEnterpriseModel::update($data, ['id' => $data['id']]);
  256. }
  257. ajax_return();
  258. }
  259. public function importEnterprise()
  260. {
  261. return view('public/import', [
  262. 'url' => url('human/importEnterprisePost'),
  263. 'last_table' => 'lay-human-enterpriseList-table',
  264. 'template_file' => '/static/common/exl/human_enterprise.xls',
  265. ]);
  266. }
  267. public function importEnterprisePost()
  268. {
  269. $file_url = input('file_url/s', "");
  270. if (!file_exists($file_url)) {
  271. ajax_return(1, '文件不存在');
  272. }
  273. //初始化数据
  274. $data = ['name', 'capital', 'tel', 'address', 'introduction', 'join', 'join_mobile'];
  275. $list = import_exl($file_url, $data, 1);
  276. if (empty($list)) {
  277. ajax_return(1, '请上传有数据的文件');
  278. }
  279. $empty_check = [
  280. 'name' => '企业名称',
  281. 'capital' => '注册资本',
  282. 'tel' => '联系电话',
  283. 'address' => '企业地址',
  284. ];
  285. //错误判断
  286. $time = time();
  287. foreach ($list as $k => $v) {
  288. foreach ($empty_check as $key => $value) {
  289. if (empty($v[$key])) {
  290. return ajax_return(1, '第' . ($k + 2) . '行的' . $value . '不能为空');
  291. }
  292. }
  293. $list[$k]['priority'] = 255;
  294. $list[$k]['create_time'] = $list[$k]['update_time'] = $time;
  295. }
  296. HumanEnterpriseModel::insertAll($list);
  297. ajax_return(0);
  298. }
  299. }