Human.php 8.8 KB

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