Browse Source

花材提示

shish 1 year ago
parent
commit
f03e942298
2 changed files with 126 additions and 0 deletions
  1. 10 0
      app-hd/controllers/ItemController.php
  2. 116 0
      biz-hd/product/classes/ProductClass.php

+ 10 - 0
app-hd/controllers/ItemController.php

@@ -116,6 +116,16 @@ class ItemController extends BaseController
             $list = ProductClass::itemListGroup($list, $level);
         } elseif ($requestType == 'changePrice') {
             $list = ProductClass::changePriceGroup($list, $level);
+        } elseif ($requestType == 'break') {
+            $list = ProductClass::breakItemGroup($list, $level);
+        } elseif ($requestType == 'part') {
+            $list = ProductClass::partItemGroup($list, $level);
+        } elseif ($requestType == 'check') {
+            $list = ProductClass::checkItemGroup($list, $level);
+        } elseif ($requestType == 'changeStock') {
+            $list = ProductClass::changeStockGroup($list, $level);
+        } elseif ($requestType == 'stockOut') {
+            $list = ProductClass::stockOutGroup($list, $level);
         } else {
             util::fail('没有数据');
         }

+ 116 - 0
biz-hd/product/classes/ProductClass.php

@@ -274,4 +274,120 @@ class ProductClass extends BaseClass
         return $list;
     }
 
+    public static function breakItemGroup($list, $level = 0)
+    {
+        foreach ($list as $k => $v) {
+            $shortCover = $v['cover'] ?? '';
+
+            $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 20;
+            $stockInfo = self::formatStock($v['stock'], $ratio);
+            $list[$k]['bigNum'] = $stockInfo['bigNum'];
+            $list[$k]['smallNum'] = $stockInfo['smallNum'];
+
+            $list[$k]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
+        }
+        return $list;
+    }
+
+    public static function partItemGroup($list, $level = 0)
+    {
+        foreach ($list as $k => $v) {
+            $shortCover = $v['cover'] ?? '';
+
+            $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 20;
+            $stockInfo = self::formatStock($v['stock'], $ratio);
+            $list[$k]['bigNum'] = $stockInfo['bigNum'];
+            $list[$k]['smallNum'] = $stockInfo['smallNum'];
+
+            $list[$k]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
+        }
+        return $list;
+    }
+
+    public static function checkItemGroup($list, $level = 0)
+    {
+        foreach ($list as $k => $v) {
+            $shortCover = $v['cover'] ?? '';
+            $list[$k]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
+
+            $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 1;
+            $stockInfo = self::formatStock($v['stock'], $ratio);
+            $list[$k]['bigNum'] = $stockInfo['bigNum'];
+            $list[$k]['smallNum'] = $stockInfo['smallNum'];
+
+        }
+        return $list;
+    }
+
+    //通用花材列表数组组合
+    public static function changeStockGroup($list, $level = 0)
+    {
+        //各个等级对应的price addPrice字段
+        $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
+        $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
+        foreach ($list as $k => $v) {
+            $shortCover = $v['cover'] ?? '';
+            $cover = imgUtil::getPrefix() . 'hhb_small.png';
+            if (!empty($shortCover)) {
+                $parse = parse_url(self::groupImg($shortCover));
+                if (empty($parse['query'])) {
+                    $cover = self::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
+                } else {
+                    $cover = self::groupImg($shortCover);
+                }
+            }
+            $list[$k]['cover'] = $cover;
+            $list[$k]['prePrice'] = $v['price'] ?? 0;
+            //今日特价、会员价
+            $price = \bizGhs\product\classes\ProductClass::getFinalPrice($v, $level, $priceMap, $addPriceMap);
+            //零售做特价时的原价
+            if ($level == 0) {
+                $currentAddPrice = $v['skMore'] ?? 0;
+                $list[$k]['prePrice'] = bcadd($v['price'], $currentAddPrice, 2);
+            }
+            if (isset($v['discountPrice']) && $v['discountPrice'] > 0) {
+                $currentAddPrice = $v['skMore'] ?? 0;
+                $list[$k]['skPrice'] = bcadd($v['discountPrice'], $currentAddPrice, 2);
+            }
+            $list[$k]['price'] = $price;
+
+            $cost = $v['cost'] ?? 0;
+            $ml = 0;
+            if ($price > 0) {
+                $profit = bcsub($price, $cost, 2);
+                $ml = $profit;
+                $mll = bcdiv($profit, $price, 3);
+                $mll = bcmul($mll, 100);
+                $mll = round($mll, 1);
+            } else {
+                $mll = 0;
+            }
+            $list[$k]['mll'] = $mll;
+            $list[$k]['ml'] = $ml;
+        }
+        return $list;
+    }
+
+    public static function stockOutGroup($list, $level = 0)
+    {
+
+        //各个等级对应的price addPrice字段
+        $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
+        $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
+
+        foreach ($list as $k => $v) {
+            $shortCover = $v['cover'] ?? '';
+            $list[$k]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
+            $price = \bizGhs\product\classes\ProductClass::getFinalPrice($v, $level, $priceMap, $addPriceMap);
+            $list[$k]['price'] = $price;
+            $list[$k]['bigPrice'] = $price;
+            $smallRatio = $v['smallRatio'] ?? 0;
+            $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 20;
+            $smallPrice = bcdiv($price, $ratio, 2);
+            $smallPrice = bcmul($smallPrice, $smallRatio, 2);
+            $list[$k]['smallPrice'] = $smallPrice;
+        }
+        return $list;
+    }
+
 }