Files
cunkebao_v3/Server/application/superadmin/controller/traffic/GetPoolDetailController.php

126 lines
3.9 KiB
PHP
Raw Normal View History

2025-04-11 15:04:57 +08:00
<?php
2025-04-22 14:04:17 +08:00
namespace app\superadmin\controller\traffic;
use app\common\model\Company as CompanyModel;
use app\common\model\TrafficPool as TrafficPoolModel;
use app\common\model\TrafficSource as TrafficSourceModel;
use app\common\model\WechatAccount as WechatAccountModel;
use app\common\model\WechatTag as WechatTagModel;
2025-04-11 15:04:57 +08:00
use think\Controller;
2025-04-12 19:06:00 +08:00
use think\facade\Request;
2025-04-11 15:04:57 +08:00
/**
* 客户池控制器
*/
2025-04-22 14:04:17 +08:00
class GetPoolDetailController extends Controller
2025-04-11 15:04:57 +08:00
{
2025-04-13 13:48:22 +08:00
/**
* 获取客户详情
* @return \think\response\Json
*/
2025-04-22 14:04:17 +08:00
public function index()
2025-04-13 13:48:22 +08:00
{
// 获取参数
$id = Request::param('id/d');
if (!$id) {
return json(['code' => 400, 'msg' => '参数错误']);
}
try {
// 查询流量来源信息
2025-04-22 14:04:17 +08:00
$sourceInfo = TrafficSourceModel::alias('ts')
2025-04-15 16:10:09 +08:00
->join('company c', 'ts.companyId = c.companyId', 'LEFT')
2025-04-13 13:48:22 +08:00
->field([
'ts.fromd as source',
'ts.createTime as addTime',
'c.name as projectName',
'ts.identifier'
])
->where('ts.id', $id)
->find();
if (!$sourceInfo) {
return json(['code' => 404, 'msg' => '记录不存在']);
}
// 查询客户池信息
$poolInfo = TrafficPoolModel::where('identifier', $sourceInfo['identifier'])
->field('wechatId')
->find();
$result = [
'source' => $sourceInfo['source'],
'addTime' => $sourceInfo['addTime'] ? date('Y-m-d H:i:s', $sourceInfo['addTime']) : null,
2025-04-13 13:48:22 +08:00
'projectName' => $sourceInfo['projectName']
];
// 如果存在微信ID查询微信账号信息
if ($poolInfo && $poolInfo['wechatId']) {
// 查询微信账号信息
2025-04-22 14:04:17 +08:00
$wechatInfo = WechatAccountModel::where('wechatId', $poolInfo['wechatId'])
2025-04-13 13:48:22 +08:00
->field('avatar,nickname,region,gender')
->find();
if ($wechatInfo) {
$result = array_merge($result, [
'avatar' => $wechatInfo['avatar'],
'nickname' => $wechatInfo['nickname'],
'region' => $wechatInfo['region'],
'gender' => $this->formatGender($wechatInfo['gender'])
]);
// 查询标签信息
2025-04-22 14:04:17 +08:00
$tagInfo = WechatTagModel::where('wechatId', $poolInfo['wechatId'])
2025-04-13 13:48:22 +08:00
->field('tags')
->find();
if ($tagInfo) {
2025-04-22 14:04:17 +08:00
$result['tags'] = is_string($tagInfo['tags']) ?
json_decode($tagInfo['tags'], true) :
2025-04-13 13:48:22 +08:00
$tagInfo['tags'];
} else {
$result['tags'] = [];
}
}
} else {
$result = array_merge($result, [
'avatar' => '',
'nickname' => '未知',
'region' => '未知',
'gender' => $this->formatGender(0),
'tags' => []
]);
}
return json([
'code' => 200,
'msg' => '获取成功',
'data' => $result
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '系统错误:' . $e->getMessage()
]);
}
}
/**
* 格式化性别显示
* @param int $gender
* @return string
*/
protected function formatGender($gender)
{
2025-04-22 14:04:17 +08:00
switch ($gender) {
2025-04-13 13:48:22 +08:00
case 1:
return '男';
case 2:
return '女';
default:
return '保密';
}
}
2025-04-11 15:04:57 +08:00
}