|
@ -3,14 +3,15 @@ namespace backend\modules\goods\logic\goods; |
|
|
|
|
|
|
|
|
use backend\modules\file\models\ars\File; |
|
|
use backend\modules\file\models\ars\File; |
|
|
use Yii; |
|
|
use Yii; |
|
|
use yii\base\Exception; |
|
|
|
|
|
|
|
|
use yii\db\Exception; |
|
|
use backend\modules\goods\models\ars\GoodsAttr; |
|
|
use backend\modules\goods\models\ars\GoodsAttr; |
|
|
use backend\modules\goods\models\ars\Attribute; |
|
|
use backend\modules\goods\models\ars\Attribute; |
|
|
use backend\modules\goods\models\ars\GoodsSku; |
|
|
use backend\modules\goods\models\ars\GoodsSku; |
|
|
use backend\modules\goods\models\ars\Goods; |
|
|
use backend\modules\goods\models\ars\Goods; |
|
|
use backend\modules\goods\models\ars\FilterAttr; |
|
|
use backend\modules\goods\models\ars\FilterAttr; |
|
|
use backend\modules\goods\models\ars\Category; |
|
|
|
|
|
use yii\web\HttpException; |
|
|
use yii\web\HttpException; |
|
|
|
|
|
use backend\modules\file\logic\file\FileManager; |
|
|
|
|
|
use yii\web\ServerErrorHttpException; |
|
|
|
|
|
|
|
|
class GoodsManager |
|
|
class GoodsManager |
|
|
{ |
|
|
{ |
|
@ -31,7 +32,7 @@ class GoodsManager |
|
|
$createFileIdArr = array_diff($newFileIdArr, $oldFileIdArr); |
|
|
$createFileIdArr = array_diff($newFileIdArr, $oldFileIdArr); |
|
|
|
|
|
|
|
|
//创建文件
|
|
|
//创建文件
|
|
|
$class = new \backend\modules\file\logic\file\FileManager(); |
|
|
|
|
|
|
|
|
$class = new FileManager(); |
|
|
$createFileRes = $class->saveTemFileToFile($createFileIdArr, $goodsModel->id, $fileType); |
|
|
$createFileRes = $class->saveTemFileToFile($createFileIdArr, $goodsModel->id, $fileType); |
|
|
|
|
|
|
|
|
//需要删除的文件id
|
|
|
//需要删除的文件id
|
|
@ -54,15 +55,15 @@ class GoodsManager |
|
|
|
|
|
|
|
|
$tra->commit(); |
|
|
$tra->commit(); |
|
|
return ['status' => true, 'info' => '操作成功', 'first_file_id' => $firstFileId]; |
|
|
return ['status' => true, 'info' => '操作成功', 'first_file_id' => $firstFileId]; |
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
|
|
} catch (Exception $e) { |
|
|
$tra->rollBack(); |
|
|
$tra->rollBack(); |
|
|
throw new \Exception($e->getMessage()); |
|
|
|
|
|
|
|
|
throw new ServerErrorHttpException($e->getMessage()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param $data |
|
|
* @param $data |
|
|
* @param $model |
|
|
|
|
|
|
|
|
* @param Goods|$model |
|
|
* @param null $coverImageOldIdStr |
|
|
* @param null $coverImageOldIdStr |
|
|
* @param null $detailImageOldIdStr |
|
|
* @param null $detailImageOldIdStr |
|
|
* @return array |
|
|
* @return array |
|
@ -82,7 +83,7 @@ class GoodsManager |
|
|
throw new \Exception('商品保存失败'); |
|
|
throw new \Exception('商品保存失败'); |
|
|
} |
|
|
} |
|
|
$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); |
|
|
$saveDetailImageRes = 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()) { |
|
@ -198,33 +199,32 @@ class GoodsManager |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param $id |
|
|
|
|
|
* @return Attribute|array|null |
|
|
|
|
|
|
|
|
* @param GoodsAttr|FilterAttr|$attributes |
|
|
|
|
|
* @return array |
|
|
* 获取属性信息 |
|
|
* 获取属性信息 |
|
|
*/ |
|
|
*/ |
|
|
public static function getAttribute($id) |
|
|
|
|
|
|
|
|
public static function getAttribute($attributes) |
|
|
{ |
|
|
{ |
|
|
$goodsAttributes = GoodsAttr::find()->where(['goods_id' => $id, 'is_delete' => GoodsAttr::IS_DELETE_NO])->andWhere(['!=', 'attr_id', 0])->all(); |
|
|
|
|
|
$filter = []; |
|
|
|
|
|
$goodsAttributeModel = []; |
|
|
|
|
|
if (!$goodsAttributes) { |
|
|
|
|
|
return $goodsAttributeModel; |
|
|
|
|
|
|
|
|
$filter = array(); |
|
|
|
|
|
$attributeModel = array(); |
|
|
|
|
|
if (!$attributes) { |
|
|
|
|
|
return $attributeModel; |
|
|
} |
|
|
} |
|
|
foreach ($goodsAttributes as $key => $value) { |
|
|
|
|
|
|
|
|
foreach ($attributes as $key => $value) { |
|
|
$attribute = Attribute::findOne($value->attr_id); |
|
|
$attribute = Attribute::findOne($value->attr_id); |
|
|
if (!in_array($attribute->name, $filter)) { |
|
|
if (!in_array($attribute->name, $filter)) { |
|
|
$filter[] = $attribute->name; |
|
|
$filter[] = $attribute->name; |
|
|
$attribute = ['name' => $attribute->name, 'id' => $attribute->id, 'value' => [$value->attr_value]]; |
|
|
$attribute = ['name' => $attribute->name, 'id' => $attribute->id, 'value' => [$value->attr_value]]; |
|
|
$goodsAttributeModel[] = $attribute; |
|
|
|
|
|
|
|
|
$attributeModel[] = $attribute; |
|
|
} else { |
|
|
} else { |
|
|
foreach ($goodsAttributeModel as $k => $v) { |
|
|
|
|
|
|
|
|
foreach ($attributeModel as $k => $v) { |
|
|
if ($v['name'] == $attribute->name) { |
|
|
if ($v['name'] == $attribute->name) { |
|
|
$goodsAttributeModel[$k]['value'][] = $value->attr_value; |
|
|
|
|
|
|
|
|
$attributeModel[$k]['value'][] = $value->attr_value; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return $goodsAttributeModel; |
|
|
|
|
|
|
|
|
return $attributeModel; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -534,36 +534,6 @@ class GoodsManager |
|
|
return $newAttr; |
|
|
return $newAttr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param $id |
|
|
|
|
|
* @return Attribute|array|null |
|
|
|
|
|
* 获取筛选属性信息 |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function getFilterAttribute($id) |
|
|
|
|
|
{ |
|
|
|
|
|
$goodsFilterAttributes = FilterAttr::find()->where(['goods_id' => $id, 'is_delete' => FilterAttr::IS_DELETE_NO])->andWhere(['!=', 'attr_id', 0])->all(); |
|
|
|
|
|
$filter = []; |
|
|
|
|
|
$goodsFilterAttributeModel = []; |
|
|
|
|
|
if (!$goodsFilterAttributes) { |
|
|
|
|
|
return $goodsFilterAttributeModel; |
|
|
|
|
|
} |
|
|
|
|
|
foreach ($goodsFilterAttributes as $key => $value) { |
|
|
|
|
|
$attribute = Attribute::findOne($value->attr_id); |
|
|
|
|
|
if (!in_array($attribute->name, $filter)) { |
|
|
|
|
|
$filter[] = $attribute->name; |
|
|
|
|
|
$attribute = ['name' => $attribute->name, 'id' => $attribute->id, 'value' => [$value->attr_value]]; |
|
|
|
|
|
$goodsFilterAttributeModel[] = $attribute; |
|
|
|
|
|
} else { |
|
|
|
|
|
foreach ($goodsFilterAttributeModel as $k => $v) { |
|
|
|
|
|
if ($v['name'] == $attribute->name) { |
|
|
|
|
|
$goodsFilterAttributeModel[$k]['value'][] = $value->attr_value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return $goodsFilterAttributeModel; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param $goodsModel |
|
|
* @param $goodsModel |
|
|
* @return bool |
|
|
* @return bool |
|
|