Bläddra i källkod

统计每天和每月的盘盈盘亏数额

shish 5 år sedan
förälder
incheckning
935960f32e

+ 13 - 0
biz-ghs/order/classes/CheckOrderClass.php

@@ -2,6 +2,9 @@
 
 namespace bizGhs\order\classes;
 
+use biz\shop\classes\ShopClass;
+use biz\stat\classes\StatPdAddClass;
+use biz\stat\classes\StatPdSubClass;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\stock\services\StockRecordService;
 use common\components\orderSn;
@@ -111,6 +114,16 @@ class CheckOrderClass extends BaseClass
             $order->price = bcadd($addAmount, $subAmount, 2);
             $order->save();
 
+            $shop = ShopClass::getLockById($shopId);
+            //统计每天和每月的盘盈盘亏数额
+            if ($addAmount > 0) {
+                StatPdAddClass::replace($shop, $addAmount);
+            }
+            $subAmount = abs($subAmount);
+            if ($subAmount > 0) {
+                StatPdSubClass::replace($shop, $subAmount);
+            }
+
             $transaction->commit();
             return $order;
 

+ 32 - 0
biz/stat/classes/StatPdAddClass.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+
+class StatPdAddClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatPdAdd';
+
+    //盘盈统计 shish 20210827
+    public static function replace($shop, $amount)
+    {
+        $sjId = $shop->sjId;
+        $shopId = $shop->id;
+        $time = date('Ymd');
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'time' => $time, 'num' => 0], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+        $unique->totalAmount = $shop->totalPurchase;
+        $unique->num += 1;
+        $unique->save();
+        StatPdAddMonthClass::replace($shop, $amount);
+    }
+
+}

+ 34 - 0
biz/stat/classes/StatPdAddMonthClass.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+use common\components\util;
+
+class StatPdAddMonthClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatPdAddMonth';
+
+    //每月盘盈统计 shish 20210827
+    public static function replace($shop, $amount)
+    {
+        $time = date('Ym');
+        $year = date('Y');
+        $month = date('m');
+        $sjId = $shop->sjId;
+        $shopId = $shop->id;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+        $unique->totalAmount = $shop->totalPurchase;
+        $unique->num += 1;
+        $unique->save();
+    }
+
+}

+ 32 - 0
biz/stat/classes/StatPdSubClass.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+
+class StatPdSubClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatPdSub';
+
+    //盘亏统计 shish 20210827
+    public static function replace($shop, $amount)
+    {
+        $sjId = $shop->sjId;
+        $shopId = $shop->id;
+        $time = date('Ymd');
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'time' => $time, 'num' => 0], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+        $unique->totalAmount = $shop->totalPurchase;
+        $unique->num += 1;
+        $unique->save();
+        StatPdSubMonthClass::replace($shop, $amount);
+    }
+
+}

+ 34 - 0
biz/stat/classes/StatPdSubMonthClass.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+use common\components\util;
+
+class StatPdSubMonthClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatPdSubMonth';
+
+    //每月盘亏统计 shish 20210827
+    public static function replace($shop, $amount)
+    {
+        $time = date('Ym');
+        $year = date('Y');
+        $month = date('m');
+        $sjId = $shop->sjId;
+        $shopId = $shop->id;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+        $unique->totalAmount = $shop->totalPurchase;
+        $unique->num += 1;
+        $unique->save();
+    }
+
+}

+ 32 - 0
biz/stat/classes/StatWastClass.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+
+class StatWastClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatWast';
+
+    //盘盈统计 shish 20210827
+    public static function replace($shop, $amount)
+    {
+        $sjId = $shop->sjId;
+        $shopId = $shop->id;
+        $time = date('Ymd');
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'time' => $time, 'num' => 0], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+        $unique->totalAmount = $shop->totalPurchase;
+        $unique->num += 1;
+        $unique->save();
+        StatWastMonthClass::replace($shop, $amount);
+    }
+
+}

+ 34 - 0
biz/stat/classes/StatWastMonthClass.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+use common\components\util;
+
+class StatWastMonthClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatWastMonth';
+
+    //每月盘亏统计 shish 20210827
+    public static function replace($shop, $amount)
+    {
+        $time = date('Ym');
+        $year = date('Y');
+        $month = date('m');
+        $sjId = $shop->sjId;
+        $shopId = $shop->id;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+        $unique->totalAmount = $shop->totalPurchase;
+        $unique->num += 1;
+        $unique->save();
+    }
+
+}

+ 13 - 0
biz/stat/models/StatPdAdd.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\stat\models;
+
+use biz\base\models\Base;
+
+class StatPdAdd extends Base
+{
+    public static function tableName()
+    {
+        return 'xhStatPdAdd';
+    }
+}

+ 13 - 0
biz/stat/models/StatPdAddMonth.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\stat\models;
+
+use biz\base\models\Base;
+
+class StatPdAddMonth extends Base
+{
+    public static function tableName()
+    {
+        return 'xhStatPdAddMonth';
+    }
+}

+ 13 - 0
biz/stat/models/StatPdSub.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\stat\models;
+
+use biz\base\models\Base;
+
+class StatPdSub extends Base
+{
+    public static function tableName()
+    {
+        return 'xhStatPdSub';
+    }
+}

+ 15 - 0
biz/stat/models/StatPdSubMonth.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace biz\stat\models;
+
+use biz\base\models\Base;
+
+class StatPdSubMonth extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhStatPdSubMonth';
+    }
+
+}

+ 13 - 0
biz/stat/models/StatWast.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\stat\models;
+
+use biz\base\models\Base;
+
+class StatWast extends Base
+{
+    public static function tableName()
+    {
+        return 'xhStatWast';
+    }
+}

+ 13 - 0
biz/stat/models/StatWastMonth.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\stat\models;
+
+use biz\base\models\Base;
+
+class StatWastMonth extends Base
+{
+    public static function tableName()
+    {
+        return 'xhStatWastMonth';
+    }
+}