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']); } } }