超管后台 - 流量池返工
This commit is contained in:
19
Server/application/common/model/TrafficPool.php
Normal file
19
Server/application/common/model/TrafficPool.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流量池模型类
|
||||||
|
*/
|
||||||
|
class TrafficPool extends Model
|
||||||
|
{
|
||||||
|
// 设置数据表名
|
||||||
|
protected $name = 'traffic_pool';
|
||||||
|
|
||||||
|
// 自动写入时间戳
|
||||||
|
protected $autoWriteTimestamp = true;
|
||||||
|
protected $createTime = 'createTime';
|
||||||
|
protected $updateTime = 'updateTime';
|
||||||
|
}
|
||||||
@@ -28,8 +28,8 @@ Route::group('', function () {
|
|||||||
|
|
||||||
// 客户池管理路由
|
// 客户池管理路由
|
||||||
Route::group('trafficPool', function () {
|
Route::group('trafficPool', function () {
|
||||||
Route::get('list', 'app\superadmin\controller\TrafficPoolController@getList');
|
Route::get('list', 'app\superadmin\controller\traffic\GetPoolListController@index');
|
||||||
Route::get('detail', 'app\superadmin\controller\TrafficPoolController@getDetail');
|
Route::get('detail', 'app\superadmin\controller\traffic\TrafficPoolController@getDetail');
|
||||||
});
|
});
|
||||||
|
|
||||||
// 公司路由
|
// 公司路由
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\superadmin\controller\traffic;
|
||||||
|
|
||||||
|
use app\common\model\TrafficPool as TrafficPoolModel;
|
||||||
|
use app\superadmin\controller\BaseController;
|
||||||
|
use think\facade\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户池控制器
|
||||||
|
*/
|
||||||
|
class GetPoolListController extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 格式化性别显示
|
||||||
|
*
|
||||||
|
* @param int $gender
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function formatGender(?int $gender): string
|
||||||
|
{
|
||||||
|
switch ($gender) {
|
||||||
|
case 1:
|
||||||
|
return '男';
|
||||||
|
case 2:
|
||||||
|
return '女';
|
||||||
|
default:
|
||||||
|
return '保密';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理标签显示
|
||||||
|
*
|
||||||
|
* @param string|null $tags
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function handlTags(?string $tags): array
|
||||||
|
{
|
||||||
|
return is_string($tags) ? json_decode($tags, true) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化时间
|
||||||
|
*
|
||||||
|
* @param string|null $date
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
protected function formatDate(?string $date): ?string
|
||||||
|
{
|
||||||
|
return $date ? date('Y-m-d H:i:s', $date) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建返回数据
|
||||||
|
*
|
||||||
|
* @param \think\Paginator $list
|
||||||
|
* @return \think\Paginator
|
||||||
|
*/
|
||||||
|
protected function makeReturnedValue(\think\Paginator $list): \think\Paginator
|
||||||
|
{
|
||||||
|
$list->each(function ($item) {
|
||||||
|
$item->gender = $this->formatGender($item->gender);
|
||||||
|
$item->addTime = $this->formatDate($item->addTime);
|
||||||
|
$item->tags = $this->handlTags($item->tags);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建查询.
|
||||||
|
*
|
||||||
|
* @return TrafficPoolModel|\think\Paginator
|
||||||
|
*/
|
||||||
|
protected function gePoolList(): \think\Paginator
|
||||||
|
{
|
||||||
|
$query = TrafficPoolModel::alias('tp')
|
||||||
|
->field([
|
||||||
|
'ts.id',
|
||||||
|
'tp.wechatId',
|
||||||
|
'ts.createTime as addTime',
|
||||||
|
'ts.fromd as source',
|
||||||
|
'c.name as projectName',
|
||||||
|
'wa.avatar',
|
||||||
|
'wa.gender',
|
||||||
|
'wa.nickname',
|
||||||
|
'wa.region',
|
||||||
|
'wt.tags'
|
||||||
|
])
|
||||||
|
->join('traffic_source ts', 'tp.identifier = ts.identifier', 'RIGHT')
|
||||||
|
->join('company c', 'ts.companyId = c.companyId', 'LEFT')
|
||||||
|
->join('wechat_account wa', 'tp.wechatId = wa.wechatId', 'LEFT')
|
||||||
|
->join('wechat_tag wt', 'wa.wechatId = wt.wechatId', 'LEFT');
|
||||||
|
|
||||||
|
return $query->paginate($this->request->param('limit/d', 10), false, ['page' => $this->request->param('page/d', 1)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取客户池列表
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$list = $this->gePoolList();
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => 200,
|
||||||
|
'msg' => '获取成功',
|
||||||
|
'data' => [
|
||||||
|
'list' => $this->makeReturnedValue($list)->items(),
|
||||||
|
'total' => $list->total(),
|
||||||
|
'page' => $list->currentPage(),
|
||||||
|
'limit' => $list->listRows()
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user