Human.php 9.8 KB

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