企微短剧业务系统

OrderSummaryService.php 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Service;
  3. use App\Log;
  4. use App\Models\DjOrder;
  5. use App\Models\OrderSummary;
  6. use App\RedisModel;
  7. class OrderSummaryService
  8. {
  9. /**
  10. * 统计单个账号指定日期的数据统计
  11. * */
  12. public static function mpStatByDate($appIdList, $date)
  13. {
  14. # 统计数据
  15. $data = DjOrder::query()->selectRaw("bind_app_id, order_source, system_corpid as corpid,count(1) as order_count,
  16. count(distinct(external_userid)) as pay_uv, count(external_userid) as pay_pv,sum(pay_money) as pay_money")
  17. ->whereIn('bind_app_id', $appIdList)
  18. ->where('pay_status', 1)
  19. ->where('is_ad_user', 1)
  20. ->where('order_type', 1)
  21. ->where('order_pay_time', '>=', strtotime($date.' 00:00:00') * 1000)
  22. ->where('order_pay_time', '<=', strtotime($date.' 23:59:59') * 1000)
  23. ->groupBy(['bind_app_id', 'order_source'])
  24. ->get();
  25. return $data;
  26. }
  27. /**
  28. * 统计单个账号指定日期的数据统计
  29. * */
  30. public static function adqStatByDate($accountIdList, $date)
  31. {
  32. # 统计数据
  33. $data = DjOrder::query()->selectRaw("adq_account_id, order_source, system_corpid as corpid,count(1) as order_count,
  34. count(distinct(external_userid)) as pay_uv, count(external_userid) as pay_pv,sum(pay_money) as pay_money")
  35. ->whereIn('adq_account_id', $accountIdList)
  36. ->where('pay_status', 1)
  37. ->where('order_type', 2)
  38. ->where('order_pay_time', '>=', strtotime($date.' 00:00:00') * 1000)
  39. ->where('order_pay_time', '<=', strtotime($date.' 23:59:59') * 1000)
  40. ->groupBy(['adq_account_id', 'order_source'])
  41. ->get();
  42. return $data;
  43. }
  44. /**
  45. * 判断是否为往日补充订单数据
  46. * @param $orderPayTime int 订单支付时间戳
  47. * @param $appId string 订单所属账号appid
  48. * */
  49. public static function orderCheck($orderId, $orderPayTime, $appId)
  50. {
  51. $timestamps = strtotime(date('Y-m-d'));
  52. $orderPayTime = substr($orderPayTime, 0, 10);
  53. if($orderPayTime < $timestamps) { // 回调订单为往日订单数据,入Redis
  54. $supplyData = [
  55. 'app_id' => $appId,
  56. 'order_id' => $orderId,
  57. 'date' => date('Y-m-d', $orderPayTime)
  58. ];
  59. Log::logInfo('检出回调订单中出现往日数据', $supplyData, 'SupplyOrderCheck');
  60. RedisModel::lPush(OrderSummary::ORDER_SUPPLY_STAT_RDS, json_encode($supplyData));
  61. }
  62. return true;
  63. }
  64. }