Human.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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','null');
  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. return view('', [
  56. 'cooperate_list' => json_encode(HumanInstitutionModel::COOPERATE),
  57. ]);
  58. }
  59. public function enterpriseFormPost()
  60. {
  61. $data = input('post.');
  62. try {
  63. validate(HumanEnterpriseApplyValidate::class)->check($data);
  64. } catch (ValidateException $e) {
  65. ajax_return(1, $e->getError());
  66. }
  67. $data['open_id'] = session('mobile.human.open_id');
  68. HumanEnterpriseApplyModel::create($data);
  69. ajax_return();
  70. }
  71. public function tips()
  72. {
  73. $open_id = session('mobile.human.open_id');
  74. $msg = '';
  75. $type = '';
  76. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  77. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  78. if (empty($institution) && empty($enterprise)) {
  79. return redirect(url('human/index'));
  80. }
  81. if (!empty($institution)) {
  82. $type = 'institution';
  83. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  84. $msg = HumanInstitutionApplyModel::STATUS[$institution['status']];
  85. if (!empty($institution['comment'])) {
  86. $msg .= ':' . $institution['comment'];
  87. }
  88. } else {
  89. return redirect(url('human/enterpriseList'));
  90. }
  91. }
  92. if (!empty($enterprise)) {
  93. $type = 'enterprise';
  94. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  95. $msg = HumanEnterpriseApplyModel::STATUS[$enterprise['status']];
  96. if (!empty($enterprise['comment'])) {
  97. $msg .= ':' . $enterprise['comment'];
  98. }
  99. } else {
  100. return redirect(url('human/institutionList'));
  101. }
  102. }
  103. return view('', ['msg' => $msg, 'type' => $type]);
  104. }
  105. public function resetApply()
  106. {
  107. $open_id = session('mobile.human.open_id');
  108. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  109. if (!empty($institution)) {
  110. $institution->delete();
  111. }
  112. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  113. if (!empty($enterprise)) {
  114. $enterprise->delete();
  115. }
  116. return redirect(url('human/index'));
  117. }
  118. /**
  119. * 列表
  120. */
  121. public function institutionList()
  122. {
  123. $this->_listValidate();
  124. $cooperate_list = [['text' => '全部', 'value' => '']];
  125. foreach (HumanInstitutionModel::COOPERATE as $cooperate) {
  126. $cooperate_list[] = ['text' => $cooperate, 'value' => $cooperate];
  127. }
  128. return view('', [
  129. 'cooperate_list' => json_encode($cooperate_list),
  130. ]);
  131. }
  132. public function listInstitution()
  133. {
  134. $where = $this->dealLikeInput(['name', 'cooperate']);
  135. $where[] = ['status', '=', HumanInstitutionModel::STATUS_SHOW];
  136. $list = HumanInstitutionModel::where($where)
  137. ->order(['priority' => 'desc'])
  138. ->limit(input('limit', 10))
  139. ->page(input('page', 1))
  140. ->select();
  141. ajax_success($list);
  142. }
  143. public function institutionDetail()
  144. {
  145. $human = $this->_listValidate();
  146. $id = input('id');
  147. empty($id) && jump('该机构不存在或已删除');
  148. $info = HumanInstitutionModel::find($id);
  149. empty($info) && jump('该机构不存在或已删除');
  150. $apply = HumanInstitutionApplyModel::where('join_mobile', '=', $info['join_mobile'])->find();
  151. if (!empty($apply)) {
  152. $check = HumanSeeModel::where([
  153. ['join_mobile', '=', $human['data']['join_mobile']],
  154. ['human_id', '=', $apply['id']],
  155. ['type', '=', '机构'],
  156. ])->find();
  157. if (empty($check)) {
  158. HumanSeeModel::create([
  159. 'type' => '机构',
  160. 'human_id' => $apply['id'],
  161. 'name' => $human['data']['name'],
  162. 'join' => $human['data']['join'],
  163. 'join_mobile' => $human['data']['join_mobile'],
  164. ]);
  165. }
  166. }
  167. return view('', ['info' => $info]);
  168. }
  169. public function enterpriseList()
  170. {
  171. $this->_listValidate();
  172. $cooperate_list = [['text' => '全部业务', 'value' => '']];
  173. foreach (HumanInstitutionModel::COOPERATE as $cooperate) {
  174. $cooperate_list[] = ['text' => $cooperate, 'value' => $cooperate];
  175. }
  176. $industry_list = [['text' => '全部行业', 'value' => '']];
  177. foreach (HumanEnterpriseModel::INDUSTRY as $industry) {
  178. $industry_list[] = ['text' => $industry, 'value' => $industry];
  179. }
  180. return view('', [
  181. 'cooperate_list' => json_encode($cooperate_list),
  182. 'industry_list' => json_encode($industry_list),
  183. ]);
  184. }
  185. public function listEnterprise()
  186. {
  187. $where = $this->dealLikeInput(['name', 'cooperate', 'industry']);
  188. $where[] = ['status', '=', HumanEnterpriseModel::STATUS_SHOW];
  189. $list = HumanEnterpriseModel::where($where)
  190. ->order(['priority' => 'desc'])
  191. ->limit(input('limit', 10))
  192. ->page(input('page', 1))
  193. ->select();
  194. ajax_success($list);
  195. }
  196. public function enterpriseDetail()
  197. {
  198. $human = $this->_listValidate();
  199. $id = input('id');
  200. empty($id) && jump('该企业不存在或已删除');
  201. $info = HumanEnterpriseModel::find($id);
  202. empty($info) && jump('该企业不存在或已删除');
  203. $apply = HumanEnterpriseApplyModel::where('join_mobile', '=', $info['join_mobile'])->find();
  204. if (!empty($apply)) {
  205. $check = HumanSeeModel::where([
  206. ['join_mobile', '=', $human['data']['join_mobile']],
  207. ['human_id', '=', $apply['id']],
  208. ['type', '=', '企业'],
  209. ])->find();
  210. if (empty($check)) {
  211. HumanSeeModel::create([
  212. 'type' => '企业',
  213. 'human_id' => $apply['id'],
  214. 'name' => $human['data']['name'],
  215. 'join' => $human['data']['join'],
  216. 'join_mobile' => $human['data']['join_mobile'],
  217. ]);
  218. }
  219. }
  220. return view('', ['info' => $info]);
  221. }
  222. public function center()
  223. {
  224. $this->_listValidate();
  225. return view();
  226. }
  227. public function describe()
  228. {
  229. return view();
  230. }
  231. public function guide()
  232. {
  233. return view();
  234. }
  235. public function jinjiang()
  236. {
  237. return view();
  238. }
  239. public function renzi()
  240. {
  241. return view();
  242. }
  243. public function arrive()
  244. {
  245. $open_id = session('mobile.human.open_id');
  246. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  247. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  248. $msg = '';
  249. if (empty($institution) && empty($enterprise)) {
  250. $msg = '请先报名';
  251. }
  252. if (!empty($institution)) {
  253. $institution->is_arrive = HumanInstitutionApplyModel::IS_ARRIVE_YES;
  254. $institution->save();
  255. $msg = '签到成功';
  256. }
  257. if (!empty($enterprise)) {
  258. $enterprise->is_arrive = HumanEnterpriseApplyModel::IS_ARRIVE_YES;
  259. $enterprise->save();
  260. $msg = '签到成功';
  261. }
  262. return view('', ['msg' => $msg]);
  263. }
  264. public function bindMobile()
  265. {
  266. $mobile = input('mobile', '');
  267. empty($mobile) && ajax_return(1, '请输入手机号');
  268. $institution = HumanInstitutionApplyModel::where('join_mobile', $mobile)->find();
  269. if (empty($institution)) {
  270. $enterprise = HumanEnterpriseApplyModel::where('join_mobile', $mobile)->find();
  271. if (empty($enterprise)) {
  272. ajax_return(1, '该手机号未报名,请确认手机号');
  273. } else {
  274. $enterprise->open_id = session('mobile.human.open_id');
  275. $enterprise->save();
  276. }
  277. } else {
  278. $institution->open_id = session('mobile.human.open_id');
  279. $institution->save();
  280. }
  281. ajax_return();
  282. }
  283. public function seeme()
  284. {
  285. return view();
  286. }
  287. public function listSeeme()
  288. {
  289. $human = $this->_listValidate();
  290. $where = [
  291. ['type', '=', $human['type']],
  292. ['human_id', '=', $human['data']['id']],
  293. ];
  294. $list = HumanSeeModel::where($where)
  295. ->order(['update_time' => 'desc'])
  296. ->limit(input('limit', 10))
  297. ->page(input('page', 1))
  298. ->select();
  299. ajax_success($list);
  300. }
  301. private function _formValidate()
  302. {
  303. $open_id = session('mobile.human.open_id');
  304. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  305. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  306. if (!empty($institution)) {
  307. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  308. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  309. } else {
  310. throw new \think\exception\HttpResponseException(redirect(url('human/enterpriseList')));
  311. }
  312. }
  313. if (!empty($enterprise)) {
  314. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  315. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  316. } else {
  317. throw new \think\exception\HttpResponseException(redirect(url('human/institutionList')));
  318. }
  319. }
  320. }
  321. private function _listValidate()
  322. {
  323. $action = $this->request->action();
  324. if ($action != 'center') {
  325. if (time() < 1730736000) {
  326. jump('11月5日开启,敬请期待','mobile/human/center');
  327. }
  328. }
  329. $open_id = session('mobile.human.open_id');
  330. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  331. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  332. if (empty($institution) && empty($enterprise)) {
  333. throw new \think\exception\HttpResponseException(redirect(url('human/index')));
  334. }
  335. if (!empty($institution)) {
  336. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  337. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  338. }
  339. return ['type' => '机构', 'data' => $institution];
  340. }
  341. if (!empty($enterprise)) {
  342. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  343. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  344. }
  345. return ['type' => '企业', 'data' => $enterprise];
  346. }
  347. }
  348. }