超管后台 - 客户池列表
This commit is contained in:
@@ -18,18 +18,15 @@ Route::group('', function () {
|
||||
|
||||
// 管理员相关路由
|
||||
Route::group('administrator', function () {
|
||||
// 获取管理员列表
|
||||
Route::get('list', 'app\\superadmin\\controller\\Administrator@getList');
|
||||
// 获取管理员详情
|
||||
Route::get('detail/:id', 'app\\superadmin\\controller\\Administrator@getDetail');
|
||||
// 更新管理员信息
|
||||
Route::post('update', 'app\\superadmin\\controller\\Administrator@updateAdmin');
|
||||
// 添加管理员
|
||||
Route::post('add', 'app\\superadmin\\controller\\Administrator@addAdmin');
|
||||
// 删除管理员
|
||||
Route::post('delete', 'app\\superadmin\\controller\\Administrator@deleteAdmin');
|
||||
});
|
||||
|
||||
// 系统信息相关路由
|
||||
Route::get('system/info', 'app\\superadmin\\controller\\System@getInfo');
|
||||
|
||||
// 客户池管理路由
|
||||
Route::group('trafficPool', function () {
|
||||
Route::get('list', 'app\\superadmin\\controller\\TrafficPool@getList');
|
||||
});
|
||||
})->middleware(['app\\superadmin\\middleware\\AdminAuth']);
|
||||
117
Server/application/superadmin/controller/TrafficPool.php
Normal file
117
Server/application/superadmin/controller/TrafficPool.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace app\superadmin\controller;
|
||||
|
||||
use app\superadmin\model\TrafficPool as TrafficPoolModel;
|
||||
use think\Controller;
|
||||
|
||||
/**
|
||||
* 客户池控制器
|
||||
*/
|
||||
class TrafficPool extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取客户池列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
// 获取分页参数
|
||||
$page = $this->request->param('page/d', 1);
|
||||
$limit = $this->request->param('limit/d', 20);
|
||||
$keyword = $this->request->param('keyword/s', '');
|
||||
|
||||
// 构建查询条件
|
||||
$where = [];
|
||||
|
||||
// 如果有搜索关键词
|
||||
if (!empty($keyword)) {
|
||||
$where[] = ['tp.nickname|tp.identifier|tp.alias', 'like', "%{$keyword}%"];
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
$query = TrafficPoolModel::alias('tp')
|
||||
// 关联流量来源表
|
||||
->join('traffic_source ts', 'tp.identifier = ts.identifier', 'inner')
|
||||
// 关联公司表
|
||||
->join('company c', 'ts.companyId = c.id', 'left')
|
||||
// 关联微信好友表
|
||||
->join('wechat_friend wf', 'tp.wechatId = wf.wechatId', 'left')
|
||||
// 查询字段
|
||||
->field([
|
||||
'tp.id',
|
||||
'tp.avatar',
|
||||
'tp.nickname',
|
||||
'tp.wechatId',
|
||||
'tp.mobile',
|
||||
'tp.createTime',
|
||||
'ts.fromd as source',
|
||||
'ts.companyId',
|
||||
'c.name as companyName',
|
||||
'wf.gender',
|
||||
'wf.region',
|
||||
'wf.labels'
|
||||
]);
|
||||
|
||||
// 统计总数
|
||||
$total = $query->where($where)->count();
|
||||
|
||||
// 获取列表数据
|
||||
$list = $query->where($where)
|
||||
->order('tp.createTime', 'desc')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
|
||||
// 格式化数据
|
||||
$data = [];
|
||||
foreach ($list as $item) {
|
||||
$labels = [];
|
||||
// 处理标签数据
|
||||
if (!empty($item['labels'])) {
|
||||
$labelData = json_decode($item['labels'], true);
|
||||
if (is_array($labelData)) {
|
||||
foreach ($labelData as $label) {
|
||||
if (isset($label['name'])) {
|
||||
$labels[] = $label['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化性别
|
||||
$gender = '未知';
|
||||
switch ($item['gender']) {
|
||||
case 1:
|
||||
$gender = '男';
|
||||
break;
|
||||
case 2:
|
||||
$gender = '女';
|
||||
break;
|
||||
}
|
||||
|
||||
$data[] = [
|
||||
'id' => $item['id'],
|
||||
'avatar' => $item['avatar'],
|
||||
'nickname' => $item['nickname'],
|
||||
'wechatId' => $item['wechatId'],
|
||||
'gender' => $gender,
|
||||
'region' => $item['region'] ?: '未知',
|
||||
'tags' => empty($labels) ? [] : $labels,
|
||||
'source' => $item['source'] ?: '未知',
|
||||
'companyName' => $item['companyName'] ?: '未知',
|
||||
'createTime' => date('Y-m-d H:i:s', $item['createTime']),
|
||||
'mobile' => $item['mobile']
|
||||
];
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'list' => $data,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
35
Server/application/superadmin/model/Company.php
Normal file
35
Server/application/superadmin/model/Company.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 公司(项目)模型
|
||||
*/
|
||||
class Company extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'company';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 设置时间格式为datetime类型
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'lastUpdateTime';
|
||||
|
||||
// 定义字段类型
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'tenantId' => 'integer',
|
||||
'isTop' => 'integer',
|
||||
'level' => 'integer',
|
||||
'parentId' => 'integer',
|
||||
'privileges' => 'json',
|
||||
'createTime' => 'datetime',
|
||||
'lastUpdateTime' => 'datetime'
|
||||
];
|
||||
}
|
||||
13
Server/application/superadmin/model/TrafficPool.php
Normal file
13
Server/application/superadmin/model/TrafficPool.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 流量池模型
|
||||
*/
|
||||
class TrafficPool extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'traffic_pool';
|
||||
}
|
||||
13
Server/application/superadmin/model/TrafficSource.php
Normal file
13
Server/application/superadmin/model/TrafficSource.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 流量来源模型
|
||||
*/
|
||||
class TrafficSource extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'traffic_source';
|
||||
}
|
||||
42
Server/application/superadmin/model/WechatFriend.php
Normal file
42
Server/application/superadmin/model/WechatFriend.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 微信好友模型
|
||||
*/
|
||||
class WechatFriend extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'wechat_friend';
|
||||
|
||||
// 不使用自增主键
|
||||
protected $pk = null;
|
||||
|
||||
// 指定自动时间字段的格式
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 定义字段类型
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'wechatAccountId' => 'integer',
|
||||
'gender' => 'integer',
|
||||
'addFrom' => 'integer',
|
||||
'isDeleted' => 'integer',
|
||||
'isPassed' => 'integer',
|
||||
'accountId' => 'integer',
|
||||
'groupId' => 'integer',
|
||||
'updateTime' => 'integer',
|
||||
'labels' => 'json',
|
||||
'extendFields' => 'json',
|
||||
'thirdParty' => 'json',
|
||||
'deleteTime' => 'datetime',
|
||||
'passTime' => 'datetime',
|
||||
'createTime' => 'datetime'
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user