From 4948f9a0979e26a9c3933b7e8fc74a9db562dd54 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Mon, 21 Jul 2025 16:56:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E9=87=8F=E6=B1=A0=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cunkebao/controller/TrafficController.php | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Server/application/cunkebao/controller/TrafficController.php diff --git a/Server/application/cunkebao/controller/TrafficController.php b/Server/application/cunkebao/controller/TrafficController.php new file mode 100644 index 00000000..c00154de --- /dev/null +++ b/Server/application/cunkebao/controller/TrafficController.php @@ -0,0 +1,121 @@ +request->param('page',1); + $pageSize = $this->request->param('pageSize',10); + $device = $this->request->param('device',''); + $packageId = $this->request->param('packageId',''); // 流量池id + $userValue = $this->request->param('userValue',''); // 1高价值客户 2中价值客户 3低价值客户 + $addStatus = $this->request->param('addStatus',''); // 1待添加 2已添加 3添加失败 4重复用户 + $keyword = $this->request->param('keyword',''); + + $companyId = $this->request->userInfo['companyId']; + + // 1 文字 3图片 47动态图片 34语言 43视频 42名片 40/20链接 49文件 419430449转账 436207665红包 + + $where = []; + + // 添加筛选条件 + if (!empty($device)) { + $where['d.id'] = $device; + } + + if (!empty($packageId)) { + $where['tp.id'] = $packageId; + } + + if (!empty($userValue)) { + $where['tp.userValue'] = $userValue; + } + + if (!empty($addStatus)) { + $where['tp.addStatus'] = $addStatus; + } + + + // 构建查询 - 通过traffic_pool的identifier关联wechat_account的wechatId、alias或phone + $query = Db::name('traffic_pool')->alias('tp') + ->join('wechat_account wa', 'wa.wechatId = tp.wechatId', 'LEFT') + ->field('tp.id, tp.identifier,tp.createTime, tp.updateTime, + wa.wechatId, wa.alias, wa.phone, wa.nickname, wa.avatar') + ->where($where); + + // 关键词搜索 - 支持通过wechat_friendship的identifier关联wechat_account的wechatId、alias或phone + if (!empty($keyword)) { + $query->where(function($q) use ($keyword) { + $q->where('tp.identifier', 'like', '%' . $keyword . '%') + ->whereOr('wa.wechatId', 'like', '%' . $keyword . '%') + ->whereOr('wa.alias', 'like', '%' . $keyword . '%') + ->whereOr('wa.phone', 'like', '%' . $keyword . '%') + ->whereOr('wa.nickname', 'like', '%' . $keyword . '%'); + }); + } + + // 获取总数 + $total = $query->count(); + + + // 分页查询 + $list = $query->order('tp.createTime desc') + ->group('tp.identifier') + ->order('tp.id desc') + ->page($page, $pageSize) + ->select(); + + + + return json([ + 'code' => 200, + 'msg' => '获取成功', + 'data' => [ + 'list' => $list, + 'total' => $total, + ] + ]); + } + + + /** + * 用户旅程 + * @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 json_encode(['code' => 200,'data'=>['list' => $list,'total'=>$total],'获取成功']); + } + + +} \ No newline at end of file