shish hace 4 años
padre
commit
46e9fd5532

+ 1 - 1
app-hd/controllers/GroupController.php

@@ -16,7 +16,7 @@ class GroupController extends BaseController
     public function actionList()
     {
         $date = date("Y-m-d 00:00:00");
-        $where = ['shopId' => $this->shopId, 'addTime>' => $date];
+        $where = ['mainId' => $this->mainId, 'addTime>' => $date];
         $list = GroupClass::getGroupList($where);
         util::success($list);
     }

+ 2 - 1
app-hd/controllers/ItemController.php

@@ -18,7 +18,8 @@ class ItemController extends BaseController
     {
         $where['mainId'] = $this->mainId;
         $where['delStatus'] = 0;
-        $list = ItemClass::getShowList($where);
+
+        $list = \bizHd\item\classes\ItemClass::getShowList($where);
         util::success(['list' => $list]);
     }
 

+ 1 - 1
biz-ghs/item/classes/ItemClassClass.php

@@ -88,7 +88,7 @@ class ItemClassClass extends BaseClass
         $class = [['id' => self::TJ_CLASS_ID, 'name' => '今日特价']];
         $data = self::getAllList('id,name', ['sjId' => $sjId], 'inTurn desc');
         if (!empty($data)) {
-            $class = array_merge($class, $data);
+            $class = array_merge($data,$class);
         }
         return $class;
     }

+ 106 - 21
biz-hd/item/classes/ItemClass.php

@@ -1,15 +1,100 @@
 <?php
+
 namespace bizHd\item\classes;
 
 
 use bizHd\base\classes\BaseClass;
+use common\components\imgUtil;
 use common\components\util;
 use common\services\xhItemService;
