$item) { $orderSn = $item->orderSn ?? ''; if (empty($orderSn)) { continue; } $refund = RefundOrderClass::getByCondition(['orderSn' => $orderSn], true); if (empty($refund)) { continue; } $sjId = $refund->sjId ?? 0; $shopId = $refund->shopId ?? 0; $item->sjId = $sjId; $item->shopId = $shopId; $item->save(); $date = date('Ymd', strtotime($refund->addTime)); StatItemClass::refundReplace($item, $date); } } // ./yii refund-item/order public function actionOrder() { ini_set('memory_limit', '2045M'); set_time_limit(0); $query = new \yii\db\Query(); $query->from(Order::tableName()); $query->where(['>', 'status', 1]); foreach ($query->batch() as $purchases) { foreach ($purchases as $order) { $status = $order['status'] ?? 0; if (in_array($status, [1, 5])) { continue; } $orderSn = $order['orderSn'] ?? ''; if (empty($orderSn)) { continue; } $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true); if (!empty($itemList)) { foreach ($itemList as $itemInfo) { $sjId = $itemInfo->sjId ?? 0; $shopId = $itemInfo->shopId ?? 0; $productId = $itemInfo->productId ?? 0; if (empty($sjId) || empty($shopId)) { $p = ProductClass::getById($productId, true); $sjId = $p->sjId ?? 0; $shopId = $p->shopId ?? 0; $itemInfo->sjId = $sjId; $itemInfo->shopId = $shopId; $itemInfo->save(); echo "发现没有sjId shopId 已经补充 orderItemId:{$itemInfo->id} sjId:{$sjId} shopId:{$shopId} 如果是0表示没有补到 \n"; } $date = date('Ymd', strtotime($order['addTime'])); $mainId = $itemInfo->mainId ?? 0; $itemId = $itemInfo->productId ?? 0; $num = $itemInfo->num ?? 0; $price = $itemInfo->price ?? 0; $params = [ 'mainId' => $mainId, 'itemId' => $itemId, 'price' => $price, 'num' => $num, ]; StatItemClass::replace($params, $date); } } } } } }