代码提交

This commit is contained in:
wong
2025-07-29 17:04:00 +08:00
parent 9726518a46
commit 2b67bd6b77
5 changed files with 194 additions and 70 deletions

View File

@@ -23,7 +23,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
protected function makeWhere(array $params = []): array
{
if (!empty($keyword = $this->request->param('keyword'))) {
$where[] = ['p.identifier|wa.nickname|wa.phone|wa.wechatId|wa.alias','like', '%'. $keyword .'%'];
$where[] = ['p.identifier|wa.nickname|wa.phone|wa.wechatId|wa.alias', 'like', '%' . $keyword . '%'];
}
// 状态筛选
@@ -35,10 +35,10 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
// 来源的筛选
if ($fromd = $this->request->param('packageId')) {
if ($fromd != -1){
if ($fromd != -1) {
$where['tsp.id'] = $fromd;
}else{
$where[] = ['tsp.id',null];
} else {
$where[] = ['tsp.id', null];
}
}
@@ -48,7 +48,6 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
}
$where['s.companyId'] = $this->getUserInfo('companyId');
return array_merge($where, $params);
@@ -65,16 +64,16 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
$query = TrafficPoolModel::alias('p')
->field(
[
'p.id','p.identifier', 'p.mobile', 'p.wechatId', 'p.identifier',
's.fromd', 's.status', 's.createTime','s.companyId','s.sourceId','s.type',
'p.id', 'p.identifier', 'p.mobile', 'p.wechatId', 'p.identifier',
's.fromd', 's.status', 's.createTime', 's.companyId', 's.sourceId', 's.type',
'wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone',
]
)
->join('traffic_source s', 'p.identifier=s.identifier','left')
->join('wechat_account wa', 'p.identifier=wa.wechatId','left')
->join('traffic_source_package_item tspi', 'p.identifier = tspi.identifier AND s.companyId = tspi.companyId','left')
->join('traffic_source_package tsp', 'tspi.packageId=tsp.id','left')
->join('device_wechat_login d', 's.sourceId=d.wechatId','left')
->join('traffic_source s', 'p.identifier=s.identifier', 'left')
->join('wechat_account wa', 'p.identifier=wa.wechatId', 'left')
->join('traffic_source_package_item tspi', 'p.identifier = tspi.identifier AND s.companyId = tspi.companyId', 'left')
->join('traffic_source_package tsp', 'tspi.packageId=tsp.id', 'left')
->join('device_wechat_login d', 's.sourceId=d.wechatId', 'left')
->order('p.id DESC,s.id DESC')
->group('p.identifier');
@@ -90,7 +89,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
$query->where($key, $value);
}
$result = $query->paginate($this->request->param('limit/d', 10), false, ['page' => $this->request->param('page/d', 1)]);
$result = $query->paginate($this->request->param('limit/d', 10), false, ['page' => $this->request->param('page/d', 1)]);
$list = $result->items();
$total = $result->total();
@@ -98,29 +97,29 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
//流量池筛选
$package = Db::name('traffic_source_package_item')->alias('tspi')
->join('traffic_source_package p', 'tspi.packageId=p.id AND tspi.companyId=p.companyId')
->where(['tspi.companyId' => $item->companyId,'tspi.identifier' => $item->identifier])
->where(['tspi.companyId' => $item->companyId, 'tspi.identifier' => $item->identifier])
->column('p.name');
$package2 = Db::name('traffic_source_package_item')->alias('tspi')
->join('traffic_source_package p', 'tspi.packageId=p.id')
->where(['tspi.companyId' => $item->companyId,'tspi.identifier' => $item->identifier,'p.isSys' => 1])
->where(['tspi.companyId' => $item->companyId, 'tspi.identifier' => $item->identifier, 'p.isSys' => 1])
->column('p.name');
$packages = array_merge($package, $package2);
$item['packages'] = $packages;
if ($item->type == 1){
if ($item->type == 1) {
$tag = Db::name('wechat_friendship')->where(['wechatId' => $item->wechatId])->column('tags');
$tags = [];
foreach ($tag as $k => $v) {
$v = json_decode($v,true);
$tags = array_merge($tags, $v);
$v = json_decode($v, true);
if (!empty($v)) {
$tags = array_merge($tags, $v);
}
}
$item['tags'] = $tags;
}
}
unset($item);
$data = ['list' => $list, 'total' => $total];
@@ -135,11 +134,11 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
public function index()
{
try {
$result = $this->getPoolListByCompanyId( $this->makeWhere() );
$result = $this->getPoolListByCompanyId($this->makeWhere());
$result = json_decode($result, true);
return ResponseHelper::success(
[
'list' => $result['list'],
'list' => $result['list'],
'total' => $result['total'],
]
);
@@ -148,7 +147,62 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
}
}
public function getUser()
{
$userId = $this->request->param('userId', '');
if (empty($userId)) {
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
}
$item = TrafficPoolModel::alias('p')
->field(
[
'p.id', 'p.identifier', 'p.mobile', 'p.wechatId', 'p.identifier',
's.fromd', 's.status', 's.createTime', 's.companyId', 's.sourceId', 's.type',
'wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone',
]
)
->join('traffic_source s', 'p.identifier=s.identifier', 'left')
->join('wechat_account wa', 'p.identifier=wa.wechatId', 'left')
->join('traffic_source_package_item tspi', 'p.identifier = tspi.identifier AND s.companyId = tspi.companyId', 'left')
->join('traffic_source_package tsp', 'tspi.packageId=tsp.id', 'left')
->join('device_wechat_login d', 's.sourceId=d.wechatId', 'left')
->order('p.id DESC,s.id DESC')
->where(['p.id' => $userId])
->group('p.identifier')
->find();
//流量池筛选
$package = Db::name('traffic_source_package_item')->alias('tspi')
->join('traffic_source_package p', 'tspi.packageId=p.id AND tspi.companyId=p.companyId')
->where(['tspi.companyId' => $item->companyId, 'tspi.identifier' => $item->identifier])
->column('p.name');
$package2 = Db::name('traffic_source_package_item')->alias('tspi')
->join('traffic_source_package p', 'tspi.packageId=p.id')
->where(['tspi.companyId' => $item->companyId, 'tspi.identifier' => $item->identifier, 'p.isSys' => 1])
->column('p.name');
$packages = array_merge($package, $package2);
$item['packages'] = $packages;
if ($item->type == 1) {
$tag = Db::name('wechat_friendship')->where(['wechatId' => $item->wechatId])->column('tags');
$tags = [];
foreach ($tag as $k => $v) {
$v = json_decode($v, true);
if (!empty($v)) {
$tags = array_merge($tags, $v);
}
}
$item['tags'] = $tags;
}
}
/**
@@ -160,10 +214,10 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
*/
public function getUserJourney()
{
$page = $this->request->param('page',1);
$pageSize = $this->request->param('pageSize',10);
$userId = $this->request->param('userId','');
if(empty($userId)){
$page = $this->request->param('page', 1);
$pageSize = $this->request->param('pageSize', 10);
$userId = $this->request->param('userId', '');
if (empty($userId)) {
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
}
@@ -174,16 +228,49 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
$total = $query->count();
$list = $query->order('createTime desc')
->page($page,$pageSize)
->page($page, $pageSize)
->select();
foreach ($list as $k=>$v){
$list[$k]['createTime'] = date('Y-m-d H:i:s',$v['createTime']);
$list[$k]['updateTime'] = date('Y-m-d H:i:s',$v['updateTime']);
foreach ($list as $k => $v) {
$list[$k]['createTime'] = date('Y-m-d H:i:s', $v['createTime']);
$list[$k]['updateTime'] = date('Y-m-d H:i:s', $v['updateTime']);
}
return ResponseHelper::success(['list' => $list,'total'=>$total]);
return ResponseHelper::success(['list' => $list, 'total' => $total]);
}
public function getUserTags()
{
$userId = $this->request->param('userId', '');
if (empty($userId)) {
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
}
$data = Db::name('traffic_pool')->alias('tp')
->join(['s2_wechat_friend' => 'wf'], 'tp.wechatId=wf.wechatId', 'left')
->where(['tp.id' => $userId])
->order('tp.createTime desc')
->column('wf.id,wf.labels,wf.siteLabels');
$tags = [];
$siteLabels = [];
foreach ($data as $k => $v) {
$tag = json_decode($v['labels'], true);
$tag2 = json_decode($v['siteLabels'], true);
if (!empty($tag)) {
$tags = array_merge($tags, $tag);
}
if (!empty($tag2)) {
$siteLabels = array_merge($siteLabels, $tag2);
}
}
$tags = array_unique($tags);
$tags = array_values($tags);
$siteLabels = array_unique($siteLabels);
$siteLabels = array_values($siteLabels);
return ResponseHelper::success(['wechat' => $tags, 'siteLabels' => $siteLabels]);
}
}