|
@ -65,34 +65,25 @@ class GoodsManager |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param $formData |
|
|
* @param $formData |
|
|
* @param Goods|$model |
|
|
|
|
|
|
|
|
* @param Goods|$goodsModel |
|
|
* @param null $coverImageOldIdStr |
|
|
* @param null $coverImageOldIdStr |
|
|
* @param null $detailImageOldIdStr |
|
|
* @param null $detailImageOldIdStr |
|
|
* @return bool |
|
|
* @return bool |
|
|
* @throws \Exception 创建修改商品操作 |
|
|
* @throws \Exception 创建修改商品操作 |
|
|
*/ |
|
|
*/ |
|
|
public static function updateGoods($formData, $model, $coverImageOldIdStr = null, $detailImageOldIdStr = null) |
|
|
|
|
|
|
|
|
public static function updateGoods($formData, $goodsModel, $coverImageOldIdStr = null, $detailImageOldIdStr = null) |
|
|
{ |
|
|
{ |
|
|
$attribute = $formData['attribute']; |
|
|
$attribute = $formData['attribute']; |
|
|
$filterAttribute = $formData['filterattribute']; |
|
|
$filterAttribute = $formData['filterattribute']; |
|
|
$model->uniform_postage *= ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_MONEY); |
|
|
|
|
|
$model->market_price *= ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_MONEY); |
|
|
|
|
|
$model->price *= ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_MONEY); |
|
|
|
|
|
|
|
|
$goodsModel->uniform_postage *= ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_MONEY); |
|
|
|
|
|
$goodsModel->market_price *= ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_MONEY); |
|
|
|
|
|
$goodsModel->price *= ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_MONEY); |
|
|
$tra = Yii::$app->db->beginTransaction(); |
|
|
$tra = Yii::$app->db->beginTransaction(); |
|
|
try { |
|
|
try { |
|
|
if (!$model->save()) { |
|
|
|
|
|
throw new \Exception('商品保存失败'); |
|
|
|
|
|
} |
|
|
|
|
|
$saveCoverImageRes = self::saveFile(explode(',', $model->coverImageId), $model, explode(',', $coverImageOldIdStr), File::OWN_TYPE_GOODS_INDEX); |
|
|
|
|
|
self::saveFile(explode(',', $model->detailImageId), $model, explode(',', $detailImageOldIdStr), File::OWN_TYPE_GOODS_DETAILS); |
|
|
|
|
|
if($saveCoverImageRes['first_file_id'] !== 0) { //保存商品首页
|
|
|
|
|
|
$model->image = $saveCoverImageRes['first_file_id']; |
|
|
|
|
|
if (!$model->save()) { |
|
|
|
|
|
throw new \Exception('图片保存失败'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
self::addAttributeOperating(['id' => $model->id, 'attribute' => $attribute]); |
|
|
|
|
|
self::addFilterAttributeOperating(['id' => $model->id, 'filterAttribute' => $filterAttribute]); |
|
|
|
|
|
|
|
|
FileManager::saveFileInModel($goodsModel, 'coverImageId', $coverImageOldIdStr, File::OWN_TYPE_GOODS_INDEX, 'image'); |
|
|
|
|
|
FileManager::saveFileInModel($goodsModel, 'detailImageId', $detailImageOldIdStr, File::OWN_TYPE_GOODS_DETAILS); |
|
|
|
|
|
self::addAttributeOperating(['id' => $goodsModel->id, 'attribute' => $attribute]); |
|
|
|
|
|
self::addFilterAttributeOperating(['id' => $goodsModel->id, 'filterAttribute' => $filterAttribute]); |
|
|
$tra->commit(); |
|
|
$tra->commit(); |
|
|
return true; |
|
|
return true; |
|
|
} catch (\yii\base\Exception $e) { |
|
|
} catch (\yii\base\Exception $e) { |
|
|