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]); } } } }