Human.php 9.2 KB

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