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