Human.php 6.5 KB

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