Human.php 12 KB

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