StatisticsCommonRepository.php 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Repositories\Statistics;
  3. use App\Models\Mongo\PayLogsModel;
  4. use App\Models\Mongo\UsersModel;
  5. use Carbon\Carbon;
  6. class StatisticsCommonRepository
  7. {
  8. /**
  9. * 根据某一天,获取当天有效的渠道UID集合(有效:当天有用户或者订单增加的).
  10. * @param $date
  11. * @return array
  12. */
  13. public function getValidChannelUidsByDate($date)
  14. {
  15. $startOfDate = Carbon::parse($date)->startOfDay();
  16. $endOfDate = Carbon::parse($date)->endOfDay();
  17. $items = UsersModel::whereBetween('created_at', [$startOfDate, $endOfDate])->distinct('channel_uid')->groupBy('channel_uid')->get(['channel_uid']);
  18. $userChannelUids = collect($items)->pluck('channel_uid')->toArray();
  19. $items = PayLogsModel::whereBetween('created_at', [$startOfDate, $endOfDate])->distinct('channel_uid')->groupBy('channel_uid')->get(['channel_uid']);
  20. $payChannelUids = collect($items)->pluck('channel_uid')->toArray();
  21. // 找到某一天的有数据的渠道UID集合.
  22. $channelUids = array_merge($userChannelUids, $payChannelUids);
  23. $channelUids = array_unique($channelUids);
  24. $channelUids = array_filter($channelUids);
  25. return $channelUids;
  26. }
  27. }