Human.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. $response = redirect('https://www.jucai.gov.cn/api/auth/wechat_auth?url=' . urlencode(url('/mobile/login/humanLogin')));
  18. throw new \think\exception\HttpResponseException($response);
  19. }
  20. }
  21. /**
  22. * 表单
  23. */
  24. public function index()
  25. {
  26. $this->_formValidate();
  27. return view();
  28. }
  29. public function institutionForm()
  30. {
  31. $this->_formValidate();
  32. return view();
  33. }
  34. public function institutionFormPost()
  35. {
  36. $data = input('post.');
  37. try {
  38. validate(HumanInstitutionApplyValidate::class)->check($data);
  39. } catch (ValidateException $e) {
  40. ajax_return(1, $e->getError());
  41. }
  42. $data['open_id'] = session('mobile.human.open_id');
  43. HumanInstitutionApplyModel::create($data);
  44. ajax_return();
  45. }
  46. public function enterpriseForm()
  47. {
  48. return view('', [
  49. 'cooperate_list' => json_encode(HumanInstitutionModel::COOPERATE),
  50. ]);
  51. }
  52. public function enterpriseFormPost()
  53. {
  54. $data = input('post.');
  55. try {
  56. validate(HumanEnterpriseApplyValidate::class)->check($data);
  57. } catch (ValidateException $e) {
  58. ajax_return(1, $e->getError());
  59. }
  60. $data['open_id'] = session('mobile.human.open_id');
  61. HumanEnterpriseApplyModel::create($data);
  62. ajax_return();
  63. }
  64. public function tips()
  65. {
  66. $open_id = session('mobile.human.open_id');
  67. $msg = '';
  68. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  69. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  70. if (empty($institution) && empty($enterprise)) {
  71. return redirect(url('human/index'));
  72. }
  73. if (!empty($institution)) {
  74. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  75. $msg = HumanInstitutionApplyModel::STATUS[$institution['status']];
  76. } else {
  77. return redirect(url('human/enterpriseList'));
  78. }
  79. }
  80. if (!empty($enterprise)) {
  81. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  82. $msg = HumanEnterpriseApplyModel::STATUS[$institution['status']];
  83. } else {
  84. return redirect(url('human/institutionList'));
  85. }
  86. }
  87. return view('', ['msg' => $msg]);
  88. }
  89. /**
  90. * 列表
  91. */
  92. public function institutionList()
  93. {
  94. $this->_listValidate();
  95. $cooperate_list = [['text' => '业务范围', 'value' => '']];
  96. foreach (HumanInstitutionModel::COOPERATE as $cooperate) {
  97. $cooperate_list[] = ['text' => $cooperate, 'value' => $cooperate];
  98. }
  99. return view('', [
  100. 'cooperate_list' => json_encode($cooperate_list),
  101. ]);
  102. }
  103. public function listInstitution()
  104. {
  105. $where = $this->dealLikeInput(['name', 'cooperate']);
  106. $where[] = ['status', '=', HumanInstitutionModel::STATUS_SHOW];
  107. $list = HumanInstitutionModel::where($where)
  108. ->order(['priority' => 'desc'])
  109. ->limit(input('limit', 10))
  110. ->page(input('page', 1))
  111. ->select();
  112. ajax_success($list);
  113. }
  114. public function institutionDetail()
  115. {
  116. $this->_listValidate();
  117. $id = input('id');
  118. empty($id) && jump('该机构不存在或已删除');
  119. $info = HumanInstitutionModel::find($id);
  120. empty($info) && jump('该机构不存在或已删除');
  121. return view('', ['info' => $info]);
  122. }
  123. public function enterpriseList()
  124. {
  125. $this->_listValidate();
  126. return view();
  127. }
  128. public function listEnterprise()
  129. {
  130. $where = $this->dealLikeInput(['name']);
  131. $where[] = ['status', '=', HumanEnterpriseModel::STATUS_SHOW];
  132. $list = HumanEnterpriseModel::where($where)
  133. ->order(['priority' => 'desc'])
  134. ->limit(input('limit', 10))
  135. ->page(input('page', 1))
  136. ->select();
  137. ajax_success($list);
  138. }
  139. public function enterpriseDetail()
  140. {
  141. $this->_listValidate();
  142. $id = input('id');
  143. empty($id) && jump('该企业不存在或已删除');
  144. $info = HumanEnterpriseModel::find($id);
  145. empty($info) && jump('该企业不存在或已删除');
  146. return view('', ['info' => $info]);
  147. }
  148. public function center()
  149. {
  150. $this->_listValidate();
  151. return view();
  152. }
  153. public function describe()
  154. {
  155. return view();
  156. }
  157. public function guide()
  158. {
  159. $this->_listValidate();
  160. return view();
  161. }
  162. public function jinjiang()
  163. {
  164. return view();
  165. }
  166. private function _formValidate()
  167. {
  168. $open_id = session('mobile.human.open_id');
  169. $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();
  170. $enterprise = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();
  171. if (!empty($institution)) {
  172. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  173. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  174. } else {
  175. throw new \think\exception\HttpResponseException(redirect(url('human/enterpriseList')));
  176. }
  177. }
  178. if (!empty($enterprise)) {
  179. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  180. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  181. } else {
  182. throw new \think\exception\HttpResponseException(redirect(url('human/institutionList')));
  183. }
  184. }
  185. }
  186. private function _listValidate()
  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. if (empty($institution) && empty($enterprise)) {
  192. throw new \think\exception\HttpResponseException(redirect(url('human/index')));
  193. }
  194. if (!empty($institution)) {
  195. if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {
  196. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  197. }
  198. }
  199. if (!empty($enterprise)) {
  200. if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {
  201. throw new \think\exception\HttpResponseException(redirect(url('human/tips')));
  202. }
  203. }
  204. }
  205. }