Răsfoiți Sursa

数据更新

shish 4 ani în urmă
părinte
comite
b28cc9fd1a
1 a modificat fișierele cu 22 adăugiri și 1 ștergeri
  1. 22 1
      console/controllers/StatKdController.php

+ 22 - 1
console/controllers/StatKdController.php

@@ -4,7 +4,10 @@ namespace console\controllers;
 
 use biz\shop\classes\ShopClass;
 use biz\stat\classes\StatKdClass;
+use biz\stat\classes\StatRefundClass;
+use bizGhs\order\classes\OrderClass;
 use bizGhs\order\models\Order;
+use bizGhs\order\models\RefundOrder;
 use yii\console\Controller;
 use Yii;
 
@@ -22,7 +25,6 @@ class StatKdController extends Controller
 
         $query = new \yii\db\Query();
         $query->from(Order::tableName());
-        $query->where(['>', 'status', 1]);
 
         foreach ($query->batch() as $batch) {
 
@@ -42,6 +44,25 @@ class StatKdController extends Controller
                 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);
+            }
+        }
     }
 
 }