shish hai 11 meses
pai
achega
df23edcdc0
Modificáronse 2 ficheiros con 24 adicións e 69 borrados
  1. 2 2
      app-hd/controllers/BaseController.php
  2. 22 67
      biz-hd/order/services/OrderService.php

+ 2 - 2
app-hd/controllers/BaseController.php

@@ -47,11 +47,11 @@ class BaseController extends PublicController
             }
         }
 
-        if (empty($adminId) && in_array($action->id, $this->guestAccess) == false) {
+        if (empty($adminId) && !in_array($action->id, $this->guestAccess)) {
             util::notLogin();
         }
         $admin = AdminClass::getById($adminId, true);
-        if (empty($admin) && in_array($action->id, $this->guestAccess) == false) {
+        if (empty($admin) && !in_array($action->id, $this->guestAccess)) {
             util::notLogin();
         }
         $adminId = $admin ? intval($admin->id) : 0;

+ 22 - 67
biz-hd/order/services/OrderService.php

@@ -49,36 +49,7 @@ class OrderService extends BaseService
         //组合
         $groupId = $data['groupId'] ?? 0;
         if (!empty($groupId)) {
-            $group = GroupClass::getById($groupId, true);
-            if (empty($group)) {
-                util::fail('没有找到商品组合');
-            }
-            GroupClass::valid($group, $mainId);
-            $group->num += 1;
-            $group->save();
-            $product = [];
-            $groupGoodsList = GroupGoodsClass::getAllByCondition(['groupId' => $groupId], null, '*');
-            if (!empty($groupGoodsList)) {
-                foreach ($groupGoodsList as $thisGoods) {
-                    $id = $thisGoods['goodsId'] ?? 0;
-                    $property = dict::getDict('property', 'goods');
-                    $num = $thisGoods['num'] ?? 0;
-                    $unitType = 0;
-                    $unitPrice = $thisGoods['unitPrice'] ?? 0;
-                    $product[] = ['productId' => $id, 'num' => $num, 'unitType' => $unitType, 'unitPrice' => $unitPrice, 'property' => $property];
-                }
-            }
-            $groupItemList = GroupItemClass::getAllByCondition(['groupId' => $groupId], null, '*');
-            if (!empty($groupItemList)) {
-                foreach ($groupItemList as $thisItem) {
-                    $id = $thisItem['itemId'] ?? 0;
-                    $property = dict::getDict('property', 'item');
-                    $unitType = $thisItem['unitType'] ?? 0;
-                    $num = $thisItem['num'] ?? 0;
-                    $unitPrice = $thisItem['unitPrice'] ?? 0;
-                    $product[] = ['productId' => $id, 'num' => $num, 'unitType' => $unitType, 'unitPrice' => $unitPrice, 'property' => $property];
-                }
-            }
+            util::fail('暂不支持使用组合功能');
         }
         if (empty($product)) {
             if (!isset($data['lsGoodsPrice']) || $data['lsGoodsPrice'] <= 0) {
@@ -116,12 +87,8 @@ class OrderService extends BaseService
         //临时收款会传商品金额
         $goodsPrice = isset($data['lsGoodsPrice']) && $data['lsGoodsPrice'] > 0 ? $data['lsGoodsPrice'] : 0;
 
-        //组合的花材和商品数据
-        $groupGoodsData = [];
-        $groupItemData = [];
-
         $manyType = count($product) > 1 ? 1 : 0;
-
+        $totalWeight = 0;
         foreach ($product as $key => $val) {
             if (!isset($val['property'])) {
                 util::fail('没有找到产品属性');
@@ -136,18 +103,25 @@ class OrderService extends BaseService
             $goodsPrice = bcadd($goodsPrice, $currentPrice, 2);
 
             if ($property == dict::getDict('property', 'goods')) {
-                $name = $goodsInfo[$currentId]['name'] ?? '';
-                $cover = $goodsInfo[$currentId]['cover'] ?? '';
-                $flower = $goodsInfo[$currentId]['flower'] ?? 0;
-                $kindId = $goodsInfo[$currentId]['kindId'] ?? 0;
-                $kindName = $goodsInfo[$currentId]['kindName'] ?? 0;
+                $currentGoodsInfo = $goodsInfo[$currentId] ?? [];
+                if (empty($currentGoodsInfo)) {
+                    util::fail("花束商品没有找到,编号{$currentId}");
+                }
+                $name = $currentGoodsInfo['name'] ?? '';
+                $cover = $currentGoodsInfo['cover'] ?? '';
+                $flower = $currentGoodsInfo['flower'] ?? 0;
+                $kindId = $currentGoodsInfo['kindId'] ?? 0;
+                $kindName = $currentGoodsInfo['kindName'] ?? 0;
                 if (!empty($groupCover)) {
                     $groupCover = $cover;
                 }
-                $currentMainId = $goodsInfo[$currentId]['mainId'] ?? 0;
+                $currentMainId = $currentGoodsInfo['mainId'] ?? 0;
                 if ($currentMainId != $mainId) {
                     util::fail('不是您的商品');
                 }
+                $weight = $currentGoodsInfo['weight'] ?? 0;
+                $currentWeight = bcmul($weight, $num, 2);
+                $totalWeight = bcadd($totalWeight, $currentWeight, 2);
                 $currentGoodsData = [
                     'orderSn' => $orderSn,
                     'goodsId' => $currentId,
@@ -168,7 +142,6 @@ class OrderService extends BaseService
                     'forwardStock' => $forwardStock,
                 ];
                 OrderGoodsClass::addData($currentGoodsData);
-                $groupGoodsData[] = ['goodsId' => $currentId, 'num' => $num, 'name' => $name, 'unitPrice' => $unitPrice];
             }
             if ($property == dict::getDict('property', 'item')) {
                 $currentInfo = $itemInfo[$currentId] ?? [];
@@ -182,6 +155,11 @@ class OrderService extends BaseService
                 if ($currentMainId != $mainId) {
                     util::fail('不是您的花材' . $mainId . ' ' . $currentMainId);
                 }
+
+                $weight = $currentInfo['weight'] ?? 0;
+                $currentWeight = bcmul($weight, $num, 2);
+                $totalWeight = bcadd($totalWeight, $currentWeight, 2);
+
                 if ($unitType == dict::getDict('unitType', 'big')) {
                     $unitName = $currentInfo['bigUnit'] ?? '';
                     $unitId = $currentInfo['bigUnitId'] ?? 0;
@@ -223,14 +201,6 @@ class OrderService extends BaseService
                 //库存变化在这里
                 OrderItemClass::addData($currentItemData, $custom);
 
-                $groupItemData[] = [
-                    'name' => $name,
-                    'itemId' => $currentId,
-                    'ptItemId' => $ptItemId,
-                    'num' => $num,
-                    'unitType' => $unitType,
-                    'unitPrice' => $unitPrice,
-                ];
             }
         }
         //运费
@@ -256,24 +226,9 @@ class OrderService extends BaseService
         //保存组合
         $groupName = $data['groupName'] ?? '';
         if (empty($groupId) && !empty($groupName)) {
-            $groupData = ['price' => $modifyPrice, 'mainId' => $mainId, 'name' => $groupName, 'sjId' => $sjId, 'shopId' => $shopId, 'cover' => $groupCover];
-            $group = GroupClass::add($groupData, true);
-            $groupId = $group->id ?? 0;
-            if (!empty($groupGoodsData)) {
-                foreach ($groupGoodsData as $groupGoodsVal) {
-                    $groupGoodsVal['groupId'] = $groupId;
-                    GroupGoodsClass::add($groupGoodsVal);
-                }
-
-            }
-            if (!empty($groupItemData)) {
-                foreach ($groupItemData as $groupItemVal) {
-                    $groupItemVal['groupId'] = $groupId;
-                    GroupItemClass::add($groupItemVal);
-                }
-            }
+            util::fail('组合功能不可用');
         }
-
+        $data['weight'] = $totalWeight;
         $data['goodsPrice'] = $goodsPrice;
         $data['prePrice'] = $totalPrice;
         $data['orderPrice'] = $modifyPrice;