Human.php 9.0 KB

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