123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2022/12/20
- * Time: 14:21
- */
- namespace App\Console\Repair;
- use App\Log;
- use App\Models\DjOrder;
- use App\Service\DjOrderService;
- use App\Service\HttpService;
- use App\Service\JiaShuService;
- use Illuminate\Console\Command;
- class HistoryOrderFromJiaShuWeb extends Command
- {
- protected $signature = 'HistoryOrderFromJiaShuWeb';
- protected $description = '嘉书H5历史订单获取';
- public function __construct()
- {
- parent::__construct();
- }
- public function handle()
- {
- // $startTime = '2022-12-20 03:00:00';
- // $endTime = '2022-12-20 10:00:00';
- //
- // $customerId = 111;
- // $apiKey = '5eb24c607326536d412eba0bc21018c4';
- //
- // $requestUri = 'https://video-adreport.eastdrama.com/data/v2';
- //
- // $paramsArr['customer_id'] = $customerId;
- // $paramsArr['timestamp'] = time();
- // $paramsArr['type'] = 'pay';
- // $paramsArr['start_time'] = $startTime;
- // $paramsArr['end_time'] = $endTime;
- //
- // # 生成签名
- // $params = JiaShuService::createSign($apiKey, $paramsArr);
- //
- // $response = HttpService::httpPost($requestUri, $params);
- // $responseData = json_decode($response, 1);
- // Log::logInfo('', $responseData, 'test-4');
- // DjOrderService::jiashuWebOrderSave($responseData['data']['data']);
- // print_r($responseData);
- $startId = 0;
- $this->info('开始处理');
- while(true) {
- $orderList = DjOrder::query()->select(['id', 'order_id', 'ma_app_id', 'ma_open_id', 'mp_user_register_time'
- , 'order_pay_time', 'adq_account_id', 'order_source', 'is_ad_user'])
- ->where('pay_status', 1)->where('adq_account_id', '>', '')
- ->where('is_ad_user', 1)->where('id', '>', $startId)
- ->where('create_time', '>=', '2023-12-11')
- ->orderBy('id', 'asc')->limit(1000)->get();
- if($orderList->isEmpty()) {
- $this->info('处理完成');
- break;
- }
- $count = $orderList->count();
- $this->info('本次查询数据共 '.$count.' 条,数据起始id为: '.$startId);
- $startId = $orderList->max('id');
- $orderList = $orderList->toArray();
- $firstOrderIdArr = [];
- foreach($orderList as $orderInfo) {
- if(empty($orderInfo['ma_app_id']) || empty($orderInfo['ma_open_id']) || empty($orderInfo['mp_user_register_time'])
- || empty($orderInfo['order_pay_time']) || empty($orderInfo['adq_account_id']) || empty($orderInfo['is_ad_user'])) {
- // Log::logError('处理用户首单状态-订单基础数据不全', $orderInfo, 'DealFirstOrderStatus');
- $firstOrderIdArr[0][] = $orderInfo['order_id'];
- continue;
- }
- $timeStart= date('Y-m-d 00:00:00', $orderInfo['mp_user_register_time']/1000);
- $timeEnd = date('Y-m-d 23:59:59', $orderInfo['mp_user_register_time']/1000);
- $firstOrderInfo = DjOrder::query()
- ->where('mp_user_register_time', '>=', strtotime($timeStart)*1000)
- ->where('mp_user_register_time', '<=', strtotime($timeEnd)*1000)
- ->where('order_pay_time', '>=', strtotime($timeStart)*1000)
- ->where('order_pay_time', '<=', strtotime($timeEnd)*1000)
- ->where('ma_app_id', $orderInfo['ma_app_id'])
- ->where('ma_open_id', $orderInfo['ma_open_id'])
- ->where('adq_account_id', $orderInfo['adq_account_id'])
- ->where('pay_status', 1)
- ->select(['order_id'])
- ->orderBy('order_pay_time', 'ASC')
- ->first();
- if(empty($firstOrderInfo)) {
- $firstOrderIdArr[0][] = $orderInfo['order_id'];
- continue;
- // Log::logError('处理用户首单状态-查询首单失败', $orderData, 'DealFirstOrderStatus');
- // return false;
- }
- if($firstOrderInfo->order_id == $orderInfo['order_id']) {
- $firstOrderIdArr[1][] = $orderInfo['order_id'];
- } else {
- $firstOrderIdArr[0][] = $orderInfo['order_id'];
- }
- }
- foreach($firstOrderIdArr as $key => $value) {
- DjOrder::query()->whereIn('order_id', $value)->update(['first_order_status' => $key]);
- }
- }
- }
- }
|