Human.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. $this->_listValidate();
  145. $id = input('id');
  146. empty($id) && jump('该机构不存在或已删除');
  147. $info = HumanInstitutionModel::find($id);
  148. empty($info) && jump('该机构不存在或已删除');
  149. return view('', ['info' => $info]);
  150. }
  151. public function enterpriseList()
  152. {
  153. $this->_listValidate();
  154. $cooperate_list = [['text' => '全部业务', 'value' => '']];
  155. foreach (HumanInstitutionModel::COOPERATE as $cooperate) {
  156. $cooperate_list[] = ['text' => $cooperate, 'value' => $cooperate];
  157. }
  158. $industry_list = [['text' => '全部行业', 'value' => '']];
  159. foreach (HumanEnterpriseModel::INDUSTRY as $industry) {
  160. $industry_list[] = ['text' => $industry, 'value' => $industry];
  161. }
  162. return view('', [
  163. 'cooperate_list' => json_encode($cooperate_list),
  164. 'industry_list' => json_encode($industry_list),
  165. ]);
  166. }
  167. public function listEnterprise()
  168. {
  169. $where = $this->dealLikeInput(['name', 'cooperate', 'industry']);
  170. $where[] = ['status', '=', HumanEnterpriseModel::STATUS_SHOW];
  171. $list = HumanEnterpriseModel::where($where)
  172. ->order(['priority' => 'desc'])
  173. ->limit(input('limit', 10))
  174. ->page(input('page', 1))
  175. ->select();
  176. ajax_success($list);
  177. }
  178. public function enterpriseDetail()
  179. {
  180. $human = $this->_listValidate();
  181. $id = input('id');
  182. empty($id) && jump('该企业不存在或已删除');
  183. $info = HumanEnterpriseModel::find($id);
  184. empty($info) && jump('该企业不存在或已删除');
  185. $check = HumanSeeModel::where('join_mobile', $info['join_mobile'])->where('human_id',$info['id'])->find();
  186. if (empty($check)) {
  187. HumanSeeModel::create([
  188. 'type' => $human['type'],
  189. 'name' => $human['data']['name'],
  190. 'join' => $human['data']['join'],
  191. 'join_mobile' => $human['data']['join_mobile'],
  192. ]);
  193. }
  194. return view('', ['info' => $info]);
  195. }
  196. public function center()
  197. {
  198. $this->_listValidate();
  199. return view();
  200. }
  201. public function describe()
  202. {
  203. return view();
  204. }
  205. public function guide()
  206. {
  207. return view();
  208. }
  209. public function jinjiang()
  210. {
  211. return view();
  212. }
  213. public function renzi()
  214. {
  215. return view();
  216. }
  217. public function arrive()
  218. {
  219. $open_id = session('mobile.human.open_id');
  220. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  221. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  222. $msg = '';
  223. if (empty($institution) && empty($enterprise)) {
  224. $msg = '请先报名';
  225. }
  226. if (!empty($institution)) {
  227. $institution->is_arrive = HumanInstitutionApplyModel::IS_ARRIVE_YES;
  228. $institution->save();
  229. $msg = '签到成功';
  230. }
  231. if (!empty($enterprise)) {
  232. $enterprise->is_arrive = HumanEnterpriseApplyModel::IS_ARRIVE_YES;
  233. $enterprise->save();
  234. $msg = '签到成功';
  235. }
  236. return view('', ['msg' => $msg]);
  237. }
  238. public function bindMobile()
  239. {
  240. $mobile = input('mobile', '');
  241. empty($mobile) && ajax_return(1, '请输入手机号');
  242. $institution = HumanInstitutionApplyModel::where('join_mobile', $mobile)->find();
  243. if (empty($institution)) {
  244. $enterprise = HumanEnterpriseApplyModel::where('join_mobile', $mobile)->find();
  245. if (empty($enterprise)) {
  246. ajax_return(1, '该手机号未报名,请确认手机号');
  247. } else {
  248. $enterprise->open_id = session('mobile.human.open_id');
  249. $enterprise->save();
  250. }
  251. } else {
  252. $institution->open_id = session('mobile.human.open_id');
  253. $institution->save();
  254. }
  255. ajax_return();
  256. }
  257. private function _formValidate()
  258. {
  259. $open_id = session('mobile.human.open_id');
  260. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  261. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  262. if (!empty($institution)) {
  263. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  264. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  265. } else {
  266. throw new \think\exception\HttpResponseException(redirect(url('human/enterpriseList')));
  267. }
  268. }
  269. if (!empty($enterprise)) {
  270. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  271. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  272. } else {
  273. throw new \think\exception\HttpResponseException(redirect(url('human/institutionList')));
  274. }
  275. }
  276. }
  277. private function _listValidate()
  278. {
  279. /*$action = $this->request->action();
  280. if ($action != 'center') {
  281. if (time() < 1730736000) {
  282. jump('11月5日开启,敬请期待','mobile/human/center');
  283. }
  284. }*/
  285. $open_id = session('mobile.human.open_id');
  286. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  287. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  288. if (empty($institution) && empty($enterprise)) {
  289. throw new \think\exception\HttpResponseException(redirect(url('human/index')));
  290. }
  291. if (!empty($institution)) {
  292. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  293. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  294. }
  295. return ['type' => '机构', 'data' => $institution];
  296. }
  297. if (!empty($enterprise)) {
  298. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  299. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  300. }
  301. }
  302. }
  303. }