Human.php 9.1 KB

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