shish 4 лет назад
Родитель
Сommit
1eea289f76

+ 13 - 4
app-ghs/controllers/OrderController.php

@@ -33,10 +33,19 @@ class OrderController extends BaseController
     {
         $post = Yii::$app->request->post();
         $id = $post['id'] ?? 0;
-        $order = OrderClass::getById($id, true);
-        OrderClass::valid($order, $this->shopId);
-        OrderService::arrival($order, $post);
-        util::complete();
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $order = OrderClass::getById($id, true);
+            OrderClass::valid($order, $this->shopId);
+            OrderService::arrival($order, $post);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("操作失败原因:" . $e->getMessage());
+            util::fail('操作失败');
+        }
     }
 
     //到货获取订单详情 ssh 20220323

+ 5 - 0
app-hd/controllers/ShopController.php

@@ -254,6 +254,11 @@ class ShopController extends BaseController
         $custom = CustomClass::getById($customId);
         $hasDebtPay = $custom['debt'] ?? 0;
 
+        //预订单不能欠款
+        if ($cg->book == 1) {
+            $hasDebtPay = 0;
+        }
+
         $current = time();
         $cgDeadTime = strtotime($cg->deadline);
         //让客户在失效前$aheadTime秒要支付,这样回调通知时订单才不会过期状态

+ 5 - 6
biz-ghs/order/classes/OrderClass.php

@@ -170,11 +170,11 @@ class OrderClass extends BaseClass
             return true;
         }
         if ($bookPrice > $currentPrice) {
-            $refundPrice = bcsub($bookPrice, $currentPrice, 2);
-            //退款
-            RefundOrderClass::add($data, true);
-            //门店余额减少
-            ShopClass::saleRefundReduceBalance($shop, $refund, $refundPrice);
+//            $refundPrice = bcsub($bookPrice, $currentPrice, 2);
+//            //退款
+//            RefundOrderClass::add($data, true);
+//            //门店余额减少
+//            ShopClass::saleRefundReduceBalance($shop, $refund, $refundPrice);
         } else {
             //欠款
             $currentDebt = bcsub($currentPrice, $bookPrice, 2);
@@ -467,7 +467,6 @@ class OrderClass extends BaseClass
                 if ($order['status'] != self::ORDER_STATUS_UN_PAY && $order['status'] != self::ORDER_STATUS_CANCEL) {
                     $arrival['show'] = 1;
                 }
-                $arrival['show'] = 1;
             }
 
             //待确认订单显示延期付和已付款

+ 17 - 13
biz-ghs/order/services/OrderService.php

@@ -46,6 +46,7 @@ class OrderService extends BaseService
         }
         $data['product'] = $product;
         OrderClass::arrival($order, $data);
