代码提交

This commit is contained in:
wong
2025-09-12 09:40:13 +08:00
parent db9e4eb004
commit b989c19a8a
5 changed files with 310 additions and 150 deletions

View File

@@ -288,7 +288,7 @@ class UserController extends BaseController
} }
// 如果不是预期的格式,返回原始数据 // 如果不是预期的格式,返回原始数据
return !empty($isJson) ? json_encode(['code' => 500,'data' => $response]) : errorJson('无需验证码'); return !empty($isJson) ? json_encode(['code' => 200,'msg' => '无需验证码','data' => ['verifyCodeImage' => '', 'verifySessionId' => '']]) : successJson(['verifyCodeImage' => '', 'verifySessionId' => ''],'无需验证码');
} catch (\Exception $e) { } catch (\Exception $e) {
$msg = '获取验证码失败'. $e->getMessage(); $msg = '获取验证码失败'. $e->getMessage();
return !empty($isJson) ? json_encode(['code' => 400,'msg' => $msg]) : errorJson($msg); return !empty($isJson) ? json_encode(['code' => 400,'msg' => $msg]) : errorJson($msg);

View File

@@ -65,7 +65,7 @@ class PostCreateAddFriendPlanV1Controller extends BaseController
return ResponseHelper::error('场景ID不能为空', 400); return ResponseHelper::error('场景ID不能为空', 400);
} }
if (empty($params['deveiceGroups'])) { if (empty($params['deviceGroups'])) {
return ResponseHelper::error('请选择设备', 400); return ResponseHelper::error('请选择设备', 400);
} }
@@ -77,7 +77,7 @@ class PostCreateAddFriendPlanV1Controller extends BaseController
'customTags' => $params['customTags'] ?? [], 'customTags' => $params['customTags'] ?? [],
]; ];
$reqConf = [ $reqConf = [
'device' => $params['deveiceGroups'] ?? [], 'device' => $params['deviceGroups'] ?? [],
'remarkType' => $params['remarkType'] ?? '', 'remarkType' => $params['remarkType'] ?? '',
'greeting' => $params['greeting'] ?? '', 'greeting' => $params['greeting'] ?? '',
'addFriendInterval' => $params['addFriendInterval'] ?? '', 'addFriendInterval' => $params['addFriendInterval'] ?? '',
@@ -138,9 +138,9 @@ class PostCreateAddFriendPlanV1Controller extends BaseController
//订单 //订单
if ($params['sceneId'] == 2) { if ($params['sceneId'] == 2) {
if (!empty($params['orderTableFile'])) { if (!empty($params['orderFileUrl'])) {
// 先下载到本地临时文件,再分析,最后删除 // 先下载到本地临时文件,再分析,最后删除
$originPath = $params['orderTableFile']; $originPath = $params['orderFileUrl'];
$tmpFile = tempnam(sys_get_temp_dir(), 'order_'); $tmpFile = tempnam(sys_get_temp_dir(), 'order_');
// 判断是否为远程文件 // 判断是否为远程文件
if (preg_match('/^https?:\/\//i', $originPath)) { if (preg_match('/^https?:\/\//i', $originPath)) {

View File

@@ -35,7 +35,7 @@ class PostUpdateAddFriendPlanV1Controller extends BaseController
return ResponseHelper::error('场景ID不能为空', 400); return ResponseHelper::error('场景ID不能为空', 400);
} }
if (empty($params['deveiceGroups'])) { if (empty($params['deviceGroups'])) {
return ResponseHelper::error('请选择设备', 400); return ResponseHelper::error('请选择设备', 400);
} }
@@ -55,7 +55,7 @@ class PostUpdateAddFriendPlanV1Controller extends BaseController
'customTags' => $params['customTags'] ?? [], 'customTags' => $params['customTags'] ?? [],
]; ];
$reqConf = [ $reqConf = [
'device' => $params['deveiceGroups'] ?? [], 'device' => $params['deviceGroups'] ?? [],
'remarkType' => $params['remarkType'] ?? '', 'remarkType' => $params['remarkType'] ?? '',
'greeting' => $params['greeting'] ?? '', 'greeting' => $params['greeting'] ?? '',
'addFriendInterval' => $params['addFriendInterval'] ?? '', 'addFriendInterval' => $params['addFriendInterval'] ?? '',
@@ -76,7 +76,7 @@ class PostUpdateAddFriendPlanV1Controller extends BaseController
$sceneConf['messagePlans'], $sceneConf['messagePlans'],
$sceneConf['scenarioTags'], $sceneConf['scenarioTags'],
$sceneConf['customTags'], $sceneConf['customTags'],
$sceneConf['deveiceGroups'], $sceneConf['deviceGroups'],
$sceneConf['orderTableFileName'], $sceneConf['orderTableFileName'],
$sceneConf['userInfo'], $sceneConf['userInfo'],
$sceneConf['textUrl'], $sceneConf['textUrl'],
@@ -113,9 +113,9 @@ class PostUpdateAddFriendPlanV1Controller extends BaseController
//订单 //订单
if ($params['sceneId'] == 2) { if ($params['sceneId'] == 2) {
if (!empty($params['orderTableFile'])) { if (!empty($params['orderFileUrl'])) {
// 先下载到本地临时文件,再分析,最后删除 // 先下载到本地临时文件,再分析,最后删除
$originPath = $params['orderTableFile']; $originPath = $params['orderFileUrl'];
$tmpFile = tempnam(sys_get_temp_dir(), 'order_'); $tmpFile = tempnam(sys_get_temp_dir(), 'order_');
// 判断是否为远程文件 // 判断是否为远程文件
if (preg_match('/^https?:\/\//i', $originPath)) { if (preg_match('/^https?:\/\//i', $originPath)) {

View File

@@ -22,11 +22,11 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
*/ */
protected function makeWhere(array $params = []): array protected function makeWhere(array $params = []): array
{ {
$keyword = $this->request->param('keyword',''); $keyword = $this->request->param('keyword', '');
$device = $this->request->param('deviceId'); $device = $this->request->param('deviceId');
$status = $this->request->param('addStatus',''); $status = $this->request->param('addStatus', '');
$taskId = $this->request->param('taskId',''); $taskId = $this->request->param('taskId', '');
$packageId = $this->request->param('packageId',''); $packageId = $this->request->param('packageId', '');
$where = []; $where = [];
if (!empty($keyword)) { if (!empty($keyword)) {
$where[] = ['p.identifier|wa.nickname|wa.phone|wa.wechatId|wa.alias', 'like', '%' . $keyword . '%']; $where[] = ['p.identifier|wa.nickname|wa.phone|wa.wechatId|wa.alias', 'like', '%' . $keyword . '%'];
@@ -34,35 +34,35 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
// 状态筛选 // 状态筛选
if (!empty($status)) { if (!empty($status)) {
if ($status == 1){ if ($status == 1) {
$where[] = ['s.status','=',4]; $where[] = ['s.status', '=', 4];
}elseif ($status == 2){ } elseif ($status == 2) {
$where[] = ['s.status','=',0]; $where[] = ['s.status', '=', 0];
}elseif ($status == -1){ } elseif ($status == -1) {
$where[] = ['s.status','=',2]; $where[] = ['s.status', '=', 2];
}elseif ($status == 3){ } elseif ($status == 3) {
$where[] = ['s.status','=',2]; $where[] = ['s.status', '=', 2];
} }
} }
// 来源的筛选 // 来源的筛选
if ($packageId) { if ($packageId) {
if ($packageId != -1) { if ($packageId != -1) {
$where[] = ['tsp.id','=',$packageId]; $where[] = ['tsp.id', '=', $packageId];
} else { } else {
$where[] = ['tsp.id','=', null]; $where[] = ['tsp.id', '=', null];
} }
} }
if (!empty($device)) { if (!empty($device)) {
$where[] = ['d.deviceId','=',$device]; $where[] = ['d.deviceId', '=', $device];
} }
if (!empty($taskId)){ if (!empty($taskId)) {
$where[] = ['t.sceneId','=',$taskId]; $where[] = ['t.sceneId', '=', $taskId];
} }
$where[] = ['s.companyId','=',$this->getUserInfo('companyId')]; $where[] = ['s.companyId', '=', $this->getUserInfo('companyId')];
return $where; return $where;
} }
@@ -73,14 +73,14 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
* @param array $where * @param array $where
* @return \think\Paginator * @return \think\Paginator
*/ */
protected function getPoolListByCompanyId(array $where,$isPage = true) protected function getPoolListByCompanyId(array $where, $isPage = true)
{ {
$query = TrafficPoolModel::alias('p') $query = TrafficPoolModel::alias('p')
->field( ->field(
[ [
'p.id', 'p.identifier', 'p.mobile', 'p.wechatId', 'p.identifier', 'p.id', 'p.identifier', 'p.mobile', 'p.wechatId', 'p.identifier',
's.fromd', 's.status', 's.createTime', 's.companyId', 's.sourceId', 's.type', 's.fromd', 's.status', 's.createTime', 's.companyId', 's.sourceId', 's.type',
'wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone','wa.alias' 'wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone', 'wa.alias'
] ]
) )
->join('traffic_source s', 'p.identifier=s.identifier') ->join('traffic_source s', 'p.identifier=s.identifier')
@@ -97,7 +97,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
$result = $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(); $list = $result->items();
$total = $result->total(); $total = $result->total();
}else{ } else {
$list = $result->select(); $list = $result->select();
$total = ''; $total = '';
} }
@@ -172,7 +172,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
$data = TrafficPoolModel::alias('p') $data = TrafficPoolModel::alias('p')
->field(['p.id', 'p.identifier', 'p.wechatId', ->field(['p.id', 'p.identifier', 'p.wechatId',
'wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone','wa.alias']) 'wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone', 'wa.alias'])
->join('wechat_account wa', 'p.identifier=wa.wechatId', 'left') ->join('wechat_account wa', 'p.identifier=wa.wechatId', 'left')
->order('p.id DESC') ->order('p.id DESC')
->where(['p.id' => $userId]) ->where(['p.id' => $userId])
@@ -181,15 +181,14 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
$data['lastMsgTime'] = ''; $data['lastMsgTime'] = '';
//来源 //来源
$source = Db::name('traffic_source')->alias('ts') $source = Db::name('traffic_source')->alias('ts')
->field(['wa.nickname', 'wa.avatar', 'wa.gender','wa.phone','wa.wechatId','wa.alias', ->field(['wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone', 'wa.wechatId', 'wa.alias',
'ts.createTime', 'ts.createTime',
'wf.id as friendId','wf.wechatAccountId']) 'wf.id as friendId', 'wf.wechatAccountId'])
->join('wechat_account wa', 'ts.sourceId=wa.wechatId', 'left') ->join('wechat_account wa', 'ts.sourceId=wa.wechatId', 'left')
->join(['s2_wechat_friend' => 'wf'], 'wa.wechatId=wf.ownerWechatId', 'left') ->join(['s2_wechat_friend' => 'wf'], 'wa.wechatId=wf.ownerWechatId', 'left')
->where(['ts.companyId' => $companyId,'ts.identifier' => $data['identifier'],'wf.wechatId' => $data['wechatId']]) ->where(['ts.companyId' => $companyId, 'ts.identifier' => $data['identifier'], 'wf.wechatId' => $data['wechatId']])
->order('ts.createTime DESC') ->order('ts.createTime DESC')
->select(); ->select();
@@ -201,18 +200,18 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
//最后消息 //最后消息
$v['createTime'] = date('Y-m-d H:i:s', $v['createTime']); $v['createTime'] = date('Y-m-d H:i:s', $v['createTime']);
$lastMsgTime = Db::table('s2_wechat_message') $lastMsgTime = Db::table('s2_wechat_message')
->where(['wechatFriendId' => $v['friendId'],'wechatAccountId' => $v['wechatAccountId']]) ->where(['wechatFriendId' => $v['friendId'], 'wechatAccountId' => $v['wechatAccountId']])
->value('wechatTime'); ->value('wechatTime');
$v['lastMsgTime'] = !empty($lastMsgTime) ? date('Y-m-d H:i:s', $lastMsgTime) : ''; $v['lastMsgTime'] = !empty($lastMsgTime) ? date('Y-m-d H:i:s', $lastMsgTime) : '';
//设备信息 //设备信息
$device = Db::name('device_wechat_login')->alias('dwl') $device = Db::name('device_wechat_login')->alias('dwl')
->join('device d','d.id=dwl.deviceId') ->join('device d', 'd.id=dwl.deviceId')
->where(['dwl.wechatId' => $v['wechatId']]) ->where(['dwl.wechatId' => $v['wechatId']])
->field('d.id,d.memo,d.imei,d.brand,d.extra,d.alive') ->field('d.id,d.memo,d.imei,d.brand,d.extra,d.alive')
->order('dwl.id DESC') ->order('dwl.id DESC')
->find(); ->find();
$extra = json_decode($device['extra'],true); $extra = json_decode($device['extra'], true);
unset($device['extra']); unset($device['extra']);
$device['address'] = !empty($extra['address']) ? $extra['address'] : ''; $device['address'] = !empty($extra['address']) ? $extra['address'] : '';
$v['device'] = $device; $v['device'] = $device;
@@ -235,7 +234,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
$data['packages'] = $packages; $data['packages'] = $packages;
if (!empty($wechatFriendId)){ if (!empty($wechatFriendId)) {
//消息统计 //消息统计
$msgTotal = Db::table('s2_wechat_message') $msgTotal = Db::table('s2_wechat_message')
->whereIn('wechatFriendId', $wechatFriendId) ->whereIn('wechatFriendId', $wechatFriendId)
@@ -245,12 +244,12 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
//金额计算 //金额计算
$money = Db::table('s2_wechat_message') $money = Db::table('s2_wechat_message')
->whereIn('wechatFriendId', $wechatFriendId) ->whereIn('wechatFriendId', $wechatFriendId)
->where(['isSend' => 1,'msgType' => 419430449]) ->where(['isSend' => 1, 'msgType' => 419430449])
->select(); ->select();
if (!empty($money)){ if (!empty($money)) {
foreach ($money as $v){ foreach ($money as $v) {
$content = json_decode($v['content'],true); $content = json_decode($v['content'], true);
if ($content['paysubtype'] == 1){ if ($content['paysubtype'] == 1) {
$number = number_format(str_replace("", "", $content['feedesc']), 2); $number = number_format(str_replace("", "", $content['feedesc']), 2);
$floatValue = floatval($number); $floatValue = floatval($number);
$total['money'] += $floatValue; $total['money'] += $floatValue;
@@ -260,24 +259,23 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
} }
$taskNum = Db::name('task_customer')->alias('tc') $taskNum = Db::name('task_customer')->alias('tc')
->join('customer_acquisition_task t','tc.task_id=t.id') ->join('customer_acquisition_task t', 'tc.task_id=t.id')
->where(['t.companyId' => $companyId,'t.deleteTime' => 0]) ->where(['t.companyId' => $companyId, 't.deleteTime' => 0])
->whereIn('tc.phone',[$data['phone'], $data['wechatId'], $data['alias']]) ->whereIn('tc.phone', [$data['phone'], $data['wechatId'], $data['alias']])
->count(); ->count();
$passNum = Db::name('task_customer')->alias('tc') $passNum = Db::name('task_customer')->alias('tc')
->join('customer_acquisition_task t','tc.task_id=t.id') ->join('customer_acquisition_task t', 'tc.task_id=t.id')
->where(['t.companyId' => $companyId,'t.deleteTime' => 0,'tc.status' => 4]) ->where(['t.companyId' => $companyId, 't.deleteTime' => 0, 'tc.status' => 4])
->whereIn('tc.phone',[$data['phone'], $data['wechatId'], $data['alias']]) ->whereIn('tc.phone', [$data['phone'], $data['wechatId'], $data['alias']])
->count(); ->count();
if (!empty($taskNum) && !empty($passNum)){ if (!empty($taskNum) && !empty($passNum)) {
$percentage = number_format(($taskNum / $passNum) * 100, 2); $percentage = number_format(($taskNum / $passNum) * 100, 2);
$total['percentage'] = $percentage; $total['percentage'] = $percentage;
} }
$data['total'] = $total; $data['total'] = $total;
$data['rmm'] = [ $data['rmm'] = [
'r' => 0, 'r' => 0,
@@ -332,7 +330,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
return json_encode(['code' => 500, 'msg' => '用户id不能为空']); return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
} }
$data = Db::name('traffic_pool')->alias('tp') $data = Db::name('traffic_pool')->alias('tp')
->join('wechat_friendship f', 'tp.wechatId=f.wechatId AND f.companyId='.$companyId, 'left') ->join('wechat_friendship f', 'tp.wechatId=f.wechatId AND f.companyId=' . $companyId, 'left')
->join(['s2_wechat_friend' => 'wf'], 'f.wechatId=wf.wechatId', 'left') ->join(['s2_wechat_friend' => 'wf'], 'f.wechatId=wf.wechatId', 'left')
->where(['tp.id' => $userId]) ->where(['tp.id' => $userId])
->order('tp.createTime desc') ->order('tp.createTime desc')
@@ -365,22 +363,22 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
public function getPackage() public function getPackage()
{ {
$page = $this->request->param('page',1); $page = $this->request->param('page', 1);
$limit = $this->request->param('limit',10); $limit = $this->request->param('limit', 10);
$keyword = $this->request->param('keyword',''); $keyword = $this->request->param('keyword', '');
$companyId = $this->getUserInfo('companyId'); $companyId = $this->getUserInfo('companyId');
$package = Db::name('traffic_source_package')->alias('tsp') $package = Db::name('traffic_source_package')->alias('tsp')
->join('traffic_source_package_item tspi','tspi.packageId=tsp.id','left') ->join('traffic_source_package_item tspi', 'tspi.packageId=tsp.id', 'left')
->whereIn('tsp.companyId', [$companyId,0]) ->whereIn('tsp.companyId', [$companyId, 0])
->field('tsp.id,tsp.name,tsp.description,tsp.createTime,count(tspi.id) as num') ->field('tsp.id,tsp.name,tsp.description,tsp.createTime,count(tspi.id) as num')
->group('tsp.id'); ->group('tsp.id');
if (!empty($keyword)){ if (!empty($keyword)) {
$package->where('tsp.name|tsp.description','like','%'.$keyword.'%'); $package->where('tsp.name|tsp.description', 'like', '%' . $keyword . '%');
} }
$list = $package->page($page,$limit)->select(); $list = $package->page($page, $limit)->select();
$total = $package->count(); $total = $package->count();
foreach ($list as $k => &$v) { foreach ($list as $k => &$v) {
@@ -397,36 +395,43 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
} }
public function addPackage() public function addPackage()
{ {
try { try {
$addPackageId = $this->request->param('addPackageId',''); $type = $this->request->param('type', '');
$packageName = $this->request->param('packageName',''); $addPackageId = $this->request->param('addPackageId', '');
$userIds = $this->request->param('userIds',[]); $packageName = $this->request->param('packageName', '');
$userIds = $this->request->param('userIds', []);
$tableFile = $this->request->param('tableFile', '');
$companyId = $this->getUserInfo('companyId'); $companyId = $this->getUserInfo('companyId');
$userId = $this->getUserInfo('id'); $userId = $this->getUserInfo('id');
if (empty($addPackageId) && empty($packageName)){ if (empty($addPackageId) && empty($packageName)) {
return ResponseHelper::error('存储的流量池不能为空'); return ResponseHelper::error('存储的流量池不能为空');
} }
if (!empty($addPackageId)){ if (empty($type)) {
return ResponseHelper::error('请选择类型');
}
if (!empty($addPackageId)) {
$package = Db::name('traffic_source_package') $package = Db::name('traffic_source_package')
->where(['id' => $addPackageId,'isDel' => 0]) ->where(['id' => $addPackageId, 'isDel' => 0])
->whereIn('companyId', [$companyId,0]) ->whereIn('companyId', [$companyId, 0])
->field('id,name') ->field('id,name')
->find(); ->find();
if (empty($package)){ if (empty($package)) {
return ResponseHelper::error('该流量池不存在'); return ResponseHelper::error('该流量池不存在');
} }
$packageId = $package['id']; $packageId = $package['id'];
}else{ } else {
$package = Db::name('traffic_source_package') $package = Db::name('traffic_source_package')
->where(['isDel' => 0,'name' => $packageName]) ->where(['isDel' => 0, 'name' => $packageName])
->whereIn('companyId', [$companyId,0]) ->whereIn('companyId', [$companyId, 0])
->field('id,name') ->field('id,name')
->find(); ->find();
if (!empty($package)){ if (!empty($package)) {
return ResponseHelper::error('该流量池名称已存在'); return ResponseHelper::error('该流量池名称已存在');
} }
$packageId = Db::name('traffic_source_package')->insertGetId([ $packageId = Db::name('traffic_source_package')->insertGetId([
@@ -440,24 +445,99 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
} }
if (!empty($userIds)){ if ($type == 1) {
if (!is_array($userIds)){ $result = $this->getPoolListByCompanyId($this->makeWhere(), false);
$result = json_decode($result, true);
$result = array_column($result['list'], 'identifier');
} elseif ($type == 2) {
if (empty($packageId)) {
return ResponseHelper::error('选择的用户');
}
//================== 表格数据处理 ==================
if (!is_array($userIds)) {
return ResponseHelper::error('选择的用户类型错误'); return ResponseHelper::error('选择的用户类型错误');
} }
$result = Db::name('traffic_pool')->alias('tp') $result = Db::name('traffic_pool')->alias('tp')
->join('traffic_source tc','tp.identifier=tc.identifier') ->join('traffic_source tc', 'tp.identifier=tc.identifier')
->whereIn('tp.id',$userIds) ->whereIn('tp.id', $userIds)
->where(['companyId' => $companyId]) ->where(['companyId' => $companyId])
->group('tp.identifier') ->group('tp.identifier')
->column('tc.identifier'); ->column('tc.identifier');
}else{ } else {
$result = $this->getPoolListByCompanyId($this->makeWhere(),false); /*if (empty($tableFile)){
$result = json_decode($result, true); return ResponseHelper::error('请上传用户文件');
$result = array_column($result['list'],'identifier');
} }
// 先下载到本地临时文件,再分析,最后删除
$originPath = $tableFile;
$tmpFile = tempnam(sys_get_temp_dir(), 'user_');
// 判断是否为远程文件
if (preg_match('/^https?:\/\//i', $originPath)) {
// 远程URL下载到本地
$fileContent = file_get_contents($originPath);
if ($fileContent === false) {
exit('远程文件下载失败: ' . $originPath);
}
file_put_contents($tmpFile, $fileContent);
} else {
// 本地文件直接copy
if (!file_exists($originPath)) {
exit('文件不存在: ' . $originPath);
}
copy($originPath, $tmpFile);
}
// 解析临时文件
$ext = strtolower(pathinfo($originPath, PATHINFO_EXTENSION));
$rows = [];
if (in_array($ext, ['xls', 'xlsx'])) {
// 直接用composer自动加载的PHPExcel
$excel = \PHPExcel_IOFactory::load($tmpFile);
$sheet = $excel->getActiveSheet();
$data = $sheet->toArray();
if (count($data) > 1) {
array_shift($data); // 去掉表头
}
foreach ($data as $cols) {
$rows[] = [
'name' => isset($cols[0]) ? trim($cols[0]) : '',
'phone' => isset($cols[1]) ? trim($cols[1]) : '',
'source' => isset($cols[2]) ? trim($cols[2]) : '',
];
}
} elseif ($ext === 'csv') {
$content = file_get_contents($tmpFile);
$lines = preg_split('/\r\n|\r|\n/', $content);
if (count($lines) > 1) {
array_shift($lines); // 去掉表头
foreach ($lines as $line) {
if (trim($line) === '') continue;
$cols = str_getcsv($line);
if (count($cols) >= 6) {
$rows[] = [
'name' => isset($cols[0]) ? trim($cols[0]) : '',
'phone' => isset($cols[1]) ? trim($cols[1]) : '',
'source' => isset($cols[2]) ? trim($cols[2]) : '',
];
}
}
}
} else {
unlink($tmpFile);
exit('暂不支持的文件类型: ' . $ext);
}
// 删除临时文件
unlink($tmpFile);*/
//================== 表格数据处理 ==================
}
$rows = [
['name' => '张三', 'phone' => '18883458888', 'source' => '234'],
['name' => '李四', 'phone' => '18878988889', 'source' => '456'],
];
if (in_array($type, [1, 2])) {
// 1000条为一组进行批量处理 // 1000条为一组进行批量处理
$batchSize = 1000; $batchSize = 1000;
$totalRows = count($result); $totalRows = count($result);
@@ -466,9 +546,8 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
$batchRows = array_slice($result, $i, $batchSize); $batchRows = array_slice($result, $i, $batchSize);
if (!empty($batchRows)) { if (!empty($batchRows)) {
// 2. 批量查询已存在的手机 // 2. 批量查询已存在的手机
$existingPhones = [];
$existing = Db::name('traffic_source_package_item') $existing = Db::name('traffic_source_package_item')
->where(['companyId' => $companyId,'packageId' => $packageId]) ->where(['companyId' => $companyId, 'packageId' => $packageId])
->whereIn('identifier', $batchRows) ->whereIn('identifier', $batchRows)
->field('identifier') ->field('identifier')
->select(); ->select();
@@ -491,6 +570,89 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
} }
} }
} }
} else {
// 1000条为一组进行批量处理
$batchSize = 1000;
$totalRows = count($rows);
try {
for ($i = 0; $i < $totalRows; $i += $batchSize) {
Db::startTrans();
$batchRows = array_slice($rows, $i, $batchSize);
if (!empty($batchRows)) {
$identifiers = array_column($batchRows, 'phone');
//流量池处理
$existing = Db::name('traffic_pool')
->whereIn('identifier', $identifiers)
->column('identifier');
$newData = [];
foreach ($batchRows as $row) {
if (!in_array($row['phone'], $existing)) {
$newData[] = [
'identifier' => $row['phone'],
'mobile' => $row['phone'],
'createTime' => time(),
];
}
}
if (!empty($newData)) {
Db::name('traffic_pool')->insertAll($newData);
}
//流量池来源处理
$newData2 = [];
$existing2 = Db::name('traffic_source')
->where(['companyId' => $companyId])
->whereIn('identifier', $identifiers)
->column('identifier');
foreach ($batchRows as $row) {
if (!in_array($row['phone'], $existing2)) {
$newData2[] = [
'type' => 0,
'name' => $row['name'],
'identifier' => $row['phone'],
'fromd' => $row['source'],
'companyId' => $companyId,
'createTime' => time(),
'updateTime' => time(),
];
}
}
if (!empty($newData2)) {
Db::name('traffic_source')->insertAll($newData2);
}
//流量池包数据处理
$newData3 = [];
$existing3 = Db::name('traffic_source_package_item')
->where(['companyId' => $companyId, 'packageId' => $packageId])
->whereIn('identifier', $identifiers)
->field('identifier')
->select();
foreach ($batchRows as $row) {
if (!in_array($row['phone'], $existing3)) {
$newData3[] = [
'packageId' => $packageId,
'companyId' => $companyId,
'identifier' => $row['phone'],
'createTime' => time(),
];
}
}
if (!empty($newData3)) {
Db::name('traffic_source_package_item')->insertAll($newData3);
}
Db::commit();
}
}
} catch (\Exception $e) {
DB::rollback();
}
}
return ResponseHelper::success('添加成功'); return ResponseHelper::success('添加成功');
} catch (\Exception $e) { } catch (\Exception $e) {
return ResponseHelper::error($e->getMessage(), $e->getCode()); return ResponseHelper::error($e->getMessage(), $e->getCode());
@@ -523,6 +685,4 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
}*/ }*/
} }

View File

@@ -292,7 +292,7 @@ class CreateCompanyController extends BaseController
$this->createFuncUsers($params); $this->createFuncUsers($params);
Db::commit(); Db::commit();
// 设置部门权限 // 设置部门权限 ?????
$this->setDepartmentPrivileges($params); $this->setDepartmentPrivileges($params);
return ResponseHelper::success(); return ResponseHelper::success();