User.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace app\api\controller\h5;
  3. use app\api\services\UserServices;
  4. use app\api\validate\UserValidate;
  5. use app\common\model\SystemArticleModel;
  6. use app\Request;
  7. use think\Exception;
  8. use think\exception\ValidateException;
  9. use think\facade\Db;
  10. use think\facade\View;
  11. class User
  12. {
  13. protected $service = null;
  14. public function __construct (UserServices $services)
  15. {
  16. $this->service = $services;
  17. }
  18. // 隐私政策
  19. public function privateInfo (Request $request)
  20. {
  21. $id = $request->param('id/d', '');
  22. $m_article = new SystemArticleModel();
  23. $row = $m_article->where(['type' => 3])->findOrEmpty();
  24. empty($row) && abort(403, '页面异常');
  25. View::assign('row', $row);
  26. return View::fetch();
  27. }
  28. // 用户协议
  29. public function userAgreementInfo (Request $request)
  30. {
  31. $id = $request->param('id/d', '');
  32. $m_article = new SystemArticleModel();
  33. $row = $m_article->where(['type' => 4])->findOrEmpty();
  34. empty($row) && abort(403, '页面异常');
  35. View::assign('row', $row);
  36. return View::fetch();
  37. }
  38. // 帮助中心
  39. public function helpCenter ()
  40. {
  41. $list = Db::name('system_faq')->where('status', 1)->select()->toArray();
  42. $list = array_column($list, null, 'id');
  43. $tree = array();
  44. foreach ($list as $key => $row) {
  45. $pid = $row['parent_id'];
  46. if ($pid == 0) {
  47. $tree[] =& $list[$key];
  48. } else if (isset($list[$pid])) {
  49. $parent =& $list[$pid];
  50. $parent['son'][] =& $list[$key];
  51. }
  52. }
  53. View::assign('list', $tree);
  54. return View::fetch();
  55. }
  56. /**
  57. * 帮助中心详情
  58. * @param Request $request
  59. * @return string
  60. */
  61. public function helpDetails (Request $request)
  62. {
  63. $id = $request->param('id', 0, 'intval'); // 详情id
  64. !$id && abort(403, '页面异常');
  65. try {
  66. $info = Db::name('system_faq')->where('id', $id)->where('status', 1)->find();
  67. View::assign('info', $info);
  68. } catch (\Exception $e) {
  69. abort(403, '页面异常');
  70. }
  71. return View::fetch();
  72. }
  73. // 关于我们
  74. public function aboutUs (Request $request)
  75. {
  76. $id = $request->param('id/d', '');
  77. $m_article = new SystemArticleModel();
  78. $row = $m_article->where(['type' => 5])->findOrEmpty();
  79. empty($row) && abort(403, '页面异常');
  80. View::assign('row', $row);
  81. return View::fetch();
  82. }
  83. /**
  84. * h5注册
  85. * @param Request $request
  86. * @return string
  87. */
  88. public function registerH5 (Request $request)
  89. {
  90. if ($request->isPost()) {
  91. $data = $request->post();
  92. try {
  93. validate(UserValidate::class)
  94. ->scene('register')
  95. ->check($data);
  96. $userserivce = new UserServices();
  97. if (!vertifyPass($data['password'])){
  98. throw new Exception('密码必须包含字母和数字,长度大于8位');
  99. }
  100. $param = [
  101. 'invite_code'=>$data['invite_code'],
  102. 'code'=>$data['code'],
  103. 'mobile'=>$data['mobile'],
  104. 'password'=>$data['password'],
  105. 'req_type'=>'h5web',
  106. 'user_name'=>$data['user_name']
  107. ];
  108. $userserivce->userRegister($param);
  109. return api_succ_return('注册成功');
  110. } catch (ValidateException $e) {
  111. return api_error_return($e->getMessage());
  112. } catch (\Exception $e) {
  113. return api_error_return($e->getMessage());
  114. }
  115. }
  116. $code = $request->param('code');
  117. if ($code) {
  118. !$code && abort(40003, '页面错误');
  119. $is_px = false;
  120. $invite = Db::name('user')->where('code', $code)->field('code,id')->find();
  121. if (!$invite){
  122. $invite = Db::name('user')->where('px_code', $code)->field('px_code,id')->find();
  123. $is_px = true;
  124. }
  125. if (!$invite){
  126. return '邀请码错误,还请核实';
  127. }
  128. if ($is_px){
  129. $code = $invite['px_code'];
  130. }else{
  131. $code = $invite['code'];
  132. }
  133. }
  134. View::assign([
  135. 'code' => $code,
  136. 'appkey' => env('aliyun.verify_appkey'),
  137. 'scene' => env('aliyun.verify_scene'),
  138. 'downappurl' => getWebUrl().'/api/downapp',
  139. 'info'=>[
  140. 'name'=>env('app.name')
  141. ]
  142. ]);
  143. return View::fetch();
  144. }
  145. /**
  146. * 人机验证
  147. * @return string
  148. */
  149. public function loginVerify ()
  150. {
  151. View::assign('appkey', env('aliyun.verify_appkey'));
  152. View::assign('scene', env('aliyun.verify_scene'));
  153. View::assign('view', input('view', ''));
  154. return View::fetch();
  155. }
  156. /**
  157. * 新手教程
  158. * @return string
  159. */
  160. public function newhandurl(Request $request){
  161. $m_article = new SystemArticleModel();
  162. $row = $m_article->where(['type' => 5])->findOrEmpty();
  163. empty($row) && abort(403, '页面异常');
  164. View::assign('row', $row);
  165. return View::fetch();
  166. }
  167. /**
  168. * 新手指引
  169. * @return string
  170. */
  171. public function newguideurl(Request $request){
  172. $m_article = new SystemArticleModel();
  173. $row = $m_article->where(['type' => 6])->findOrEmpty();
  174. empty($row) && abort(403, '页面异常');
  175. View::assign('row', $row);
  176. return View::fetch();
  177. }
  178. /**
  179. * 关于福袋
  180. * @return string
  181. */
  182. public function aboutboxurl(Request $request){
  183. $m_article = new SystemArticleModel();
  184. $row = $m_article->where(['type' => 7])->findOrEmpty();
  185. empty($row) && abort(403, '页面异常');
  186. View::assign('row', $row);
  187. return View::fetch();
  188. }
  189. }