Commit 393ea64c by 朱继来

添加客服池

parent 524492a7
......@@ -11,6 +11,7 @@ use App\Model\Pcb\PcbPublicModel;
use App\Model\Pcb\PcbPurchaseModel;
use App\Model\Pcb\PcbServerModel;
use App\Model\KefuModel;
use App\Model\CmsModel;
class ApiController extends Controller
{
......@@ -95,7 +96,35 @@ class ApiController extends Controller
public function ApiKefuList($request)
{
$KefuModel = new KefuModel;
return $KefuModel->lists($request);
$this->ExportLayui($KefuModel->lists($request));
}
// 新增客服
public function ApiAddKefu($request)
{
$KefuModel = new KefuModel;
$this->Export($KefuModel->add($request));
}
// 编辑客服
public function ApiEditKefu($request)
{
$KefuModel = new KefuModel;
$this->Export($KefuModel->edit($request));
}
// 删除客服
public function ApiDelKefu($request)
{
$KefuModel = new KefuModel;
$this->Export($KefuModel->del($request));
}
// 删除客服
public function ApiTopKefu($request)
{
$KefuModel = new KefuModel;
$this->Export($KefuModel->top($request));
}
}
......@@ -13,7 +13,7 @@ class KefuModel extends Model
protected $primaryKey = 'id';
protected $guarded = ['id'];
public $timestamps = true;
const CREATED_AT = 'add_time';
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
/** * @param \DateTime|int $value * @return false|int * @author dividez */
......@@ -57,7 +57,7 @@ class KefuModel extends Model
}
})
->select($field)
->orderBy('add_time', 'desc');
->orderBy('status', 'desc');
if ($export) {
$list = $list->get()->toArray();
......@@ -70,9 +70,94 @@ class KefuModel extends Model
} else {
$list = $list->paginate($limit, ['*'], 'page', $page)->toArray();
return ['code'=>0, 'msg'=>'获取成功', 'data'=>$list['data'], 'count'=>$list['total']];
return [0, '获取成功', $list['data'], $list['total']];
}
}
// 新增客服
public function add($request)
{
$email = $request->input('email');
$CmsModel = new CmsModel;
$sales = $CmsModel->where('email', $email)->select('userId', 'name', 'status')->first();
if (!$sales) return [1, '客服邮箱不存在'];
if ($sales->status == 4) return [1, '客服已离职'];
$exists = $this->where('email', $email)->first();
if ($exists) return [1, '客服已存在'];
$data['sale_id'] = $sales->userId;
$data['sale_name'] = $sales->name;
$data['email'] = $email;
$data['operator_id'] = $request->user->userId;
$data['operator_name'] = $request->user->name;
$count = $this->count(); // 客服池数量
if (!$count) $data['status'] = 1; // 待分配
$res = $this->create($data);
if ($res === false) return [1, '新增客服失败'];
return [0, '新增客服成功'];
}
// 编辑客服
public function edit($request)
{
$id = $request->input('id');
$email = $request->input('email');
$res = $this->where('id', $id)->update(['email'=>$email]);
if ($res === false) return [1, '更新客服失败'];
return [0, '更新客服成功'];
}
// 删除客服
public function del($request)
{
$id = $request->input('id');
$status = $request->input('status');
$res = $this->where('id', $id)->delete();
if ($res === false) return [1, '删除客服失败'];
if ($status == 1) {
$first = $this->select('id')->orderBy('id', 'asc')->first();
$res = $this->where('id', $first['id'])->update(['status'=>1]);
if ($res === false) return [1, '更新第一条客服状态失败'];
}
return [0, '删除客服成功'];
}
// 置顶客服
public function top($request)
{
$id = $request->input('id');
try {
DB::connection('order')->beginTransaction(); // 开启事务
DB::connection('order')->update('UPDATE lie_kefu SET status = 0');
$this->where('id', $id)->update(['status'=>1]);
DB::connection('order')->commit();
return [0, '置顶客服成功'];
} catch(Exception $e) {
DB::connection('order')->rollback();
return [1, '置顶客服失败,'.$e->getMessage()];
}
}
}
\ No newline at end of file
/**
* Created by ICHUNT on 2019-06-03.
*/
$(document).on('mouseenter','.preview',function(){
var url=$(this).data('url');
if(!url || url == 'undefined') return false;
return top.layer.tips('<img src="'+url+'" width="150px">',$(this),{tips:[3,"#fff"],time:0,shade:0});
});
$(document).on('mouseleave','.preview',function(){
return top.layer.close(layer.index);
});
/**
* 和PHP一样的时间戳格式化函数
* @param {string} format 格式
* @param {int} timestamp 要格式化的时间 默认为当前时间
* @return {string} 格式化的时间字符串
*/
function date(format, timestamp){
if(!timestamp) return '';
var a, jsdate=((timestamp) ? new Date(timestamp*1000) : new Date());
var pad = function(n, c){
if((n = n + "").length < c){
return new Array(++c - n.length).join("0") + n;
} else {
return n;
}
};
var txt_weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var txt_ordin = {1:"st", 2:"nd", 3:"rd", 21:"st", 22:"nd", 23:"rd", 31:"st"};
var txt_months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var f = {
// Day
d: function(){return pad(f.j(), 2)},
D: function(){return f.l().substr(0,3)},
j: function(){return jsdate.getDate()},
l: function(){return txt_weekdays[f.w()]},
N: function(){return f.w() + 1},
S: function(){return txt_ordin[f.j()] ? txt_ordin[f.j()] : 'th'},
w: function(){return jsdate.getDay()},
z: function(){return (jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5 >> 0},
// Week
W: function(){
var a = f.z(), b = 364 + f.L() - a;
var nd2, nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1;
if(b <= 2 && ((jsdate.getDay() || 7) - 1) <= 2 - b){
return 1;
} else{
if(a <= 2 && nd >= 4 && a >= (6 - nd)){
nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31");
return date("W", Math.round(nd2.getTime()/1000));
} else{
return (1 + (nd <= 3 ? ((a + nd) / 7) : (a - (7 - nd)) / 7) >> 0);
}
}
},
// Month
F: function(){return txt_months[f.n()]},
m: function(){return pad(f.n(), 2)},
M: function(){return f.F().substr(0,3)},
n: function(){return jsdate.getMonth() + 1},
t: function(){
var n;
if( (n = jsdate.getMonth() + 1) == 2 ){
return 28 + f.L();
} else{
if( n & 1 && n < 8 || !(n & 1) && n > 7 ){
return 31;
} else{
return 30;
}
}
},
// Year
L: function(){var y = f.Y();return (!(y & 3) && (y % 1e2 || !(y % 4e2))) ? 1 : 0},
//o not supported yet
Y: function(){return jsdate.getFullYear()},
y: function(){return (jsdate.getFullYear() + "").slice(2)},
// Time
a: function(){return jsdate.getHours() > 11 ? "pm" : "am"},
A: function(){return f.a().toUpperCase()},
B: function(){
// peter paul koch:
var off = (jsdate.getTimezoneOffset() + 60)*60;
var theSeconds = (jsdate.getHours() * 3600) + (jsdate.getMinutes() * 60) + jsdate.getSeconds() + off;
var beat = Math.floor(theSeconds/86.4);
if (beat > 1000) beat -= 1000;
if (beat < 0) beat += 1000;
if ((String(beat)).length == 1) beat = "00"+beat;
if ((String(beat)).length == 2) beat = "0"+beat;
return beat;
},
g: function(){return jsdate.getHours() % 12 || 12},
G: function(){return jsdate.getHours()},
h: function(){return pad(f.g(), 2)},
H: function(){return pad(jsdate.getHours(), 2)},
i: function(){return pad(jsdate.getMinutes(), 2)},
s: function(){return pad(jsdate.getSeconds(), 2)},
//u not supported yet
// Timezone
//e not supported yet
//I not supported yet
O: function(){
var t = pad(Math.abs(jsdate.getTimezoneOffset()/60*100), 4);
if (jsdate.getTimezoneOffset() > 0) t = "-" + t; else t = "+" + t;
return t;
},
P: function(){var O = f.O();return (O.substr(0, 3) + ":" + O.substr(3, 2))},
//T not supported yet
//Z not supported yet
// Full Date/Time
c: function(){return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P()},
//r not supported yet
U: function(){return Math.round(jsdate.getTime()/1000)}
};
return format.replace(/[\\]?([a-zA-Z])/g, function(t, s){
if( t!=s ){
// escaped
ret = s;
} else if( f[s] ){
// a date function exists
ret = f[s]();
} else{
// nothing special
ret = s;
}
return ret;
});
}
\ No newline at end of file
......@@ -20,24 +20,17 @@ layui.use(['form', 'table', 'laydate'], function(){
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
,cols: [[ //表头
{title: '序号', type: 'numbers', fixed: 'left', width: 78}
,{field: 'sale_id', title: '客服ID', width: 300}
,{field: 'sale_name', title: '客服名称', width: 160}
,{field: 'email', title: '邮箱', width: 150}
,{field: 'operator_name', title: '操作人名称', width: 150}
,{field: 'status', title: '审核状态', templet: '#status', width: 160}
{title: '序号', type: 'numbers', fixed: 'left', width: 80}
,{field: 'sale_id', title: '客服ID', width: 200}
,{field: 'sale_name', title: '客服名称', width: 200}
,{field: 'email', title: '邮箱', width: 300}
,{field: 'operator_name', title: '操作人名称', width: 200}
,{field: 'status', title: '审核状态', templet: '#status', width: 200}
,{field: 'create_time', title: '创建时间', width: 200}
,{title: '操作', align:'center', fixed: 'right', toolbar: '#list_action', width: 200}
,{title: '操作', align:'center', fixed: 'right', toolbar: '#list_action', width: 218}
]]
,limit: 10
,limits: [10, 20, 50,]
,done:function(res,curr,count){
// 图片展示
layer.photos({
photos: '.layer-img'
,shift: 5 //0-6的选择,指定弹出图片动画类型,默认随机
});
}
});
};
......@@ -55,61 +48,94 @@ layui.use(['form', 'table', 'laydate'], function(){
return false;
});
$('.add').click(function() {
layer.open({
area: ['400px', '200px'],
title: '新增客服',
type: 1,
content: $('#kefu-action'),
btn: ['确认', '取消'],
yes: function(index) {
var email = $('.kefu-email').val();
if (!email) {
layer.tips('请输入邮箱', $('.kefu-email'));
return false;
}
$.ajax({
url : '/api/ApiAddKefu',
type: 'post',
data: {email: email},
dataType: 'json',
success: function(resp) {
if (resp.errcode == 0) {
layer.close(index);
layer.msg(resp.errmsg);
renderTable(); // 重新加载table
return false;
}
layer.msg(resp.errmsg);
},
error: function(err) {
console.log(err)
}
})
layer.msg('新增客服中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
return false;
},
cancel: function(index) {
layer.close(index);
}
})
$('.kefu-email').val('');
})
// tool操作
table.on('tool(auth)', function(obj){ //注:tool是工具条事件名,test是table原始容器的属性lay-filter="对应的值"
table.on('tool(kefu)', function(obj){ //注:tool是工具条事件名,test是table原始容器的属性lay-filter="对应的值"
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var url = '';
var title = '';
var content = '';
var url = '/ajax/authCheck';
var datax = {};
datax.id = data.id;
datax.user_id = data.user_id;
if(layEvent === 're-check') { // 重新审核
title = '重新审核会员认证';
content = '确定重新审核会员认证吗?';
datax.status = 1;
} else if (layEvent === 'pass') { // 通过
title = '审核会员认证';
content = '确定通过会员认证吗?';
datax.status = 3;
// datax.company_name = data.company_name;
// datax.auth_type = data.auth_type;
// datax.company_type = data.company_type;
} else if (layEvent === 'reject') { // 驳回
title = '驳回会员认证';
content = '<div class="layui-form-item layui-form-text">'+
'<textarea placeholder="请输入驳回原因" class="layui-textarea" name="reason" id="reason"></textarea>'+
'</div>';
datax.status = 2;
} else if (layEvent === 'cancel') { // 取消认证
title = '取消会员认证';
content = '<div class="layui-form-item layui-form-text">'+
'<textarea placeholder="请输入取消原因" class="layui-textarea" name="reason" id="reason"></textarea>'+
'</div>';
datax.status = -1;
if(layEvent === 'edit') {
url = '/api/ApiEditKefu';
title = '编辑客服';
content = $('#kefu-action');
} else if (layEvent === 'del') {
url = '/api/ApiDelKefu';
title = '删除客服';
content = '<div style="margin: 40px;">确定删除该客服吗?</div>';
datax.status = data.status;
} else if (layEvent === 'top') {
url = '/api/ApiTopKefu';
title = '置顶客服';
content = '<div style="margin: 40px;">确定置顶该客服吗?</div>';
}
layer.open({
// area: ['400px', '200px'],
area: ['400px', '200px'],
title: title,
type: 1,
content: content,
btn: ['确认', '取消'],
yes: function(index) {
if (layEvent == 'reject' || layEvent == 'cancel') {
var reason = $('#reason').val();
if (!reason) {
layer.tips('请输入原因', $('#reason'));
if (layEvent == 'edit') {
var email = $('.kefu-email').val();
if (!email) {
layer.tips('请输入邮箱', $('.kefu-email'));
return false;
}
datax.reason = reason;
datax.email = email;
}
$.ajax({
......@@ -118,14 +144,15 @@ layui.use(['form', 'table', 'laydate'], function(){
data: datax,
dataType: 'json',
success: function(resp) {
if (resp.err_code == 0) {
layer.msg(resp.err_msg);
if (resp.errcode == 0) {
layer.close(index);
layer.msg(resp.errmsg);
renderTable(); // 重新加载table
return false;
}
layer.alert(resp.err_msg);
layer.msg(resp.errmsg);
},
error: function(err) {
console.log(err)
......@@ -140,6 +167,10 @@ layui.use(['form', 'table', 'laydate'], function(){
layer.close(index);
}
})
if (layEvent == 'edit') {
$('.kefu-email').val(data.email);
}
});
......
......@@ -6,7 +6,7 @@
<title>{{config('website.webTitle')}} | {{$title}}</title>
<script>document.domain="{{ config('website.domain') }}";</script>
<link href="/js/layui/css/layui.css" rel="stylesheet">
<link href="/css/admin.css" rel="stylesheet">
@include('table.css')
<script src="/js/jquery-2.2.1.js"></script>
<style>
......@@ -39,7 +39,7 @@
</div>
@include('table.js')
<script src="/js/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script src="/js/web/common.js"></script>
@if(empty($into))
<script src="/js/web/{{$id}}.js?v={{time()}}"></script>
@endif
......
......@@ -29,13 +29,29 @@
<div class="layui-form-item">
<div class="layui-btn-container" style="text-align: center; margin-top: 10px;">
<button lay-submit lay-filter="load" class="layui-btn" data-type="search">搜索</button>
<button type="button" class="layui-btn layui-btn-normal export">导出</button>
<a class="layui-btn layui-btn-normal add">新增</a>
</div>
</div>
</form>
<table id="kefu" lay-filter="kefu"></table>
<style>
#kefu-action{ display: none; }
#kefu-action form{ margin-top: 40px; }
#kefu-action .layui-input-inline{ width: 240px; }
</style>
<div id="kefu-action">
<form class="layui-form">
<div class="layui-item">
<label class="layui-form-label">客服邮箱</label>
<div class="layui-input-inline">
<input type="text" name="kefu-email" placeholder="客服邮箱" autocomplete="off" class="layui-input kefu-email">
</div>
</div>
</div>
</div>
<script type="text/html" id="status">
@{{# if (d.status == 1) { }}
<div style="color:#DC143C;">待分配</div>
......@@ -47,5 +63,8 @@
<script type="text/html" id="list_action">
<a class="btn btn-xs btn-warning" lay-event="edit">编辑</a>
<a class="btn btn-xs btn-danger" lay-event="del">删除</a>
@{{# if (d.status == 0) { }}
<a class="btn btn-xs btn-info" lay-event="top">置顶</a>
@{{# } }}
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment