User.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. // $info['content'] = imageSrcReplace($info['content']);
  68. View::assign('info', $info);
  69. } catch (\Exception $e) {
  70. abort(403, '页面异常');
  71. }
  72. return View::fetch();
  73. }
  74. // 关于我们
  75. public function aboutUs (Request $request)
  76. {
  77. $id = $request->param('id/d', '');
  78. $m_article = new SystemArticleModel();
  79. $row = $m_article->where(['type' => 5])->findOrEmpty();
  80. empty($row) && abort(403, '页面异常');
  81. View::assign('row', $row);
  82. return View::fetch();
  83. }
  84. /**
  85. * h5注册
  86. * @param Request $request
  87. * @return string
  88. */
  89. public function registerH5 (Request $request)
  90. {
  91. if ($request->isPost()) {
  92. $data = $request->post();
  93. try {
  94. validate(UserValidate::class)
  95. ->scene('register')
  96. ->check($data);
  97. $userserivce = new UserServices();
  98. if (!vertifyPass($data['password'])){
  99. throw new Exception('密码必须包含字母和数字,长度大于8位');
  100. }
  101. $param = [
  102. 'invite_code'=>$data['invite_code'],
  103. 'code'=>$data['code'],
  104. 'mobile'=>$data['mobile'],
  105. 'password'=>$data['password'],
  106. 'req_type'=>'h5web',
  107. 'user_name'=>$data['user_name']
  108. ];
  109. $userserivce->userRegister($param);
  110. return api_succ_return('注册成功');
  111. // return api_succ_return(['msg'=>'注册成功','code'=>0]);
  112. } catch (ValidateException $e) {
  113. return api_error_return($e->getMessage());
  114. } catch (\Exception $e) {
  115. return api_error_return($e->getMessage());
  116. }
  117. }
  118. $code = $request->param('code');
  119. if ($code) {
  120. !$code && abort(40003, '页面错误');
  121. $is_px = false;
  122. $invite = Db::name('user')->where('code', $code)->field('code,id')->find();
  123. if (!$invite){
  124. $invite = Db::name('user')->where('px_code', $code)->field('px_code,id')->find();
  125. $is_px = true;
  126. }
  127. if (!$invite){
  128. return '邀请码错误,还请核实';
  129. }
  130. if ($is_px){
  131. $code = $invite['px_code'];
  132. }else{
  133. $code = $invite['code'];
  134. }
  135. }
  136. View::assign([
  137. 'code' => $code,
  138. 'appkey' => env('aliyun.verify_appkey'),
  139. 'scene' => env('aliyun.verify_scene'),
  140. 'downappurl' => getWebUrl().'/api/downapp',
  141. 'info'=>[
  142. 'name'=>env('app.name')
  143. ]
  144. ]);
  145. return View::fetch();
  146. }
  147. /**
  148. * 人机验证
  149. * @return string
  150. */
  151. public function loginVerify ()
  152. {
  153. View::assign('appkey', env('aliyun.verify_appkey'));
  154. View::assign('scene', env('aliyun.verify_scene'));
  155. View::assign('view', input('view', ''));
  156. return View::fetch();
  157. }
  158. /**
  159. * 新手教程
  160. * @return string
  161. */
  162. public function newhandurl(Request $request){
  163. $m_article = new SystemArticleModel();
  164. $row = $m_article->where(['type' => 5])->findOrEmpty();
  165. empty($row) && abort(403, '页面异常');
  166. View::assign('row', $row);
  167. return View::fetch();
  168. }
  169. /**
  170. * 新手指引
  171. * @return string
  172. */
  173. public function newguideurl(Request $request){
  174. // $id = $request->param('id/d', '');
  175. $m_article = new SystemArticleModel();
  176. $row = $m_article->where(['type' => 6])->findOrEmpty();
  177. empty($row) && abort(403, '页面异常');
  178. View::assign('row', $row);
  179. return View::fetch();
  180. }
  181. /**
  182. * 关于福袋
  183. * @return string
  184. */
  185. public function aboutboxurl(Request $request){
  186. $m_article = new SystemArticleModel();
  187. $row = $m_article->where(['type' => 7])->findOrEmpty();
  188. empty($row) && abort(403, '页面异常');
  189. View::assign('row', $row);
  190. return View::fetch();
  191. }
  192. }