Jonlin %!s(int64=6) %!d(string=hai) anos
pai
achega
31008ab156

+ 9 - 2
application/admin/controller/Index.php

@@ -81,6 +81,13 @@ class Index extends Base
     // 修改管理员密码
     public function changePassword()
     {
+        $token = input("param.token/s");
+        $res = model('Admins')->checktoken($token);
+        if($res == -1){
+            return $res;
+        }
+        $user_id = $res;
+
         if(request()->isPost()){
 
             $param = input('post.');
@@ -96,7 +103,7 @@ class Index extends Base
 
             if(!empty($param['old_pwd']) && !empty($param['password'])){
 
-                $userPwd = db('admins')->where('id', cookie('user_id'))->find();
+                $userPwd = db('admins')->where('id', $user_id)->find();
                 if(empty($userPwd)){
                     return json(['code' => -4, 'data' => '', 'msg' => '管理员不存在']);
                 }
@@ -109,7 +116,7 @@ class Index extends Base
                 $reLogin = true;
             }
 
-            db('admins')->where('id', cookie('user_id'))->setField('password', $info['password']);
+            db('admins')->where('id', $user_id)->setField('password', $info['password']);
 
             return json(['code' => 1, 'data' => $reLogin, 'msg' => '修改信息成功']);
         }

+ 9 - 5
application/admin/controller/Messages.php

@@ -21,11 +21,13 @@ class Messages extends Base
             if (empty($param['searchText']) === false) {
                 $where['user_name'] = $param['searchText'];
             }
-
             $join   = [
-                'accounts b'      => 'a.user_id = b.id',
+                'accounts b'      => 'a.account_id = b.id',
+            ];
+            $leftjoin   = [
+                'users c'      => 'a.user_id = c.id',
             ];
-            $result = model('Accountsmessage')->selectJoin($join,$where, $offset, $limit);
+            $result = model('Accountsmessage')->selectJoin($join,$leftjoin,$where, $offset, $limit);
             foreach($result as $key=>$vo){
                 // 优化显示附件
                 $result[$key]['image'] = '<img src="' . $vo['image'] . '" width="40px" height="40px">';
@@ -65,9 +67,11 @@ class Messages extends Base
 
         $id = input('param.id/d');
         $info = db('Accountsmessage')->where('message_id', $id)->find();
-        $user = db('Accounts')->where('id', $info['user_id'])->find();
+        $account = db('Accounts')->where('id', $info['account_id'])->find();
+        $user = db('Users')->where('id', $info['user_id'])->find();
+        $info['account_name'] = $account['account_name'];
+        $info['account_email'] = $account['account_email'];
         $info['user_name'] = $user['user_name'];
-        $info['user_email'] = $user['user_email'];
 
         // 优化时间
         if(null != $info['add_time']){

+ 7 - 1
application/admin/model/Accountsmessage.php

@@ -18,7 +18,7 @@ class Accountsmessage extends Model
      * @param mixed $order 排序
      * @return array 返回类型
      */
-    public function selectJoin($join, $where=[], $offset='', $limit='', $order=['a.message_id'=>'desc'])
+    public function selectJoin($join,$leftjoin, $where=[], $offset='', $limit='', $order=['a.message_id'=>'desc'])
     {
         $result = $this;
         if (empty($join) === false) {
@@ -28,6 +28,12 @@ class Accountsmessage extends Model
             }
         }
 
+        if (empty($leftjoin) === false) {
+            foreach ($leftjoin as $k => $v) {
+                $result = $result->join('users c', 'a.user_id = c.id','LEFT');
+            }
+        }
+
         if (empty($where) === false) {
             $result = $result->where($where);
         }

+ 2 - 1
application/admin/model/Admins.php

@@ -13,7 +13,8 @@ class Admins extends Model
             $time = time()-$user['expire_time'];
             if($time<3600){
                 db('admins')->where('id', $user['id'])->update(['expire_time' => time()]);
-                return 1;
+                $user_id = explode('/',base64_decode($token))['2'];
+                return $user_id;
             }else{
                 return -1;
             }

+ 3 - 3
application/admin/view/messages/detail.html

@@ -25,7 +25,7 @@
                         <div class="form-group">
                             <label class="col-sm-3 control-label">用户名称:</label>
                             <div class="input-group col-sm-4">
-                                <input id="user_name" type="text" class="form-control" name="user_name" required="" aria-required="true" value="{$info['user_name']}">
+                                <input id="account_name" type="text" class="form-control" name="Account_name" required="" aria-required="true" value="{$info['account_name']}">
                             </div>
                         </div>
                         <div class="form-group">
@@ -57,7 +57,7 @@
                         <div class="form-group">
                             <label class="col-sm-3 control-label">邮箱:</label>
                             <div class="input-group col-sm-4">
-                                <input id="user_email" type="text" class="form-control" name="user_pwd" value="{$info['user_email']}">
+                                <input id="account_email" type="text" class="form-control" name="account_email" value="{$info['account_email']}">
                             </div>
                         </div>
                         <div class="form-group">
@@ -69,7 +69,7 @@
                         <div class="form-group">
                             <label class="col-sm-3 control-label">处理人:</label>
                             <div class="input-group col-sm-4">
-                                <input id="kefu_name" type="text" class="form-control" name="user_pwd" value="{$info['kefu_name']}">
+                                <input id="user_name" type="text" class="form-control" name="user_pwd" value="{$info['user_name']}">
                             </div>
                         </div>
                         <div class="form-group">

+ 3 - 3
application/admin/view/messages/index.html

@@ -37,14 +37,14 @@
                 <div class="example">
                     <table id="cusTable">
                         <thead>
-                        <th class="user_name" id="user_name" data-field="user_name">用户名称</th>
+                        <th class="user_name" id="user_name" data-field="account_name">用户名称</th>
                         <th class="add_time" id="add_time" data-field="add_time">留言时间</th>
                         <th data-field="content">内容</th>
                         <th data-field="image">附件</th>
                         <th data-field="phone">手机</th>
-                        <th data-field="user_email">邮箱</th>
+                        <th data-field="account_email">邮箱</th>
                         <th data-field="status">当前状态</th>
-                        <th data-field="kefu_name">处理人</th>
+                        <th data-field="user_name">处理人</th>
                         <th data-field="dealWith_time">处理时间</th>
                         <th data-field="operate">操作</th>
                         </thead>

+ 2 - 2
application/index/controller/Login.php

@@ -37,8 +37,8 @@ class Login extends Controller
                 return json(['code' => -2, 'data' => '', 'msg' => '密码不能为空']);
             }
 
-            $user_name = db('accounts')->where('user_name', $userName)->find();
-            $user_email = db('accounts')->where('user_name', $userName)->find();
+            $user_name = db('accounts')->where('account_name', $userName)->find();
+            $user_email = db('accounts')->where('account_email', $userName)->find();
 
             if(empty($user_name) && empty($user_email)){
                 return json(['code' => -3, 'data' => '', 'msg' => '用户名或邮箱不存在']);

+ 4 - 4
application/index/controller/Register.php

@@ -50,20 +50,20 @@ class Register extends Controller
                 return json(['code' => -5, 'data' => '', 'msg' => '验证码不正确']);
             }
 
-            $name = db('accounts')->where('user_name', $userName)->find();
+            $name = db('accounts')->where('account_name', $userName)->find();
             if(!empty($name)){
                 return json(['code' => -6, 'data' => '', 'msg' => '用户名已存在']);
             }
 
-            $email = db('accounts')->where('user_email', $userEmail)->find();
+            $email = db('accounts')->where('account_email', $userEmail)->find();
             if(!empty($email)){
                 return json(['code' => -7, 'data' => '', 'msg' => '邮箱已存在']);
             }
 
             // 添加用户信息
             $userInfo = [
-                'user_name' => $userName,
-                'user_email' => $userEmail,
+                'account_name' => $userName,
+                'account_email' => $userEmail,
                 'password' => md5($password . config('salt')),
                 'status' => 1,
                 'add_time' => time(),

+ 49 - 17
application/index/controller/User.php

@@ -84,27 +84,59 @@ class User extends Controller
         if(request()->isPost()){
             $content = input("param.content/s");
             $phone = input("param.phone/s");
-        }
-
-        if(empty($content)){
-            return json(['code' => -1, 'data' => '', 'msg' => '内容不能为空']);
-        }
 
-        if(empty($phone)){
-            return json(['code' => -2, 'data' => '', 'msg' => '电话不能为空']);
+            $file = request()->file('file');
+
+            if(empty($content)){
+                return json(['code' => -1, 'data' => '', 'msg' => '内容不能为空']);
+            }
+
+            if(empty($phone)){
+                return json(['code' => -2, 'data' => '', 'msg' => '电话不能为空']);
+            }
+
+            if(empty($file)){
+                return json(['code' => -3, 'data' => '', 'msg' => '附件不能为空']);
+            }
+            $fileInfo = $file->getInfo();
+            /*if($fileInfo['size'] > 1024 * 1024 * 2){
+                // 上传失败获取错误信息
+                return json( ['code' => -2, 'data' => '', 'msg' => '文件超过2M'] );
+            }*/
+
+            //检测图片格式
+            $ext = explode('.', $fileInfo['name']);
+            $ext = array_pop($ext);
+
+            $extArr = explode('|', 'jpg|png|gif|jpeg');
+            if(!in_array($ext, $extArr)){
+                return json(['code' => -3, 'data' => '', 'msg' => '只能上传jpg|png|gif|jpeg的文件']);
+            }
+
+            // 移动到框架应用根目录/public/uploads/ 目录下
+            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
+            if($info){
+                $src =  '/uploads' . '/' . date('Ymd') . '/' . $info->getFilename();
+            }else{
+                // 上传失败获取错误信息
+                return json(['code' => -1, 'data' => '', 'msg' => $file->getError()]);
+            }
+
+            $param = [
+                'account_id' => $user_id,
+                'content' => $content,
+                'image' => $src,
+                'phone' => $phone,
+                'message_status' => 0,
+                'add_time' => time()
+            ];
+
+            db('accountsmessage')->insertGetId($param);
+
+            return json(['code' => 1, 'data' => url('user/index'), 'msg' => '留言成功']);
         }
 
-        $param = [
-            'user_id' => $user_id,
-            'content' => $content,
-            'phone' => $phone,
-            'message_status' => 0,
-            'add_time' => time()
-        ];
-
-        db('accountsmessage')->insertGetId($param);
 
-        return json(['code' => 1, 'data' => url('user/index'), 'msg' => '留言成功']);
 
     }