From 6ea8813274f254ff31cbf32a5331a297af0cb6cd Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 22 Nov 2019 11:39:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0antgoods=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=B1=82logic=EF=BC=8C=E5=88=A0=E9=99=A4=E4=BF=AE=E6=94=B9attr?= =?UTF-8?q?ibute=E8=A1=A8=E7=9A=84type=E5=AD=97=E6=AE=B5=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6=EF=BC=8C=E5=88=9B=E5=BB=BA?= =?UTF-8?q?antgoods=E6=A8=A1=E5=9D=97=E7=9A=84=E5=95=86=E5=93=81=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E6=96=87=E4=BB=B6=EF=BC=8C=E5=9C=A8=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E9=80=BB=E8=BE=91=E6=96=87=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E7=BB=9F=E4=B8=80type=E5=AD=97=E6=AE=B5=E5=86=85=E5=AE=B9?= =?UTF-8?q?=EF=BC=8C=E5=9C=A8=E5=95=86=E5=93=81=E9=80=BB=E8=BE=91=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E5=BC=80=E5=8F=91=E5=B0=86=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BF=9D=E5=AD=98=E7=9A=84=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/config/main.php | 1 + backend/logic/file/FileManager.php | 17 +++-- common/models/ars/File.php | 2 + common/models/ars/TemFile.php | 6 -- .../goods/src/controllers/GoodsController.php | 5 +- .../goods/src/logic/goods/GoodsManager.php | 70 +++++++++++++++++++ ...olumn_type_in_table_antgoods_attribute.php | 28 -------- .../antgoods/goods/src/models/ars/Goods.php | 7 ++ .../antgoods/goods/src/views/goods/_form.php | 2 +- 9 files changed, 95 insertions(+), 43 deletions(-) create mode 100644 vendor/antgoods/goods/src/logic/goods/GoodsManager.php delete mode 100644 vendor/antgoods/goods/src/migrations/m191121_111825_update_column_type_in_table_antgoods_attribute.php diff --git a/backend/config/main.php b/backend/config/main.php index 81c6961..352b926 100644 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -56,6 +56,7 @@ return [ ], ], 'file' => ['class' => 'backend\logic\file\FileManager'], + 'goods' => ['class' => 'antgoods\goods\logic\goods\GoodsManager'], ], 'params' => $params, ]; diff --git a/backend/logic/file/FileManager.php b/backend/logic/file/FileManager.php index 4ab3ffd..9be289f 100644 --- a/backend/logic/file/FileManager.php +++ b/backend/logic/file/FileManager.php @@ -7,12 +7,19 @@ use common\models\ars\TemFile; class FileManager { + //数据表ats_file和ats_tem_file的类型字段type + const TYPE_IMAGE = 1;//图片 + const TYPE_VIDEO = 2;//影视 + const TYPE_EXCEL = 3;//excel表单 + const TYPE_WORD = 4;//word文本 + const TYPE_TXT = 5;//txt文本 + public static $extension = [ - TemFile::TYPE_IMAGE => ['jpg', 'png', 'jpeg'], - TemFile::TYPE_VIDEO => ['mp4'], - TemFile::TYPE_EXCEL => [], - TemFile::TYPE_WORD => ['docx'], - TemFile::TYPE_TXT => ['txt'], + self::TYPE_IMAGE => ['jpg', 'png', 'jpeg'], + self::TYPE_VIDEO => ['mp4'], + self::TYPE_EXCEL => [], + self::TYPE_WORD => ['docx'], + self::TYPE_TXT => ['txt'], ]; /** diff --git a/common/models/ars/File.php b/common/models/ars/File.php index fc1be27..1c6a983 100644 --- a/common/models/ars/File.php +++ b/common/models/ars/File.php @@ -22,6 +22,8 @@ use yii\behaviors\TimestampBehavior; */ class File extends \yii\db\ActiveRecord { + const OWN_TYPE_GOODS_INDEX = 1;//商品首页 + const OWN_TYPE_GOODS_DETAILS = 2;//商品详情 /** * {@inheritdoc} */ diff --git a/common/models/ars/TemFile.php b/common/models/ars/TemFile.php index 3123d8a..450f34c 100644 --- a/common/models/ars/TemFile.php +++ b/common/models/ars/TemFile.php @@ -19,12 +19,6 @@ use yii\behaviors\TimestampBehavior; */ class TemFile extends \yii\db\ActiveRecord { - //类型type - const TYPE_IMAGE = 1;//图片 - const TYPE_VIDEO = 2;//影视 - const TYPE_EXCEL = 3;//excel表单 - const TYPE_WORD = 4;//word文本 - const TYPE_TXT = 5;//txt文本 /** * {@inheritdoc} diff --git a/vendor/antgoods/goods/src/controllers/GoodsController.php b/vendor/antgoods/goods/src/controllers/GoodsController.php index b0c3ae1..d9e1f56 100644 --- a/vendor/antgoods/goods/src/controllers/GoodsController.php +++ b/vendor/antgoods/goods/src/controllers/GoodsController.php @@ -11,6 +11,7 @@ use yii\filters\VerbFilter; use common\models\ars\TemFile; use common\models\ars\File; use backend\logic\file\FileManager; +use antgoods\goods\logic\goods\GoodsManager; /** * GoodsController implements the CRUD actions for Goods model. @@ -81,9 +82,7 @@ class GoodsController extends Controller { $model = new Goods(); - if ($model->load(Yii::$app->request->post())) { - $img_id_arr = explode(',', $model->image); - $model->save(); + if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect('index'); } diff --git a/vendor/antgoods/goods/src/logic/goods/GoodsManager.php b/vendor/antgoods/goods/src/logic/goods/GoodsManager.php new file mode 100644 index 0000000..98ee109 --- /dev/null +++ b/vendor/antgoods/goods/src/logic/goods/GoodsManager.php @@ -0,0 +1,70 @@ + false, 'info' => '参数错误']; + } + + $img_id_arr = explode(',', $imgIdStr); + $i = 1; + $first_file_id = 0; + foreach ($img_id_arr as $key => $value) { + $tem_file = TemFile::findOne($key); + + if(!$tem_file) { + return ['status' => false, 'info' => '存在查找不到的文件']; + } + + $res = self::saveNewFile($tem_file, $ownId, $ownType); + if(!$res['status']) { + return ['status' => false, 'info' => '存在文件保存失败']; + } + if($i == 1) { + $first_file_id = $res['file_id']; + } + + $i++; + } + + return ['status' => true, 'info' => '保存成功', 'first_file_id' => $first_file_id]; + } + + /** + * @param $temFile + * @param $ownId + * @param $ownType + * @return bool + * 创建新的文件 + */ + private function saveNewFile($temFile, $ownId, $ownType) + { + $new_file = new File(); + $new_file->name = $temFile->name; + $new_file->type = $temFile->type; + $new_file->own_id = $ownId; + $new_file->own_type = $ownType; + $new_file->alias = $temFile->alias; + $new_file->path = $temFile->path; + if($new_file->save()) { + return ['status' => true, 'file_id' => $new_file->id]; + } else { + return ['status' => false]; + } + } +} \ No newline at end of file diff --git a/vendor/antgoods/goods/src/migrations/m191121_111825_update_column_type_in_table_antgoods_attribute.php b/vendor/antgoods/goods/src/migrations/m191121_111825_update_column_type_in_table_antgoods_attribute.php deleted file mode 100644 index 2d6e34b..0000000 --- a/vendor/antgoods/goods/src/migrations/m191121_111825_update_column_type_in_table_antgoods_attribute.php +++ /dev/null @@ -1,28 +0,0 @@ -dropColumn('antgoods_attribute', 'type'); - $this->addColumn('antgoods_attribute', 'type', $this->smallInteger(2)->notNull()->defaultValue(1)->comment('类型:1:商品sku属性')); - } - - /** - * {@inheritdoc} - */ - public function down() - { - $this->dropColumn('antgoods_attribute', 'type'); - $this->addColumn('antgoods_attribute', 'type', $this->smallInteger(2)->defaultValue(null)->comment('类型')); - return true; - } -} diff --git a/vendor/antgoods/goods/src/models/ars/Goods.php b/vendor/antgoods/goods/src/models/ars/Goods.php index ab00598..0939e12 100644 --- a/vendor/antgoods/goods/src/models/ars/Goods.php +++ b/vendor/antgoods/goods/src/models/ars/Goods.php @@ -45,6 +45,7 @@ use yii\behaviors\TimestampBehavior; class Goods extends \yii\db\ActiveRecord { public $imagePath; + public $imageId; //是否删除is_delete const IS_DELETE_NO = 0;//未删除 const IS_DELETE_YES = 1;//已删除 @@ -176,4 +177,10 @@ class Goods extends \yii\db\ActiveRecord } return parent::beforeSave($insert); // TODO: Change the autogenerated stub } + + public function afterSave($insert, $changedAttributes) + { + d($this->imageId);die(); + parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub + } } diff --git a/vendor/antgoods/goods/src/views/goods/_form.php b/vendor/antgoods/goods/src/views/goods/_form.php index 1eeb656..fec13ab 100644 --- a/vendor/antgoods/goods/src/views/goods/_form.php +++ b/vendor/antgoods/goods/src/views/goods/_form.php @@ -68,7 +68,7 @@ use antgoods\goods\models\ars\Supplier; field($model, 'express_template')->textInput() ?> - field($model, 'image')->hiddenInput()->label('') ?> + field($model, 'imageId')->hiddenInput()->label('') ?> field($model, 'imagePath')->widget(\iron\widgets\Upload::className(), [ 'url' => 'upload', 'deleteUrl' => 'imageDel',