流量池接口提交
This commit is contained in:
@@ -52,13 +52,18 @@ Route::group('v1/', function () {
|
||||
// 流量池相关
|
||||
Route::group('traffic/pool', function () {
|
||||
Route::get('', 'app\cunkebao\controller\traffic\GetPotentialListWithInCompanyV1Controller@index');
|
||||
Route::get('getUserJourney', 'app\cunkebao\controller\traffic\GetPotentialListWithInCompanyV1Controller@getUserJourney');
|
||||
|
||||
|
||||
|
||||
|
||||
Route::get('converted', 'app\cunkebao\controller\traffic\GetConvertedListWithInCompanyV1Controller@index');
|
||||
Route::get('types', 'app\cunkebao\controller\traffic\GetPotentialTypeSectionV1Controller@index');
|
||||
Route::get('sources', 'app\cunkebao\controller\traffic\GetTrafficSourceSectionV1Controller@index');
|
||||
Route::get('statistics', 'app\cunkebao\controller\traffic\GetPoolStatisticsV1Controller@index');
|
||||
|
||||
|
||||
Route::get('list', 'app\cunkebao\controller\TrafficController@getList');
|
||||
|
||||
});
|
||||
|
||||
// 工作台相关
|
||||
|
||||
@@ -7,6 +7,7 @@ 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;
|
||||
|
||||
/**
|
||||
* 流量池控制器
|
||||
@@ -22,21 +23,32 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
protected function makeWhere(array $params = []): array
|
||||
{
|
||||
if (!empty($keyword = $this->request->param('keyword'))) {
|
||||
$where[] = ['exp', "p.identifier LIKE '%{$keyword}%'"];
|
||||
$where[] = ['p.identifier|wa.nickname|wa.phone|wa.wechatId|wa.alias','like', '%'. $keyword .'%'];
|
||||
}
|
||||
|
||||
// 状态筛选
|
||||
if ($status = $this->request->param('status')) {
|
||||
if ($status = $this->request->param('addStatus')) {
|
||||
$where['s.status'] = $status;
|
||||
} else {
|
||||
$where['s.status'] = array('<>', TrafficSourceModel::STATUS_PASSED);
|
||||
}
|
||||
|
||||
// 来源的筛选
|
||||
if ($fromd = $this->request->param('fromd')) {
|
||||
$where['s.fromd'] = $fromd;
|
||||
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);
|
||||
@@ -48,33 +60,71 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
* @param array $where
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
protected function getPoolListByCompanyId(array $where): \think\Paginator
|
||||
protected function getPoolListByCompanyId(array $where)
|
||||
{
|
||||
$query = TrafficPoolModel::alias('p')
|
||||
->field(
|
||||
[
|
||||
'p.identifier nickname', 'p.mobile', 'p.wechatId', 'p.identifier',
|
||||
's.id', 's.fromd', 's.status', 's.createTime'
|
||||
'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')
|
||||
->order('s.id desc');
|
||||
->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);
|
||||
}
|
||||
|
||||
return $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();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,15 +136,54 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
{
|
||||
try {
|
||||
$result = $this->getPoolListByCompanyId( $this->makeWhere() );
|
||||
|
||||
$result = json_decode($result, true);
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'list' => $result->items(),
|
||||
'total' => $result->total(),
|
||||
'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]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user