shish 3 лет назад
Родитель
Сommit
1b3ddefb90
1 измененных файлов с 54 добавлено и 46 удалено
  1. 54 46
      app-ghs/controllers/PurchaseOrderController.php

+ 54 - 46
app-ghs/controllers/PurchaseOrderController.php

@@ -55,9 +55,9 @@ class PurchaseOrderController extends BaseController
             if ($key % 2 == 1) {
                 $content .= '<TEXT x="415" y="20" font="12" w="2" h="2" r="90">.</TEXT>';
             }
-            if(in_array($mainId,[52,1459])){
+            if (in_array($mainId, [52, 1459])) {
                 $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">惠雅鲜花</TEXT>';
-            }else{
+            } else {
                 $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
             }
 
@@ -103,9 +103,9 @@ class PurchaseOrderController extends BaseController
         $p->times = $num;
         $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
         $content .= '<BC128 x="260" y="30" h="80" s="1" r="90" n="5" w="12">' . $ptItemId . '</BC128>';
-        if(in_array($mainId,[52,1459])){
+        if (in_array($mainId, [52, 1459])) {
             $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">惠雅鲜花</TEXT>';
-        }else{
+        } else {
             $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
         }
 
@@ -130,57 +130,65 @@ class PurchaseOrderController extends BaseController
             util::fail('超管才能修改');
         }
 
-        // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
-        $ghsItemInfo = $post['itemInfo'] ?? '';
-        if (empty($ghsItemInfo)) {
-            util::fail('请选择花材');
-        }
-        $ghsItemInfo = json_decode($ghsItemInfo, true);
-        if (!is_array($ghsItemInfo)) {
-            util::fail('花材格式不正确');
-        }
-        //合并
-        $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
-        //判断花材格式,是否属于当前门店
-        ProductClass::valid($ghsItemInfo, $this->mainId);
-        //获取供货商信息
-        $ghsId = $post['ghsId'];
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
+            $ghsItemInfo = $post['itemInfo'] ?? '';
+            if (empty($ghsItemInfo)) {
+                util::fail('请选择花材');
+            }
+            $ghsItemInfo = json_decode($ghsItemInfo, true);
+            if (!is_array($ghsItemInfo)) {
+                util::fail('花材格式不正确');
+            }
+            //合并
+            $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
+            //判断花材格式,是否属于当前门店
+            ProductClass::valid($ghsItemInfo, $this->mainId);
+            //获取供货商信息
+            $ghsId = $post['ghsId'];
 //        if (getenv('YII_ENV') == 'production') {
 //            if ($this->shopId == 763) {
 //                $ghsId = 832;
 //                $post['ghsId'] = 832;
 //            }
 //        }
-        if (empty($ghsId)) {
-            util::fail("请选择供货商");
-        }
-        $ghsInfo = GhsClass::getGhsInfo($ghsId);
-        GhsClass::valid($ghsInfo, $this->shopId);
-        $post['ghsInfo'] = json_encode($ghsInfo);
-        $post['ghsName'] = $ghsInfo['name'] ?? '';
-        $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
-
-        //判断花材里的信息
-        foreach ($ghsItemInfo as $v) {
-            $bigNum = $v['bigNum'] ?? 0;
-            $productId = $v['productId'] ?? 0;
-            $smallNum = $v['smallNum'] ?? 0;
-            if (!isset($v['itemPrice'])) {
-                util::fail('采购价格不能为空');
-            }
-            if (!$productId) {
-                util::fail('花材不存在');
+            if (empty($ghsId)) {
+                util::fail("请选择供货商");
             }
-            if ($bigNum <= 0 && $smallNum <= 0) {
-                util::fail('花材数量不能为0');
+            $ghsInfo = GhsClass::getGhsInfo($ghsId);
+            GhsClass::valid($ghsInfo, $this->shopId);
+            $post['ghsInfo'] = json_encode($ghsInfo);
+            $post['ghsName'] = $ghsInfo['name'] ?? '';
+            $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
+
+            //判断花材里的信息
+            foreach ($ghsItemInfo as $v) {
+                $bigNum = $v['bigNum'] ?? 0;
+                $productId = $v['productId'] ?? 0;
+                $smallNum = $v['smallNum'] ?? 0;
+                if (!isset($v['itemPrice'])) {
+                    util::fail('采购价格不能为空');
+                }
+                if (!$productId) {
+                    util::fail('花材不存在');
+                }
+                if ($bigNum <= 0 && $smallNum <= 0) {
+                    util::fail('花材数量不能为0');
+                }
             }
+            $post['itemInfo'] = $ghsItemInfo;
+            $post['debt'] = PurchaseOrderClass::DEBT_YES;
+            $order = PurchaseOrderClass::addOrder($post);
+            $transaction->commit();
+            util::success($order);
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            noticeUtil::push('批发店采购入库失败,原因:' . $e->getMessage(), '15280215347');
+            Yii::error("操作失败原因:" . $e->getMessage());
+            util::fail('操作失败');
         }
-        $post['itemInfo'] = $ghsItemInfo;
-        $post['debt'] = PurchaseOrderClass::DEBT_YES;
-        $order = PurchaseOrderClass::addOrder($post);
-
-        util::success($order);
-        util::fail();
     }
 
     //订单列表