|
@@ -135,19 +135,67 @@ class AgentClickController extends Controller
|
|
|
->header('Content-Type', 'image/gif')
|
|
->header('Content-Type', 'image/gif')
|
|
|
->header('Content-Length', strlen($gif));
|
|
->header('Content-Length', strlen($gif));
|
|
|
}
|
|
}
|
|
|
- static function changePlatformData($orgChannel,$newChannel)
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 用户归属渠道变更时,同步分渠道日统计(RecordPlatformData),并尽力同步 LogOnLineCountSum(若表含 Channel 列)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int|string $orgChannel 原渠道
|
|
|
|
|
+ * @param int|string $newChannel 新渠道
|
|
|
|
|
+ * @param string|null $dateId 统计日期 Ymd(应用注册日);null 则当前服务器日,兼容旧调用
|
|
|
|
|
+ */
|
|
|
|
|
+ static function changePlatformData($orgChannel, $newChannel, $dateId = null)
|
|
|
{
|
|
{
|
|
|
|
|
+ $org = (int) $orgChannel;
|
|
|
|
|
+ $nw = (int) $newChannel;
|
|
|
|
|
+ if ($org === $nw) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $dateId = $dateId ?: date('Ymd');
|
|
|
|
|
+
|
|
|
DB::connection('write')->table(TableName::QPRecordDB() . 'RecordPlatformData')
|
|
DB::connection('write')->table(TableName::QPRecordDB() . 'RecordPlatformData')
|
|
|
- ->where('DateID', date('Ymd'))
|
|
|
|
|
- ->where('Channel', $orgChannel)
|
|
|
|
|
- ->update(['RegPeple'=>DB::raw('RegPeple-1'),'ActivePeple'=>DB::raw('ActivePeple-1')]);
|
|
|
|
|
|
|
+ ->where('DateID', $dateId)
|
|
|
|
|
+ ->where('Channel', $org)
|
|
|
|
|
+ ->update(['RegPeple' => DB::raw('RegPeple-1')]);
|
|
|
|
|
|
|
|
DB::connection('write')->table(TableName::QPRecordDB() . 'RecordPlatformData')
|
|
DB::connection('write')->table(TableName::QPRecordDB() . 'RecordPlatformData')
|
|
|
- ->where('DateID', date('Ymd'))
|
|
|
|
|
- ->where('Channel', $newChannel)
|
|
|
|
|
- ->update(['RegPeple'=>DB::raw('RegPeple+1'),'ActivePeple'=>DB::raw('ActivePeple+1')]);
|
|
|
|
|
|
|
+ ->where('DateID', $dateId)
|
|
|
|
|
+ ->where('Channel', $nw)
|
|
|
|
|
+ ->update(['RegPeple' => DB::raw('RegPeple+1')]);
|
|
|
|
|
|
|
|
|
|
+ //self::syncLogOnLineCountSumRegisterByChannel($org, $nw, $dateId);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 若 QPRecordDB.dbo.LogOnLineCountSum 存在 Channel、RegisterCount 且按日聚合,则在渠道迁移时调整分渠道新增注册数。
|
|
|
|
|
+ * 若库表无 Channel 列或结构与假设不符,静默跳过(记录 debug 日志)。
|
|
|
|
|
+ */
|
|
|
|
|
+ private static function syncLogOnLineCountSumRegisterByChannel(int $orgChannel, int $newChannel, string $dateId): void
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!preg_match('/^\d{8}$/', $dateId)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ $dateStr = substr($dateId, 0, 4) . '-' . substr($dateId, 4, 2) . '-' . substr($dateId, 6, 2);
|
|
|
|
|
+ try {
|
|
|
|
|
+ $tbl = TableName::QPRecordDB() . 'LogOnLineCountSum';
|
|
|
|
|
+ DB::connection('write')->update(
|
|
|
|
|
+ 'UPDATE ' . $tbl . ' SET RegisterCount = CASE WHEN RegisterCount > 0 THEN RegisterCount - 1 ELSE 0 END '
|
|
|
|
|
+ . 'WHERE CAST(InsertDateTime AS DATE) = CAST(? AS DATE) AND Channel = ?',
|
|
|
|
|
+ [$dateStr, $orgChannel]
|
|
|
|
|
+ );
|
|
|
|
|
+ DB::connection('write')->update(
|
|
|
|
|
+ 'UPDATE ' . $tbl . ' SET RegisterCount = RegisterCount + 1 '
|
|
|
|
|
+ . 'WHERE CAST(InsertDateTime AS DATE) = CAST(? AS DATE) AND Channel = ?',
|
|
|
|
|
+ [$dateStr, $newChannel]
|
|
|
|
|
+ );
|
|
|
|
|
+ } catch (\Throwable $e) {
|
|
|
|
|
+ Log::debug('LogOnLineCountSum RegisterCount sync skipped (schema mismatch or no Channel)', [
|
|
|
|
|
+ 'message' => $e->getMessage(),
|
|
|
|
|
+ 'org' => $orgChannel,
|
|
|
|
|
+ 'new' => $newChannel,
|
|
|
|
|
+ 'dateId' => $dateId,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
public static function checkClick($UserID)
|
|
public static function checkClick($UserID)
|
|
|
{
|
|
{
|
|
@@ -162,14 +210,19 @@ class AgentClickController extends Controller
|
|
|
}
|
|
}
|
|
|
if(intval($SpreaderID)){
|
|
if(intval($SpreaderID)){
|
|
|
if($UserID!=$SpreaderID){
|
|
if($UserID!=$SpreaderID){
|
|
|
- $orgChannel=AccountsInfo::find($UserID)->Channel;
|
|
|
|
|
- $newChannel=AccountsInfo::find($SpreaderID)->Channel;
|
|
|
|
|
|
|
+ $userAcc = AccountsInfo::find($UserID);
|
|
|
|
|
+ if (!$userAcc) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ $orgChannel = $userAcc->Channel;
|
|
|
|
|
+ $newChannel = AccountsInfo::find($SpreaderID)->Channel;
|
|
|
|
|
+ $registerDateId = $userAcc->RegisterDate ? date('Ymd', strtotime($userAcc->RegisterDate)) : date('Ymd');
|
|
|
$BlockInviteChannel=DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel',$newChannel)->value('BlockInviteChannel');
|
|
$BlockInviteChannel=DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel',$newChannel)->value('BlockInviteChannel');
|
|
|
if($BlockInviteChannel==1){
|
|
if($BlockInviteChannel==1){
|
|
|
AccountsInfo::where('UserID', $UserID)->update(['SpreaderID' => $SpreaderID]);
|
|
AccountsInfo::where('UserID', $UserID)->update(['SpreaderID' => $SpreaderID]);
|
|
|
}else {
|
|
}else {
|
|
|
AccountsInfo::where('UserID', $UserID)->update(['SpreaderID' => $SpreaderID, 'Channel' => $newChannel]);
|
|
AccountsInfo::where('UserID', $UserID)->update(['SpreaderID' => $SpreaderID, 'Channel' => $newChannel]);
|
|
|
- self::changePlatformData($orgChannel, $newChannel);
|
|
|
|
|
|
|
+ self::changePlatformData($orgChannel, $newChannel, $registerDateId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return;
|
|
return;
|
|
@@ -203,8 +256,13 @@ class AgentClickController extends Controller
|
|
|
$click->save();
|
|
$click->save();
|
|
|
|
|
|
|
|
|
|
|
|
|
- $orgChannel=AccountsInfo::find($UserID)->Channel;
|
|
|
|
|
- $newChannel=AccountsInfo::find($agentInfo->UserID)->Channel;
|
|
|
|
|
|
|
+ $userAcc = AccountsInfo::find($UserID);
|
|
|
|
|
+ if (!$userAcc) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ $orgChannel = $userAcc->Channel;
|
|
|
|
|
+ $newChannel = AccountsInfo::find($agentInfo->UserID)->Channel;
|
|
|
|
|
+ $registerDateId = $userAcc->RegisterDate ? date('Ymd', strtotime($userAcc->RegisterDate)) : date('Ymd');
|
|
|
|
|
|
|
|
$BlockInviteChannel=DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel',$newChannel)->value('BlockInviteChannel');
|
|
$BlockInviteChannel=DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel',$newChannel)->value('BlockInviteChannel');
|
|
|
|
|
|
|
@@ -212,7 +270,7 @@ class AgentClickController extends Controller
|
|
|
AccountsInfo::where('UserID', $UserID)->update(['SpreaderID' => $agentInfo->UserID]);
|
|
AccountsInfo::where('UserID', $UserID)->update(['SpreaderID' => $agentInfo->UserID]);
|
|
|
}else {
|
|
}else {
|
|
|
AccountsInfo::where('UserID', $UserID)->update(['SpreaderID'=>$agentInfo->UserID,'Channel'=>$newChannel]);
|
|
AccountsInfo::where('UserID', $UserID)->update(['SpreaderID'=>$agentInfo->UserID,'Channel'=>$newChannel]);
|
|
|
- self::changePlatformData($orgChannel,$newChannel);
|
|
|
|
|
|
|
+ self::changePlatformData($orgChannel, $newChannel, $registerDateId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|