|
|
@@ -27,6 +27,8 @@ class Accounts extends Base
|
|
|
$result = db('accounts')->whereBetween('add_time', [$start, $end])->where($where)->limit($offset, $limit)->order('add_time', 'desc')->select();
|
|
|
//所有客服
|
|
|
$users = db('users')->select();
|
|
|
+ //所有标签
|
|
|
+ $label = db('accountslabel')->select();
|
|
|
foreach($result as $key=>$vo){
|
|
|
$result[$key]['add_time'] = date('Y-m-d H:i:s',$result[$key]['add_time']);
|
|
|
$result[$key]['last_login_time'] = date('Y-m-d H:i:s',$result[$key]['last_login_time']);
|
|
|
@@ -35,6 +37,11 @@ class Accounts extends Base
|
|
|
$result[$key]['user_name'] = $users[$i]['user_name'];
|
|
|
}
|
|
|
}
|
|
|
+ for($j=0;$j<count($label);$j++){
|
|
|
+ if($vo['label_id'] == $label[$j]['id']){
|
|
|
+ $result[$key]['label'] = $label[$j]['name'];
|
|
|
+ }
|
|
|
+ }
|
|
|
// 生成操作按钮
|
|
|
$result[$key]['operate'] = $this->makeBtn($vo['id']);
|
|
|
}
|
|
|
@@ -85,7 +92,7 @@ class Accounts extends Base
|
|
|
$info['account_email'] = $param['account_email'];
|
|
|
$info['account_phone'] = $param['account_phone'];
|
|
|
$info['address'] = $param['address'];
|
|
|
- $info['label'] = $param['label'];
|
|
|
+ $info['label_id'] = $param['label_id'];
|
|
|
$info['remark'] = $param['remark'];
|
|
|
if(!empty($param['user_id']) && $param['user_id'] != 0){
|
|
|
$info['user_id'] = $param['user_id'];
|
|
|
@@ -101,9 +108,17 @@ class Accounts extends Base
|
|
|
|
|
|
$id = input('param.id/d');
|
|
|
$info = db('accounts')->where('id', $id)->find();
|
|
|
+ $label = db('accountslabel')->where('id', $info['label_id'])->find();
|
|
|
+ $info['label'] = $label['name'];
|
|
|
+ //所有标签
|
|
|
+ $label = db('accountslabel')->select();
|
|
|
|
|
|
//服务记录
|
|
|
- $service_log = db('service_log a')->join('users b','a.kf_id=b.id')->field('a.servicelog_id,a.start_time,b.user_name')->where('a.user_id', $id)->select();
|
|
|
+ //前一个月的时间戳
|
|
|
+ $start = time()-2592000;
|
|
|
+ //当前时间戳
|
|
|
+ $end = time();
|
|
|
+ $service_log = db('service_log a')->join('users b','a.kf_id=b.id')->field('a.servicelog_id,a.start_time,b.user_name')->whereBetween('a.start_time', [$start, $end])->where('a.user_id', $id)->select();
|
|
|
for($i=0;$i<count($service_log);$i++){
|
|
|
$service_log[$i]['start_time'] = date("Y-m-d H:i:s",$service_log[$i]['start_time']);
|
|
|
}
|
|
|
@@ -117,6 +132,7 @@ class Accounts extends Base
|
|
|
$this->assign([
|
|
|
'info' => $info,
|
|
|
'users' => $users,
|
|
|
+ 'label' => $label,
|
|
|
'service_log' => $service_log,
|
|
|
'status' => config('kf_status')
|
|
|
]);
|
|
|
@@ -149,4 +165,113 @@ class Accounts extends Base
|
|
|
|
|
|
return $operate;
|
|
|
}
|
|
|
+
|
|
|
+ // 用户标签列表
|
|
|
+ public function label()
|
|
|
+ {
|
|
|
+ if(request()->isAjax()){
|
|
|
+ $param = input('param.');
|
|
|
+ $limit = $param['pageSize'];
|
|
|
+ $offset = (($param['pageNumber'] - 1) * $limit);
|
|
|
+ $where = [];
|
|
|
+ if (empty($param['searchText']) === false) {
|
|
|
+ $where['name'] = ['like', '%' . $param['searchText'] . '%'];
|
|
|
+ }
|
|
|
+ $result = db('accountslabel')->where($where)->limit($offset, $limit)->order('add_time', 'desc')->select();
|
|
|
+
|
|
|
+ foreach($result as $key=>$vo){
|
|
|
+ $result[$key]['add_time'] = date('Y-m-d H:i:s',$result[$key]['add_time']);
|
|
|
+
|
|
|
+ // 生成操作按钮
|
|
|
+ $result[$key]['operate'] = $this->makeBtnLabel($vo['id']);
|
|
|
+ }
|
|
|
+ $return['total'] = db('accountslabel')->count(); //总数据
|
|
|
+ $return['rows'] = $result;
|
|
|
+ return json($return);
|
|
|
+ }
|
|
|
+ return $this->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加用户标签
|
|
|
+ public function addlabel()
|
|
|
+ {
|
|
|
+ if (request()->isAjax()) {
|
|
|
+ $param = input('post.');
|
|
|
+ $has = db('accountslabel')->where('name',$param['name'])->find();
|
|
|
+ if(!empty($has)){
|
|
|
+ return json(['code' => -1, 'data' => '', 'msg' => '此用户标签已存在']);
|
|
|
+ }
|
|
|
+ $info = array();
|
|
|
+ $info['name'] = $param['name'];
|
|
|
+ $info['add_time'] = time();
|
|
|
+ try {
|
|
|
+ db('accountslabel')->insert($info);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
|
|
|
+ }
|
|
|
+ return json(['code' => 1, 'data' => '', 'msg' => '添加用户标签成功']);
|
|
|
+ }
|
|
|
+ $this->assign([
|
|
|
+ 'status' => config('kf_status')
|
|
|
+ ]);
|
|
|
+ return $this->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 编辑用户标签
|
|
|
+ public function editlabel()
|
|
|
+ {
|
|
|
+ // 菜单id
|
|
|
+ $id = input('param.id/d');
|
|
|
+ if (request()->isAjax()) {
|
|
|
+ $param = input('post.');
|
|
|
+ $has = db('accountslabel')->where('name',$param['name'])->where('id','<>',$id)->find();
|
|
|
+ if(!empty($has)){
|
|
|
+ return json(['code' => -1, 'data' => '', 'msg' => '此用户标签已存在']);
|
|
|
+ }
|
|
|
+ $info = array();
|
|
|
+ $info['name'] = $param['name'];
|
|
|
+
|
|
|
+ try {
|
|
|
+ db('accountslabel')->where('id', $param['id'])->update($info);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
|
|
|
+ }
|
|
|
+ return json(['code' => 1, 'data' => '', 'msg' => '编辑用户标签成功']);
|
|
|
+ }
|
|
|
+ $label = db('accountslabel')->where('id',$id)->find();
|
|
|
+
|
|
|
+ $this->assign([
|
|
|
+ 'label' => $label,
|
|
|
+ 'id' => $id,
|
|
|
+ 'status' => config('kf_status')
|
|
|
+ ]);
|
|
|
+ return $this->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除用户标签
|
|
|
+ public function delLabel()
|
|
|
+ {
|
|
|
+ if (request()->isAjax()) {
|
|
|
+ //留言类型id
|
|
|
+ $id = input('param.id/d');
|
|
|
+
|
|
|
+ try {
|
|
|
+ db('accountslabel')->where('id', $id)->delete();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
|
|
|
+ }
|
|
|
+ return json(['code' => 1, 'data' => '', 'msg' => '删除用户标签成功']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成标签按钮
|
|
|
+ private function makeBtnLabel($id)
|
|
|
+ {
|
|
|
+ $operate = '<a style="margin-left:5px;" href="' . url('Accounts/editlabel', ['id' => $id]) . '"><button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 编辑</button></a> ';
|
|
|
+
|
|
|
+ $operate .= '<a href="javascript:labelDel(' . $id . ')"><button type="button" class="btn btn-danger btn-sm">';
|
|
|
+ $operate .= '<i class="fa fa-trash-o"></i> 删除</button></a> ';
|
|
|
+
|
|
|
+ return $operate;
|
|
|
+ }
|
|
|
}
|