Human.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <?php
  2. namespace app\mobile\controller;
  3. use app\common\model\HumanEnterpriseApplyModel;
  4. use app\common\model\HumanEnterpriseModel;
  5. use app\common\model\HumanInstitutionApplyModel;
  6. use app\common\model\HumanInstitutionModel;
  7. use app\common\model\HumanSeeModel;
  8. use app\common\validate\HumanEnterpriseApplyValidate;
  9. use app\common\validate\HumanInstitutionApplyValidate;
  10. use app\mobile\MobileBaseController;
  11. use think\exception\ValidateException;
  12. class Human extends MobileBaseController
  13. {
  14. protected function initialize()
  15. {
  16. // session('mobile.human.open_id','o8F4O6OW6pUzLWulOi-OzuGaBzoE');
  17. // session('mobile.human.open_id', 'aa');
  18. $open_id = session('mobile.human.open_id');
  19. if (empty($open_id)) {
  20. session('mobile.human.back_url', request()->url(true));
  21. $response = redirect('https://www.jucai.gov.cn/api/auth/wechat_auth?url=' . urlencode(url('/mobile/login/humanLogin')));
  22. throw new \think\exception\HttpResponseException($response);
  23. }
  24. }
  25. /**
  26. * 表单
  27. */
  28. public function index()
  29. {
  30. $this->_formValidate();
  31. return view();
  32. }
  33. public function institutionForm()
  34. {
  35. $this->_formValidate();
  36. return view('', [
  37. 'cooperate_list' => json_encode(HumanInstitutionModel::COOPERATE),
  38. ]);
  39. }
  40. public function institutionFormPost()
  41. {
  42. $data = input('post.');
  43. try {
  44. validate(HumanInstitutionApplyValidate::class)->check($data);
  45. } catch (ValidateException $e) {
  46. ajax_return(1, $e->getError());
  47. }
  48. $data['open_id'] = session('mobile.human.open_id');
  49. HumanInstitutionApplyModel::create($data);
  50. ajax_return();
  51. }
  52. public function enterpriseForm()
  53. {
  54. $this->_formValidate();
  55. $industry_list = [];
  56. foreach (HumanEnterpriseModel::INDUSTRY as $industry) {
  57. $industry_list[] = ['text' => $industry, 'value' => $industry];
  58. }
  59. return view('', [
  60. 'cooperate_list' => json_encode(HumanInstitutionModel::COOPERATE),
  61. 'industry_list' => json_encode($industry_list),
  62. ]);
  63. }
  64. public function enterpriseFormPost()
  65. {
  66. $data = input('post.');
  67. try {
  68. validate(HumanEnterpriseApplyValidate::class)->check($data);
  69. } catch (ValidateException $e) {
  70. ajax_return(1, $e->getError());
  71. }
  72. $data['open_id'] = session('mobile.human.open_id');
  73. HumanEnterpriseApplyModel::create($data);
  74. ajax_return();
  75. }
  76. public function tips()
  77. {
  78. $open_id = session('mobile.human.open_id');
  79. $msg = '';
  80. $type = '';
  81. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  82. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  83. if (empty($institution) && empty($enterprise)) {
  84. return redirect(url('human/index'));
  85. }
  86. if (!empty($institution)) {
  87. $type = 'institution';
  88. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  89. $msg = HumanInstitutionApplyModel::STATUS[$institution['status']];
  90. if (!empty($institution['comment'])) {
  91. $msg .= ':' . $institution['comment'];
  92. }
  93. } else {
  94. return redirect(url('human/enterpriseList'));
  95. }
  96. }
  97. if (!empty($enterprise)) {
  98. $type = 'enterprise';
  99. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  100. $msg = HumanEnterpriseApplyModel::STATUS[$enterprise['status']];
  101. if (!empty($enterprise['comment'])) {
  102. $msg .= ':' . $enterprise['comment'];
  103. }
  104. } else {
  105. return redirect(url('human/institutionList'));
  106. }
  107. }
  108. return view('', ['msg' => $msg, 'type' => $type]);
  109. }
  110. public function resetApply()
  111. {
  112. $open_id = session('mobile.human.open_id');
  113. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  114. if (!empty($institution)) {
  115. $institution->delete();
  116. }
  117. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  118. if (!empty($enterprise)) {
  119. $enterprise->delete();
  120. }
  121. return redirect(url('human/index'));
  122. }
  123. /**
  124. * 列表
  125. */
  126. public function institutionList()
  127. {
  128. $this->_listValidate();
  129. $cooperate_list = [['text' => '全部', 'value' => '']];
  130. foreach (HumanInstitutionModel::COOPERATE as $cooperate) {
  131. $cooperate_list[] = ['text' => $cooperate, 'value' => $cooperate];
  132. }
  133. return view('', [
  134. 'cooperate_list' => json_encode($cooperate_list),
  135. ]);
  136. }
  137. public function listInstitution()
  138. {
  139. $where = $this->dealLikeInput(['name', 'cooperate']);
  140. $where[] = ['status', '=', HumanInstitutionModel::STATUS_SHOW];
  141. $list = HumanInstitutionModel::where($where)
  142. ->order(['priority' => 'desc'])
  143. ->limit(input('limit', 10))
  144. ->page(input('page', 1))
  145. ->select();
  146. ajax_success($list);
  147. }
  148. public function institutionDetail()
  149. {
  150. $human = $this->_listValidate();
  151. $id = input('id');
  152. empty($id) && jump('该机构不存在或已删除');
  153. $info = HumanInstitutionModel::find($id);
  154. empty($info) && jump('该机构不存在或已删除');
  155. $apply = HumanInstitutionApplyModel::where('join_mobile', '=', $info['join_mobile'])->find();
  156. if (!empty($apply)) {
  157. $check = HumanSeeModel::where([
  158. ['join_mobile', '=', $human['data']['join_mobile']],
  159. ['human_id', '=', $apply['id']],
  160. ['type', '=', '机构'],
  161. ])->find();
  162. if (empty($check)) {
  163. HumanSeeModel::create([
  164. 'type' => '机构',
  165. 'human_id' => $apply['id'],
  166. 'name' => $human['data']['name'],
  167. 'join' => $human['data']['join'],
  168. 'join_mobile' => $human['data']['join_mobile'],
  169. ]);
  170. }
  171. }
  172. return view('', ['info' => $info]);
  173. }
  174. public function enterpriseList()
  175. {
  176. $this->_listValidate();
  177. $cooperate_list = [['text' => '全部业务', 'value' => '']];
  178. foreach (HumanInstitutionModel::COOPERATE as $cooperate) {
  179. $cooperate_list[] = ['text' => $cooperate, 'value' => $cooperate];
  180. }
  181. $industry_list = [['text' => '全部行业', 'value' => '']];
  182. foreach (HumanEnterpriseModel::INDUSTRY as $industry) {
  183. $industry_list[] = ['text' => $industry, 'value' => $industry];
  184. }
  185. return view('', [
  186. 'cooperate_list' => json_encode($cooperate_list),
  187. 'industry_list' => json_encode($industry_list),
  188. ]);
  189. }
  190. public function listEnterprise()
  191. {
  192. $where = $this->dealLikeInput(['name', 'cooperate', 'industry']);
  193. $where[] = ['status', '=', HumanEnterpriseModel::STATUS_SHOW];
  194. $list = HumanEnterpriseModel::where($where)
  195. ->order(['priority' => 'desc'])
  196. ->limit(input('limit', 10))
  197. ->page(input('page', 1))
  198. ->select();
  199. ajax_success($list);
  200. }
  201. public function enterpriseDetail()
  202. {
  203. $human = $this->_listValidate();
  204. $id = input('id');
  205. empty($id) && jump('该企业不存在或已删除');
  206. $info = HumanEnterpriseModel::find($id);
  207. empty($info) && jump('该企业不存在或已删除');
  208. $apply = HumanEnterpriseApplyModel::where('join_mobile', '=', $info['join_mobile'])->find();
  209. if (!empty($apply)) {
  210. $check = HumanSeeModel::where([
  211. ['join_mobile', '=', $human['data']['join_mobile']],
  212. ['human_id', '=', $apply['id']],
  213. ['type', '=', '企业'],
  214. ])->find();
  215. if (empty($check)) {
  216. HumanSeeModel::create([
  217. 'type' => '企业',
  218. 'human_id' => $apply['id'],
  219. 'name' => $human['data']['name'],
  220. 'join' => $human['data']['join'],
  221. 'join_mobile' => $human['data']['join_mobile'],
  222. ]);
  223. }
  224. }
  225. return view('', ['info' => $info]);
  226. }
  227. public function center()
  228. {
  229. $this->_listValidate();
  230. return view();
  231. }
  232. public function describe()
  233. {
  234. return view();
  235. }
  236. public function guide()
  237. {
  238. return view();
  239. }
  240. public function jinjiang()
  241. {
  242. return view();
  243. }
  244. public function renzi()
  245. {
  246. return view();
  247. }
  248. public function arrive()
  249. {
  250. $open_id = session('mobile.human.open_id');
  251. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  252. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  253. $msg = '';
  254. if (empty($institution) && empty($enterprise)) {
  255. $msg = '请先报名';
  256. }
  257. if (!empty($institution)) {
  258. $institution->is_arrive = HumanInstitutionApplyModel::IS_ARRIVE_YES;
  259. $institution->save();
  260. $msg = '签到成功';
  261. }
  262. if (!empty($enterprise)) {
  263. $enterprise->is_arrive = HumanEnterpriseApplyModel::IS_ARRIVE_YES;
  264. $enterprise->save();
  265. $msg = '签到成功';
  266. }
  267. return view('', ['msg' => $msg]);
  268. }
  269. public function bindMobile()
  270. {
  271. $mobile = input('mobile', '');
  272. empty($mobile) && ajax_return(1, '请输入手机号');
  273. $institution = HumanInstitutionApplyModel::where('join_mobile', $mobile)->find();
  274. if (empty($institution)) {
  275. $enterprise = HumanEnterpriseApplyModel::where('join_mobile', $mobile)->find();
  276. if (empty($enterprise)) {
  277. ajax_return(1, '该手机号未报名,请确认手机号');
  278. } else {
  279. HumanEnterpriseApplyModel::create([
  280. 'open_id' => session('mobile.human.open_id'),
  281. 'name' => $enterprise->name,
  282. 'join' => $enterprise->join,
  283. 'join_mobile' => $enterprise->join_mobile,
  284. 'cooperate' => $enterprise->cooperate,
  285. 'status' => HumanEnterpriseApplyModel::STATUS_PASS,
  286. ]);
  287. }
  288. } else {
  289. HumanInstitutionApplyModel::create([
  290. 'open_id' => session('mobile.human.open_id'),
  291. 'name' => $institution->name,
  292. 'join' => $institution->join,
  293. 'join_mobile' => $institution->join_mobile,
  294. 'cooperate' => $institution->cooperate,
  295. 'status' => HumanInstitutionApplyModel::STATUS_PASS,
  296. ]);
  297. }
  298. ajax_return();
  299. }
  300. public function seeme()
  301. {
  302. $this->_listValidate();
  303. return view();
  304. }
  305. public function tuwen()
  306. {
  307. return view();
  308. }
  309. public function listSeeme()
  310. {
  311. $human = $this->_listValidate();
  312. $where = [
  313. ['type', '=', $human['type']],
  314. ['human_id', '=', $human['data']['id']],
  315. ];
  316. $list = HumanSeeModel::where($where)
  317. ->order(['update_time' => 'desc'])
  318. ->limit(input('limit', 10))
  319. ->page(input('page', 1))
  320. ->select();
  321. ajax_success($list);
  322. }
  323. private function _formValidate()
  324. {
  325. $open_id = session('mobile.human.open_id');
  326. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  327. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  328. if (!empty($institution)) {
  329. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  330. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  331. } else {
  332. throw new \think\exception\HttpResponseException(redirect(url('human/enterpriseList')));
  333. }
  334. }
  335. if (!empty($enterprise)) {
  336. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  337. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  338. } else {
  339. throw new \think\exception\HttpResponseException(redirect(url('human/institutionList')));
  340. }
  341. }
  342. }
  343. private function _listValidate()
  344. {
  345. $action = $this->request->action();
  346. if ($action != 'center') {
  347. if (time() < 1730779200) {
  348. jump('11月5日12点开启,敬请期待','mobile/human/center');
  349. }
  350. }
  351. $open_id = session('mobile.human.open_id');
  352. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  353. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  354. if (empty($institution) && empty($enterprise)) {
  355. throw new \think\exception\HttpResponseException(redirect(url('human/index')));
  356. }
  357. if (!empty($institution)) {
  358. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  359. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  360. }
  361. return ['type' => '机构', 'data' => $institution];
  362. }
  363. if (!empty($enterprise)) {
  364. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  365. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  366. }
  367. return ['type' => '企业', 'data' => $enterprise];
  368. }
  369. }
  370. }