Human.php 13 KB

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