Jonlin 6 éve
szülő
commit
82060286d1

+ 0 - 4
application/admin/controller/Base.php

@@ -7,10 +7,6 @@ class Base extends Controller
 {
     public function _initialize()
     {
-        if(empty(cookie('user_name'))){
-            $this->redirect(url('login/index'));
-        }
-
         $this->assign([
             'version' => config('version'),
             'socket' =>config('socket'),

+ 0 - 4
application/service/controller/Base.php

@@ -7,10 +7,6 @@ class Base extends Controller
 {
     public function _initialize()
     {
-        if(empty(cookie('l_user_name'))){
-
-            $this->redirect(url('login/index'));
-        }
         $this->assign([
             'version' => config('version'),
             'socket' => config('socket')

+ 15 - 3
application/service/controller/Login.php

@@ -35,6 +35,21 @@ class Login extends Controller
             cookie('l_user_id', $user['id'], config('save_time'));
             cookie('l_user_avatar', $user['user_avatar'], config('save_time'));
 
+            // 登陆成功 生成token
+            $module = mt_rand(100000,999999);
+            $token = base64_encode($module.'#$@%!^*/'.time().'/'.$user['id']);
+            // 更新管理员状态
+            $param = [
+                'token' => $token,
+                'expire_time' => time()
+            ];
+            db('users')->where('id', $user['id'])->update($param);
+
+            $this->assign([
+                'token' => $token,
+                'user_name' => $userName
+            ]);
+
             return json(['code' => 1, 'data' => url('index/index'), 'msg' => '登录成功']);
         }
 
@@ -43,9 +58,6 @@ class Login extends Controller
 
     public function loginOut()
     {
-        cookie('l_user_name', null);
-        cookie('l_user_id', null);
-        cookie('l_user_avatar', null);
 
         $this->redirect(url('login/index'));
     }

+ 101 - 0
application/service/controller/Message.php

@@ -0,0 +1,101 @@
+<?php
+namespace app\service\controller;
+
+class Message extends Base
+{
+    public function index()
+    {
+        // 留言信息
+        $message = db('accountsmessage')->join('accounts','accounts.id=ws_accountsmessage.account_id')->where('message_status', 0)->select();
+        //print_r($message);
+        $this->assign([
+            'message' => $message,
+        ]);
+
+        return $this->fetch();
+    }
+
+    // 处理留言
+    public function dealmessage()
+    {
+        if(request()->isPost()){
+
+            //客服id
+            $user_id = input('post.user_id');
+            //留言id
+            $message_id = input('post.message_id');
+
+            $user = db('users')->where('id', $user_id)->find();
+            if(empty($user)){
+                return json(['code' => -1, 'data' => '', 'msg' => '客服不存在']);
+            }
+            $message = db('accountsmessage')->where('message_id', $message_id)->find();
+            if(empty($message)){
+                return json(['code' => -1, 'data' => '', 'msg' => '留言不存在']);
+            }
+
+            // 更新留言状态
+            $param = [
+                'user_id' => $user_id,
+                'dealWith_time' => time()
+            ];
+            db('accountsmessage')->where('message_id', $message_id)->update($param);
+
+            return json(['code' => 1, 'data' => url('message/index'), 'msg' => '登录成功']);
+        }
+    }
+
+    // 获取聊天记录
+    public function getChatLog()
+    {
+        if(request()->isAjax()){
+
+            $param = input('param.');
+
+            $limit = 10; // 一次显示10 条聊天记录
+            $offset = ($param['page'] - 1) * $limit;
+
+            $logs = db('chat_log')->where(function($query) use($param){
+                $query->where('from_id', $param['uid'])->where('to_id', 'KF' . cookie('l_user_id'));
+            })->whereOr(function($query) use($param){
+                $query->where('from_id', 'KF' . cookie('l_user_id'))->where('to_id', $param['uid']);
+            })->limit($offset, $limit)->order('id', 'desc')->select();
+
+            $total =  db('chat_log')->where(function($query) use($param){
+                $query->where('from_id', $param['uid'])->where('to_id', 'KF' . cookie('l_user_id'));
+            })->whereOr(function($query) use($param){
+                $query->where('from_id', 'KF' . cookie('l_user_id'))->where('to_id', $param['uid']);
+            })->count();
+
+            foreach($logs as $key=>$vo){
+
+                $logs[$key]['type'] = 'user';
+                $logs[$key]['time_line'] = date('Y-m-d H:i:s', $vo['time_line']);
+
+                if($vo['from_id'] == 'KF' . cookie('l_user_id')){
+                    $logs[$key]['type'] = 'mine';
+                }
+            }
+
+            return json(['code' => 1, 'data' => $logs, 'msg' => intval($param['page']), 'total' => ceil($total / $limit)]);
+        }
+    }
+
+    // ip 定位
+    public function getCity()
+    {
+        $ip = input('param.ip');
+
+        $ip2region = new \Ip2Region();
+        $info = $ip2region->btreeSearch($ip);
+
+        $city = explode('|', $info['region']);
+
+        if(0 != $info['city_id']){
+            return json(['code' => 1, 'data' => $city['2'] . $city['3'] . $city['4'], 'msg' => 'ok']);
+        }else{
+
+            return json(['code' => 1, 'data' => $city['0'], 'msg' => 'ok']);
+        }
+    }
+}