|
@ -13,19 +13,20 @@ use backend\modules\goods\models\ars\FilterAttr; |
|
|
use yii\db\StaleObjectException; |
|
|
use yii\db\StaleObjectException; |
|
|
use backend\modules\file\logic\file\FileManager; |
|
|
use backend\modules\file\logic\file\FileManager; |
|
|
use yii\web\ServerErrorHttpException; |
|
|
use yii\web\ServerErrorHttpException; |
|
|
|
|
|
use backend\modules\shop\logic\ShopManager; |
|
|
|
|
|
|
|
|
class GoodsManager |
|
|
class GoodsManager |
|
|
{ |
|
|
{ |
|
|
/** |
|
|
/** |
|
|
* @param $newFileIdArr |
|
|
* @param $newFileIdArr |
|
|
* @param $goodsModel |
|
|
|
|
|
|
|
|
* @param $hostObject |
|
|
* @param array $oldFileIdArr |
|
|
* @param array $oldFileIdArr |
|
|
* @param int $fileType |
|
|
* @param int $fileType |
|
|
* @return array |
|
|
* @return array |
|
|
* @throws \Exception |
|
|
* @throws \Exception |
|
|
* 保存新文件,删除不需要的文件操作 |
|
|
* 保存新文件,删除不需要的文件操作 |
|
|
*/ |
|
|
*/ |
|
|
public static function saveFile($newFileIdArr, $goodsModel, $oldFileIdArr = [], $fileType = 1) |
|
|
|
|
|
|
|
|
public static function saveFile($newFileIdArr, $hostObject, $oldFileIdArr = [], $fileType = File::OWN_TYPE_GOODS_INDEX) |
|
|
{ |
|
|
{ |
|
|
$tra = Yii::$app->db->beginTransaction(); |
|
|
$tra = Yii::$app->db->beginTransaction(); |
|
|
try { |
|
|
try { |
|
@ -34,7 +35,7 @@ class GoodsManager |
|
|
|
|
|
|
|
|
//创建文件
|
|
|
//创建文件
|
|
|
$class = new FileManager(); |
|
|
$class = new FileManager(); |
|
|
$createFileRes = $class->saveTemFileToFile($createFileIdArr, $goodsModel->id, $fileType); |
|
|
|
|
|
|
|
|
$createFileRes = $class->saveTemFileToFile($createFileIdArr, $hostObject->id, $fileType); |
|
|
|
|
|
|
|
|
//需要删除的文件id
|
|
|
//需要删除的文件id
|
|
|
$delFileIdArr = array_diff($oldFileIdArr, $newFileIdArr); |
|
|
$delFileIdArr = array_diff($oldFileIdArr, $newFileIdArr); |
|
@ -63,21 +64,20 @@ class GoodsManager |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param $data |
|
|
|
|
|
|
|
|
* @param $formData |
|
|
* @param Goods|$model |
|
|
* @param Goods|$model |
|
|
* @param null $coverImageOldIdStr |
|
|
* @param null $coverImageOldIdStr |
|
|
* @param null $detailImageOldIdStr |
|
|
* @param null $detailImageOldIdStr |
|
|
* @return array |
|
|
|
|
|
* @throws \Exception |
|
|
|
|
|
* 创建修改商品操作 |
|
|
|
|
|
|
|
|
* @return bool |
|
|
|
|
|
* @throws \Exception 创建修改商品操作 |
|
|
*/ |
|
|
*/ |
|
|
public static function updateGoods($data, $model, $coverImageOldIdStr = null, $detailImageOldIdStr = null) |
|
|
|
|
|
|
|
|
public static function updateGoods($formData, $model, $coverImageOldIdStr = null, $detailImageOldIdStr = null) |
|
|
{ |
|
|
{ |
|
|
$attribute = $data['attribute']; |
|
|
|
|
|
$filterAttribute = $data['filterattribute']; |
|
|
|
|
|
$model->uniform_postage *= 100; |
|
|
|
|
|
$model->market_price *= 100; |
|
|
|
|
|
$model->price *= 100; |
|
|
|
|
|
|
|
|
$attribute = $formData['attribute']; |
|
|
|
|
|
$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); |
|
|
$tra = Yii::$app->db->beginTransaction(); |
|
|
$tra = Yii::$app->db->beginTransaction(); |
|
|
try { |
|
|
try { |
|
|
if (!$model->save()) { |
|
|
if (!$model->save()) { |
|
@ -85,7 +85,7 @@ class GoodsManager |
|
|
} |
|
|
} |
|
|
$saveCoverImageRes = self::saveFile(explode(',', $model->coverImageId), $model, explode(',', $coverImageOldIdStr), File::OWN_TYPE_GOODS_INDEX); |
|
|
$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); |
|
|
self::saveFile(explode(',', $model->detailImageId), $model, explode(',', $detailImageOldIdStr), File::OWN_TYPE_GOODS_DETAILS); |
|
|
if($saveCoverImageRes['first_file_id'] !== 0) { |
|
|
|
|
|
|
|
|
if($saveCoverImageRes['first_file_id'] !== 0) { //保存商品首页
|
|
|
$model->image = $saveCoverImageRes['first_file_id']; |
|
|
$model->image = $saveCoverImageRes['first_file_id']; |
|
|
if (!$model->save()) { |
|
|
if (!$model->save()) { |
|
|
throw new \Exception('图片保存失败'); |
|
|
throw new \Exception('图片保存失败'); |
|
@ -94,7 +94,7 @@ class GoodsManager |
|
|
self::addAttributeOperating(['id' => $model->id, 'attribute' => $attribute]); |
|
|
self::addAttributeOperating(['id' => $model->id, 'attribute' => $attribute]); |
|
|
self::addFilterAttributeOperating(['id' => $model->id, 'filterAttribute' => $filterAttribute]); |
|
|
self::addFilterAttributeOperating(['id' => $model->id, 'filterAttribute' => $filterAttribute]); |
|
|
$tra->commit(); |
|
|
$tra->commit(); |
|
|
return ['status' => true]; |
|
|
|
|
|
|
|
|
return true; |
|
|
} catch (\yii\base\Exception $e) { |
|
|
} catch (\yii\base\Exception $e) { |
|
|
$tra->rollBack(); |
|
|
$tra->rollBack(); |
|
|
throw new \Exception($e->getMessage()); |
|
|
throw new \Exception($e->getMessage()); |
|
|