| 123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace App\Repositories\Statistics;
- use App\Models\Mongo\PayLogsModel;
- use App\Models\Mongo\UsersModel;
- use Carbon\Carbon;
- class StatisticsCommonRepository
- {
- /**
- * 根据某一天,获取当天有效的渠道UID集合(有效:当天有用户或者订单增加的).
- * @param $date
- * @return array
- */
- public function getValidChannelUidsByDate($date)
- {
- $startOfDate = Carbon::parse($date)->startOfDay();
- $endOfDate = Carbon::parse($date)->endOfDay();
- $items = UsersModel::whereBetween('created_at', [$startOfDate, $endOfDate])->distinct('channel_uid')->groupBy('channel_uid')->get(['channel_uid']);
- $userChannelUids = collect($items)->pluck('channel_uid')->toArray();
- $items = PayLogsModel::whereBetween('created_at', [$startOfDate, $endOfDate])->distinct('channel_uid')->groupBy('channel_uid')->get(['channel_uid']);
- $payChannelUids = collect($items)->pluck('channel_uid')->toArray();
- // 找到某一天的有数据的渠道UID集合.
- $channelUids = array_merge($userChannelUids, $payChannelUids);
- $channelUids = array_unique($channelUids);
- $channelUids = array_filter($channelUids);
- return $channelUids;
- }
- }
|