shish před 1 rokem
rodič
revize
2f71de6750

+ 55 - 0
app-hd/controllers/ItemClassController.php

@@ -8,12 +8,67 @@ namespace hd\controllers;
 
 use bizGhs\item\classes\ItemClassClass;
 use bizGhs\item\services\ItemClassService;
+use bizHd\product\classes\ProductClass;
 use common\components\dict;
+use common\components\imgUtil;
 use common\components\util;
 use Yii;
 
 class ItemClassController extends BaseController
 {
+
+    //获取花材列表的菜单 ssh 20240222
+    //这里不能取出className,否则会影响前端显示,重要注意事项,请搜索关键词import_class_name!!!!!!!!!!!!!!
+    public function actionGetMenu()
+    {
+        $mainId = $this->mainId;
+        $itemList = ProductClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0, 'status' => 1], null, 'id,name,reachNum,reachNumDiscount,presell,discountPrice', null, true);
+        $arr = [];
+        if (!empty($itemList)) {
+            foreach ($itemList as $item) {
+                $reachNum = $item->reachNum ?? 0;
+                $reachNumDiscount = $item->reachNumDiscount ?? 0;
+                if (isset($item->presell) && $item->presell == 1) {
+                    $arr[3] = [
+                        'id' => -3,
+                        'name' => '预售专区',
+                        'shortCover' => 'item_class/mrfl.png',
+                        'cover' => imgUtil::groupImg('item_class/mrfl.png') . "?x-oss-process=image/resize,m_fill,h_130,w_130"
+                    ];
+                }
+                if (isset($item->discountPrice) && $item->discountPrice > 0) {
+                    $arr[1] = [
+                        'id' => -1,
+                        'name' => '今日推荐',
+                        'shortCover' => 'item_class/tj.jpg',
+                        'cover' => imgUtil::groupImg('item_class/tj.jpg') . "?x-oss-process=image/resize,m_fill,h_130,w_130"
+                    ];
+                }
+                if ($reachNum > 0 && $reachNumDiscount > 0) {
+                    $arr[2] = [
+                        'id' => -2,
+                        'name' => '满减活动',
+                        'shortCover' => 'item_class/mrfl.png',
+                        'cover' => imgUtil::groupImg('item_class/mrfl.png') . "?x-oss-process=image/resize,m_fill,h_130,w_130"
+                    ];
+                }
+            }
+        }
+        $classInfo = ItemClassClass::getGhsItemClassAll($mainId);
+        $index = [];
+        if (!empty($classInfo)) {
+            foreach ($classInfo as $class) {
+                $id = $class['id'] ?? 0;
+                $index[$id] = $class;
+            }
+        }
+        if (!empty($arr)) {
+            $arr = array_values($arr);
+            $classInfo = array_merge($arr, $classInfo);
+        }
+        util::success(['class' => $classInfo, 'classIndex' => $index]);
+    }
+
     public function actionList()
     {
         $where = ['mainId' => $this->mainId];

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

@@ -7,14 +7,118 @@ use biz\item\classes\PtItemClass;
 
 use bizGhs\item\classes\ItemClass;
 use bizGhs\item\services\ItemService;
+use bizHd\custom\classes\CustomClass;
 use bizHd\product\classes\ProductClass;
 use common\components\dict;
+use common\components\stringUtil;
 use common\components\util;
 use Yii;
 
 class ItemController extends BaseController
 {
 
+    //列出所有花材 ssh 20240222
+    public function actionGetItemList()
+    {
+        $get = Yii::$app->request->get();
+        $search = $get['search'] ?? '';
+        $requestType = $get['requestType'] ?? 'kd';
+        $classId = $get['classId'] ?? 0;
+        $lookStock = $get['lookStock'] ?? 0;
+
+        $where['mainId'] = $this->mainId;
+        if ($requestType == 'kd') {
+            $where['delStatus'] = 0;
+            $where['status'] = 1;
+        } elseif ($requestType == 'itemList') {
+            $where['delStatus'] = 0;
+            if ($lookStock == 1) {
+                $where['stock>'] = 0;
+            }
+            if ($lookStock == 2) {
+                $where['stock'] = 0;
+            }
+            unset($where['status']);
+        } elseif ($requestType == 'changePrice') {
+            $where['delStatus'] = 0;
+            $where['stock>'] = 0;
+        } elseif ($requestType == 'hasStockList') {
+            $where['delStatus'] = 0;
+            $where['stock>'] = 0;
+        } elseif ($requestType == 'book') {
+            $where['delStatus'] = 0;
+            unset($where['status']);
+        } elseif ($requestType == 'outList') {
+            $where['delStatus'] = 0;
+            $where['status'] = 2;
+            $where['removeStatus'] = 0;
+        } elseif ($requestType == 'stopList') {
+            $where['delStatus'] = 1;
+            unset($where['status']);
+            $where['removeStatus'] = 0;
+        } elseif ($requestType == 'removeList') {
+            $where['delStatus'] = 1;
+            unset($where['status']);
+            $where['removeStatus'] = 1;
+        } elseif ($requestType == 'cg') {
+            $where['delStatus'] = 0;
+            unset($where['status']);
+        } elseif ($requestType == 'changeStock') {
+            $where['delStatus'] = 0;
+            unset($where['status']);
+        } elseif ($requestType == 'check') {
+            $where['delStatus'] = 0;
+            unset($where['status']);
+        } elseif ($requestType == 'stockOut') {
+            $where['delStatus'] = 0;
+            $where['status'] = 1;
+        } elseif ($requestType == 'break') {
+            $where['delStatus'] = 0;
+            $where['status'] = 1;
+        } else {
+            util::fail('没有定义的请求方式');
+        }
+        if (!empty($search)) {
+            if (stringUtil::isLetter($search)) {
+                $search = strtolower($search);
+                $where['py'] = ['like', $search];
+            } else {
+                $where['name'] = ['like', $search];
+            }
+        } else {
+            if (!empty($classId)) {
+                if ($classId == -1) {
+                    $where['discountPrice>'] = 0;
+                } elseif ($classId == -2) {
+                    $where['reachNum>'] = 0;
+                } elseif ($classId == -3) {
+                    $where['presell'] = 1;
+                } else {
+                    $where['classId'] = $classId;
+                }
+            }
+        }
+        $customId = $get['customId'] ?? 0;
+        $custom = CustomClass::getById($customId, true);
+        if (!empty($custom)) {
+            if ($custom->shopId != $this->shopId) {
+                util::fail('不是你的客户哦,编号55236');
+            }
+        }
+        $level = $custom->level ?? 1;
+        $field = '*';
+
+        $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
+        $list = $result['list'] ?? [];
+        if ($requestType == 'kd') {
+            $list = ProductClass::kdItemGroup($list, $level);
+        } else {
+            util::fail('没有数据');
+        }
+        $result['list'] = $list;
+        util::success($result);
+    }
+
     //增加和减少半扎 ssh 20250417
     public function actionChangeHalf()
     {

+ 60 - 1
biz-hd/product/classes/ProductClass.php

@@ -4,6 +4,7 @@ namespace bizHd\product\classes;
 
 use biz\item\classes\PtItemClass;
 use bizHd\base\classes\BaseClass;
+use common\components\imgUtil;
 use common\components\noticeUtil;
 use common\components\sms;
 use common\components\util;
@@ -14,6 +15,40 @@ class ProductClass extends BaseClass
 
     public static $baseFile = '\bizHd\product\models\Product';
 
+    public static function kdItemGroup($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);
+                }
+            }
+            $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 1;
+            $list[$k]['cover'] = $cover;
+
+            $stockInfo = self::formatStock($v['stock'], $ratio);
+            $list[$k]['bigNum'] = $stockInfo['bigNum'];
+            $list[$k]['smallNum'] = $stockInfo['smallNum'];
+
+            $price = \bizGhs\product\classes\ProductClass::getFinalPrice($v, $level, $priceMap, $addPriceMap);
+            $list[$k]['price'] = $price;
+            $list[$k]['bigPrice'] = $price;
+            $smallRatio = $v['smallRatio'] ?? 0;
+            $smallPrice = bcdiv($price, $ratio, 2);
+            $smallPrice = bcmul($smallPrice, $smallRatio, 2);
+            $list[$k]['smallPrice'] = $smallPrice;
+        }
+        return $list;
+    }
+
     //花店的花材转成批发店花材 ssh 20230308
     public static function hdToggleGhs($list, $ghsShop)
     {
@@ -117,4 +152,28 @@ class ProductClass extends BaseClass
         }
     }
 
-}
+    //花材的库存转换: 库存是小数,根据各个花材的unitNum, 计算出多少扎,多少支
+    public static function formatStock($stock, $unitNum)
+    {
+        $pn = true; //正数
+        if ($stock < 0) {
+            $pn = false;
+            $stock = abs($stock);
+        }
+        $bigNum = floor($stock); // 扎
+        $stockArr = explode('.', $stock);
+        $smallNum = 0; //支
+        if (count($stockArr) === 2) {
+            $smallNum = bcmul(($stock - $bigNum), $unitNum);
+        }
+        if (!$pn) {
+            $bigNum *= -1;
+            $smallNum *= -1;
+        }
+        return [
+            'bigNum' => $bigNum,
+            'smallNum' => $smallNum,
+        ];
+    }
+
+}