Human.php 12 KB

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