Human.php 12 KB

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