Browse Source
增加antgoods逻辑层logic,删除修改attribute表的type字段数据迁移文件,创建antgoods模块的商品逻辑文件,在文件模块逻辑文件中统一type字段内容,在商品逻辑文件中开发将临时文件保存的文件中的方法
wechat_public_accounts
增加antgoods逻辑层logic,删除修改attribute表的type字段数据迁移文件,创建antgoods模块的商品逻辑文件,在文件模块逻辑文件中统一type字段内容,在商品逻辑文件中开发将临时文件保存的文件中的方法
wechat_public_accounts
linyaostalker
5 years ago
9 changed files with 95 additions and 43 deletions
-
1backend/config/main.php
-
17backend/logic/file/FileManager.php
-
2common/models/ars/File.php
-
6common/models/ars/TemFile.php
-
5vendor/antgoods/goods/src/controllers/GoodsController.php
-
70vendor/antgoods/goods/src/logic/goods/GoodsManager.php
-
28vendor/antgoods/goods/src/migrations/m191121_111825_update_column_type_in_table_antgoods_attribute.php
-
7vendor/antgoods/goods/src/models/ars/Goods.php
-
2vendor/antgoods/goods/src/views/goods/_form.php
@ -0,0 +1,70 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace antgoods\goods\logic\goods; |
|||
|
|||
use common\models\ars\TemFile; |
|||
use common\models\ars\File; |
|||
|
|||
class GoodsManager |
|||
{ |
|||
/** |
|||
* @param $imgIdStr |
|||
* @param $ownId |
|||
* @param $ownType |
|||
* @return array |
|||
* 将临时文件保存在文件中 |
|||
*/ |
|||
public function saveTemFileToFile($imgIdStr, $ownId, $ownType) |
|||
{ |
|||
if(!$imgIdStr || !$ownId) { |
|||
return ['status' => 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]; |
|||
} |
|||
} |
|||
} |
@ -1,28 +0,0 @@ |
|||
<?php |
|||
|
|||
use yii\db\Migration; |
|||
|
|||
/** |
|||
* Class m191121_111825_update_column_type_in_table_antgoods_attribute |
|||
*/ |
|||
class m191121_111825_update_column_type_in_table_antgoods_attribute extends Migration |
|||
{ |
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function up() |
|||
{ |
|||
$this->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; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue