From 0681c69d67435f7f67883729b0a1c95e31a9d9e5 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Wed, 20 Aug 2025 17:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=BB=BA=E7=BE=A4=E7=BE=A4?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=20+=20=E8=87=AA=E5=8A=A8=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WorkbenchController.php | 199 ++++++++++-------- ...PotentialListWithInCompanyV1Controller.php | 43 +++- .../cunkebao/validate/Workbench.php | 26 ++- 3 files changed, 164 insertions(+), 104 deletions(-) diff --git a/Server/application/cunkebao/controller/WorkbenchController.php b/Server/application/cunkebao/controller/WorkbenchController.php index 8f8c6d5f..599efbfa 100644 --- a/Server/application/cunkebao/controller/WorkbenchController.php +++ b/Server/application/cunkebao/controller/WorkbenchController.php @@ -123,11 +123,14 @@ class WorkbenchController extends Controller case self::TYPE_GROUP_CREATE: // 自动建群 $config = new WorkbenchGroupCreate; $config->workbenchId = $workbench->id; - $config->groupNamePrefix = $param['groupNamePrefix']; - $config->maxGroups = $param['maxGroups']; - $config->membersPerGroup = $param['membersPerGroup']; - $config->devices = json_encode($param['deveiceGroups']); - $config->targetGroups = json_encode($param['targetGroups']); + $config->devices = json_encode($param['deveiceGroups'], JSON_UNESCAPED_UNICODE); + $config->startTime = $param['startTime']; + $config->endTime = $param['endTime']; + $config->groupSizeMin = $param['groupSizeMin']; + $config->groupSizeMax = $param['groupSizeMax']; + $config->maxGroupsPerDay = $param['maxGroupsPerDay']; + $config->groupNameTemplate = $param['groupNameTemplate']; + $config->groupDescription = $param['groupDescription']; $config->createTime = time(); $config->updateTime = time(); $config->save(); @@ -197,6 +200,9 @@ class WorkbenchController extends Controller 'groupPush' => function ($query) { $query->field('workbenchId,pushType,startTime,endTime,maxPerDay,pushOrder,isLoop,status,groups,contentLibraries'); }, + 'groupCreate' => function($query) { + $query->field('workbenchId,devices,startTime,endTime,groupSizeMin,groupSizeMax,maxGroupsPerDay,groupNameTemplate,groupDescription'); + }, 'user' => function ($query) { $query->field('id,username'); } @@ -279,7 +285,6 @@ class WorkbenchController extends Controller if (!empty($item->groupCreate)) { $item->config = $item->groupCreate; $item->config->devices = json_decode($item->config->devices, true); - $item->config->targetGroups = json_decode($item->config->targetGroups, true); } unset($item->groupCreate, $item->group_create); break; @@ -385,11 +390,10 @@ class WorkbenchController extends Controller 'groupPush' => function ($query) { $query->field('workbenchId,pushType,startTime,endTime,maxPerDay,pushOrder,isLoop,status,groups,contentLibraries'); }, - // 'groupCreate' => function($query) { - // $query->field('workbenchId,groupNamePrefix,maxGroups,membersPerGroup,devices,targetGroups'); - // } + 'groupCreate' => function($query) { + $query->field('workbenchId,devices,startTime,endTime,groupSizeMin,groupSizeMax,maxGroupsPerDay,groupNameTemplate,groupDescription'); + } ]; - $workbench = Workbench::where([ ['id', '=', $id], ['userId', '=', $this->request->userInfo['id']], @@ -454,65 +458,6 @@ class WorkbenchController extends Controller $workbench->config = $workbench->groupPush; $workbench->config->wechatGroups = json_decode($workbench->config->groups, true); $workbench->config->contentLibraries = json_decode($workbench->config->contentLibraries, true); - - /* // 获取群组内容库 - $contentLibraryList = ContentLibrary::where('id', 'in', $workbench->config->contentLibraries) - ->field('id,name,sourceFriends,sourceGroups,keywordInclude,keywordExclude,aiEnabled,aiPrompt,timeEnabled,timeStart,timeEnd,status,sourceType,userId,createTime,updateTime') - ->with(['user' => function ($query) { - $query->field('id,username'); - }]) - ->order('id', 'desc') - ->select(); - - // 处理JSON字段 - foreach ($contentLibraryList as &$item) { - $item['sourceFriends'] = json_decode($item['sourceFriends'] ?: '[]', true); - $item['sourceGroups'] = json_decode($item['sourceGroups'] ?: '[]', true); - $item['keywordInclude'] = json_decode($item['keywordInclude'] ?: '[]', true); - $item['keywordExclude'] = json_decode($item['keywordExclude'] ?: '[]', true); - // 添加创建人名称 - $item['creatorName'] = $item['user']['username'] ?? ''; - $item['itemCount'] = Db::name('content_item')->where('libraryId', $item['id'])->count(); - - // 获取好友详细信息 - if (!empty($item['sourceFriends'] && $item['sourceType'] == 1)) { - $friendIds = $item['sourceFriends']; - $friendsInfo = []; - - if (!empty($friendIds)) { - // 查询好友信息,使用wechat_friendship表 - $friendsInfo = Db::name('wechat_friendship')->alias('wf') - ->field('wf.id,wf.wechatId, wa.nickname, wa.avatar') - ->join('wechat_account wa', 'wf.wechatId = wa.wechatId') - ->whereIn('wf.id', $friendIds) - ->select(); - } - - // 将好友信息添加到返回数据中 - $item['selectedFriends'] = $friendsInfo; - } - - - if (!empty($item['sourceGroups']) && $item['sourceType'] == 2) { - $groupIds = $item['sourceGroups']; - $groupsInfo = []; - - if (!empty($groupIds)) { - // 查询群组信息 - $groupsInfo = Db::name('wechat_group')->alias('g') - ->field('g.id, g.chatroomId, g.name, g.avatar, g.ownerWechatId') - ->whereIn('g.id', $groupIds) - ->select(); - } - - // 将群组信息添加到返回数据中 - $item['selectedGroups'] = $groupsInfo; - } - - unset($item['user']); // 移除关联数据 - } - $workbench->config->contentLibraryList = $contentLibraryList;*/ - unset($workbench->groupPush, $workbench->group_push); } break; @@ -521,7 +466,7 @@ class WorkbenchController extends Controller if (!empty($workbench->groupCreate)) { $workbench->config = $workbench->groupCreate; $workbench->config->deveiceGroups = json_decode($workbench->config->devices, true); - $workbench->config->targetGroups = json_decode($workbench->config->targetGroups, true); + unset($workbench->groupCreate, $workbench->group_create); } break; //流量分发 @@ -534,7 +479,6 @@ class WorkbenchController extends Controller $config_item = Db::name('workbench_traffic_config_item')->where(['workbenchId' => $workbench->id])->order('id DESC')->find(); $workbench->config->lastUpdated = !empty($config_item) ? date('Y-m-d H:i', $config_item['createTime']) : '--'; - //统计 $labels = $workbench->config->pools; $totalUsers = Db::table('s2_wechat_friend')->alias('wf') @@ -768,11 +712,14 @@ class WorkbenchController extends Controller case self::TYPE_GROUP_CREATE: $config = WorkbenchGroupCreate::where('workbenchId', $param['id'])->find(); if ($config) { - $config->groupNamePrefix = $param['groupNamePrefix']; - $config->maxGroups = $param['maxGroups']; - $config->membersPerGroup = $param['membersPerGroup']; - $config->devices = json_encode($param['deveiceGroups']); - $config->targetGroups = json_encode($param['targetGroups']); + $config->devices = json_encode($param['deveiceGroups'], JSON_UNESCAPED_UNICODE); + $config->startTime = $param['startTime']; + $config->endTime = $param['endTime']; + $config->groupSizeMin = $param['groupSizeMin']; + $config->groupSizeMax = $param['groupSizeMax']; + $config->maxGroupsPerDay = $param['maxGroupsPerDay']; + $config->groupNameTemplate = $param['groupNameTemplate']; + $config->groupDescription = $param['groupDescription']; $config->updateTime = time(); $config->save(); } @@ -954,12 +901,16 @@ class WorkbenchController extends Controller if ($config) { $newConfig = new WorkbenchGroupCreate; $newConfig->workbenchId = $newWorkbench->id; - $newConfig->groupNamePrefix = $config->groupNamePrefix; - $newConfig->maxGroups = $config->maxGroups; - $newConfig->membersPerGroup = $config->membersPerGroup; $newConfig->devices = $config->devices; - $newConfig->targetGroups = $config->targetGroups; - $newConfig->account = $config->account; + $newConfig->startTime = $config->startTime; + $newConfig->endTime = $config->endTime; + $newConfig->groupSizeMin = $config->groupSizeMin; + $newConfig->groupSizeMax = $config->groupSizeMax; + $newConfig->maxGroupsPerDay = $config->maxGroupsPerDay; + $newConfig->groupNameTemplate = $config->groupNameTemplate; + $newConfig->groupDescription = $config->groupDescription; + $newConfig->createTime = time(); + $newConfig->updateTime = time(); $newConfig->save(); } break; @@ -990,8 +941,6 @@ class WorkbenchController extends Controller // 查询点赞记录 $list = Db::name('workbench_auto_like_item')->alias('wali') ->join(['s2_wechat_moments' => 'wm'], 'wali.snsId = wm.snsId') - ->join(['s2_wechat_account' => 'wa'], 'wali.wechatAccountId = wa.id') - ->join(['s2_wechat_friend' => 'wf'], 'wali.wechatFriendId = wf.id') ->field([ 'wali.id', 'wali.workbenchId', @@ -1004,10 +953,6 @@ class WorkbenchController extends Controller 'wm.resUrls', 'wm.createTime as momentTime', 'wm.userName', - 'wa.nickName as operatorName', - 'wa.avatar as operatorAvatar', - 'wf.nickName as friendName', - 'wf.avatar as friendAvatar', ]) ->where($where) ->order('wali.createTime', 'desc') @@ -1015,8 +960,36 @@ class WorkbenchController extends Controller ->page($page, $limit) ->select(); + // 处理数据 foreach ($list as &$item) { + //处理用户信息 + $friend = Db::table('s2_wechat_friend') + ->where(['id' => $item['wechatFriendId']]) + ->field('nickName,avatar') + ->find(); + if(!empty($friend)){ + $item['friendName'] = $friend['nickName']; + $item['friendAvatar'] = $friend['avatar']; + }else{ + $item['friendName'] = ''; + $item['friendAvatar'] = ''; + } + + + //处理客服 + $friend = Db::table('s2_wechat_account') + ->where(['id' => $item['wechatAccountId']]) + ->field('nickName,avatar') + ->find(); + if(!empty($friend)){ + $item['operatorName'] = $friend['nickName']; + $item['operatorAvatar'] = $friend['avatar']; + }else{ + $item['operatorName'] = ''; + $item['operatorAvatar'] = ''; + } + // 处理时间格式 $item['likeTime'] = date('Y-m-d H:i:s', $item['likeTime']); $item['momentTime'] = !empty($item['momentTime']) ? date('Y-m-d H:i:s', $item['momentTime']) : ''; @@ -1573,4 +1546,56 @@ class WorkbenchController extends Controller } + public function getTrafficList() + { + $companyId = $this->request->userInfo['companyId']; + $page = $this->request->param('page', 1); + $limit = $this->request->param('limit', 10); + $keyword = $this->request->param('keyword', ''); + $workbenchId = $this->request->param('workbenchId', ''); + if (empty($workbenchId)) { + return json(['code' => 400, 'msg' => '参数错误']); + } + + $workbench = Db::name('workbench')->where(['id' => $workbenchId,'isDel' => 0,'companyId' => $companyId,'type' => 5])->find(); + + if (empty($workbench)){ + return json(['code' => 400, 'msg' => '该任务不存在或已删除']); + } + $query = Db::name('workbench_traffic_config_item')->alias('wtc') + ->join(['s2_wechat_friend' => 'wf'],'wtc.wechatFriendId = wf.id') + ->join('users u','wtc.wechatAccountId = u.s2_accountId','left') + ->field([ + 'wtc.id','wtc.isRecycle','wtc.isRecycle','wtc.createTime', + 'wf.wechatId','wf.alias','wf.nickname','wf.avatar','wf.gender','wf.phone', + 'u.account','u.username' + ]) + ->where(['wtc.workbenchId' => $workbenchId]) + ->order('wtc.id DESC'); + + if (!empty($keyword)){ + $query->where('wf.wechatId|wf.alias|wf.nickname|wf.phone|u.account|u.username','like','%' . $keyword . '%'); + } + + + + $total = $query->count(); + $list = $query->page($page, $limit)->select(); + + foreach ($list as &$item) { + $item['createTime'] = date('Y-m-d H:i:s', $item['createTime']); + } + unset($item); + + + + $data = [ + 'total' => $total, + 'list' => $list, + ]; + + return json(['code' => 200, 'msg' => '获取成功', 'data' => $data]); + + } + } \ No newline at end of file diff --git a/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php b/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php index e8f2260f..006e800b 100644 --- a/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php +++ b/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php @@ -364,12 +364,36 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController public function getPackage() { + + $page = $this->request->param('page',1); + $limit = $this->request->param('limit',10); + $keyword = $this->request->param('keyword',''); + $companyId = $this->getUserInfo('companyId'); - $package = Db::name('traffic_source_package') - ->whereIn('companyId', [$companyId,0]) - ->field('id,name') - ->select(); - return ResponseHelper::success($package); + $package = Db::name('traffic_source_package')->alias('tsp') + ->join('traffic_source_package_item tspi','tspi.packageId=tsp.id','left') + ->whereIn('tsp.companyId', [$companyId,0]) + ->field('tsp.id,tsp.name,tsp.description,tsp.createTime,count(tspi.id) as num') + ->group('tsp.id'); + + if (!empty($keyword)){ + $package->where('tsp.name|tsp.description','like','%'.$keyword.'%'); + } + + $list = $package->page($page,$limit)->select(); + $total = $package->count(); + + foreach ($list as $k => &$v) { + $v['createTime'] = !empty($v['createTime']) ? date('Y-m-d H:i:s', $v['createTime']) : ''; + } + unset($v); + + $data = [ + 'total' => $total, + 'list' => $list, + ]; + + return ResponseHelper::success($data); } @@ -405,7 +429,14 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController if (!empty($package)){ return ResponseHelper::error('该流量池名称已存在'); } - $packageId = Db::name('traffic_source_package')->insertGetId(['userId' => $userId,'companyId' => $companyId,'name' => $packageName,'isDel' => 0]); + $packageId = Db::name('traffic_source_package')->insertGetId([ + 'userId' => $userId, + 'companyId' => $companyId, + 'name' => $packageName, + 'matchingRules' => json_encode($this->makeWhere()), + 'createTime' => time(), + 'isDel' => 0, + ]); } diff --git a/Server/application/cunkebao/validate/Workbench.php b/Server/application/cunkebao/validate/Workbench.php index 7f801503..01fa360c 100644 --- a/Server/application/cunkebao/validate/Workbench.php +++ b/Server/application/cunkebao/validate/Workbench.php @@ -46,9 +46,10 @@ class Workbench extends Validate 'groups' => 'requireIf:type,3|array|min:1', 'contentLibraries' => 'requireIf:type,3|array|min:1', // 自动建群特有参数 - 'groupNamePrefix' => 'requireIf:type,4|max:50', - 'maxGroups' => 'requireIf:type,4|number|min:1', - 'membersPerGroup' => 'requireIf:type,4|number|min:1', + 'groupNameTemplate' => 'requireIf:type,4|max:50', + 'maxGroupsPerDay' => 'requireIf:type,4|number|min:1', + 'groupSizeMin' => 'requireIf:type,4|number|min:1', + 'groupSizeMax' => 'requireIf:type,4|number|min:1', // 流量分发特有参数 'distributeType' => 'requireIf:type,5|in:1,2', 'maxPerDay' => 'requireIf:type,5|number|min:1', @@ -121,14 +122,17 @@ class Workbench extends Validate 'groups.array' => '推送群组格式错误', 'groups.min' => '至少选择一个推送群组', // 自动建群相关提示 - 'groupNamePrefix.requireIf' => '请设置群名称前缀', - 'groupNamePrefix.max' => '群名称前缀最多50个字符', - 'maxGroups.requireIf' => '请设置最大建群数量', - 'maxGroups.number' => '最大建群数量必须为数字', - 'maxGroups.min' => '最大建群数量必须大于0', - 'membersPerGroup.requireIf' => '请设置每个群的人数', - 'membersPerGroup.number' => '每个群的人数必须为数字', - 'membersPerGroup.min' => '每个群的人数必须大于0', + 'groupNameTemplate.requireIf' => '请设置群名称前缀', + 'groupNameTemplate.max' => '群名称前缀最多50个字符', + 'maxGroupsPerDay.requireIf' => '请设置最大建群数量', + 'maxGroupsPerDay.number' => '最大建群数量必须为数字', + 'maxGroupsPerDay.min' => '最大建群数量必须大于0', + 'groupSizeMin.requireIf' => '请设置每个群的人数', + 'groupSizeMin.number' => '每个群的人数必须为数字', + 'groupSizeMin.min' => '每个群的人数必须大于0', + 'groupSizeMax.requireIf' => '请设置每个群的人数', + 'groupSizeMax.number' => '每个群的人数必须为数字', + 'groupSizeMax.min' => '每个群的人数必须大于0', // 流量分发相关提示 'distributeType.requireIf' => '请选择流量分发类型', 'distributeType.in' => '流量分发类型错误',