Explorar el Código

客户采购统计

shish hace 4 años
padre
commit
cbe8f3ba60

+ 3 - 0
biz-ghs/order/services/OrderService.php

@@ -7,6 +7,7 @@ use biz\shop\classes\ShopAdminClass;
 use biz\shop\classes\ShopCapitalClass;
 use biz\shop\classes\ShopClass;
 use biz\stat\classes\StatKdClass;
+use biz\stat\classes\StatKhCgClass;
 use biz\stat\classes\StatSaleClass;
 use biz\wx\classes\WxMessageClass;
 use bizGhs\base\services\BaseService;
@@ -649,6 +650,8 @@ class OrderService extends BaseService
         StatOrderClass::updateOrInsert($shop);
         //销售统计
         StatSaleClass::replace($shop, $amount);
+        //客户采购统计
+        StatKhCgClass::replace($order);
 
         //显示已下单流程
         $time = date("Y-m-d H:i:s");

+ 66 - 0
biz/stat/classes/StatKhCgClass.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+
+class StatKhCgClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatKhCg';
+
+    //客户采购统计 shish 2021012
+    public static function replace($order, $date = null)
+    {
+        $sjId = $order->sjId ?? 0;
+        $shopId = $order->shopId ?? 0;
+        $customId = $order->customId ?? 0;
+        $time = $date == null ? date('Ymd') : $date;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
+        }
+        $id = $stat->id;
+        $amount = $order->actPrice ?? 0;
+        $unique = self::getLockById($id);
+
+        $num = $order->itemNum ?? 0;
+
+        $currentNum = bcadd($unique->num, $num, 2);
+        $unique->num = $currentNum;
+
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+
+        $unique->save();
+        StatKhCgMonthClass::replace($order, $time);
+    }
+
+    //客户退款统计
+    public static function refundReplace($order, $date = null)
+    {
+        $sjId = $order['sjId'] ?? 0;
+        $shopId = $order['shopId'] ?? 0;
+        $customId = $order['customId'] ?? 0;
+        $time = $date == null ? date('Ymd') : $date;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+
+        $num = $order['itemNum'] ?? 0;
+        $unitePrice = $order['itemPrice'] ?? 0;
+        $price = bcmul($unitePrice, $num, 2);
+
+        $currentRefundNum = bcadd($unique->refundNum, $num, 2);
+        $currentRefundAmount = bcadd($unique->refundAmount, $price, 2);
+        $unique->refundNum = $currentRefundNum;
+        $unique->refundAmount = $currentRefundAmount;
+        $unique->save();
+
+        StatKhCgMonthClass::refundReplace($order, $time);
+    }
+
+}

+ 84 - 0
biz/stat/classes/StatKhCgMonthClass.php

@@ -0,0 +1,84 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+use biz\stat\models\StatCg;
+use common\components\util;
+
+class StatKhCgMonthClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatKhCgMonth';
+
+    //每月客户采购统计 shish 20211012
+    public static function replace($order, $date = null)
+    {
+        if ($date == null) {
+            $time = date('Ym');
+            $year = date('Y');
+            $month = date('m');
+        } else {
+            $timestamp = strtotime($date);
+            $time = date('Ym', $timestamp);
+            $year = date('Y', $timestamp);
+            $month = date('m', $timestamp);
+        }
+        $sjId = $order->sjId ?? 0;
+        $shopId = $order->shopId ?? 0;
+        $customId = $order->customId ?? 0;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time, 'year' => $year, 'month' => $month], true);
+        }
+        $id = $stat->id;
+        $amount = $order->actPrice ?? 0;
+        $unique = self::getLockById($id);
+
+        $num = $order->itemNum ?? 0;
+
+        $currentNum = bcadd($unique->num, $num, 2);
+        $unique->num = $currentNum;
+
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+
+        $unique->save();
+    }
+
+    //客户退款
+    public static function refundReplace($order, $date = null)
+    {
+        if ($date == null) {
+            $time = date('Ym');
+            $year = date('Y');
+            $month = date('m');
+        } else {
+            $timestamp = strtotime($date);
+            $time = date('Ym', $timestamp);
+            $year = date('Y', $timestamp);
+            $month = date('m', $timestamp);
+        }
+        $sjId = $order['sjId'] ?? 0;
+        $shopId = $order['shopId'] ?? 0;
+        $customId = $order['customId'] ?? 0;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time, 'year' => $year, 'month' => $month], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+
+        $num = $order['itemNum'] ?? 0;
+        $unitePrice = $order['itemPrice'] ?? 0;
+        $price = bcmul($unitePrice, $num, 2);
+
+        $currentRefundNum = bcadd($unique->refundNum, $num, 2);
+        $currentRefundAmount = bcadd($unique->refundAmount, $price, 2);
+        $unique->refundNum = $currentRefundNum;
+        $unique->refundAmount = $currentRefundAmount;
+
+        $unique->save();
+    }
+
+}

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

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

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

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

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 6 - 0
console/controllers/ProductController.php


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio