Human.php 8.1 KB

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