|
|
@@ -0,0 +1,110 @@
|
|
|
+<?php
|
|
|
+namespace app\index\controller;
|
|
|
+
|
|
|
+use think\Controller;
|
|
|
+
|
|
|
+class User extends Controller
|
|
|
+{
|
|
|
+ // 用户首页
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $token = input("param.token/s");
|
|
|
+ $res = \app\index\model\Accounts::checktoken($token);
|
|
|
+ if($res == -1){
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+ $user_id = explode('/',base64_decode($token))['2'];
|
|
|
+ $userInfo = db('accounts')->where('id', $user_id)->find();
|
|
|
+ //print_r($userInfo);exit;
|
|
|
+ $this->assign([
|
|
|
+ 'userInfo' => $userInfo
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return $this->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改密码
|
|
|
+ public function uqdatePwd()
|
|
|
+ {
|
|
|
+ $token = input("param.token/s");
|
|
|
+ $res = \app\index\model\Accounts::checktoken($token);
|
|
|
+ if($res == -1){
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+ $user_id = explode('/',base64_decode($token))['2'];
|
|
|
+ $userInfo = db('accounts')->where('id', $user_id)->find();
|
|
|
+
|
|
|
+ if(request()->isPost()){
|
|
|
+ $password = input("param.password/s");
|
|
|
+ $newPassword = input("param.newPassword/s");
|
|
|
+ $confirmPassword = input("param.confirmPassword/s");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($password)){
|
|
|
+ return json(['code' => -1, 'data' => '', 'msg' => '原密码不能为空']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($newPassword)){
|
|
|
+ return json(['code' => -2, 'data' => '', 'msg' => '新密码不能为空']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($confirmPassword)){
|
|
|
+ return json(['code' => -3, 'data' => '', 'msg' => '确认新密码不能为空']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($newPassword != $confirmPassword){
|
|
|
+ return json(['code' => -3, 'data' => '', 'msg' => '新密码不一致']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $userInfo = db('accounts')->where('id', $user_id)->find();
|
|
|
+
|
|
|
+ if(md5($password . session('salt')) != $userInfo['password']){
|
|
|
+ return json(['code' => -3, 'data' => '', 'msg' => '原密码不正确']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $param = [
|
|
|
+ 'password' => md5($newPassword . config('salt'))
|
|
|
+ ];
|
|
|
+
|
|
|
+ db('accounts')->where('id', $user_id)->update($param);
|
|
|
+
|
|
|
+ return json(['code' => 1, 'data' => url('user/index'), 'msg' => '密码修改成功']);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户留言
|
|
|
+ public function LeavingMessage()
|
|
|
+ {
|
|
|
+ $token = input("param.token/s");
|
|
|
+ $res = \app\index\model\Accounts::checktoken($token);
|
|
|
+ if($res == -1){
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(request()->isPost()){
|
|
|
+ $title = input("param.title/s");
|
|
|
+ $content = input("param.content/s");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($title)){
|
|
|
+ return json(['code' => -1, 'data' => '', 'msg' => '标题不能为空']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($content)){
|
|
|
+ return json(['code' => -2, 'data' => '', 'msg' => '内容不能为空']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $param = [
|
|
|
+ 'user_id' => session('user_id'),
|
|
|
+ 'title' => $title,
|
|
|
+ 'content' => $content,
|
|
|
+ 'add_time' => time()
|
|
|
+ ];
|
|
|
+
|
|
|
+ db('accounts_message')->insertGetId($param);
|
|
|
+
|
|
|
+ return json(['code' => 1, 'data' => url('user/index'), 'msg' => '留言成功']);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|