toDateString(); if (!empty($deviceType)) { $key .= ':'. $deviceType; } return Redis::pfcount($key); } else { if ($channelUid == '') { // 空字符串,代表官方. $fixChannelUid = 'office__'; } else { $fixChannelUid = $channelUid; } $key = $keyFlag . 'ch:'. $fixChannelUid . ':' . Carbon::parse($date)->toDateString(); if (!empty($deviceType)) { $key .= ':'. $deviceType; } return Redis::pfcount($key); } } /** * 统计时间段的日活. * @param mixed $startDate 开始日期 * @param mixed $endDate 结束日期 * @param null|string $channelUid 渠道UID * @param null|string $deviceType 设备类型 * @param null|string $momAppUid 母包UD * @return int */ public function countSomeDaysActive($startDate, $endDate, $channelUid = null, $deviceType = null, $momAppUid = null) { $startDateObj = Carbon::parse($startDate); $endDateObj = Carbon::parse($endDate); if ($startDateObj > $endDateObj) { // 开始日期大于结束日期,错误的,为了容错,特意设置返回0. return 0; } if (abs(Carbon::parse($startDate)->diffInDays(Carbon::parse($endDateObj))) > 366) { // 不允许超过1年,为了容错,特意设置返回0. return 0; } $dateObj = Carbon::parse($startDate); $deviceType = strtoupper($deviceType); $keyFlag = 'day_active:'; if (is_null($channelUid)) { $arrDates = []; while ($dateObj <= $endDateObj) { $key = $keyFlag . $dateObj->toDateString(); if (!empty($deviceType)) { $key .= ':'. $deviceType; } $arrDates[] = $key; $dateObj = $dateObj->addDays(1); } return Redis::pfcount($arrDates); } else { if ($channelUid == '') { // 空字符串,代表官方. $fixChannelUid = 'office__'; } else { $fixChannelUid = $channelUid; } $arrDates = []; while ($dateObj <= $endDateObj) { $date = $startDate; $dateObj = Carbon::parse($date); $key = $keyFlag . 'ch:' . $fixChannelUid . ':' . $dateObj->toDateString(); if (!empty($deviceType)) { $key .= ':'. $deviceType; } $arrDates[] = $key; $dateObj = $dateObj->addDays(1); } return Redis::pfcount($arrDates); } } }