2025-05-13 12:10:39 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\cunkebao\controller\traffic;
|
|
|
|
|
|
|
|
|
|
use app\common\model\TrafficPool as TrafficPoolModel;
|
2025-05-13 17:21:58 +08:00
|
|
|
use app\common\model\TrafficSource as TrafficSourceModel;
|
2025-05-13 12:10:39 +08:00
|
|
|
use app\common\model\WechatFriendShip as WechatFriendShipModel;
|
|
|
|
|
use app\cunkebao\controller\BaseController;
|
|
|
|
|
use library\ResponseHelper;
|
2025-07-23 16:00:01 +08:00
|
|
|
use think\Db;
|
2025-05-13 12:10:39 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 流量池控制器
|
|
|
|
|
*/
|
2025-05-13 14:43:21 +08:00
|
|
|
class GetPotentialListWithInCompanyV1Controller extends BaseController
|
2025-05-13 12:10:39 +08:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 构建查询条件
|
|
|
|
|
*
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function makeWhere(array $params = []): array
|
|
|
|
|
{
|
2025-08-15 15:37:00 +08:00
|
|
|
$keyword = $this->request->param('keyword','');
|
|
|
|
|
$device = $this->request->param('deviceId');
|
|
|
|
|
$status = $this->request->param('addStatus','');
|
|
|
|
|
$taskId = $this->request->param('taskId','');
|
|
|
|
|
$packageId = $this->request->param('packageId','');
|
|
|
|
|
$where = [];
|
|
|
|
|
if (!empty($keyword)) {
|
2025-07-29 17:04:00 +08:00
|
|
|
$where[] = ['p.identifier|wa.nickname|wa.phone|wa.wechatId|wa.alias', 'like', '%' . $keyword . '%'];
|
2025-05-13 12:10:39 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-13 15:36:02 +08:00
|
|
|
// 状态筛选
|
2025-08-15 15:37:00 +08:00
|
|
|
if (!empty($status)) {
|
|
|
|
|
if ($status == 1){
|
|
|
|
|
$where[] = ['s.status','=',4];
|
|
|
|
|
}elseif ($status == 2){
|
|
|
|
|
$where[] = ['s.status','=',0];
|
|
|
|
|
}elseif ($status == -1){
|
|
|
|
|
$where[] = ['s.status','=',2];
|
|
|
|
|
}elseif ($status == 3){
|
|
|
|
|
$where[] = ['s.status','=',2];
|
|
|
|
|
}
|
2025-05-13 15:36:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 来源的筛选
|
2025-08-15 15:37:00 +08:00
|
|
|
if ($packageId) {
|
|
|
|
|
if ($packageId != -1) {
|
|
|
|
|
$where[] = ['tsp.id','=',$packageId];
|
2025-07-29 17:04:00 +08:00
|
|
|
} else {
|
2025-08-15 15:37:00 +08:00
|
|
|
$where[] = ['tsp.id','=', null];
|
2025-07-23 16:00:01 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-13 15:36:02 +08:00
|
|
|
}
|
|
|
|
|
|
2025-08-15 15:37:00 +08:00
|
|
|
if (!empty($device)) {
|
|
|
|
|
$where[] = ['d.deviceId','=',$device];
|
2025-07-23 16:00:01 +08:00
|
|
|
}
|
|
|
|
|
|
2025-08-15 15:37:00 +08:00
|
|
|
if (!empty($taskId)){
|
|
|
|
|
$where[] = ['t.sceneId','=',$taskId];
|
|
|
|
|
}
|
|
|
|
|
$where[] = ['s.companyId','=',$this->getUserInfo('companyId')];
|
2025-07-23 16:00:01 +08:00
|
|
|
|
2025-08-15 15:37:00 +08:00
|
|
|
return $where;
|
2025-05-13 12:10:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取流量池列表
|
|
|
|
|
*
|
|
|
|
|
* @param array $where
|
|
|
|
|
* @return \think\Paginator
|
|
|
|
|
*/
|
2025-08-15 15:37:00 +08:00
|
|
|
protected function getPoolListByCompanyId(array $where,$isPage = true)
|
2025-05-13 12:10:39 +08:00
|
|
|
{
|
2025-05-13 15:36:02 +08:00
|
|
|
$query = TrafficPoolModel::alias('p')
|
2025-05-13 12:10:39 +08:00
|
|
|
->field(
|
|
|
|
|
[
|
2025-07-29 17:04:00 +08:00
|
|
|
'p.id', 'p.identifier', 'p.mobile', 'p.wechatId', 'p.identifier',
|
|
|
|
|
's.fromd', 's.status', 's.createTime', 's.companyId', 's.sourceId', 's.type',
|
2025-08-15 15:37:00 +08:00
|
|
|
'wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone','wa.alias'
|
2025-05-13 12:10:39 +08:00
|
|
|
]
|
|
|
|
|
)
|
2025-08-15 15:37:00 +08:00
|
|
|
->join('traffic_source s', 'p.identifier=s.identifier')
|
2025-07-29 17:04:00 +08:00
|
|
|
->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')
|
2025-08-15 15:37:00 +08:00
|
|
|
->where($where);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = $query->order('p.id DESC,s.id DESC')->group('p.identifier');
|
|
|
|
|
|
|
|
|
|
if ($isPage) {
|
|
|
|
|
$result = $query->paginate($this->request->param('limit/d', 10), false, ['page' => $this->request->param('page/d', 1)]);
|
|
|
|
|
$list = $result->items();
|
|
|
|
|
$total = $result->total();
|
|
|
|
|
}else{
|
|
|
|
|
$list = $result->select();
|
|
|
|
|
$total = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($isPage) {
|
|
|
|
|
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.identifier' => $item->identifier])
|
|
|
|
|
->whereIn('tspi.companyId', [0, $item->companyId])
|
|
|
|
|
->column('p.name');
|
|
|
|
|
$item['packages'] = $package;
|
|
|
|
|
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);
|
|
|
|
|
if (!empty($v)) {
|
|
|
|
|
$tags = array_merge($tags, $v);
|
|
|
|
|
}
|
2025-07-29 17:04:00 +08:00
|
|
|
}
|
2025-08-15 15:37:00 +08:00
|
|
|
$item['tags'] = $tags;
|
2025-07-23 16:00:01 +08:00
|
|
|
}
|
|
|
|
|
|
2025-08-15 15:37:00 +08:00
|
|
|
}
|
2025-07-23 16:00:01 +08:00
|
|
|
}
|
|
|
|
|
unset($item);
|
|
|
|
|
$data = ['list' => $list, 'total' => $total];
|
|
|
|
|
return json_encode($data, JSON_UNESCAPED_UNICODE);
|
2025-05-13 12:10:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取流量池列表
|
|
|
|
|
*
|
|
|
|
|
* @return \think\response\Json
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-07-29 17:04:00 +08:00
|
|
|
$result = $this->getPoolListByCompanyId($this->makeWhere());
|
2025-07-23 16:00:01 +08:00
|
|
|
$result = json_decode($result, true);
|
2025-05-13 12:10:39 +08:00
|
|
|
return ResponseHelper::success(
|
|
|
|
|
[
|
2025-07-29 17:04:00 +08:00
|
|
|
'list' => $result['list'],
|
2025-07-23 16:00:01 +08:00
|
|
|
'total' => $result['total'],
|
2025-05-13 12:10:39 +08:00
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-23 16:00:01 +08:00
|
|
|
|
2025-07-29 17:04:00 +08:00
|
|
|
public function getUser()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$userId = $this->request->param('userId', '');
|
2025-07-30 17:51:18 +08:00
|
|
|
$companyId = $this->getUserInfo('companyId');
|
|
|
|
|
|
2025-07-29 17:04:00 +08:00
|
|
|
if (empty($userId)) {
|
|
|
|
|
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 17:51:18 +08:00
|
|
|
$total = [
|
|
|
|
|
'msg' => 0,
|
|
|
|
|
'money' => 0,
|
|
|
|
|
'isFriend' => false,
|
|
|
|
|
'percentage' => '0.00%',
|
|
|
|
|
];
|
2025-07-29 17:04:00 +08:00
|
|
|
|
2025-07-30 17:51:18 +08:00
|
|
|
|
|
|
|
|
$data = TrafficPoolModel::alias('p')
|
|
|
|
|
->field(['p.id', 'p.identifier', 'p.wechatId',
|
|
|
|
|
'wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone','wa.alias'])
|
2025-07-29 17:04:00 +08:00
|
|
|
->join('wechat_account wa', 'p.identifier=wa.wechatId', 'left')
|
2025-07-30 17:51:18 +08:00
|
|
|
->order('p.id DESC')
|
2025-07-29 17:04:00 +08:00
|
|
|
->where(['p.id' => $userId])
|
|
|
|
|
->group('p.identifier')
|
|
|
|
|
->find();
|
2025-07-30 17:51:18 +08:00
|
|
|
$data['lastMsgTime'] = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//来源
|
|
|
|
|
$source = Db::name('traffic_source')->alias('ts')
|
|
|
|
|
->field(['wa.nickname', 'wa.avatar', 'wa.gender','wa.phone','wa.wechatId','wa.alias',
|
|
|
|
|
'ts.createTime',
|
|
|
|
|
'wf.id as friendId','wf.wechatAccountId'])
|
|
|
|
|
->join('wechat_account wa', 'ts.sourceId=wa.wechatId', 'left')
|
|
|
|
|
->join(['s2_wechat_friend' => 'wf'], 'wa.wechatId=wf.ownerWechatId', 'left')
|
|
|
|
|
->where(['ts.companyId' => $companyId,'ts.identifier' => $data['identifier'],'wf.wechatId' => $data['wechatId']])
|
|
|
|
|
->order('ts.createTime DESC')
|
|
|
|
|
->select();
|
|
|
|
|
|
|
|
|
|
$wechatFriendId = [];
|
|
|
|
|
if (!empty($source)) {
|
|
|
|
|
$total['isFriend'] = true;
|
|
|
|
|
foreach ($source as &$v) {
|
|
|
|
|
$wechatFriendId[] = $v['friendId'];
|
|
|
|
|
//最后消息
|
|
|
|
|
$v['createTime'] = date('Y-m-d H:i:s', $v['createTime']);
|
|
|
|
|
$lastMsgTime = Db::table('s2_wechat_message')
|
|
|
|
|
->where(['wechatFriendId' => $v['friendId'],'wechatAccountId' => $v['wechatAccountId']])
|
|
|
|
|
->value('wechatTime');
|
|
|
|
|
$v['lastMsgTime'] = !empty($lastMsgTime) ? date('Y-m-d H:i:s', $lastMsgTime) : '';
|
|
|
|
|
|
|
|
|
|
//设备信息
|
|
|
|
|
$device = Db::name('device_wechat_login')->alias('dwl')
|
|
|
|
|
->join('device d','d.id=dwl.deviceId')
|
|
|
|
|
->where(['dwl.wechatId' => $v['wechatId']])
|
|
|
|
|
->field('d.id,d.memo,d.imei,d.brand,d.extra,d.alive')
|
|
|
|
|
->order('dwl.id DESC')
|
|
|
|
|
->find();
|
|
|
|
|
$extra = json_decode($device['extra'],true);
|
|
|
|
|
unset($device['extra']);
|
|
|
|
|
$device['address'] = !empty($extra['address']) ? $extra['address'] : '';
|
|
|
|
|
$v['device'] = $device;
|
|
|
|
|
}
|
|
|
|
|
unset($v);
|
|
|
|
|
}
|
|
|
|
|
$data['source'] = $source;
|
2025-07-29 17:04:00 +08:00
|
|
|
|
|
|
|
|
|
2025-07-30 17:51:18 +08:00
|
|
|
//流量池
|
2025-07-29 17:04:00 +08:00
|
|
|
$package = Db::name('traffic_source_package_item')->alias('tspi')
|
|
|
|
|
->join('traffic_source_package p', 'tspi.packageId=p.id AND tspi.companyId=p.companyId')
|
2025-07-30 17:51:18 +08:00
|
|
|
->where(['tspi.companyId' => $companyId, 'tspi.identifier' => $data['identifier']])
|
2025-07-29 17:04:00 +08:00
|
|
|
->column('p.name');
|
|
|
|
|
$package2 = Db::name('traffic_source_package_item')->alias('tspi')
|
|
|
|
|
->join('traffic_source_package p', 'tspi.packageId=p.id')
|
2025-07-30 17:51:18 +08:00
|
|
|
->where(['tspi.companyId' => $companyId, 'tspi.identifier' => $data['identifier']])
|
2025-07-29 17:04:00 +08:00
|
|
|
->column('p.name');
|
|
|
|
|
$packages = array_merge($package, $package2);
|
2025-07-30 17:51:18 +08:00
|
|
|
$data['packages'] = $packages;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($wechatFriendId)){
|
|
|
|
|
//消息统计
|
|
|
|
|
$msgTotal = Db::table('s2_wechat_message')
|
|
|
|
|
->whereIn('wechatFriendId', $wechatFriendId)
|
|
|
|
|
->count();
|
|
|
|
|
$total['msg'] = $msgTotal;
|
|
|
|
|
|
|
|
|
|
//金额计算
|
|
|
|
|
$money = Db::table('s2_wechat_message')
|
|
|
|
|
->whereIn('wechatFriendId', $wechatFriendId)
|
|
|
|
|
->where(['isSend' => 1,'msgType' => 419430449])
|
|
|
|
|
->select();
|
|
|
|
|
if (!empty($money)){
|
|
|
|
|
foreach ($money as $v){
|
|
|
|
|
$content = json_decode($v['content'],true);
|
|
|
|
|
if ($content['paysubtype'] == 1){
|
|
|
|
|
$number = number_format(str_replace("¥", "", $content['feedesc']), 2);
|
|
|
|
|
$floatValue = floatval($number);
|
|
|
|
|
$total['money'] += $floatValue;
|
|
|
|
|
}
|
2025-07-29 17:04:00 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 17:51:18 +08:00
|
|
|
$taskNum = Db::name('task_customer')->alias('tc')
|
|
|
|
|
->join('customer_acquisition_task t','tc.task_id=t.id')
|
|
|
|
|
->where(['t.companyId' => $companyId,'t.deleteTime' => 0])
|
|
|
|
|
->whereIn('tc.phone',[$data['phone'], $data['wechatId'], $data['alias']])
|
|
|
|
|
->count();
|
|
|
|
|
|
|
|
|
|
$passNum = Db::name('task_customer')->alias('tc')
|
|
|
|
|
->join('customer_acquisition_task t','tc.task_id=t.id')
|
|
|
|
|
->where(['t.companyId' => $companyId,'t.deleteTime' => 0,'tc.status' => 4])
|
|
|
|
|
->whereIn('tc.phone',[$data['phone'], $data['wechatId'], $data['alias']])
|
|
|
|
|
->count();
|
|
|
|
|
|
|
|
|
|
if (!empty($taskNum) && !empty($passNum)){
|
|
|
|
|
$percentage = number_format(($taskNum / $passNum) * 100, 2);
|
|
|
|
|
$total['percentage'] = $percentage;
|
|
|
|
|
}
|
2025-08-06 18:00:50 +08:00
|
|
|
|
2025-07-30 17:51:18 +08:00
|
|
|
|
2025-07-23 16:00:01 +08:00
|
|
|
|
2025-07-30 17:51:18 +08:00
|
|
|
$data['total'] = $total;
|
|
|
|
|
$data['rmm'] = [
|
|
|
|
|
'r' => 0,
|
|
|
|
|
'f' => 0,
|
|
|
|
|
'm' => 0,
|
|
|
|
|
];
|
|
|
|
|
return ResponseHelper::success($data);
|
2025-07-29 17:04:00 +08:00
|
|
|
}
|
2025-07-23 16:00:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户旅程
|
|
|
|
|
* @return false|string
|
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
* @throws \think\exception\DbException
|
|
|
|
|
*/
|
|
|
|
|
public function getUserJourney()
|
|
|
|
|
{
|
2025-07-29 17:04:00 +08:00
|
|
|
$page = $this->request->param('page', 1);
|
|
|
|
|
$pageSize = $this->request->param('pageSize', 10);
|
|
|
|
|
$userId = $this->request->param('userId', '');
|
|
|
|
|
if (empty($userId)) {
|
2025-07-23 16:00:01 +08:00
|
|
|
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')
|
2025-07-29 17:04:00 +08:00
|
|
|
->page($page, $pageSize)
|
2025-07-23 16:00:01 +08:00
|
|
|
->select();
|
|
|
|
|
|
|
|
|
|
|
2025-07-29 17:04:00 +08:00
|
|
|
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']);
|
2025-07-23 16:00:01 +08:00
|
|
|
}
|
2025-07-29 17:04:00 +08:00
|
|
|
return ResponseHelper::success(['list' => $list, 'total' => $total]);
|
|
|
|
|
|
|
|
|
|
}
|
2025-07-23 16:00:01 +08:00
|
|
|
|
2025-07-29 17:04:00 +08:00
|
|
|
|
|
|
|
|
public function getUserTags()
|
|
|
|
|
{
|
|
|
|
|
$userId = $this->request->param('userId', '');
|
2025-08-06 18:00:50 +08:00
|
|
|
$companyId = $this->getUserInfo('companyId');
|
2025-07-29 17:04:00 +08:00
|
|
|
if (empty($userId)) {
|
|
|
|
|
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
|
|
|
|
|
}
|
|
|
|
|
$data = Db::name('traffic_pool')->alias('tp')
|
2025-08-06 18:00:50 +08:00
|
|
|
->join('wechat_friendship f', 'tp.wechatId=f.wechatId AND f.companyId='.$companyId, 'left')
|
|
|
|
|
->join(['s2_wechat_friend' => 'wf'], 'f.wechatId=wf.wechatId', 'left')
|
2025-07-29 17:04:00 +08:00
|
|
|
->where(['tp.id' => $userId])
|
|
|
|
|
->order('tp.createTime desc')
|
|
|
|
|
->column('wf.id,wf.labels,wf.siteLabels');
|
2025-08-06 18:00:50 +08:00
|
|
|
if (empty($data)) {
|
|
|
|
|
return ResponseHelper::success(['wechat' => [], 'siteLabels' => []]);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-29 17:04:00 +08:00
|
|
|
|
|
|
|
|
$tags = [];
|
|
|
|
|
$siteLabels = [];
|
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
|
$tag = json_decode($v['labels'], true);
|
|
|
|
|
$tag2 = json_decode($v['siteLabels'], true);
|
|
|
|
|
if (!empty($tag)) {
|
|
|
|
|
$tags = array_merge($tags, $tag);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($tag2)) {
|
|
|
|
|
$siteLabels = array_merge($siteLabels, $tag2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$tags = array_unique($tags);
|
|
|
|
|
$tags = array_values($tags);
|
|
|
|
|
$siteLabels = array_unique($siteLabels);
|
|
|
|
|
$siteLabels = array_values($siteLabels);
|
|
|
|
|
return ResponseHelper::success(['wechat' => $tags, 'siteLabels' => $siteLabels]);
|
2025-07-23 16:00:01 +08:00
|
|
|
}
|
|
|
|
|
|
2025-08-15 15:37:00 +08:00
|
|
|
|
|
|
|
|
public function getPackage()
|
|
|
|
|
{
|
2025-08-20 17:35:34 +08:00
|
|
|
|
|
|
|
|
$page = $this->request->param('page',1);
|
|
|
|
|
$limit = $this->request->param('limit',10);
|
|
|
|
|
$keyword = $this->request->param('keyword','');
|
|
|
|
|
|
2025-08-15 15:37:00 +08:00
|
|
|
$companyId = $this->getUserInfo('companyId');
|
2025-08-20 17:35:34 +08:00
|
|
|
$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);
|
2025-08-15 15:37:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function addPackage()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$addPackageId = $this->request->param('addPackageId','');
|
|
|
|
|
$packageName = $this->request->param('packageName','');
|
|
|
|
|
$userIds = $this->request->param('userIds',[]);
|
|
|
|
|
$companyId = $this->getUserInfo('companyId');
|
|
|
|
|
$userId = $this->getUserInfo('id');
|
|
|
|
|
if (empty($addPackageId) && empty($packageName)){
|
|
|
|
|
return ResponseHelper::error('存储的流量池不能为空');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($addPackageId)){
|
|
|
|
|
$package = Db::name('traffic_source_package')
|
|
|
|
|
->where(['id' => $addPackageId,'isDel' => 0])
|
|
|
|
|
->whereIn('companyId', [$companyId,0])
|
|
|
|
|
->field('id,name')
|
|
|
|
|
->find();
|
|
|
|
|
if (empty($package)){
|
|
|
|
|
return ResponseHelper::error('该流量池不存在');
|
|
|
|
|
}
|
|
|
|
|
$packageId = $package['id'];
|
|
|
|
|
}else{
|
|
|
|
|
$package = Db::name('traffic_source_package')
|
|
|
|
|
->where(['isDel' => 0,'name' => $packageName])
|
|
|
|
|
->whereIn('companyId', [$companyId,0])
|
|
|
|
|
->field('id,name')
|
|
|
|
|
->find();
|
|
|
|
|
if (!empty($package)){
|
|
|
|
|
return ResponseHelper::error('该流量池名称已存在');
|
|
|
|
|
}
|
2025-08-20 17:35:34 +08:00
|
|
|
$packageId = Db::name('traffic_source_package')->insertGetId([
|
|
|
|
|
'userId' => $userId,
|
|
|
|
|
'companyId' => $companyId,
|
|
|
|
|
'name' => $packageName,
|
|
|
|
|
'matchingRules' => json_encode($this->makeWhere()),
|
|
|
|
|
'createTime' => time(),
|
|
|
|
|
'isDel' => 0,
|
|
|
|
|
]);
|
2025-08-15 15:37:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($userIds)){
|
|
|
|
|
if (!is_array($userIds)){
|
|
|
|
|
return ResponseHelper::error('选择的用户类型错误');
|
|
|
|
|
}
|
|
|
|
|
$result = Db::name('traffic_pool')->alias('tp')
|
|
|
|
|
->join('traffic_source tc','tp.identifier=tc.identifier')
|
|
|
|
|
->whereIn('tp.id',$userIds)
|
|
|
|
|
->where(['companyId' => $companyId])
|
|
|
|
|
->group('tp.identifier')
|
|
|
|
|
->column('tc.identifier');
|
|
|
|
|
}else{
|
|
|
|
|
$result = $this->getPoolListByCompanyId($this->makeWhere(),false);
|
|
|
|
|
$result = json_decode($result, true);
|
|
|
|
|
$result = array_column($result['list'],'identifier');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1000条为一组进行批量处理
|
|
|
|
|
$batchSize = 1000;
|
|
|
|
|
$totalRows = count($result);
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < $totalRows; $i += $batchSize) {
|
|
|
|
|
$batchRows = array_slice($result, $i, $batchSize);
|
|
|
|
|
if (!empty($batchRows)) {
|
|
|
|
|
// 2. 批量查询已存在的手机
|
|
|
|
|
$existingPhones = [];
|
|
|
|
|
$existing = Db::name('traffic_source_package_item')
|
|
|
|
|
->where(['companyId' => $companyId,'packageId' => $packageId])
|
|
|
|
|
->whereIn('identifier', $batchRows)
|
|
|
|
|
->field('identifier')
|
|
|
|
|
->select();
|
|
|
|
|
$existingPhones = array_column($existing, 'identifier');
|
|
|
|
|
// 3. 过滤出新数据,批量插入
|
|
|
|
|
$newData = [];
|
|
|
|
|
foreach ($batchRows as $row) {
|
|
|
|
|
if (!in_array($row, $existingPhones)) {
|
|
|
|
|
$newData[] = [
|
|
|
|
|
'packageId' => $packageId,
|
|
|
|
|
'companyId' => $companyId,
|
|
|
|
|
'identifier' => $row,
|
|
|
|
|
'createTime' => time(),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 4. 批量插入新数据
|
|
|
|
|
if (!empty($newData)) {
|
|
|
|
|
Db::name('traffic_source_package_item')->insertAll($newData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResponseHelper::success('添加成功');
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-08-06 18:00:50 +08:00
|
|
|
/* public function editUserTags()
|
|
|
|
|
{
|
|
|
|
|
$userId = $this->request->param('userId', '');
|
|
|
|
|
if (empty($userId)) {
|
|
|
|
|
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
|
|
|
|
|
}
|
|
|
|
|
$tags = $this->request->param('tags', []);
|
|
|
|
|
$tags = $this->request->param('tags', []);
|
|
|
|
|
$isWechat = $this->request->param('isWechat', false);
|
|
|
|
|
$companyId = $this->getUserInfo('companyId');
|
|
|
|
|
|
|
|
|
|
$friend = Db::name('traffic_pool')->alias('tp')
|
|
|
|
|
->join('wechat_friendship f', 'tp.wechatId=f.wechatId AND f.companyId='.$companyId, 'left')
|
|
|
|
|
->join(['s2_wechat_friend' => 'wf'], 'f.wechatId=wf.wechatId', 'left')
|
|
|
|
|
->where(['tp.id' => $userId])
|
|
|
|
|
->order('tp.createTime desc')
|
|
|
|
|
->column('wf.id,wf.accountId,wf.labels,wf.siteLabels');
|
|
|
|
|
if (empty($data)) {
|
|
|
|
|
return ResponseHelper::error('该用户不存在');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-29 17:04:00 +08:00
|
|
|
|
2025-05-13 12:10:39 +08:00
|
|
|
}
|