Kirin 2 vuotta sitten
vanhempi
commit
eab87757bb
1 muutettua tiedostoa jossa 14 lisäystä ja 7 poistoa
  1. 14 7
      app/admin/model/store/StoreProductAttr.php

+ 14 - 7
app/admin/model/store/StoreProductAttr.php

@@ -7,6 +7,7 @@
 namespace app\admin\model\store;
 
 use app\admin\model\system\SystemUserLevel;
+use app\models\system\SystemStoreStock;
 use crmeb\basic\BaseModel;
 use crmeb\traits\ModelTrait;
 
@@ -32,7 +33,7 @@ class StoreProductAttr extends BaseModel
     }
 
 
-    public static function createProductAttr($attrList, $valueList, $productId, $type=0)
+    public static function createProductAttr($attrList, $valueList, $productId, $type = 0)
     {
         $result = ['attr' => $attrList, 'value' => $valueList];
         $attrValueList = [];
@@ -93,7 +94,7 @@ class StoreProductAttr extends BaseModel
                 'cost' => $value['cost'],
                 'ot_price' => $value['ot_price'],
                 'stock' => $value['stock'],
-                'unique' => StoreProductAttrValue::where(['product_id'=>$productId,'suk'=>$suk,'type'=>$type])->value('unique') ? : '',
+                'unique' => StoreProductAttrValue::where(['product_id' => $productId, 'suk' => $suk, 'type' => $type])->value('unique') ?: '',
                 'image' => $value['pic'],
                 'bar_code' => $value['bar_code'] ?? '',
                 'weight' => $value['weight'] ?? 0,
@@ -105,28 +106,34 @@ class StoreProductAttr extends BaseModel
                 'quota_show' => $value['quota'] ?? 0,
                 'level_price' => isset($value['level_price']) ? json_encode($value['level_price']) : '',
                 'level_discount' => isset($value['level_discount']) ? json_encode($value['level_discount']) : '',
-                'stock_right'=>$value['stock_right']??0,
-                'upgrade'=>$value['upgrade']??0,
+                'stock_right' => $value['stock_right'] ?? 0,
+                'upgrade' => $value['upgrade'] ?? 0,
             ];
         }
         if (!count($attrGroup) || !count($valueGroup)) return self::setErrorInfo('请设置至少一个属性!');
         $attrModel = new self;
         $attrValueModel = new StoreProductAttrValue;
-        if (!self::clearProductAttr($productId,$type)) return false;
+        if (!self::clearProductAttr($productId, $type)) return false;
         $res = false !== $attrModel->saveAll($attrGroup)
             && false !== $attrValueModel->saveAll($valueGroup)
             && false !== StoreProductAttrResult::setResult($result, $productId, $type);
+
+        foreach ($valueList as $v) {
+            if ($v['bar_code']) {
+                SystemStoreStock::where('bar_code', $v['bar_code'])->update(['price' => $v['price']]);
+            }
+        }
         if ($res)
             return true;
         else
             return self::setErrorInfo('编辑商品属性失败!');
     }
 
-    public static function clearProductAttr($productId,$type=0)
+    public static function clearProductAttr($productId, $type = 0)
     {
         if (empty($productId) && $productId != 0) return self::setErrorInfo('商品不存在!');
         $res = false !== self::where('product_id', $productId)->where('type', $type)->delete()
-            && false !== StoreProductAttrValue::clearProductAttrValue($productId,$type);
+            && false !== StoreProductAttrValue::clearProductAttrValue($productId, $type);
         if (!$res)
             return self::setErrorInfo('编辑属性失败,清除旧属性失败!');
         else