Human.php 17 KB

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