1
0
mirror of https://gitee.com/zhc02/timely_service.git synced 2025-06-24 12:05:30 +08:00
This commit is contained in:
白鹄 2019-12-16 23:50:02 +08:00
parent ff562362a2
commit 282988bcdd
4 changed files with 194 additions and 13 deletions

View File

@ -10,7 +10,9 @@ namespace Logic;
use think\Db;
use think\Exception;
use exception\ResponsableException;
use exception\LogicException;
class ChatLogLogic
{
public static function addChatLog($data){
@ -31,4 +33,47 @@ class ChatLogLogic
'create_time'=>date('Y-m-d H:i:s')
]);
}
/**
* 分页获聊天记录
* @param $param
* @return boolean
*/
public static function getChatLogList($vid='',$kefu_name='',$limit = 20)
{
try {
if($vid and $kefu_name =='' ){
$map1 = [
['from_id', '=',$vid],
];
$map2 = [
['to_id', '=', $vid],
];
}else if($vid and $kefu_name){
$map1 = [
['from_id', '=',$vid],
['to_name', '=',$kefu_name],
];
$map2 = [
['from_name', '=', $kefu_name],
['to_id', '=', $vid],
];
}else if($vid =='' and $kefu_name){
$map1 = [
['from_name', '=',$kefu_name],
];
$map2 = [
['to_name', '=', $kefu_name],
];
}else {
$map1=['log_id','>',0];
$map2=['log_id','>',0];
}
$list = Db::name('chat_log')->whereOr([$map1,$map2])->order('log_id desc')->paginate($limit);
return $list;
} catch (Exception $e) {
throw new ResponsableException($e->getMessage(), 404);
}
}
}

View File

@ -13,6 +13,7 @@ use think\Db;
use think\facade\Log;
use exception\ResponsableException;
use think\Exception;
use exception\BaseException;
class KefuLogic
{
/**
@ -33,7 +34,122 @@ class KefuLogic
}
}
/**
* 添加客服
* @param $param
* @return boolean
*/
public static function addKefu($name,$password)
{
try {
Db::startTrans();
$info = Db::name('kefu_info')->where('kefu_name', $name)->find();
if ($info) {
throw new LogicException('客服名已被使用', 1001);
}
$kf['kefu_code'] = 'kefu' . uniqid();
$kf['kefu_name'] = $name;
$kf['kefu_avatar'] = '/static/common/images/kefu.jpg';
$kf['kefu_password'] = strtoupper(md5($password));
$kf['online_status'] = 2;
$kf['create_time'] = date('Y-m-d H:i:s');
$kf['update_time'] = date('Y-m-d H:i:s');
Db::name('kefu_info')->insert($kf);
Db::commit();
return true;
} catch (BaseException $be) {
Db::rollback();
throw new ResponsableException($be->getMessage(), $be->getCode());
} catch (Exception $e) {
Db::rollback();
dump($e->getMessage());
throw new ResponsableException('添加失败', 404);
}
}
/**
* 删除客服
* @param $id 主键id
* @return boolean
*/
public static function delKefu($id)
{
try {
Db::startTrans();
$info = Db::name('kefu_info')->where('kefu_id', $id)->find();
if (!$info) {
throw new LogicException('客服不存在', 1001);
}
//删除账号信息
Db::name('kefu_info')->where('kefu_id', $info['kefu_id'])->delete();
Db::commit();
return true;
} catch (BaseException $be) {
Db::rollback();
throw new ResponsableException($be->getMessage(), $be->getCode());
} catch (Exception $e) {
Db::rollback();
throw new ResponsableException('删除失败', 404);
}
}
/**
* 编辑客服
* @param $param
* @return boolean
*/
public static function saveKefu($id,$name)
{
try {
Db::startTrans();
$kinfo= Db::name('kefu_info')->where('kefu_id',$id)->find();
if(!$kinfo){
throw new LogicException('记录不存在', 1001);
}
$info = Db::name('kefu_info')->whereNotIn('kefu_id',$id)->where('kefu_name', $name)->find();
if ($info) {
throw new LogicException('客服名已被使用', 1001);
}
$kf['kefu_name'] = $name;
$kf['update_time'] = date('Y-m-d H:i:s');
Db::name('kefu_info')->where('kefu_id',$id)->update($kf);
Db::commit();
return true;
} catch (BaseException $be) {
Db::rollback();
throw new ResponsableException($be->getMessage(), $be->getCode());
} catch (Exception $e) {
Db::rollback();
throw new ResponsableException($e->getMessage(), 404);
}
}
/**
* 修改客服密码
* @param $id 主键id
* @return boolean
*/
public static function resetPassword($id,$password)
{
try {
$info = Db::name('kefu_info')->where('kefu_id', $id)->find();
if (!$info) {
throw new LogicException('客服不存在', 1001);
}
$kf['kefu_password'] = strtoupper(md5($password));
$kf['update_time'] = date('Y-m-d H:i:s');
return Db::name('kefu_info')->where('kefu_id', $id)->update(['kefu_password' => strtoupper(md5(config('timely.acquiesce_password')))]);
} catch (BaseException $be) {
throw new ResponsableException($be->getMessage(), $be->getCode());
} catch (Exception $e) {
throw new ResponsableException('修改密码失败', 404);
}
}
/**
* 获取客服数量
* @param $kefu_code 客服编码
*/
public static function kefuCount($where=[]){
return Db::name('kefu_info')->where($where)->count();
}
/**
* 查找在线客服
* @param $kefu_code 客服编码

View File

@ -44,4 +44,28 @@ class Visitor
return Db::name('visitor')->where('visitor_id', $visitor_id)->update($update);
}
/**
* 查找游客列表
* @return boolean
*/
public static function getVisitorList($limit=10){
return Db::name('visitor')->order('online_status,create_time desc')->paginate($limit);
}
/**
* 获取服务记录
* @return boolean
*/
public static function getServiceList($where=[],$limit=10){
return Db::name('visitor_service_log')->where($where)->order('vsid desc')->paginate($limit);
}
/**
* 获取游客总数
* @return boolean
*/
public static function visitorCount($where=[]){
return Db::name('visitor')->where($where)->count();
}
}

View File

@ -13,26 +13,22 @@ class VisitorService
{
/**
* 访客留言立碑
* @param $seller_id
* @param $where
* 获取今日会话次数
* @return array
*/
public static function getCustomerServiceList($seller_id,$where=[],$page=1,$limit=10){
$list = Db::name('visitor_service_log')->where('seller_id',$seller_id)
->where($where)->order('service_log_id', 'desc')->page($page,$limit)->select();
return $list;
public static function getServiceNum($date=''){
if(!$date){
$date=date('Y-m-d');
}
$date=date('Y-m-d',strtotime($date));
$endDate=date('Y-m-d 23:59:59',strtotime($date));
return Db::name('visitor_service_log')->where('start_date','between time',[$date, $endDate])->count();
}
public static function getCustomerServiceCount($seller_id,$where=[]){
return Db::name('visitor_service_log')->where('seller_id',$seller_id)->where($where)->count();
}
public static function addServiceLog($data){
return Db::name('visitor_service_log')->insertGetId($data);
}
public static function setEndTimeEndId($visitor_id){
//获取最新的记录
$info= Db::name('visitor_service_log')->where('visitor_id',$visitor_id)->order('start_date desc')->find();