Files
cunkebao_v3/Server/application/superadmin/controller/TrafficPool.php

83 lines
2.3 KiB
PHP
Raw Normal View History

2025-04-11 15:04:57 +08:00
<?php
namespace app\superadmin\controller;
use app\superadmin\model\TrafficPool as TrafficPoolModel;
use think\Controller;
2025-04-12 19:06:00 +08:00
use think\facade\Request;
2025-04-11 15:04:57 +08:00
/**
* 客户池控制器
*/
class TrafficPool extends Controller
{
/**
* 获取客户池列表
* @return \think\response\Json
*/
public function getList()
{
// 获取分页参数
2025-04-12 19:06:00 +08:00
$page = Request::param('page/d', 1);
$limit = Request::param('limit/d', 30);
2025-04-11 15:04:57 +08:00
2025-04-12 19:06:00 +08:00
// 构建查询
2025-04-11 15:04:57 +08:00
$query = TrafficPoolModel::alias('tp')
2025-04-12 19:06:00 +08:00
->join('traffic_source ts', 'tp.identifier = ts.identifier', 'INNER')
->join('company c', 'ts.companyId = c.id', 'LEFT')
->join('wechat_account wa', 'tp.wechatId = wa.wechatId', 'LEFT')
->join('wechat_tag wt', 'wa.wechatId = wt.wechatId')
2025-04-11 15:04:57 +08:00
->field([
'ts.id',
2025-04-12 19:06:00 +08:00
'tp.wechatId',
'tp.createTime as addTime',
2025-04-11 15:04:57 +08:00
'ts.fromd as source',
2025-04-12 19:06:00 +08:00
'c.name as projectName',
'wa.avatar',
'wa.gender',
'wa.nickname',
'wa.region',
'wt.tags'
])
->order('tp.createTime DESC');
// 执行分页查询
$list = $query->paginate([
'list_rows' => $limit,
'page' => $page
]);
// 处理性别显示
$list->each(function($item) {
// 处理性别显示
switch($item['gender']) {
2025-04-11 15:04:57 +08:00
case 1:
2025-04-12 19:06:00 +08:00
$item['gender'] = '男';
2025-04-11 15:04:57 +08:00
break;
case 2:
2025-04-12 19:06:00 +08:00
$item['gender'] = '女';
2025-04-11 15:04:57 +08:00
break;
2025-04-12 19:06:00 +08:00
default:
$item['gender'] = '保密';
2025-04-11 15:04:57 +08:00
}
2025-04-12 19:06:00 +08:00
// 处理标签显示
if (is_string($item['tags'])) {
$item['tags'] = json_decode($item['tags'], true);
}
return $item;
});
2025-04-11 15:04:57 +08:00
2025-04-12 19:06:00 +08:00
// 返回结果
2025-04-11 15:04:57 +08:00
return json([
'code' => 200,
'msg' => '获取成功',
'data' => [
2025-04-12 19:06:00 +08:00
'total' => $list->total(),
'list' => $list->items(),
'page' => $list->currentPage(),
'limit' => $list->listRows()
2025-04-11 15:04:57 +08:00
]
]);
}
}