Jelajahi Sumber

开单数据更新

shish 4 tahun lalu
induk
melakukan
06f22905be
1 mengubah file dengan 47 tambahan dan 0 penghapusan
  1. 47 0
      console/controllers/StatKdController.php

+ 47 - 0
console/controllers/StatKdController.php

@@ -0,0 +1,47 @@
+<?php
+
+namespace console\controllers;
+
+use biz\shop\classes\ShopClass;
+use biz\stat\classes\StatKdClass;
+use bizGhs\order\models\Order;
+use yii\console\Controller;
+use Yii;
+
+class StatKdController extends Controller
+{
+
+    //销售数据更新 ./yii stat-kd/update
+    public function actionUpdate()
+    {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        $sql = 'TRUNCATE `xhStatKd`;TRUNCATE `xhStatKdMonth`;';
+        Yii::$app->db->createCommand($sql)->execute();
+
+        $query = new \yii\db\Query();
+        $query->from(Order::tableName());
+        $query->where(['>', 'status', 1]);
+
+        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;
+                $shopId = $order['shopId'] ?? 0;
+                $shop = ShopClass::getLockById($shopId);
+                if (empty($shop)) {
+                    continue;
+                }
+                $date = date('Ymd', strtotime($order['addTime']));
+                StatKdClass::replace($shop, $amount, $payWay, $date);
+            }
+        }
+    }
+
+}