db->createCommand($sql)->execute(); $query = new \yii\db\Query(); $query->from(Order::tableName()); foreach ($query->batch() as $batch) { foreach ($batch as $order) { $status = $order['status'] ?? 0; if ($status == 1 || $status == 5) { continue; } $payWay = $order['payWay'] ?? 0; $amount = $order['actPrice'] ?? 0; $refundPrice = $order['refundPrice'] ?? 0; if ($refundPrice > 0) { $amount = bcadd($amount, $refundPrice, 2); } $shopId = $order['shopId'] ?? 0; $shop = ShopClass::getLockById($shopId); if (empty($shop)) { continue; } $date = date('Ymd', strtotime($order['addTime'])); //各渠道收入金额统计 StatKdClass::replace($shop, $amount, $payWay, $date); } } $sql = 'TRUNCATE `xhStatRefund`;TRUNCATE `xhStatRefundMonth`;'; Yii::$app->db->createCommand($sql)->execute(); $query = new \yii\db\Query(); $query->from(RefundOrder::tableName()); foreach ($query->batch() as $batch) { foreach ($batch as $refund) { $relateOrderSn = $refund['relateOrderSn'] ?? ''; $order = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true); $payWay = $order->payWay ?? 0; $shopId = $refund['shopId'] ?? 0; $shop = ShopClass::getLockById($shopId); $amount = $refund['refundPrice'] ?? 0; $date = date('Ymd', strtotime($refund['addTime'])); StatRefundClass::replace($shop, $payWay, $amount, $date); } } } }