流量池详情
This commit is contained in:
@@ -151,57 +151,135 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
{
|
||||
|
||||
$userId = $this->request->param('userId', '');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($userId)) {
|
||||
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
|
||||
}
|
||||
|
||||
$total = [
|
||||
'msg' => 0,
|
||||
'money' => 0,
|
||||
'isFriend' => false,
|
||||
'percentage' => '0.00%',
|
||||
];
|
||||
|
||||
$item = TrafficPoolModel::alias('p')
|
||||
->field(
|
||||
[
|
||||
'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', 'left')
|
||||
|
||||
$data = TrafficPoolModel::alias('p')
|
||||
->field(['p.id', 'p.identifier', 'p.wechatId',
|
||||
'wa.nickname', 'wa.avatar', 'wa.gender', 'wa.phone','wa.alias'])
|
||||
->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')
|
||||
->order('p.id DESC')
|
||||
->where(['p.id' => $userId])
|
||||
->group('p.identifier')
|
||||
->find();
|
||||
$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;
|
||||
|
||||
|
||||
//流量池
|
||||
$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])
|
||||
->where(['tspi.companyId' => $companyId, 'tspi.identifier' => $data['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])
|
||||
->where(['tspi.companyId' => $companyId, 'tspi.identifier' => $data['identifier']])
|
||||
->column('p.name');
|
||||
$packages = array_merge($package, $package2);
|
||||
$item['packages'] = $packages;
|
||||
$data['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);
|
||||
if (!empty($v)) {
|
||||
$tags = array_merge($tags, $v);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
$item['tags'] = $tags;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$data['total'] = $total;
|
||||
$data['rmm'] = [
|
||||
'r' => 0,
|
||||
'f' => 0,
|
||||
'm' => 0,
|
||||
];
|
||||
return ResponseHelper::success($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user