diff --git a/extend/Logic/ChatLogLogic.php b/extend/Logic/ChatLogLogic.php index 4cc2dbc..e2ee1ca 100644 --- a/extend/Logic/ChatLogLogic.php +++ b/extend/Logic/ChatLogLogic.php @@ -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); + } + + } } diff --git a/extend/Logic/KefuLogic.php b/extend/Logic/KefuLogic.php index 523ae08..e806399 100644 --- a/extend/Logic/KefuLogic.php +++ b/extend/Logic/KefuLogic.php @@ -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 客服编码 diff --git a/extend/Logic/Visitor.php b/extend/Logic/Visitor.php index 47b8850..a319051 100644 --- a/extend/Logic/Visitor.php +++ b/extend/Logic/Visitor.php @@ -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(); + } } diff --git a/extend/Logic/VisitorService.php b/extend/Logic/VisitorService.php index 0e599f1..8761a8a 100644 --- a/extend/Logic/VisitorService.php +++ b/extend/Logic/VisitorService.php @@ -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();