Human.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. $comment = input('comment', '');
  46. HumanInstitutionApplyModel::update(['status' => $status, 'comment' => $comment], ['id' => $id_arr]);
  47. ajax_return();
  48. }
  49. public function delInstitutionApply()
  50. {
  51. $id_arr = input('id_arr/a');
  52. HumanInstitutionApplyModel::destroy($id_arr);
  53. ajax_return();
  54. }
  55. public function institutionDetail()
  56. {
  57. $id = input('id/d');
  58. $info = HumanInstitutionApplyModel::find($id);
  59. return view('', [
  60. 'info' => $info,
  61. ]);
  62. }
  63. public function exportInstitutionApply()
  64. {
  65. $map = $this->dealInInput(['id'], $this->dealEqualInput(['status', 'is_arrive'], $this->dealLikeInput(['name'])));
  66. $list = HumanInstitutionApplyModel::where($map)
  67. ->order(['status' => 'asc'])
  68. ->append(['status_text', 'is_arrive_text'])
  69. ->select();
  70. $xlsCell = [
  71. ['id', '表ID'],
  72. ['name', '机构名称'],
  73. ['join', '参会人'],
  74. ['join_mobile', '参会手机号'],
  75. ['wechat', '微信号'],
  76. ['suggestion', '对本次活动想说的话'],
  77. ['status_text', '状态'],
  78. ['create_time', '报名时间'],
  79. ['describe', '机构介绍'],
  80. ['url', '公司网址'],
  81. ['is_arrive_text', '签到'],
  82. ];
  83. export_exl("机构报名表", $xlsCell, $list, ['join_mobile', 'wechat']);
  84. }
  85. public function institutionToEnterprise()
  86. {
  87. $id = input('id/d', 0);
  88. empty($id) && ajax_return(1, '请选择机构');
  89. $info = HumanInstitutionApplyModel::find($id);
  90. empty($info) && ajax_return(1, '请机构不存在');
  91. HumanEnterpriseApplyModel::create([
  92. 'open_id' => $info['open_id'],
  93. 'name' => $info['name'],
  94. 'join' => $info['join'],
  95. 'join_mobile' => $info['join_mobile'],
  96. 'wechat' => $info['wechat'],
  97. 'cooperate' => $info['cooperate'],
  98. 'suggestion' => $info['suggestion'],
  99. 'status' => $info['status'],
  100. 'describe' => $info['describe'],
  101. 'url' => $info['url'],
  102. 'images' => $info['images'],
  103. 'is_arrive' => $info['is_arrive'],
  104. 'comment' => $info['comment'],
  105. ]);
  106. $info->delete();
  107. ajax_return();
  108. }
  109. /**
  110. * 企业报名
  111. */
  112. public function enterpriseApply()
  113. {
  114. $file_url = QrcodeService::getQrcode('human_arrive', url('/mobile/human/arrive'), 600);
  115. return view('', [
  116. 'status_list' => HumanEnterpriseApplyModel::STATUS,
  117. 'is_arrive_list' => HumanEnterpriseApplyModel::IS_ARRIVE,
  118. 'file_url' => $file_url,
  119. ]);
  120. }
  121. public function listEnterpriseApply()
  122. {
  123. $map = $this->dealEqualInput(['status', 'is_arrive'], $this->dealLikeInput(['name']));
  124. $list = HumanEnterpriseApplyModel::where($map)
  125. ->order(['status' => 'asc'])
  126. ->limit(input('limit'))
  127. ->page(input('page'))
  128. ->append(['status_text', 'is_arrive_text'])
  129. ->select();
  130. $count = HumanEnterpriseApplyModel::where($map)->count();
  131. if ($count == 0) {
  132. ajax_return(1, '未查询到数据');
  133. }
  134. list_return($list, $count);
  135. }
  136. public function statusEnterpriseApply()
  137. {
  138. $id_arr = input('id_arr/a');
  139. $status = input('status', 1);
  140. $comment = input('comment', '');
  141. HumanEnterpriseApplyModel::update(['status' => $status, 'comment' => $comment], ['id' => $id_arr]);
  142. ajax_return();
  143. }
  144. public function delEnterpriseApply()
  145. {
  146. $id_arr = input('id_arr/a');
  147. HumanEnterpriseApplyModel::destroy($id_arr);
  148. ajax_return();
  149. }
  150. public function enterpriseDetail()
  151. {
  152. $id = input('id/d');
  153. $info = HumanEnterpriseApplyModel::find($id);
  154. return view('', [
  155. 'info' => $info,
  156. ]);
  157. }
  158. public function exportEnterpriseApply()
  159. {
  160. $map = $this->dealInInput(['id'], $this->dealEqualInput(['status', 'is_arrive'], $this->dealLikeInput(['name'])));
  161. $list = HumanEnterpriseApplyModel::where($map)
  162. ->order(['status' => 'asc'])
  163. ->append(['status_text', 'is_arrive_text'])
  164. ->select();
  165. foreach ($list as $v) {
  166. $v['cooperate_text'] = implode(',', $v['cooperate']);
  167. }
  168. $xlsCell = [
  169. ['id', '表ID'],
  170. ['name', '企业名称'],
  171. ['join', '参会人'],
  172. ['join_mobile', '参会手机号'],
  173. ['wechat', '微信号'],
  174. ['cooperate_text', '希望合作的业务'],
  175. ['suggestion', '对本次活动想说的话'],
  176. ['status_text', '状态'],
  177. ['create_time', '报名时间'],
  178. ['describe', '机构介绍'],
  179. ['url', '公司网址'],
  180. ['is_arrive_text', '签到'],
  181. ];
  182. export_exl("企业报名表", $xlsCell, $list, ['join_mobile', 'wechat']);
  183. }
  184. /**
  185. * 机构列表
  186. */
  187. public function institutionList()
  188. {
  189. return view('', [
  190. 'status_list' => HumanInstitutionModel::STATUS,
  191. ]);
  192. }
  193. public function listInstitution()
  194. {
  195. $map = $this->dealEqualInput(['status'], $this->dealLikeInput(['name']));
  196. $list = HumanInstitutionModel::where($map)
  197. ->order(['priority' => 'desc', 'update_time' => 'desc'])
  198. ->limit(input('limit'))
  199. ->page(input('page'))
  200. ->append(['status_text'])
  201. ->select();
  202. $count = HumanInstitutionModel::where($map)->count();
  203. if ($count == 0) {
  204. ajax_return(1, '未查询到数据');
  205. }
  206. list_return($list, $count);
  207. }
  208. public function delInstitution()
  209. {
  210. $id_arr = input('id_arr/a');
  211. HumanInstitutionModel::destroy($id_arr);
  212. ajax_return();
  213. }
  214. /**
  215. * 编辑
  216. */
  217. public function institutionForm()
  218. {
  219. $id = input('id/d, 0');
  220. $info = HumanInstitutionModel::find($id);
  221. return view('', [
  222. 'info' => $info,
  223. 'status_list' => HumanInstitutionModel::STATUS,
  224. 'cooperate_list' => HumanInstitutionModel::COOPERATE,
  225. ]);
  226. }
  227. public function editInstitution()
  228. {
  229. $data = input('post.');
  230. try {
  231. validate(HumanInstitutionValidate::class)->check($data);
  232. } catch (ValidateException $e) {
  233. ajax_return(1, $e->getError());
  234. }
  235. if (empty($data['cooperate'])) {
  236. $data['cooperate'] = [];
  237. } else {
  238. $data['cooperate'] = array_values($data['cooperate']);
  239. }
  240. if (empty($data['id'])) {
  241. HumanInstitutionModel::create($data);
  242. } else {
  243. HumanInstitutionModel::update($data, ['id' => $data['id']]);
  244. }
  245. ajax_return();
  246. }
  247. public function importInstitution()
  248. {
  249. return view('public/import', [
  250. 'url' => url('human/importInstitutionPost'),
  251. 'last_table' => 'lay-human-institutionList-table',
  252. 'template_file' => '/static/common/exl/human_institution.xls',
  253. ]);
  254. }
  255. public function importInstitutionPost()
  256. {
  257. $file_url = input('file_url/s', "");
  258. if (!file_exists($file_url)) {
  259. ajax_return(1, '文件不存在');
  260. }
  261. //初始化数据
  262. $data = ['name', 'tel', 'address', 'introduction', 'cooperate', 'join', 'join_mobile'];
  263. $list = import_exl($file_url, $data, 1);
  264. if (empty($list)) {
  265. ajax_return(1, '请上传有数据的文件');
  266. }
  267. $empty_check = [
  268. 'name' => '企业名称',
  269. 'tel' => '联系电话',
  270. 'address' => '企业地址',
  271. ];
  272. //错误判断
  273. $time = time();
  274. foreach ($list as $k => $v) {
  275. foreach ($empty_check as $key => $value) {
  276. if (empty($v[$key])) {
  277. ajax_return(1, '第' . ($k + 2) . '行的' . $value . '不能为空');
  278. }
  279. }
  280. $cooperate = explode(',', $v['cooperate']);
  281. if (!empty($cooperate)) {
  282. foreach ($cooperate as $c) {
  283. if (!in_array($c, HumanInstitutionModel::COOPERATE)) {
  284. ajax_return(1, '第' . ($k + 2) . '行的业务范围(' . $c . ')不在业务范围列表中');
  285. }
  286. }
  287. }
  288. $list[$k]['cooperate'] = $cooperate;
  289. $list[$k]['priority'] = 255;
  290. $list[$k]['create_time'] = $list[$k]['update_time'] = $time;
  291. }
  292. HumanInstitutionModel::insertAll($list);
  293. ajax_return(0);
  294. }
  295. public function enterpriseToInstitution()
  296. {
  297. $id = input('id/d', 0);
  298. empty($id) && ajax_return(1, '请选择企业');
  299. $info = HumanEnterpriseApplyModel::find($id);
  300. empty($info) && ajax_return(1, '请企业不存在');
  301. HumanInstitutionApplyModel::create([
  302. 'open_id' => $info['open_id'],
  303. 'name' => $info['name'],
  304. 'join' => $info['join'],
  305. 'join_mobile' => $info['join_mobile'],
  306. 'wechat' => $info['wechat'],
  307. 'cooperate' => $info['cooperate'],
  308. 'suggestion' => $info['suggestion'],
  309. 'status' => $info['status'],
  310. 'describe' => $info['describe'],
  311. 'url' => $info['url'],
  312. 'images' => $info['images'],
  313. 'is_arrive' => $info['is_arrive'],
  314. 'comment' => $info['comment'],
  315. ]);
  316. $info->delete();
  317. ajax_return();
  318. }
  319. /**
  320. * 企业列表
  321. */
  322. public function enterpriseList()
  323. {
  324. return view('', [
  325. 'status_list' => HumanEnterpriseModel::STATUS,
  326. ]);
  327. }
  328. public function listEnterprise()
  329. {
  330. $map = $this->dealEqualInput(['status'], $this->dealLikeInput(['name']));
  331. $list = HumanEnterpriseModel::where($map)
  332. ->order(['priority' => 'desc', 'update_time' => 'desc'])
  333. ->limit(input('limit'))
  334. ->page(input('page'))
  335. ->append(['status_text'])
  336. ->select();
  337. $count = HumanEnterpriseModel::where($map)->count();
  338. if ($count == 0) {
  339. ajax_return(1, '未查询到数据');
  340. }
  341. list_return($list, $count);
  342. }
  343. public function delEnterprise()
  344. {
  345. $id_arr = input('id_arr/a');
  346. HumanEnterpriseModel::destroy($id_arr);
  347. ajax_return();
  348. }
  349. /**
  350. * 编辑
  351. */
  352. public function enterpriseForm()
  353. {
  354. $id = input('id/d, 0');
  355. $info = HumanEnterpriseModel::find($id);
  356. return view('', [
  357. 'info' => $info,
  358. 'status_list' => HumanEnterpriseModel::STATUS,
  359. ]);
  360. }
  361. public function editEnterprise()
  362. {
  363. $data = input('post.');
  364. try {
  365. validate(HumanEnterpriseValidate::class)->check($data);
  366. } catch (ValidateException $e) {
  367. ajax_return(1, $e->getError());
  368. }
  369. if (empty($data['id'])) {
  370. HumanEnterpriseModel::create($data);
  371. } else {
  372. HumanEnterpriseModel::update($data, ['id' => $data['id']]);
  373. }
  374. ajax_return();
  375. }
  376. public function importEnterprise()
  377. {
  378. return view('public/import', [
  379. 'url' => url('human/importEnterprisePost'),
  380. 'last_table' => 'lay-human-enterpriseList-table',
  381. 'template_file' => '/static/common/exl/human_enterprise.xls',
  382. ]);
  383. }
  384. public function importEnterprisePost()
  385. {
  386. $file_url = input('file_url/s', "");
  387. if (!file_exists($file_url)) {
  388. ajax_return(1, '文件不存在');
  389. }
  390. //初始化数据
  391. $data = ['name', 'capital', 'tel', 'address', 'introduction', 'join', 'join_mobile'];
  392. $list = import_exl($file_url, $data, 1);
  393. if (empty($list)) {
  394. ajax_return(1, '请上传有数据的文件');
  395. }
  396. $empty_check = [
  397. 'name' => '企业名称',
  398. 'capital' => '注册资本',
  399. 'tel' => '联系电话',
  400. 'address' => '企业地址',
  401. ];
  402. //错误判断
  403. $time = time();
  404. foreach ($list as $k => $v) {
  405. foreach ($empty_check as $key => $value) {
  406. if (empty($v[$key])) {
  407. return ajax_return(1, '第' . ($k + 2) . '行的' . $value . '不能为空');
  408. }
  409. }
  410. $list[$k]['priority'] = 255;
  411. $list[$k]['create_time'] = $list[$k]['update_time'] = $time;
  412. }
  413. HumanEnterpriseModel::insertAll($list);
  414. ajax_return(0);
  415. }
  416. }