企微短剧业务系统

HistoryOrderFromJiaShuWeb.php 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/12/20
  6. * Time: 14:21
  7. */
  8. namespace App\Console\Repair;
  9. use App\Log;
  10. use App\Models\DjOrder;
  11. use App\Service\DjOrderService;
  12. use App\Service\HttpService;
  13. use App\Service\JiaShuService;
  14. use Illuminate\Console\Command;
  15. class HistoryOrderFromJiaShuWeb extends Command
  16. {
  17. protected $signature = 'HistoryOrderFromJiaShuWeb';
  18. protected $description = '嘉书H5历史订单获取';
  19. public function __construct()
  20. {
  21. parent::__construct();
  22. }
  23. public function handle()
  24. {
  25. // $startTime = '2022-12-20 03:00:00';
  26. // $endTime = '2022-12-20 10:00:00';
  27. //
  28. // $customerId = 111;
  29. // $apiKey = '5eb24c607326536d412eba0bc21018c4';
  30. //
  31. // $requestUri = 'https://video-adreport.eastdrama.com/data/v2';
  32. //
  33. // $paramsArr['customer_id'] = $customerId;
  34. // $paramsArr['timestamp'] = time();
  35. // $paramsArr['type'] = 'pay';
  36. // $paramsArr['start_time'] = $startTime;
  37. // $paramsArr['end_time'] = $endTime;
  38. //
  39. // # 生成签名
  40. // $params = JiaShuService::createSign($apiKey, $paramsArr);
  41. //
  42. // $response = HttpService::httpPost($requestUri, $params);
  43. // $responseData = json_decode($response, 1);
  44. // Log::logInfo('', $responseData, 'test-4');
  45. // DjOrderService::jiashuWebOrderSave($responseData['data']['data']);
  46. // print_r($responseData);
  47. $startId = 0;
  48. $this->info('开始处理');
  49. while(true) {
  50. $orderList = DjOrder::query()->select(['id', 'order_id', 'ma_app_id', 'ma_open_id', 'mp_user_register_time'
  51. , 'order_pay_time', 'adq_account_id', 'order_source', 'is_ad_user'])
  52. ->where('pay_status', 1)->where('adq_account_id', '>', '')
  53. ->where('is_ad_user', 1)->where('id', '>', $startId)
  54. ->where('create_time', '>=', '2023-12-11')
  55. ->orderBy('id', 'asc')->limit(1000)->get();
  56. if($orderList->isEmpty()) {
  57. $this->info('处理完成');
  58. break;
  59. }
  60. $count = $orderList->count();
  61. $this->info('本次查询数据共 '.$count.' 条,数据起始id为: '.$startId);
  62. $startId = $orderList->max('id');
  63. $orderList = $orderList->toArray();
  64. $firstOrderIdArr = [];
  65. foreach($orderList as $orderInfo) {
  66. if(empty($orderInfo['ma_app_id']) || empty($orderInfo['ma_open_id']) || empty($orderInfo['mp_user_register_time'])
  67. || empty($orderInfo['order_pay_time']) || empty($orderInfo['adq_account_id']) || empty($orderInfo['is_ad_user'])) {
  68. // Log::logError('处理用户首单状态-订单基础数据不全', $orderInfo, 'DealFirstOrderStatus');
  69. $firstOrderIdArr[0][] = $orderInfo['order_id'];
  70. continue;
  71. }
  72. $timeStart= date('Y-m-d 00:00:00', $orderInfo['mp_user_register_time']/1000);
  73. $timeEnd = date('Y-m-d 23:59:59', $orderInfo['mp_user_register_time']/1000);
  74. $firstOrderInfo = DjOrder::query()
  75. ->where('mp_user_register_time', '>=', strtotime($timeStart)*1000)
  76. ->where('mp_user_register_time', '<=', strtotime($timeEnd)*1000)
  77. ->where('order_pay_time', '>=', strtotime($timeStart)*1000)
  78. ->where('order_pay_time', '<=', strtotime($timeEnd)*1000)
  79. ->where('ma_app_id', $orderInfo['ma_app_id'])
  80. ->where('ma_open_id', $orderInfo['ma_open_id'])
  81. ->where('adq_account_id', $orderInfo['adq_account_id'])
  82. ->where('pay_status', 1)
  83. ->select(['order_id'])
  84. ->orderBy('order_pay_time', 'ASC')
  85. ->first();
  86. if(empty($firstOrderInfo)) {
  87. $firstOrderIdArr[0][] = $orderInfo['order_id'];
  88. continue;
  89. // Log::logError('处理用户首单状态-查询首单失败', $orderData, 'DealFirstOrderStatus');
  90. // return false;
  91. }
  92. if($firstOrderInfo->order_id == $orderInfo['order_id']) {
  93. $firstOrderIdArr[1][] = $orderInfo['order_id'];
  94. } else {
  95. $firstOrderIdArr[0][] = $orderInfo['order_id'];
  96. }
  97. }
  98. foreach($firstOrderIdArr as $key => $value) {
  99. DjOrder::query()->whereIn('order_id', $value)->update(['first_order_status' => $key]);
  100. }
  101. }
  102. }
  103. }