From 658f0b4f2cddbc27d16f5036ea296761549f2185 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Wed, 23 Jul 2025 16:00:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E9=87=8F=E6=B1=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/application/cunkebao/config/route.php | 7 +- ...PotentialListWithInCompanyV1Controller.php | 119 +++++++++++++++--- 2 files changed, 110 insertions(+), 16 deletions(-) diff --git a/Server/application/cunkebao/config/route.php b/Server/application/cunkebao/config/route.php index 430c9516..8ba2d2d9 100644 --- a/Server/application/cunkebao/config/route.php +++ b/Server/application/cunkebao/config/route.php @@ -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'); + }); // 工作台相关 diff --git a/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php b/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php index 09442050..0ebfe936 100644 --- a/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php +++ b/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php @@ -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]); + + } + } \ No newline at end of file