调整流量池数据结构

This commit is contained in:
柳清爽
2025-04-12 19:06:00 +08:00
parent 8d96110767
commit 151db81258
8 changed files with 202 additions and 106 deletions

View File

@@ -3,6 +3,7 @@ namespace app\superadmin\controller;
use app\superadmin\model\TrafficPool as TrafficPoolModel;
use think\Controller;
use think\facade\Request;
/**
* 客户池控制器
@@ -16,102 +17,66 @@ class TrafficPool extends Controller
public function getList()
{
// 获取分页参数
$page = $this->request->param('page/d', 1);
$limit = $this->request->param('limit/d', 20);
$keyword = $this->request->param('keyword/s', '');
$page = Request::param('page/d', 1);
$limit = Request::param('limit/d', 30);
// 构建查询条件
$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')
// 查询字段
->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')
->field([
'distinct ts.identifier',
'tp.id',
'tp.avatar',
'tp.nickname',
'tp.wechatId',
'tp.mobile',
'tp.createTime',
'tp.wechatId',
'tp.createTime as addTime',
'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']) {
'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']) {
case 1:
$gender = '男';
$item['gender'] = '男';
break;
case 2:
$gender = '女';
$item['gender'] = '女';
break;
default:
$item['gender'] = '保密';
}
$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']
];
}
// 处理标签显示
if (is_string($item['tags'])) {
$item['tags'] = json_decode($item['tags'], true);
}
return $item;
});
// 返回结果
return json([
'code' => 200,
'msg' => '获取成功',
'data' => [
'list' => $data,
'total' => $total,
'page' => $page,
'limit' => $limit
'total' => $list->total(),
'list' => $list->items(),
'page' => $list->currentPage(),
'limit' => $list->listRows()
]
]);
}

View File

@@ -0,0 +1,13 @@
<?php
namespace app\superadmin\model;
use think\Model;
/**
* 场景模型
*/
class Scene extends Model
{
// 设置数据表名
protected $name = 'scene';
}

View File

@@ -4,10 +4,45 @@ namespace app\superadmin\model;
use think\Model;
/**
* 流量池模型
* 客户池模型
*/
class TrafficPool extends Model
{
// 设置数据表名
protected $name = 'traffic_pool';
// 设置表前缀
protected $prefix = 'ck_';
// 设置主键
protected $pk = 'id';
// 自动写入时间戳
protected $autoWriteTimestamp = true;
// 定义时间戳字段名
protected $createTime = 'createTime';
protected $updateTime = 'updateTime';
// 定义字段类型
protected $type = [
'id' => 'integer',
'wechatId' => 'string',
'createTime' => 'datetime',
'updateTime' => 'integer'
];
// 定义字段验证规则
protected $rule = [
'wechatId' => 'require|max:64',
'identifier' => 'require|max:64'
];
// 定义字段验证提示信息
protected $message = [
'wechatId.require' => '微信ID不能为空',
'wechatId.max' => '微信ID最多不能超过64个字符',
'identifier.require' => '标识符不能为空',
'identifier.max' => '标识符最多不能超过64个字符'
];
}

View File

@@ -10,4 +10,41 @@ class TrafficSource extends Model
{
// 设置数据表名
protected $name = 'traffic_source';
// 设置表前缀
protected $prefix = 'ck_';
// 设置主键
protected $pk = 'id';
// 自动写入时间戳
protected $autoWriteTimestamp = true;
// 定义时间戳字段名
protected $createTime = 'createTime';
protected $updateTime = 'updateTime';
// 定义字段类型
protected $type = [
'id' => 'integer',
'identifier' => 'string',
'companyId' => 'integer',
'createTime' => 'datetime',
'updateTime' => 'integer'
];
// 定义字段验证规则
protected $rule = [
'identifier' => 'require|max:64',
'companyId' => 'number',
'fromd' => 'max:255'
];
// 定义字段验证提示信息
protected $message = [
'identifier.require' => '标识符不能为空',
'identifier.max' => '标识符最多不能超过64个字符',
'companyId.number' => '公司ID必须为数字',
'fromd.max' => '来源最多不能超过255个字符'
];
}

View File

@@ -0,0 +1,13 @@
<?php
namespace app\superadmin\model;
use think\Model;
/**
* 微信账号模型
*/
class WechatAccount extends Model
{
// 设置数据表名
protected $name = 'wechat_account';
}

View File

@@ -0,0 +1,13 @@
<?php
namespace app\superadmin\model;
use think\Model;
/**
* 微信标签模型
*/
class WechatTag extends Model
{
// 设置数据表名
protected $name = 'wechat_tag';
}