Explorar o código

大单位采购

shish %!s(int64=4) %!d(string=hai) anos
pai
achega
41e3c7a2d0

+ 95 - 0
app-ghs/controllers/StatCgGhsController.php

@@ -0,0 +1,95 @@
+<?php
+
+namespace ghs\controllers;
+
+use biz\ghs\classes\GhsClass;
+use biz\stat\classes\StatCgGhsClass;
+use common\components\arrayUtil;
+use common\components\dateUtil;
+use Yii;
+use common\components\util;
+
+class StatCgGhsController extends BaseController
+{
+
+    //采购列表 shish 20211017
+    public function actionProfile()
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['shopId'] = $this->shopId;
+        if (isset($get['shopId']) && !empty($get['shopId'])) {
+            $where['shopId'] = $get['shopId'];
+        }
+        $selectTime = $get['selectTime'] ?? 'thisMonth';
+        if (!empty($selectTime)) {
+            $startTime = $get['startTime'] ?? '';
+            $endTime = $get['endTime'] ?? '';
+            $period = dateUtil::formatTime($selectTime, $startTime, $endTime, true);
+            $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
+        }
+
+        $list = StatCgGhsClass::getAllByCondition($where, null, '*');
+        $ghsIds = [];
+        $arr = [];
+        if (!empty($list)) {
+            foreach ($list as $ke => $item) {
+                $ghsId = $item['ghsId'] ?? 0;
+                $num = $item['num'] ?? 0;
+                $refundNum = $item['refundNum'] ?? 0;
+                $amount = $item['amount'] ?? 0;
+                $refundAmount = $item['refundAmount'] ?? 0;
+                $ghsIds[$ghsId] = 1;
+
+                if (isset($arr[$ghsId]['num'])) {
+                    $arr[$ghsId]['num'] = bcadd($arr[$ghsId]['num'], $num, 2);
+                } else {
+                    $arr[$ghsId]['num'] = $num;
+                }
+
+                if (isset($arr[$ghsId]['refundNum'])) {
+                    $arr[$ghsId]['refundNum'] = bcadd($arr[$ghsId]['refundNum'], $refundNum, 2);
+                } else {
+                    $arr[$ghsId]['refundNum'] = $refundNum;
+                }
+
+                if (isset($arr[$ghsId]['amount'])) {
+                    $arr[$ghsId]['amount'] = bcadd($arr[$ghsId]['amount'], $amount, 2);
+                } else {
+                    $arr[$ghsId]['amount'] = $amount;
+                }
+
+                if (isset($arr[$ghsId]['refundAmount'])) {
+                    $arr[$ghsId]['refundAmount'] = bcadd($arr[$ghsId]['refundAmount'], $refundAmount, 2);
+                } else {
+                    $arr[$ghsId]['refundAmount'] = $refundAmount;
+                }
+
+            }
+        }
+        $ghsIds = array_keys($ghsIds);
+        $ghsData = GhsClass::getByIds($ghsIds);
+        $cg = [];
+        foreach ($ghsData as $ghs) {
+            $ghsId = $ghs['id'] ?? 0;
+            $ghsName = $ghs['name'] ?? '';
+            $ghsPy = $ghs['py'] ?? '';
+            $num = $arr[$ghsId]['num'] ?? 0;
+            $refundNum = $arr[$ghsId]['refundNum'] ?? 0;
+            $amount = $arr[$ghsId]['amount'] ?? 0;
+            $refundAmount = $arr[$ghsId]['refundAmount'] ?? 0;
+            $lastAmount = bcsub($amount, $refundAmount, 2);
+            $lastNum = bcsub($num, $refundNum, 2);
+            $cg[] = [
+                'ghsId' => $ghsId,
+                'ghsName' => $ghsName,
+                'py' => $ghsPy,
+                'num' => $lastNum,
+                'amount' => $lastAmount,
+            ];
+        }
+        $cg = arrayUtil::arraySort($cg, 'num');
+        util::success(['list' => $cg]);
+    }
+
+}

+ 14 - 0
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -6,6 +6,7 @@ use biz\ghs\classes\GhsClass;
 use biz\shop\classes\ShopCapitalClass;
 use biz\shop\classes\ShopClass;
 use biz\stat\classes\StatCgClass;
+use biz\stat\classes\StatCgGhsClass;
 use biz\stat\classes\StatOutClass;
 use bizGhs\base\classes\BaseClass;
 use bizGhs\custom\classes\CustomClass;
@@ -60,6 +61,8 @@ class PurchaseOrderClass extends BaseClass
         $bigNum = 0;
         //总共多少支
         $smallNum = 0;
+        //总数量
+        $totalNum = 0;
         $totalItemPrice = 0;
         $totalWeight = 0;
         $ghsItemInfoMap = [];