+
 class ItemClass extends BaseClass
 {
 
     public static $baseFile = '\bizHd\item\models\Item';
 
+    public static function getShowList($where)
+    {
+        $level = 0;
+        $list = self::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*");
+        if (empty($list)) {
+            return $list;
+        }
+        $list = self::groupProductInfo($list, $level);
+        $data = [];
+        $data[ItemClassClass::TJ_CLASS_ID] = [];
+        foreach ($list as $it) {
+            $classId = $it['classId'] ?? 0;
+            $data[$classId][] = $it;
+            if (isset($it['discountPrice']) && $it['discountPrice'] > 0) {
+                $data[ItemClassClass::TJ_CLASS_ID][] = $it;
+            }
+        }
+        return $data;
+    }
+
+    //花材图片,名称,大小单位,小单位价格
+    public static function groupProductInfo($list, $level = 0)
+    {
+        foreach ($list as $k => $v) {
+            $shortCover = $v['cover'] ?? '';
+            $cover = imgUtil::getPrefix() . 'hhb_small.png';
+            $bigCover = 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_110,w_110";
+                } else {
+                    $cover = self::groupImg($shortCover);
+                }
+                $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
+            }
+            $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 1;
+            $stockInfo = self::formatStock($v['stock'], $ratio);
+            $list[$k]['cover'] = $cover;
+            $list[$k]['bigCover'] = $bigCover;
+            $list[$k]['shortCover'] = $shortCover;
+            $list[$k]['bigNum'] = $stockInfo['bigNum'];
+            $list[$k]['smallNum'] = $stockInfo['smallNum'];
+            $list[$k]['itemName'] = $v['name'] ?? '';
+
+            $skPrice = $v['skPrice'] ?? 0;
+
+            $list[$k]['prePrice'] = $skPrice;
+            $list[$k]['price'] = $skPrice;
+            $list[$k]['bigPrice'] = $skPrice;
+            $smallRatio = $v['smallRatio'] ?? 0;
+            $div = bcdiv($skPrice, $ratio, 2);
+            $smallPrice = bcmul($div, $smallRatio, 2);
+            $list[$k]['smallPrice'] = $smallPrice;
+        }
+        return $list;
+    }
+
+    //花材的库存转换: 库存是小数,根据各个花材的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,
+        ];
+    }
+
     //列表数据
     public static function getItemList($where)
     {
@@ -18,11 +103,11 @@ class ItemClass extends BaseClass
         if (empty($list)) {
             return $data;
         }
-        $itemIds = array_column($list,'itemId');
+        $itemIds = array_column($list, 'itemId');
         $itemData = xhItemService::getByIds($itemIds);
-        $itemData =array_column($itemData,null,'id');
-        foreach ($list as $k=>$v){
-            $list[$k]['itemName'] =$itemData[$v['itemId']]['name']??'';
+        $itemData = array_column($itemData, null, 'id');
+        foreach ($list as $k => $v) {
+            $list[$k]['itemName'] = $itemData[$v['itemId']]['name'] ?? '';
         }
         $data['list'] = $list;
         return $data;
@@ -36,17 +121,17 @@ class ItemClass extends BaseClass
     }
 
     //修改花材的信息(库存预警、每扎加价、每扎重量)
-    public static function updateItem($id,$stockWarning,$addPrice,$weight,$cost)
+    public static function updateItem($id, $stockWarning, $addPrice, $weight, $cost)
     {
         $model = self::getById($id);
-        if(!$model){
+        if (!$model) {
             util::fail("该花材不存在");
         }
         $data['stockWarning'] = $stockWarning;
         $data['addPrice'] = $addPrice;
         $data['weight'] = $weight;
         $data['cost'] = $cost;
-        self::updateById($id,$data);
+        self::updateById($id, $data);
         return true;
 
     }
@@ -61,20 +146,20 @@ class ItemClass extends BaseClass
     //根据花材分类ID,获取itemIds
     public static function getItemIdsByClassId($classId)
     {
-        $data = self::getAllList("itemId",['classId'=>$classId]);
-        if($data){
-            $data= array_column($data,'itemId');
+        $data = self::getAllList("itemId", ['classId' => $classId]);
+        if ($data) {
+            $data = array_column($data, 'itemId');
         }
         return $data;
     }
 
     //获取当前供应商下的所有item
-    public static function getItemAll($sjId,$select="*")
+    public static function getItemAll($sjId, $select = "*")
     {
         $where = [
-            'sjId'=>$sjId
+            'sjId' => $sjId
         ];
-        $data = self::getAllList($select,$where);
+        $data = self::getAllList($select, $where);
         return $data;
     }
 
@@ -84,24 +169,24 @@ class ItemClass extends BaseClass
     {
         //统一转小写
         $pyName = strtolower($pyName);
-        $where = ['py'=>$pyName];
-        $data = xhItemService::getAllByCondition($where,null,'id');
-        if($data){
-            $data= array_column($data,'id');
+        $where = ['py' => $pyName];
+        $data = xhItemService::getAllByCondition($where, null, 'id');
+        if ($data) {
+            $data = array_column($data, 'id');
         }
         return $data;
     }
 
     //获取某个花材的信息 lqh 2021.1.28
-    public static function getItemData($itemId,$sjId)
+    public static function getItemData($itemId, $sjId)
     {
-        return self::getByCondition(['itemId'=>$itemId,'sjId'=>$sjId]);
+        return self::getByCondition(['itemId' => $itemId, 'sjId' => $sjId]);
     }
 
     //修改某个花材的成本价(采购之后要用到) lqh 2021.1.28
-    public static function changeCost($itemId,$sjId,$cost)
+    public static function changeCost($itemId, $sjId, $cost)
     {
-        return self::updateByCondition(['itemId'=>$itemId,'sjId'=>$sjId],['cost'=>$cost]);
+        return self::updateByCondition(['itemId' => $itemId, 'sjId' => $sjId], ['cost' => $cost]);
     }
 
 }

+ 3 - 0
biz-hd/item/classes/ItemClassClass.php

@@ -9,6 +9,9 @@ class ItemClassClass extends BaseClass
 
     public static $baseFile = '\bizHd\item\models\ItemClass';
 
+    //特价花材分类
+    const TJ_CLASS_ID = '-1';
+
     public static function getItemClassList($where)
     {
         $data = self::getList('*', $where, 'addTime DESC');

+ 3 - 1
biz-hd/item/models/Item.php

@@ -3,8 +3,10 @@ namespace bizHd\item\models;
 use bizHd\base\models\Base;
 class Item extends Base
 {
+
     public static function tableName()
     {
-        return 'xhItem';
+        return 'xhGhsItem';
     }
+
 }