Human.php 10 KB

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