+
         $cgId = $order->purchaseId ?? 0;
         $cg = PurchaseClass::getById($cgId, true);
         if (empty($cg)) {
@@ -54,39 +55,42 @@ class OrderService extends BaseService
 
         //花材转换
         $ids = array_column($product, 'productId');
-        $productInfo = ProductClass::getByIds($ids);
-        if (empty($productInfo)) {
+        $ghsProductInfo = ProductClass::getByIds($ids);
+        if (empty($ghsProductInfo)) {
             util::fail('没有花材??');
         }
-        $relation = [];
-        foreach ($productInfo as $p) {
-            $id = $p['id'] ?? 0;
-            $ptItemId = $p['itemId'] ?? 0;
-            $relation[$ptItemId] = $id;
+        $ghsPtIdRelation = [];
+        foreach ($ghsProductInfo as $ghsProduct) {
+            $id = $ghsProduct['id'] ?? 0;
+            $ptItemId = $ghsProduct['itemId'] ?? 0;
+            $ghsPtIdRelation[$ptItemId] = $id;
         }
-        $ptIds = array_keys($relation);
+        $ptIds = array_keys($ghsPtIdRelation);
+
         $cgMainId = $cg->mainId ?? 0;
         $cgItem = ProductClass::getAllByCondition(['mainId' => $cgMainId, 'itemId' => ['in', $ptIds]], null, '*');
-        $relateInfo = [];
+        $ghsHdIdRelate = [];
         foreach ($cgItem as $it) {
             $ptItemId = $it['itemId'] ?? 0;
-            $saleItemId = $relation[$ptItemId] ?? 0;
+            $ghsItemId = $ghsPtIdRelation[$ptItemId] ?? 0;
             $cgItemId = $it['id'] ?? 0;
-            $relateInfo[$saleItemId] = $cgItemId;
+            $ghsHdIdRelate[$ghsItemId] = $cgItemId;
         }
+
         $cgProduct = [];
         foreach ($product as $pro) {
             $price = $pro['price'] ?? 0;
             $num = $pro['num'] ?? 0;
             $productId = $pro['productId'] ?? 0;
-            $currentId = $relateInfo[$productId] ?? 0;
+            $currentId = $ghsHdIdRelate[$productId] ?? 0;
             $cgProduct[] = [
                 'num' => $num,
                 'price' => $price,
                 'productId' => $currentId,
             ];
         }
-print_r($cgProduct);die;
+        print_r($cgProduct);
+        die;
         $cgData = [
             'product' => $cgProduct,
         ];

+ 6 - 5
biz-ghs/product/classes/ProductClass.php

@@ -39,9 +39,9 @@ class ProductClass extends BaseClass
     const LOCK_CHECK_STOCK = 'lock_check_stock'; //判断库存
 
     //根据itemIds获取相应的花材信息
-    public static function getProductInfoByItemIds(array $itemIds, $shopId)
+    public static function getProductInfoByItemIds(array $itemIds, $hdMainId)
     {
-        $where = ['itemId' => ['in', $itemIds], 'delStatus' => 0, 'shopId' => $shopId];
+        $where = ['itemId' => ['in', $itemIds], 'delStatus' => 0, 'mainId' => $hdMainId];
         $data = self::getAllList('*', $where);
         $data = self::groupItemBaseInfo($data);
         return $data;
@@ -964,13 +964,13 @@ class ProductClass extends BaseClass
 
     //供应商的productId => 零售端的productId  ,不存在的补productId(放在默认分类)
     //productList [{"productId":"113","bigNum":1,"smallNum":0,"classId":"-2","itemId":1}]
-    public static function toggleProductList($productList, $hdShopId, $hdSjId)
+    public static function toggleProductList($productList, $hdShopId, $hdSjId, $hdMainId)
     {
         $itemIds = array_column($productList, "itemId");
-        $hdProductData = self::getProductInfoByItemIds($itemIds, $hdShopId);
+        $hdProductData = self::getProductInfoByItemIds($itemIds, $hdMainId);
         $hdProductData = array_column($hdProductData, null, "itemId");
         //获取默认分类ID
-        $defaultClassId = ItemClassClass::getDefaultClassId($hdSjId);
+        $defaultClassId = ItemClassClass::getDefaultClassId($hdMainId);
 
         foreach ($productList as $k => $v) {
             $itemId = $v['itemId'] ?? 0;
@@ -982,6 +982,7 @@ class ProductClass extends BaseClass
                 $productData = $ptItem;
                 $productData['sjId'] = $hdSjId;
                 $productData['shopId'] = $hdShopId;
+                $productData['mainId'] = $hdMainId;
                 $productData['itemId'] = $itemId;
                 $productData['classId'] = $defaultClassId;
                 unset($productData['id']);

+ 3 - 3
biz-hd/cg/services/CgRefundService.php

@@ -98,7 +98,7 @@ class CgRefundService extends BaseService
         $cgRefund = CgRefundClass::add($data, true);
         if ($ghsItemInfo) {
             //写入cgRefundItem, 转hdProductId
-            $ghsItemInfo = self::toggleProductList($ghsItemInfo, $cg->shopId, $cg->sjId);
+            $ghsItemInfo = self::toggleProductList($ghsItemInfo, $cg->shopId, $cg->sjId, $cg->mainId);
             //将hdProductId =》productId
             foreach ($ghsItemInfo as $k => $v) {
                 $ghsItemInfo[$k]['productId'] = $v['hdProductId'];
@@ -293,7 +293,7 @@ class CgRefundService extends BaseService
     }
 
     //供货商productId 转 hdProductId [{productId:1,...}]
-    public static function toggleProductList($ghsItemInfo, $hdShopId, $hdSjId)
+    public static function toggleProductList($ghsItemInfo, $hdShopId, $hdSjId,$mainId)
     {
         $productIds = array_column($ghsItemInfo, "productId");
         $productData = ProductClass::getProductByIds($productIds);
@@ -304,7 +304,7 @@ class CgRefundService extends BaseService
             $productMap[$v['id']] = $v['itemId'];
         }
 
-        $hdProductData = ProductClass::getProductInfoByItemIds($itemIds, $hdShopId);
+        $hdProductData = ProductClass::getProductInfoByItemIds($itemIds, $mainId);
         $hdProductData = array_column($hdProductData, null, "itemId");
 
         foreach ($ghsItemInfo as $k => $v) {

+ 4 - 2
biz-hd/purchase/classes/PurchaseClass.php

@@ -88,7 +88,8 @@ class PurchaseClass extends BaseClass
         //数据格式 [{"productId":"113","bigNum":1,"smallNum":0,"classId":"-2","hdProductId":1}]
         $shopId = $data['shopId'] ?? 0;
         $sjId = $data['sjId'] ?? 0;
-        $productList = ProductClass::toggleProductList($productList, $shopId, $sjId);
+        $mainId = $data['mainId'] ?? 0;
+        $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
 
         $productData = self::getProductMapData($productList, "productId");
         $hdProductData = self::getProductMapData($productList, "hdProductId");
@@ -337,7 +338,8 @@ class PurchaseClass extends BaseClass
         $productList = self::mergeItemInfo($productList);
         $data['kindNum'] = count($productList); //多少种花材
         //供应商productId转成零售的productId
-        $productList = ProductClass::toggleProductList($productList, $shopId, $sjId);
+        $mainId = $purchase->mainId ?? 0;
+        $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
 
         $productData = self::getProductMapData($productList, "productId");
         $hdProductData = self::getProductMapData($productList, "hdProductId");

+ 7 - 7
biz/ghs/classes/GhsClass.php

@@ -159,23 +159,23 @@ class GhsClass extends BaseClass
         if (empty($list)) {
             return $list;
         }
-
         $shopIds = array_column($list, 'shopId');
-        $shopData = ShopClass::getByIds($shopIds, null, 'id');
-
+        $shopInfo = ShopClass::getByIds($shopIds, null, 'id');
         foreach ($list as $key => $val) {
             $avatar = $val['avatar'] ?? '';
             $list[$key]['avatar'] = imgUtil::groupImg($avatar);
             $currentShopId = $val['shopId'] ?? 0;
             //新人福利和推荐福利
-            $xrFl = $shopData[$currentShopId]['xrFl'] ?? 0;
-            $xrFlAmount = $shopData[$currentShopId]['xrFlAmount'] ?? 0;
-            $tjFl = $shopData[$currentShopId]['tjFl'] ?? 0;
-            $tjFlAmount = $shopData[$currentShopId]['tjFlAmount'] ?? 0;
+            $xrFl = $shopInfo[$currentShopId]['xrFl'] ?? 0;
+            $xrFlAmount = $shopInfo[$currentShopId]['xrFlAmount'] ?? 0;
+            $tjFl = $shopInfo[$currentShopId]['tjFl'] ?? 0;
+            $tjFlAmount = $shopInfo[$currentShopId]['tjFlAmount'] ?? 0;
             $list[$key]['xrFl'] = $xrFl;
             $list[$key]['xrFlAmount'] = $xrFlAmount;
             $list[$key]['tjFl'] = $tjFl;
             $list[$key]['tjFlAmount'] = $tjFlAmount;
+            $list[$key]['miniKilo'] = $shopInfo[$currentShopId]['miniKilo'] ?? 0;
+            $list[$key]['kiloFee'] = $shopInfo[$currentShopId]['kiloFee'] ?? 0;
         }
         return $list;
     }