Human.php 10 KB

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