189 lines
6.1 KiB
PHP
189 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace app\cunkebao\controller\traffic;
|
|
|
|
use app\common\model\TrafficPool as TrafficPoolModel;
|
|
use app\common\model\TrafficSource as TrafficSourceModel;
|
|
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
|
use app\cunkebao\controller\BaseController;
|
|
use library\ResponseHelper;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 流量池控制器
|
|
*/
|
|
class GetPotentialListWithInCompanyV1Controller extends BaseController
|
|
{
|
|
/**
|
|
* 构建查询条件
|
|
*
|
|
* @param array $params
|
|
* @return array
|
|
*/
|
|
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 .'%'];
|
|
}
|
|
|
|
// 状态筛选
|
|
if ($status = $this->request->param('addStatus')) {
|
|
$where['s.status'] = $status;
|
|
} else {
|
|
$where['s.status'] = array('<>', TrafficSourceModel::STATUS_PASSED);
|
|
}
|
|
|
|
// 来源的筛选
|
|
if ($fromd = $this->request->param('packageId')) {
|
|
if ($fromd != -1){
|
|
$where['tsp.id'] = $fromd;
|
|
}else{
|
|
$where[] = ['tsp.id',null];
|
|
}
|
|
|
|
}
|
|
|
|
if ($device = $this->request->param('device')) {
|
|
$where['d.deviceId'] = $device;
|
|
}
|
|
|
|
|
|
|
|
$where['s.companyId'] = $this->getUserInfo('companyId');
|
|
|
|
return array_merge($where, $params);
|
|
}
|
|
|
|
/**
|
|
* 获取流量池列表
|
|
*
|
|
* @param array $where
|
|
* @return \think\Paginator
|
|
*/
|
|
protected function getPoolListByCompanyId(array $where)
|
|
{
|
|
$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',
|
|
'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')
|
|
->group('p.identifier');
|
|
|
|
foreach ($where as $key => $value) {
|
|
if (is_numeric($key) && is_array($value) && isset($value[0]) && $value[0] === 'exp') {
|
|
$query->whereExp('', $value[1]);
|
|
continue;
|
|
}
|
|
if (is_array($value)) {
|
|
$query->where($key, ...$value);
|
|
continue;
|
|
}
|
|
$query->where($key, $value);
|
|
}
|
|
|
|
$result = $query->paginate($this->request->param('limit/d', 10), false, ['page' => $this->request->param('page/d', 1)]);
|
|
$list = $result->items();
|
|
$total = $result->total();
|
|
|
|
foreach ($list as &$item) {
|
|
//流量池筛选
|
|
$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);
|
|
$tags = array_merge($tags, $v);
|
|
}
|
|
$item['tags'] = $tags;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
unset($item);
|
|
$data = ['list' => $list, 'total' => $total];
|
|
return json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
}
|
|
|
|
/**
|
|
* 获取流量池列表
|
|
*
|
|
* @return \think\response\Json
|
|
*/
|
|
public function index()
|
|
{
|
|
try {
|
|
$result = $this->getPoolListByCompanyId( $this->makeWhere() );
|
|
$result = json_decode($result, true);
|
|
return ResponseHelper::success(
|
|
[
|
|
'list' => $result['list'],
|
|
'total' => $result['total'],
|
|
]
|
|
);
|
|
} catch (\Exception $e) {
|
|
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 用户旅程
|
|
* @return false|string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function getUserJourney()
|
|
{
|
|
$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不能为空']);
|
|
}
|
|
|
|
$query = Db::name('user_portrait')
|
|
->field('id,type,trafficPoolId,remark,count,createTime,updateTime')
|
|
->where(['trafficPoolId' => $userId]);
|
|
|
|
$total = $query->count();
|
|
|
|
$list = $query->order('createTime desc')
|
|
->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']);
|
|
}
|
|
return ResponseHelper::success(['list' => $list,'total'=>$total]);
|
|
|
|
}
|
|
|
|
}
|