My.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. namespace app\mobile\controller;
  3. use app\common\model\FeedbackModel;
  4. use app\common\model\NoticeModel;
  5. use app\common\model\UserModel;
  6. use app\mobile\MobileBaseController;
  7. use app\mobile\validate\UserValidate;
  8. use think\App;
  9. use think\exception\ValidateException;
  10. use think\facade\View;
  11. class My extends MobileBaseController
  12. {
  13. private $_user = null;
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. $this->_user = get_user();
  18. View::assign('user', $this->_user);
  19. }
  20. public function index()
  21. {
  22. return view();
  23. }
  24. public function info()
  25. {
  26. return view();
  27. }
  28. public function infoPost()
  29. {
  30. $data = input('post.');
  31. $edit = ['avatar', 'nickname', 'gender', 'birthday'];
  32. try {
  33. validate(UserValidate::class)->check($data);
  34. } catch (ValidateException $e) {
  35. ajax_return(1, $e->getError());
  36. }
  37. //账号验证
  38. if (empty($this->_user['account'])) {
  39. empty($data['account']) && ajax_return(1, '请填写账号');
  40. $check = UserModel::where('account', $data['account'])->find();
  41. if (!empty($check)) {
  42. ajax_return(1, '该账号已存在');
  43. }
  44. $edit[] = 'account';
  45. }
  46. foreach ($edit as $v) {
  47. $this->_user->$v = $data[$v];
  48. }
  49. $this->_user->save();
  50. ajax_return();
  51. }
  52. public function password()
  53. {
  54. return view();
  55. }
  56. public function passwordPost()
  57. {
  58. $new_password = input('post.new_password');
  59. $renew_password = input('post.renew_password');
  60. if ($new_password != $renew_password) {
  61. ajax_return(1, '两次密码不一致');
  62. }
  63. if (preg_match("/^(?![^a-zA-Z]+$)(?!\D+$).{6,}$/", $new_password) === false) {
  64. ajax_return(1, '密码必须大于6位,且包括字母和数字');
  65. }
  66. if (!empty($this->_user['password'])) {
  67. $old_password = input('post.old_password');
  68. if (md5(md5($this->_user->salt) . $new_password) != $old_password) {
  69. ajax_return(1, '旧密码错误');
  70. }
  71. }
  72. $this->_user->salt = rand_str();
  73. $this->_user->password = md5(md5($this->_user->salt) . $new_password);
  74. $this->_user->save();
  75. ajax_return();
  76. }
  77. public function mobile()
  78. {
  79. return view();
  80. }
  81. public function mobilePost()
  82. {
  83. $param = input('post.');
  84. empty($param['mobile']) && ajax_return(1, '请输入手机号');
  85. empty($param['verify']) && ajax_return(1, '请输入验证码');
  86. //验证码校验
  87. if (config('mobile.sms_verify_expire') > 0) {
  88. $verify_expire = session('mobile.login.verify_expire');
  89. if ($verify_expire + config('mobile.sms_verify_expire') < time()) {
  90. session('mobile.login.verify', null);
  91. session('mobile.login.verify_expire', null);
  92. ajax_return(1, '验证码已过期');
  93. }
  94. }
  95. $verify = session('mobile.login.verify');
  96. if ($verify != $param['verify']) {
  97. ajax_return(1, '验证码不正确');
  98. }
  99. $check = UserModel::where('mobile', $param['mobile'])->find();
  100. if (!empty($check)) {
  101. ajax_return(1, '该手机号已绑定');
  102. }
  103. $this->_user->mobile = $param['mobile'];
  104. $this->_user->save();
  105. ajax_return();
  106. }
  107. public function auth()
  108. {
  109. return view();
  110. }
  111. public function authPost()
  112. {
  113. if (!in_array($this->_user['is_auth'], [UserModel::AUTH_UN, UserModel::AUTH_REJECT])) {
  114. ajax_return(1, '当前状态无法提交');
  115. }
  116. $data = [];
  117. foreach (UserModel::MOBILE_EDIT_ALLOW as $v) {
  118. $data[$v] = input("post.{$v}");
  119. }
  120. try {
  121. validate([
  122. 'realname' => 'require',
  123. 'idcard' => 'require|idCard',
  124. 'idcard_front_pic' => 'require',
  125. 'idcard_back_pic' => 'require',
  126. ], [
  127. 'realname' => '请填写真实姓名',
  128. 'idcard' => '身份证格式错误',
  129. 'idcard_front_pic' => '请上传身份证(头像页)',
  130. 'idcard_back_pic' => '请上传身份证(国徽页)',
  131. ])->check($data);
  132. } catch (ValidateException $e) {
  133. ajax_return(1, $e->getError());
  134. }
  135. $data['is_auth'] = UserModel::AUTH_WAIT;
  136. UserModel::update($data, ['id' => $this->_user['id']], UserModel::MOBILE_EDIT_ALLOW);
  137. ajax_return();
  138. }
  139. public function about()
  140. {
  141. return view();
  142. }
  143. public function notice()
  144. {
  145. return view();
  146. }
  147. public function listNotice()
  148. {
  149. $list = NoticeModel::where('status', NoticeModel::STATUS_PUBLISH)
  150. ->order(['priority' => 'desc', 'update_time' => 'desc'])
  151. ->limit(input('limit', 10))
  152. ->page(input('page', 1))
  153. ->select();
  154. ajax_success($list);
  155. }
  156. public function noticeDetail()
  157. {
  158. $id = input('id/d', 0);
  159. empty($id) && jump('该消息不存在');
  160. $info = NoticeModel::where('status', NoticeModel::STATUS_PUBLISH)->find($id);
  161. empty($info) && jump('该消息不存在');
  162. return view('', [
  163. 'info' => $info,
  164. ]);
  165. }
  166. public function feedback()
  167. {
  168. return view();
  169. }
  170. public function feedbackPost()
  171. {
  172. $param = input('param.');
  173. $param['user_id'] = $this->_user['id'];
  174. FeedbackModel::create($param);
  175. ajax_return();
  176. }
  177. }