@@ -77,6 +80,14 @@ class PurchaseOrderClass extends BaseClass
             }
             $bigNum += $v['bigNum'] ?? 0;
             $smallNum += $v['smallNum'] ?? 0;
+
+            //限制不允许小单位采购,这样大单位就量总数量 shish 20211021
+            if (isset($v['smallNum']) && $v['smallNum'] > 0) {
+                util::fail('采购最小单位必须扎');
+            }
+            $currentBigNum = $v['bigNum'] ?? 0;
+            $totalNum = bcadd($totalNum, $currentBigNum, 2);
+
             $currentTotalPrice = bcmul($v['bigNum'], $v['itemPrice'], 2);
             $totalItemPrice = bcadd($totalItemPrice, $currentTotalPrice, 2);
             $ghsItemInfoMap[$v['productId']] = $v;
@@ -87,6 +98,7 @@ class PurchaseOrderClass extends BaseClass
         }
 
         $data['bigNum'] = $bigNum;
+        $data['itemNum'] = $totalNum;
         $data['smallNum'] = $smallNum;
         $data['price'] = $totalItemPrice;
         $data['totalWeight'] = $totalWeight;
@@ -262,6 +274,8 @@ class PurchaseOrderClass extends BaseClass
 
             //采购统计
             StatCgClass::replace($shop, $currentPrice);
+            //采购按供货商统计
+            StatCgGhsClass::ghsReplace($order, $currentPrice);
             //当天和当月支出统计
             StatOutClass::updateOrInsert($shop, $currentPrice);
 

+ 67 - 0
biz/stat/classes/StatCgGhsClass.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+
+class StatCgGhsClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatCgGhs';
+
+    //采购统计 shish 2021012
+    public static function ghsReplace($cgInfo, $amount, $date = null)
+    {
+        $sjId = $cgInfo->sjId ?? 0;
+        $shopId = $cgInfo->shopId ?? 0;
+        $ghsId = $cgInfo->ghsId ?? 0;
+        $time = $date == null ? date('Ymd') : $date;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'ghsId' => $ghsId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time], true);
+        }
+        $id = $stat->id;
+
+        $unique = self::getLockById($id);
+
+        $num = $cgInfo->itemNum ?? 0;
+
+        $currentNum = bcadd($unique->num, $num, 2);
+        $unique->num = $currentNum;
+
+        $currentAmount = bcadd($unique->amount, $amount, 2);
+        $unique->amount = $currentAmount;
+
+        $unique->save();
+        StatCgGhsMonthClass::ghsReplace($cgInfo, $amount, $time);
+    }
+
+    //退款统计
+    public static function ghsRefundReplace($cgInfo, $date = null)
+    {
+        $sjId = $cgInfo->sjId ?? 0;
+        $shopId = $cgInfo->shopId ?? 0;
+        $ghsId = $cgInfo->ghsId ?? 0;
+        $time = $date == null ? date('Ymd') : $date;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'ghsId' => $ghsId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+
+        $num = $cgInfo->itemNum ?? 0;
+        $refundPrice = $cgInfo->refundPrice ?? 0;
+
+        $currentRefundNum = bcadd($unique->refundNum, $num, 2);
+
+        $currentRefundAmount = bcadd($unique->refundAmount, $refundPrice, 2);
+
+        $unique->refundNum = $currentRefundNum;
+        $unique->refundAmount = $currentRefundAmount;
+
+        $unique->save();
+        StatCgGhsMonthClass::ghsRefundReplace($cgInfo, $time);
+    }
+
+}

+ 81 - 0
biz/stat/classes/StatCgGhsMonthClass.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace biz\stat\classes;
+
+use biz\base\classes\BaseClass;
+
+class StatCgGhsMonthClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\stat\models\StatCgGhsMonth';
+
+    //每月采购统计 shish 20211012
+    public static function ghsReplace($order, $amount, $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;
+        $ghsId = $order->ghsId ?? 0;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'ghsId' => $ghsId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time, 'year' => $year, 'month' => $month], true);
+        }
+        $id = $stat->id;
+        $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 ghsRefundReplace($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;
+        $ghsId = $order['ghsId'] ?? 0;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'ghsId' => $ghsId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time, 'year' => $year, 'month' => $month], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+
+        $num = $order->itemNum ?? 0;
+        $currentRefundNum = bcadd($unique->refundNum, $num, 2);
+
+        $refundPrice = $order->refundPrice ?? 0;
+        $currentRefundAmount = bcadd($unique->refundAmount, $refundPrice, 2);
+
+        $unique->refundNum = $currentRefundNum;
+        $unique->refundAmount = $currentRefundAmount;
+
+        $unique->save();
+    }
+
+}

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

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

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

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