From 2ac7073fca7c5a91bf8a33cb2ca99f9babeb23dc Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Wed, 4 Dec 2019 14:53:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9antgoods=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84=E7=BB=A7=E6=89=BF=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- antgoods/Module.php | 24 + .../custom/sku.49a56a9198d9c3ec233c.js | 0 .../custom/sku.52802ed907a316501cd7.js | 0 .../custom/sku.9a46222d01b3d601e5ad.js | 0 .../custom/sku_item.6649e882bedbeb22ea3d.js | 0 antgoods/{web => assets}/js/jquery.js | 0 antgoods/views/goods/attribute.php | 2 +- antgoods/views/goods/filter_attribute.php | 2 +- antgoods/views/goods/sku_edit.php | 2 +- antgoods/web/GoodsAttributeAsset.php | 22 + antgoods/web/GoodsFilterAttributeAsset.php | 21 + antgoods/web/GoodsSkuEditAsset.php | 21 + {antgoods => antgoods123}/.gitignore | 0 {antgoods => antgoods123}/assets/AppAsset.php | 0 .../assets/GoodsAttributeAsset.php | 0 .../assets/GoodsFilterAttributeAsset.php | 0 .../assets/GoodsSkuEditAsset.php | 0 {antgoods => antgoods123}/config/.gitignore | 0 .../config/bootstrap.php | 0 {antgoods => antgoods123}/config/main.php | 0 {antgoods => antgoods123}/config/params.php | 0 .../controllers/AttributeController.php | 170 + antgoods123/controllers/BrandController.php | 151 + .../controllers/CategoryController.php | 276 + .../controllers/ConfigController.php | 0 antgoods123/controllers/GoodsController.php | 359 + .../controllers/ShopCategoryController.php | 287 + .../controllers/SiteController.php | 0 .../controllers/SupplierController.php | 151 + antgoods123/logic/goods/GoodsManager.php | 578 ++ ...1119_021851_create_table_shop_category.php | 42 + .../m191119_022641_create_table_category.php | 39 + .../m191119_022939_create_table_attribute.php | 36 + ...m191119_023115_create_table_goods_attr.php | 35 + .../m191119_024029_create_table_brand.php | 33 + .../m191119_024205_create_table_goods.php | 27 + .../m191119_024345_create_table_goods_sku.php | 27 + .../m191119_025607_create_table_supplier.php | 36 + ...191119_025843_create_table_filter_attr.php | 35 + ..._column_icon_type_in_antgoods_category.php | 22 + ...n_icon_type_in_table_antgoods_category.php | 20 + ...id_and_icon_in_table_antgoods_category.php | 26 + ...n_type_in_table_antgoods_shop_category.php | 20 + ...d_icon_in_table_antgoods_shop_category.php | 26 + ..._is_manaul_in_table_antgoods_goods_sku.php | 20 + ..._add_column_sku_mode_in_antgoods_goods.php | 20 + ...d_attr_id_in_table_antgoods_goods_attr.php | 26 + ...umn_cat_id_in_table_antgoods_attribute.php | 20 + ...op_columns_in_table_antgoods_goods_sku.php | 27 + antgoods123/migrations/sql/goods.sql | 37 + antgoods123/migrations/sql/goods_sku.sql | 24 + {antgoods => antgoods123}/models/.gitkeep | 0 antgoods123/models/ars/Attribute.php | 111 + antgoods123/models/ars/Brand.php | 82 + antgoods123/models/ars/Category.php | 114 + antgoods123/models/ars/FilterAttr.php | 81 + antgoods123/models/ars/Goods.php | 232 + antgoods123/models/ars/GoodsAttr.php | 81 + antgoods123/models/ars/GoodsSku.php | 102 + antgoods123/models/ars/ShopCategory.php | 122 + antgoods123/models/ars/Supplier.php | 96 + .../models/searchs/AttributeSearch.php | 162 + antgoods123/models/searchs/BrandSearch.php | 152 + antgoods123/models/searchs/CategorySearch.php | 172 + antgoods123/models/searchs/GoodsSearch.php | 241 + .../models/searchs/ShopCategorySearch.php | 162 + antgoods123/models/searchs/SupplierSearch.php | 161 + antgoods123/views/attribute/_form.php | 32 + antgoods123/views/attribute/_search.php | 49 + antgoods123/views/attribute/create.php | 18 + antgoods123/views/attribute/index.php | 28 + antgoods123/views/attribute/update.php | 19 + antgoods123/views/attribute/view.php | 33 + antgoods123/views/brand/_form.php | 24 + antgoods123/views/brand/_search.php | 49 + antgoods123/views/brand/create.php | 18 + antgoods123/views/brand/index.php | 28 + antgoods123/views/brand/update.php | 19 + antgoods123/views/brand/view.php | 30 + antgoods123/views/category/_form.php | 47 + antgoods123/views/category/_search.php | 49 + antgoods123/views/category/create.php | 18 + antgoods123/views/category/index.php | 28 + antgoods123/views/category/update.php | 19 + antgoods123/views/category/view.php | 41 + antgoods123/views/config/index.php | 27 + antgoods123/views/goods/_form.php | 107 + antgoods123/views/goods/_search.php | 49 + antgoods123/views/goods/attribute.php | 22 + antgoods123/views/goods/create.php | 72 + antgoods123/views/goods/filter_attribute.php | 22 + antgoods123/views/goods/goods.php | 64 + antgoods123/views/goods/index.php | 28 + antgoods123/views/goods/new_editor.php | 31 + antgoods123/views/goods/picture.php | 37 + antgoods123/views/goods/sku_edit.php | 15 + antgoods123/views/goods/update.php | 80 + antgoods123/views/goods/view.php | 113 + .../views/layouts/base.php | 0 .../views/layouts/breadcrumb.php | 0 .../views/layouts/footer.php | 0 .../views/layouts/header.php | 0 .../views/layouts/main.php | 0 .../views/layouts/sidebar.php | 0 antgoods123/views/shop-category/_form.php | 55 + antgoods123/views/shop-category/_search.php | 49 + antgoods123/views/shop-category/create.php | 18 + antgoods123/views/shop-category/index.php | 28 + antgoods123/views/shop-category/update.php | 19 + antgoods123/views/shop-category/view.php | 64 + .../views/site/error.php | 0 .../views/site/index.php | 0 .../views/site/login.php | 0 {antgoods => antgoods123}/views/site/test.php | 0 antgoods123/views/supplier/_form.php | 30 + antgoods123/views/supplier/_search.php | 49 + antgoods123/views/supplier/create.php | 18 + antgoods123/views/supplier/index.php | 28 + antgoods123/views/supplier/update.php | 19 + antgoods123/views/supplier/view.php | 33 + {antgoods => antgoods123}/web/.gitignore | 0 .../web/assets/.gitignore | 0 {antgoods => antgoods123}/web/css/reset.css | 0 {antgoods => antgoods123}/web/css/site.css | 0 .../web/custom/sku.49a56a9198d9c3ec233c.js | 58 + .../web/custom/sku.52802ed907a316501cd7.js | 58 + .../web/custom/sku.9a46222d01b3d601e5ad.js | 58 + .../custom/sku_item.6649e882bedbeb22ea3d.js | 64 + {antgoods => antgoods123}/web/favicon.ico | Bin {antgoods => antgoods123}/web/img/avatar.png | Bin .../web/img/avatar04.png | Bin {antgoods => antgoods123}/web/img/avatar2.png | Bin {antgoods => antgoods123}/web/img/avatar3.png | Bin {antgoods => antgoods123}/web/img/avatar5.png | Bin .../web/img/credit/american-express.png | Bin .../web/img/credit/cirrus.png | Bin .../web/img/credit/mastercard.png | Bin .../web/img/credit/mestro.png | Bin .../web/img/credit/paypal.png | Bin .../web/img/credit/paypal2.png | Bin .../web/img/credit/visa.png | Bin .../web/img/default-50x50.gif | Bin {antgoods => antgoods123}/web/img/icons.png | Bin {antgoods => antgoods123}/web/img/logo.jpeg | Bin {antgoods => antgoods123}/web/img/photo1.png | Bin {antgoods => antgoods123}/web/img/photo2.png | Bin {antgoods => antgoods123}/web/img/photo3.jpg | Bin {antgoods => antgoods123}/web/img/photo4.jpg | Bin .../web/img/user1-128x128.jpg | Bin .../web/img/user2-160x160.jpg | Bin .../web/img/user3-128x128.jpg | Bin .../web/img/user4-128x128.jpg | Bin .../web/img/user5-128x128.jpg | Bin .../web/img/user6-128x128.jpg | Bin .../web/img/user7-128x128.jpg | Bin .../web/img/user8-128x128.jpg | Bin {antgoods => antgoods123}/web/js/common.js | 0 antgoods123/web/js/jquery.js | 9210 +++++++++++++++++ .../web/js/jquery.min.js | 0 159 files changed, 15806 insertions(+), 3 deletions(-) create mode 100644 antgoods/Module.php rename antgoods/{web => assets}/custom/sku.49a56a9198d9c3ec233c.js (100%) rename antgoods/{web => assets}/custom/sku.52802ed907a316501cd7.js (100%) rename antgoods/{web => assets}/custom/sku.9a46222d01b3d601e5ad.js (100%) rename antgoods/{web => assets}/custom/sku_item.6649e882bedbeb22ea3d.js (100%) rename antgoods/{web => assets}/js/jquery.js (100%) create mode 100644 antgoods/web/GoodsAttributeAsset.php create mode 100644 antgoods/web/GoodsFilterAttributeAsset.php create mode 100644 antgoods/web/GoodsSkuEditAsset.php rename {antgoods => antgoods123}/.gitignore (100%) rename {antgoods => antgoods123}/assets/AppAsset.php (100%) rename {antgoods => antgoods123}/assets/GoodsAttributeAsset.php (100%) rename {antgoods => antgoods123}/assets/GoodsFilterAttributeAsset.php (100%) rename {antgoods => antgoods123}/assets/GoodsSkuEditAsset.php (100%) rename {antgoods => antgoods123}/config/.gitignore (100%) rename {antgoods => antgoods123}/config/bootstrap.php (100%) rename {antgoods => antgoods123}/config/main.php (100%) rename {antgoods => antgoods123}/config/params.php (100%) create mode 100644 antgoods123/controllers/AttributeController.php create mode 100644 antgoods123/controllers/BrandController.php create mode 100644 antgoods123/controllers/CategoryController.php rename {antgoods => antgoods123}/controllers/ConfigController.php (100%) create mode 100644 antgoods123/controllers/GoodsController.php create mode 100644 antgoods123/controllers/ShopCategoryController.php rename {antgoods => antgoods123}/controllers/SiteController.php (100%) create mode 100644 antgoods123/controllers/SupplierController.php create mode 100644 antgoods123/logic/goods/GoodsManager.php create mode 100644 antgoods123/migrations/m191119_021851_create_table_shop_category.php create mode 100644 antgoods123/migrations/m191119_022641_create_table_category.php create mode 100644 antgoods123/migrations/m191119_022939_create_table_attribute.php create mode 100644 antgoods123/migrations/m191119_023115_create_table_goods_attr.php create mode 100644 antgoods123/migrations/m191119_024029_create_table_brand.php create mode 100644 antgoods123/migrations/m191119_024205_create_table_goods.php create mode 100644 antgoods123/migrations/m191119_024345_create_table_goods_sku.php create mode 100644 antgoods123/migrations/m191119_025607_create_table_supplier.php create mode 100644 antgoods123/migrations/m191119_025843_create_table_filter_attr.php create mode 100644 antgoods123/migrations/m191125_012449_update_column_icon_type_in_antgoods_category.php create mode 100644 antgoods123/migrations/m191125_083820_drop_column_icon_type_in_table_antgoods_category.php create mode 100644 antgoods123/migrations/m191125_084547_update_column_pid_and_icon_in_table_antgoods_category.php create mode 100644 antgoods123/migrations/m191125_104137_drop_column_icon_type_in_table_antgoods_shop_category.php create mode 100644 antgoods123/migrations/m191125_104510_update_column_pid_and_icon_in_table_antgoods_shop_category.php create mode 100644 antgoods123/migrations/m191127_114228_add_column_is_manaul_in_table_antgoods_goods_sku.php create mode 100644 antgoods123/migrations/m191129_010349_add_column_sku_mode_in_antgoods_goods.php create mode 100644 antgoods123/migrations/m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr.php create mode 100644 antgoods123/migrations/m191130_004933_add_column_cat_id_in_table_antgoods_attribute.php create mode 100644 antgoods123/migrations/m191202_082041_drop_columns_in_table_antgoods_goods_sku.php create mode 100755 antgoods123/migrations/sql/goods.sql create mode 100755 antgoods123/migrations/sql/goods_sku.sql rename {antgoods => antgoods123}/models/.gitkeep (100%) create mode 100644 antgoods123/models/ars/Attribute.php create mode 100644 antgoods123/models/ars/Brand.php create mode 100644 antgoods123/models/ars/Category.php create mode 100644 antgoods123/models/ars/FilterAttr.php create mode 100644 antgoods123/models/ars/Goods.php create mode 100644 antgoods123/models/ars/GoodsAttr.php create mode 100644 antgoods123/models/ars/GoodsSku.php create mode 100644 antgoods123/models/ars/ShopCategory.php create mode 100644 antgoods123/models/ars/Supplier.php create mode 100644 antgoods123/models/searchs/AttributeSearch.php create mode 100644 antgoods123/models/searchs/BrandSearch.php create mode 100644 antgoods123/models/searchs/CategorySearch.php create mode 100644 antgoods123/models/searchs/GoodsSearch.php create mode 100644 antgoods123/models/searchs/ShopCategorySearch.php create mode 100644 antgoods123/models/searchs/SupplierSearch.php create mode 100644 antgoods123/views/attribute/_form.php create mode 100644 antgoods123/views/attribute/_search.php create mode 100644 antgoods123/views/attribute/create.php create mode 100644 antgoods123/views/attribute/index.php create mode 100644 antgoods123/views/attribute/update.php create mode 100644 antgoods123/views/attribute/view.php create mode 100644 antgoods123/views/brand/_form.php create mode 100644 antgoods123/views/brand/_search.php create mode 100644 antgoods123/views/brand/create.php create mode 100644 antgoods123/views/brand/index.php create mode 100644 antgoods123/views/brand/update.php create mode 100644 antgoods123/views/brand/view.php create mode 100644 antgoods123/views/category/_form.php create mode 100644 antgoods123/views/category/_search.php create mode 100644 antgoods123/views/category/create.php create mode 100644 antgoods123/views/category/index.php create mode 100644 antgoods123/views/category/update.php create mode 100644 antgoods123/views/category/view.php create mode 100755 antgoods123/views/config/index.php create mode 100644 antgoods123/views/goods/_form.php create mode 100644 antgoods123/views/goods/_search.php create mode 100755 antgoods123/views/goods/attribute.php create mode 100644 antgoods123/views/goods/create.php create mode 100755 antgoods123/views/goods/filter_attribute.php create mode 100644 antgoods123/views/goods/goods.php create mode 100644 antgoods123/views/goods/index.php create mode 100644 antgoods123/views/goods/new_editor.php create mode 100644 antgoods123/views/goods/picture.php create mode 100644 antgoods123/views/goods/sku_edit.php create mode 100644 antgoods123/views/goods/update.php create mode 100644 antgoods123/views/goods/view.php rename {antgoods => antgoods123}/views/layouts/base.php (100%) rename {antgoods => antgoods123}/views/layouts/breadcrumb.php (100%) rename {antgoods => antgoods123}/views/layouts/footer.php (100%) rename {antgoods => antgoods123}/views/layouts/header.php (100%) rename {antgoods => antgoods123}/views/layouts/main.php (100%) rename {antgoods => antgoods123}/views/layouts/sidebar.php (100%) create mode 100644 antgoods123/views/shop-category/_form.php create mode 100644 antgoods123/views/shop-category/_search.php create mode 100644 antgoods123/views/shop-category/create.php create mode 100644 antgoods123/views/shop-category/index.php create mode 100644 antgoods123/views/shop-category/update.php create mode 100644 antgoods123/views/shop-category/view.php rename {antgoods => antgoods123}/views/site/error.php (100%) rename {antgoods => antgoods123}/views/site/index.php (100%) rename {antgoods => antgoods123}/views/site/login.php (100%) rename {antgoods => antgoods123}/views/site/test.php (100%) create mode 100644 antgoods123/views/supplier/_form.php create mode 100644 antgoods123/views/supplier/_search.php create mode 100644 antgoods123/views/supplier/create.php create mode 100644 antgoods123/views/supplier/index.php create mode 100644 antgoods123/views/supplier/update.php create mode 100644 antgoods123/views/supplier/view.php rename {antgoods => antgoods123}/web/.gitignore (100%) rename {antgoods => antgoods123}/web/assets/.gitignore (100%) rename {antgoods => antgoods123}/web/css/reset.css (100%) rename {antgoods => antgoods123}/web/css/site.css (100%) create mode 100644 antgoods123/web/custom/sku.49a56a9198d9c3ec233c.js create mode 100644 antgoods123/web/custom/sku.52802ed907a316501cd7.js create mode 100644 antgoods123/web/custom/sku.9a46222d01b3d601e5ad.js create mode 100644 antgoods123/web/custom/sku_item.6649e882bedbeb22ea3d.js rename {antgoods => antgoods123}/web/favicon.ico (100%) rename {antgoods => antgoods123}/web/img/avatar.png (100%) rename {antgoods => antgoods123}/web/img/avatar04.png (100%) rename {antgoods => antgoods123}/web/img/avatar2.png (100%) rename {antgoods => antgoods123}/web/img/avatar3.png (100%) rename {antgoods => antgoods123}/web/img/avatar5.png (100%) rename {antgoods => antgoods123}/web/img/credit/american-express.png (100%) rename {antgoods => antgoods123}/web/img/credit/cirrus.png (100%) rename {antgoods => antgoods123}/web/img/credit/mastercard.png (100%) rename {antgoods => antgoods123}/web/img/credit/mestro.png (100%) rename {antgoods => antgoods123}/web/img/credit/paypal.png (100%) rename {antgoods => antgoods123}/web/img/credit/paypal2.png (100%) rename {antgoods => antgoods123}/web/img/credit/visa.png (100%) rename {antgoods => antgoods123}/web/img/default-50x50.gif (100%) rename {antgoods => antgoods123}/web/img/icons.png (100%) rename {antgoods => antgoods123}/web/img/logo.jpeg (100%) rename {antgoods => antgoods123}/web/img/photo1.png (100%) rename {antgoods => antgoods123}/web/img/photo2.png (100%) rename {antgoods => antgoods123}/web/img/photo3.jpg (100%) rename {antgoods => antgoods123}/web/img/photo4.jpg (100%) rename {antgoods => antgoods123}/web/img/user1-128x128.jpg (100%) rename {antgoods => antgoods123}/web/img/user2-160x160.jpg (100%) rename {antgoods => antgoods123}/web/img/user3-128x128.jpg (100%) rename {antgoods => antgoods123}/web/img/user4-128x128.jpg (100%) rename {antgoods => antgoods123}/web/img/user5-128x128.jpg (100%) rename {antgoods => antgoods123}/web/img/user6-128x128.jpg (100%) rename {antgoods => antgoods123}/web/img/user7-128x128.jpg (100%) rename {antgoods => antgoods123}/web/img/user8-128x128.jpg (100%) rename {antgoods => antgoods123}/web/js/common.js (100%) create mode 100755 antgoods123/web/js/jquery.js rename {antgoods => antgoods123}/web/js/jquery.min.js (100%) diff --git a/antgoods/Module.php b/antgoods/Module.php new file mode 100644 index 0000000..974e55c --- /dev/null +++ b/antgoods/Module.php @@ -0,0 +1,24 @@ +title = '添加SKU'; $this->params['breadcrumbs'][] = ['label' => '商品列表', 'url' => ['index']]; diff --git a/antgoods/web/GoodsAttributeAsset.php b/antgoods/web/GoodsAttributeAsset.php new file mode 100644 index 0000000..9cd6e4a --- /dev/null +++ b/antgoods/web/GoodsAttributeAsset.php @@ -0,0 +1,22 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Attribute models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new AttributeSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single Attribute model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Attribute model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Attribute(); + $model->sort_order = 0; + $model->cat_id = 0; + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + $model->value = str_replace(',', ',', $model->value); + $array = explode(',', $model->value); + if (count($array) != count(array_unique($array))) { + \Yii::$app->getSession()->setFlash('error', '不能有相同的属性值'); + return $this->render('create', ['model' => $model]); + } + if ($model->save()) { + return $this->redirect(['index']); + } + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Attribute model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + $model->value = str_replace(',', ',', $model->value); + $array = explode(',', $model->value); + if (count($array) != count(array_unique($array))) { + \Yii::$app->getSession()->setFlash('error', '不能有相同的属性值'); + return $this->render('create', ['model' => $model]); + } + if ($model->save()) { + return $this->redirect(['index']); + } + return $this->redirect('index'); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Attribute model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $model = $this->findModel($id); + $model->is_delete = Attribute::IS_DELETE_YES; + $model->save(); + + return $this->redirect(['index']); + } + + /** + * Finds the Attribute model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Attribute the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Attribute::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new AttributeSearch(); + $params = Yii::$app->request->queryParams; + if ($params['page-type'] == 'all') { + $dataProvider = $searchModel->allData($params); + } else { + $dataProvider = $searchModel->search($params); + } + \iron\widget\Excel::export([ + 'models' => $dataProvider->getModels(), + 'format' => 'Xlsx', + 'asAttachment' => true, + 'fileName' =>'Attributes'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } +} diff --git a/antgoods123/controllers/BrandController.php b/antgoods123/controllers/BrandController.php new file mode 100644 index 0000000..af957b2 --- /dev/null +++ b/antgoods123/controllers/BrandController.php @@ -0,0 +1,151 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Brand models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new BrandSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single Brand model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Brand model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Brand(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Brand model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Brand model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $model = $this->findModel($id); + $model->is_delete = Brand::IS_DELETE_YES; + $model->save(); + + return $this->redirect(['index']); + } + + /** + * Finds the Brand model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Brand the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Brand::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new BrandSearch(); + $params = Yii::$app->request->queryParams; + if ($params['page-type'] == 'all') { + $dataProvider = $searchModel->allData($params); + } else { + $dataProvider = $searchModel->search($params); + } + \iron\widget\Excel::export([ + 'models' => $dataProvider->getModels(), + 'format' => 'Xlsx', + 'asAttachment' => true, + 'fileName' =>'Brands'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } +} diff --git a/antgoods123/controllers/CategoryController.php b/antgoods123/controllers/CategoryController.php new file mode 100644 index 0000000..fcc2366 --- /dev/null +++ b/antgoods123/controllers/CategoryController.php @@ -0,0 +1,276 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + public function actions() + { + return [ + 'upload' => [ + 'class' => 'iron\actions\UploadAction', + 'path' => 'xls/', + 'maxSize' => 20480, + ] + ]; + } + + /** + * Lists all Category models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single Category model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Category model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Category(); + $model->is_show = Category::IS_SHOW_DISPLAY; + $model->sort_order = 0; + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + + //类目图片上传保存处理 + $icon_image_id_str = $model->iconImageId; + $model->save(); + $save_icon_image_res = GoodsManager::saveFile(explode(',', $icon_image_id_str), $model, [], File::OWN_TYPE_CATEGORY_ICON); + if($save_icon_image_res['status']){ + $model->icon = $save_icon_image_res['first_file_id']; + $model->save(); + } + + return $this->redirect('index'); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Category model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model->iconImageId = $model->icon; + //记录已保存的类目图片id,用于修改 + $icon_image_old_id_arr = $model->icon; + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + + //类目图片上传保存处理 + $icon_image_id_str = $model->iconImageId; + $model->save(); + $save_icon_image_res = GoodsManager::saveFile(explode(',', $icon_image_id_str), $model, explode(',', $icon_image_old_id_arr), File::OWN_TYPE_CATEGORY_ICON); + if($save_icon_image_res['status'] && $save_icon_image_res['first_file_id'] !== 0){ + $model->icon = $save_icon_image_res['first_file_id']; + $model->save(); + } + + return $this->redirect('index'); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Category model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $model = $this->findModel($id); + + $model->is_delete = Category::IS_DELETE_YES; + $model->save(); + + return $this->redirect(['index']); + } + + /** + * Finds the Category model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Category the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Category::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new CategorySearch(); + $params = Yii::$app->request->queryParams; + if ($params['page-type'] == 'all') { + $dataProvider = $searchModel->allData($params); + } else { + $dataProvider = $searchModel->search($params); + } + \iron\widget\Excel::export([ + 'models' => $dataProvider->getModels(), + 'format' => 'Xlsx', + 'asAttachment' => true, + 'fileName' =>'Categories'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } + + /** + * 处理文件上传成功后回调保存到临时文件表中,并返回临时文件id + */ + public function actionSaveFile() + { + if(!class_exists('\common\models\ars\TemFile') || !class_exists('\backend\logic\file\FileManager')){ + return ''; + } + + $data = Yii::$app->request->get('data'); + $file_name = Yii::$app->request->get('fileName')[0]; + + if ($data['status'] == true) { + $model = new \common\models\ars\TemFile(); + $model->user_id = Yii::$app->user->identity->id; + $model->name = $file_name; + $file_manager = new \backend\logic\file\FileManager(); + $type_res = $file_manager->searchType(\backend\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); + if ($type_res['status']) { + $model->type = $type_res['type']; + } + $model->alias = $data['alias']; + $model->path = $data['path']; + $model->save(); + return $model->id; + } + } + + /** + * @return string + * 点击删除按钮时同时删除字符串中的id + */ + public function actionImgIdDel() + { + //判断该类是否存在 + if(!class_exists('\common\models\ars\TemFile') || !class_exists('\common\models\ars\File')){ + return ''; + } + + $img_id = Yii::$app->request->get('imgid'); + $img_id_arr = explode(',', $img_id); + if(isset(Yii::$app->request->get('data')['alias'])) { + $alias = Yii::$app->request->get('data')['alias']; + $tem_file = \common\models\ars\TemFile::findOne(['alias' => $alias]); + if ($tem_file) { + $img_id_arr = array_diff($img_id_arr, [$tem_file->id]); + } + }else{ + foreach (Yii::$app->request->get() as $key => $value) { + $tem_file = \common\models\ars\File::findOne(['alias' => $value]); + if ($tem_file) { + $img_id_arr = array_diff($img_id_arr, [$tem_file->id]); + } + } + } + $img_id_str = implode(',', $img_id_arr); + return $img_id_str; + } + + /** + * @return bool|false|string + * 加载已有的文件 + */ + public function actionImageFile() + { + //判断该类是否存在 + if(!class_exists('\common\models\ars\File')){ + return false; + } + + $file_id_str = Yii::$app->request->get('fileidstr'); + $file_id_arr = explode(',', $file_id_str); + $data = \common\models\ars\File::find()->where(['id' => $file_id_arr])->all(); + $res = array(); + if($data) { + $i = 0; + foreach ($data as $key => $value) { + $res[$i]['name'] = $value->alias; + $res[$i]['path'] = Yii::$app->request->hostInfo . '/' . $value->path; + $res[$i]['size'] = filesize($value->path); + $i++; + } + } + return json_encode($res); + } +} diff --git a/antgoods/controllers/ConfigController.php b/antgoods123/controllers/ConfigController.php similarity index 100% rename from antgoods/controllers/ConfigController.php rename to antgoods123/controllers/ConfigController.php diff --git a/antgoods123/controllers/GoodsController.php b/antgoods123/controllers/GoodsController.php new file mode 100644 index 0000000..c2891cc --- /dev/null +++ b/antgoods123/controllers/GoodsController.php @@ -0,0 +1,359 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + public function actions() + { + return [ + 'upload' => [ + 'class' => 'iron\actions\UploadAction', + 'path' => 'xls/', + 'maxSize' => 20480, + ], + 'ueditor' => [ + 'class' => 'common\widgets\ueditor\UeditorAction', + 'config' => [ + //上传图片配置 + 'imageUrlPrefix' => "", /* 图片访问路径前缀 */ + 'imagePathFormat' => "/uploads/origin/introduce/" . md5(time() . rand(000, 999)), /* 上传保存路径,可以自定义保存路径和文件名格式 */ + ] + ], + ]; + } + + /** + * Lists all Goods models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new GoodsSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single Goods model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Goods model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Goods(); + $model->is_sale = Goods::IS_SALE_YES; + $model->stock = -1; + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + //商品封面图和商品详情图上传保存处理 + $res = GoodsManager::updateGoods(Yii::$app->request->post(), $model); + if ($res['status']) { + return $this->redirect('index'); + } + } else { + $model->ruleVerify = 1; + } + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Goods model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model->coverImageId = $model->image; + $model->detailImageId = implode(',', File::find()->select('id')->where(['is_delete' => File::IS_DELETE_NO, 'own_id' => $model->id, 'own_type' => File::OWN_TYPE_GOODS_DETAILS])->column()); + //记录已保存的商品图片id,用于修改 + $cover_image_old_id_str = $model->image; + $detail_image_old_id_str = $model->detailImageId; + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + //商品封面图和商品详情图上传保存处理 + $res = GoodsManager::updateGoods(Yii::$app->request->post(), $model, $cover_image_old_id_str, $detail_image_old_id_str); + if ($res['status']) { + return $this->redirect('index'); + } + } + $attributeModel = GoodsManager::getAttribute($id); + $checkAttr = GoodsManager::getSkuInfo($id); + $filterAttributeModel = GoodsManager::getFilterAttribute($id); + $judgeGoodsCategory = GoodsManager::judgeGoodsCategory($model); + return $this->render('update', [ + 'model' => $model, + 'attributeModel' => $attributeModel, + 'attrValue' => $checkAttr, + 'filterAttributeModel' => $filterAttributeModel, + 'judgeGoodsCategory' => $judgeGoodsCategory, + ]); + } + + /** + * Deletes an existing Goods model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $model = $this->findModel($id); + $model->is_delete = Goods::IS_DELETE_YES; + $model->save(); + + return $this->redirect(['index']); + } + + /** + * Finds the Goods model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Goods the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Goods::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new GoodsSearch(); + $params = Yii::$app->request->queryParams; + if ($params['page-type'] == 'all') { + $dataProvider = $searchModel->allData($params); + } else { + $dataProvider = $searchModel->search($params); + } + \iron\widget\Excel::export([ + 'models' => $dataProvider->getModels(), + 'format' => 'Xlsx', + 'asAttachment' => true, + 'fileName' =>'Goods'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } + + /** + * 处理文件上传成功后回调保存到临时文件表中,并返回临时文件id + */ + public function actionSaveFile() + { + if(!class_exists('\common\models\ars\TemFile') || !class_exists('\backend\logic\file\FileManager')){ + return ''; + } + + $data = Yii::$app->request->get('data'); + $file_name = Yii::$app->request->get('fileName')[0]; + + if ($data['status'] == true) { + $model = new \common\models\ars\TemFile(); + $model->user_id = Yii::$app->user->identity->id; + $model->name = $file_name; + $file_manager = new \backend\logic\file\FileManager(); + $type_res = $file_manager->searchType(\backend\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); + if ($type_res['status']) { + $model->type = $type_res['type']; + } + $model->alias = $data['alias']; + $model->path = $data['path']; + $model->save(); + return $model->id; + } + } + + /** + * @return string + * 点击删除按钮时同时删除字符串中的id + */ + public function actionImgIdDel() + { + //判断该类是否存在 + if(!class_exists('\common\models\ars\TemFile') || !class_exists('\common\models\ars\File')){ + return ''; + } + + $img_id = Yii::$app->request->get('imgid'); + $img_id_arr = explode(',', $img_id); + if(isset(Yii::$app->request->get('data')['alias'])) { + $alias = Yii::$app->request->get('data')['alias']; + $tem_file = \common\models\ars\TemFile::findOne(['alias' => $alias]); + if ($tem_file) { + $img_id_arr = array_diff($img_id_arr, [$tem_file->id]); + } + }else{ + foreach (Yii::$app->request->get() as $key => $value) { + $tem_file = \common\models\ars\File::findOne(['alias' => $value]); + if ($tem_file) { + $img_id_arr = array_diff($img_id_arr, [$tem_file->id]); + } + } + } + $img_id_str = implode(',', $img_id_arr); + return $img_id_str; + } + + /** + * @return bool|false|string + * 加载已有的文件 + */ + public function actionImageFile() + { + //判断该类是否存在 + if(!class_exists('\common\models\ars\File')){ + return false; + } + + $rule_verify = Yii::$app->request->get('ruleverify'); + $file_id_str = Yii::$app->request->get('fileidstr'); + $file_id_arr = explode(',', $file_id_str); + if ($rule_verify == 1) { + $data = \common\models\ars\TemFile::find()->where(['id' => $file_id_arr])->all(); + } else { + $data = \common\models\ars\File::find()->where(['id' => $file_id_arr])->all(); + } + $res = array(); + if($data) { + $i = 0; + foreach ($data as $key => $value) { + $res[$i]['name'] = $value->alias; + $res[$i]['path'] = Yii::$app->request->hostInfo . '/' . $value->path; + $res[$i]['size'] = filesize($value->path); + $i++; + } + } + return json_encode($res); + } + + /** + * @param $id + * @return string + * 商品编辑sku + */ + + public function actionEditSku($id) + { + $sku = GoodsManager::getCreatedSku($id); + $attributes = GoodsManager::getAttrs($id); + return $this->render('sku_edit', [ + 'attributes' => $attributes, + 'sku' => $sku,]); + } + + /** + * @return array + * @throws \Throwable + * 添加sku + */ + public function actionAddSku() + { + $data = []; + Yii::$app->response->format = 'json'; + $res = Yii::$app->request->post('sku'); + $goodsId = Yii::$app->request->post('goodsId'); + $tra = Yii::$app->db->beginTransaction(); + try { + $data['originalIds'] = GoodsManager::getOriginalIds($res['type'], $goodsId); + $data['acceptIds'] = []; + foreach ($res['data'] as $sku) { + GoodsManager::AddOrUpdateData($sku, $res['type'], $goodsId); + if ($sku['id'] > 0) { + $data['acceptIds'][] = $sku['id']; + } + } + GoodsManager::deleteSku($res['type'], $data, $goodsId); + $tra->commit(); + return ['status' => true]; + } catch (\Exception $e) { + $tra->rollBack(); + return ['status' => false, 'info' => $e->getMessage()]; + } + } + + public function actionSwitch() + { + Yii::$app->response->format = 'json'; + $data = []; + $type = Yii::$app->request->get('type'); + $id = Yii::$app->request->get('goodsId'); + $data['sku'] = GoodsManager::getCreatedSku($id, $type); + $data['attributes'] = GoodsManager::getAttrs($id, $type); + return $data; + } + + /** + * @return false|string + * 根据商品分类获取商品属性 + */ + public function actionFilterAttribute() + { + $catId = Yii::$app->request->get('catId')??0; + $goodsId = Yii::$app->request->get('goodsId')??0; + $allAttr = Attribute::find()->where(['type' => Attribute::TYPE_ATTR])->andWhere(['cat_id' => [0,$catId]])->asArray()->all(); + return json_encode($allAttr); + } +} diff --git a/antgoods123/controllers/ShopCategoryController.php b/antgoods123/controllers/ShopCategoryController.php new file mode 100644 index 0000000..3a32b55 --- /dev/null +++ b/antgoods123/controllers/ShopCategoryController.php @@ -0,0 +1,287 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + public function actions() + { + return [ + 'upload' => [ + 'class' => 'iron\actions\UploadAction', + 'path' => 'xls/', + 'maxSize' => 20480, + ] + ]; + } + + /** + * Lists all ShopCategory models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ShopCategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single ShopCategory model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new ShopCategory model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new ShopCategory(); + $model->is_show = ShopCategory::IS_SHOW_HIDE; + $model->sort_order = 0; + + if ($model->load(Yii::$app->request->post())) { + if ($model->filter_attr != null && is_array($model->filter_attr)) { + $model->filter_attr = implode(',', $model->filter_attr); + } else { + $model->filter_attr = ''; + } + + //类目图片上传保存处理 + $icon_image_id_str = $model->iconImageId; + $model->save(); + $save_icon_image_res = GoodsManager::saveFile(explode(',', $icon_image_id_str), $model, [], File::OWN_TYPE_CATEGORY_ICON); + if($save_icon_image_res['status']){ + $model->icon = $save_icon_image_res['first_file_id']; + $model->save(); + } + + return $this->redirect('index'); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing ShopCategory model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + if ($model->filter_attr != null) { + $model->filter_attr = explode(',', $model->filter_attr); + } + $model->iconImageId = $model->icon; + $icon_image_old_id_arr = $model->icon;//记录已保存的类目图片id,用于修改 + + if ($model->load(Yii::$app->request->post())) { + if ($model->filter_attr != null && is_array($model->filter_attr)) { + $model->filter_attr = implode(',', $model->filter_attr); + } else { + $model->filter_attr = ''; + } + + //类目图片上传保存处理 + $icon_image_id_str = $model->iconImageId; + $model->save(); + $save_icon_image_res = GoodsManager::saveFile(explode(',', $icon_image_id_str), $model, explode(',', $icon_image_old_id_arr), File::OWN_TYPE_CATEGORY_ICON); + if($save_icon_image_res['status'] && $save_icon_image_res['first_file_id'] !== 0){ + $model->icon = $save_icon_image_res['first_file_id']; + $model->save(); + } + + return $this->redirect('index'); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing ShopCategory model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $model = $this->findModel($id); + $model->is_delete = ShopCategory::IS_DELETE_YES; + $model->save(); + + return $this->redirect(['index']); + } + + /** + * Finds the ShopCategory model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return ShopCategory the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = ShopCategory::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new ShopCategorySearch(); + $params = Yii::$app->request->queryParams; + if ($params['page-type'] == 'all') { + $dataProvider = $searchModel->allData($params); + } else { + $dataProvider = $searchModel->search($params); + } + \iron\widget\Excel::export([ + 'models' => $dataProvider->getModels(), + 'format' => 'Xlsx', + 'asAttachment' => true, + 'fileName' =>'Shop Categories'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } + + /** + * 处理文件上传成功后回调保存到临时文件表中,并返回临时文件id + */ + public function actionSaveFile() + { + if(!class_exists('\common\models\ars\TemFile') || !class_exists('\backend\logic\file\FileManager')){ + return ''; + } + + $data = Yii::$app->request->get('data'); + $file_name = Yii::$app->request->get('fileName')[0]; + + if ($data['status'] == true) { + $model = new \common\models\ars\TemFile(); + $model->user_id = Yii::$app->user->identity->id; + $model->name = $file_name; + $file_manager = new \backend\logic\file\FileManager(); + $type_res = $file_manager->searchType(\backend\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); + if ($type_res['status']) { + $model->type = $type_res['type']; + } + $model->alias = $data['alias']; + $model->path = $data['path']; + $model->save(); + return $model->id; + } + } + + /** + * @return string + * 点击删除按钮时同时删除字符串中的id + */ + public function actionImgIdDel() + { + //判断该类是否存在 + if(!class_exists('\common\models\ars\TemFile') || !class_exists('\common\models\ars\File')){ + return ''; + } + + $img_id = Yii::$app->request->get('imgid'); + $img_id_arr = explode(',', $img_id); + if(isset(Yii::$app->request->get('data')['alias'])) { + $alias = Yii::$app->request->get('data')['alias']; + $tem_file = \common\models\ars\TemFile::findOne(['alias' => $alias]); + if ($tem_file) { + $img_id_arr = array_diff($img_id_arr, [$tem_file->id]); + } + }else{ + foreach (Yii::$app->request->get() as $key => $value) { + $tem_file = \common\models\ars\File::findOne(['alias' => $value]); + if ($tem_file) { + $img_id_arr = array_diff($img_id_arr, [$tem_file->id]); + } + } + } + $img_id_str = implode(',', $img_id_arr); + return $img_id_str; + } + + /** + * @return bool|false|string + * 加载已有的文件 + */ + public function actionImageFile() + { + //判断该类是否存在 + if(!class_exists('\common\models\ars\File')){ + return false; + } + + $file_id_str = Yii::$app->request->get('fileidstr'); + $file_id_arr = explode(',', $file_id_str); + $data = \common\models\ars\File::find()->where(['id' => $file_id_arr])->all(); + $res = array(); + if($data) { + $i = 0; + foreach ($data as $key => $value) { + $res[$i]['name'] = $value->alias; + $res[$i]['path'] = Yii::$app->request->hostInfo . '/' . $value->path; + $res[$i]['size'] = filesize($value->path); + $i++; + } + } + return json_encode($res); + } +} diff --git a/antgoods/controllers/SiteController.php b/antgoods123/controllers/SiteController.php similarity index 100% rename from antgoods/controllers/SiteController.php rename to antgoods123/controllers/SiteController.php diff --git a/antgoods123/controllers/SupplierController.php b/antgoods123/controllers/SupplierController.php new file mode 100644 index 0000000..67c067b --- /dev/null +++ b/antgoods123/controllers/SupplierController.php @@ -0,0 +1,151 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Supplier models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new SupplierSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single Supplier model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Supplier model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Supplier(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Supplier model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Supplier model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $model = $this->findModel($id); + $model->is_delete = Supplier::IS_DELETE_YES; + $model->save(); + + return $this->redirect(['index']); + } + + /** + * Finds the Supplier model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Supplier the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Supplier::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new SupplierSearch(); + $params = Yii::$app->request->queryParams; + if ($params['page-type'] == 'all') { + $dataProvider = $searchModel->allData($params); + } else { + $dataProvider = $searchModel->search($params); + } + \iron\widget\Excel::export([ + 'models' => $dataProvider->getModels(), + 'format' => 'Xlsx', + 'asAttachment' => true, + 'fileName' =>'Suppliers'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } +} diff --git a/antgoods123/logic/goods/GoodsManager.php b/antgoods123/logic/goods/GoodsManager.php new file mode 100644 index 0000000..c9d134d --- /dev/null +++ b/antgoods123/logic/goods/GoodsManager.php @@ -0,0 +1,578 @@ + false, 'info' => '操作失败']; + } + + //需要新建的文件id + $createFileIdArr = array_diff($newFileIdArr, $oldFileIdArr); + + //创建文件 + $class = new \backend\logic\file\FileManager(); + $createFileRes = $class->saveTemFileToFile($createFileIdArr, $goodsModel->id, $fileType); + + //需要删除的文件id + $delFileIdArr = array_diff($oldFileIdArr, $newFileIdArr); + + //删除文件 + $class->deleteFile($delFileIdArr); + + //记录第一张图片id + $firstFileId = 0; + + //查看修改数组是否为空 + if (!$newFileIdArr[0]) { + $firstFileId = null; + }else { + if ($createFileRes['status']) { + $firstFileId = $createFileRes['first_file_id']; + } + } + + return ['status' => true, 'info' => '操作成功', 'first_file_id' => $firstFileId]; + } + + /** + * @param $data + * @param $model + * @param null $coverImageOldIdStr + * @param null $detailImageOldIdStr + * @return array + * @throws \Throwable + * 创建修改商品操作 + */ + public static function updateGoods($data, $model, $coverImageOldIdStr = null, $detailImageOldIdStr = null) + { + $attribute = $data['attribute']; + $filterAttribute = $data['filterattribute']; + $tra = Yii::$app->db->beginTransaction(); + try { + if (!$model->save()) { + throw new Exception(''); + } + $saveCoverImageRes = self::saveFile(explode(',', $model->coverImageId), $model, explode(',', $coverImageOldIdStr)); + $saveDetailImageRes = self::saveFile(explode(',', $model->detailImageId), $model, explode(',', $detailImageOldIdStr), File::OWN_TYPE_GOODS_DETAILS); + if ($saveCoverImageRes['status'] && $saveDetailImageRes['status']) { + if($saveCoverImageRes['first_file_id'] !== 0) { + $model->image = $saveCoverImageRes['first_file_id']; + if (!$model->save()) { + throw new Exception('图片保存失败'); + } + } + } else { + throw new Exception('图片保存失败'); + } + self::addAttributeOperating(['id' => $model->id, 'attribute' => $attribute]); + self::addFilterAttributeOperating(['id' => $model->id, 'filterAttribute' => $filterAttribute]); + $tra->commit(); + return ['status' => true]; + } catch (\yii\base\Exception $e) { + $tra->rollBack(); + return ['status' => false, 'info' => $e->getMessage()]; + } + } + + /** + * @param $data + * @return bool + * @throws Exception + * 创建修改商品属性操作 + */ + public static function addAttributeOperating($data) + { + if (!$data['attribute']) { + return true; + } + $data['attribute'] = json_decode($data['attribute'], true); + $oldAttr = []; + $goodsAttr = GoodsAttr::find()->where(['goods_id' => $data['id'], 'is_delete' => GoodsAttr::IS_DELETE_NO])->all(); + if ($goodsAttr) { //如果商品有旧的属性 + if(count($data['attribute']) == 0 && is_array($data['attribute'])) { //如果传上来的是空数组,删除该商品下的全部属性 + self::delAttribute($goodsAttr); + return true; + } + foreach ($goodsAttr as $key => $value) { //把旧的商品属性保存到一个数组 + $oldAttr[$value->id] = $value->attr_value; + } + } + $newAttr = self::addAttribute($data['attribute'], $data['id']); //添加新的商品属性 + $delAttr = array_diff(array_keys($oldAttr), array_keys($newAttr)); //找出需要删除的goodsAttrId + if (!$delAttr) { + return true; + } + foreach ($delAttr as $value) { + $model = GoodsAttr::find()->where(['id' => $value, 'is_delete' => GoodsAttr::IS_DELETE_NO])->One(); + if ($model) { + $model->is_delete = GoodsAttr::IS_DELETE_YES; + if (!$model->save()) { + throw new Exception('goodsAttribute delete false'); + } + } + } + } + + /** + * @param $goodsAttr + * @throws Exception + * 删除商品属性 + */ + public static function delAttribute($goodsAttr) + { + foreach ($goodsAttr as $key => $value) { + $value->is_delete = GoodsAttr::IS_DELETE_YES; + if (!$value->save()) { + throw new Exception('goods attribute delete false'); + } + } + } + + /** + * @param $attribute + * @param $goodsId + * @return array + * @throws Exception + * 保存商品属性 + */ + public static function addAttribute($attribute, $goodsId) + { + $newAttr = []; + if (!$attribute) { + return []; + } + foreach ($attribute as $value) { + foreach ($value['value'] as $k => $v) { + $goodsAttrModel = new GoodsAttr(); + $goodsAttrModel->attr_id = $value['id']; + $attr = GoodsAttr::find()->where(['goods_id' => $goodsId, 'attr_id' => $value['id'], 'attr_value' => $v, 'is_delete' => GoodsAttr::IS_DELETE_NO])->one(); + if ($attr) { + $newAttr[$attr->id] = $attr->attr_value; //原有的数据 + } else { + $goodsAttrModel->goods_id = $goodsId; + $goodsAttrModel->attr_value = $v; + if (!$goodsAttrModel->save()) { + throw new Exception('goodsAttribute save false'); + } + $newAttr[$goodsAttrModel->id] = $goodsAttrModel->attr_value; //新增的数据 + } + } + } + return $newAttr; + } + + /** + * @param $id + * @return Attribute|array|null + * 获取属性信息 + */ + public static function getAttribute($id) + { + $goodsAttributes = GoodsAttr::find()->where(['goods_id' => $id, 'is_delete' => GoodsAttr::IS_DELETE_NO])->andWhere(['!=', 'attr_id', 0])->all(); + $filter = []; + $goodsAttributeModel = []; + if (!$goodsAttributes) { + return $goodsAttributeModel; + } + foreach ($goodsAttributes 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]]; + $goodsAttributeModel[] = $attribute; + } else { + foreach ($goodsAttributeModel as $k => $v) { + if ($v['name'] == $attribute->name) { + $goodsAttributeModel[$k]['value'][] = $value->attr_value; + } + } + } + } + return $goodsAttributeModel; + } + + /** + * @param $id + * @return array + * 获取sku信息 + */ + public static function getSkuInfo($id) + { + $skus = GoodsSku::find()->where(['goods_id' => $id, 'is_delete' => GoodsSku::IS_DELETE_NO])->all(); + $attrId = []; + foreach ($skus as $sku) { + $attrId = array_merge(explode(',', $sku->goods_attr), $attrId); + } + $attrs = GoodsAttr::find()->where(['id' => $attrId, 'is_delete' => GoodsAttr::IS_DELETE_NO])->andWhere(['!=', 'attr_id', 0])->all(); + $checkAttr = []; + $filterAttr = []; + foreach ($attrs as $value) { + $attr = Attribute::findOne(['id' => $value->attr_id, 'is_delete' => Attribute::IS_DELETE_NO]); + if (!in_array($attr->name, $filterAttr)) { + $filterAttr[] = $attr->name; + $newAttr = ['id' => $attr->id, 'name' => $attr->name, 'value' => [$value->attr_value]]; + $checkAttr[] = $newAttr; + } else { + foreach ($checkAttr as $key => $item) { + if ($item['name'] == $attr->name) { //如果attr_id与$filter的attr_id相符,入栈 + $checkAttr[$key]['value'][] = $value->attr_value; + } + } + } + } + return $checkAttr; + } + + /** + * @param $id + * @return mixed + * 已创建sku信息 + */ + public static function getCreatedSku($id, $type = 0) + { + $goods = Goods::findOne($id); + $data['type'] = $type ?: $goods->sku_mode; + $data['data'] = []; + if ($data['type'] == Goods::SKU_MODE_ATTR) { + $sku = GoodsSku::find() + ->where(['goods_id' => $id, 'is_manaul' => 0]) + ->all(); + } else { + $sku = GoodsSku::find() + ->where(['goods_id' => $id, 'is_manaul' => 1]) + ->all(); + } + foreach ($sku as $value) { + $data['data'][] = self::getAttrInfo($data['type'], $value); + } + return $data; + } + + /** + * @param $type + * @param $sku + * @return array + * 获取商品详情 + */ + public static function getAttrInfo($type, $sku) + { + $data = []; + if ($type == Goods::SKU_MODE_ATTR) { + $data['value'] = array_filter(explode(',', $sku->goods_attr)); + } else { + $attr = explode(',', $sku->goods_attr); + $goodsAttr = GoodsAttr::findOne($attr[0]); + $data['value'] = $goodsAttr->attr_value; + } + $data['id'] = $sku->id; + $data['price'] = $sku->price; + $data['stock'] = $sku->stock; + $data['weight'] = $sku->weight; + return $data; + } + + /** + * @param $id + * @return array + * 获取商品属性 + */ + public static function getAttrs($id) + { + $attrId = GoodsAttr::find()->where(['goods_id' => $id, 'is_delete' => GoodsAttr::IS_DELETE_NO]) + ->andWhere(['>', 'attr_id', 0]) + ->select('attr_id') + ->distinct() + ->all(); + $attributes = []; + foreach ($attrId as $v) { + $attribute = Attribute::findOne($v); + if ($attribute && $attribute->type == Attribute::TYPE_ATTR) { + $ret['name'] = $attribute->name; + $ret['id'] = $attribute->id; + $ret['attrValue'] = self::getAttrValue($attribute->id, $id); + $attributes[] = $ret; + } + } + return $attributes; + } + + /** + * @param $attrId + * @param $goodsId + * @return GoodsAttr[]|GoodsSku[]|array|File[]|\common\models\ars\TemFile[]|\yii\db\ActiveRecord[] + * 获取属性值 + */ + public static function getAttrValue($attrId, $goodsId) + { + return GoodsAttr::find() + ->select(['id', 'attr_value']) + ->where(['goods_id' => $goodsId]) + ->andWhere(['attr_id' => $attrId]) + ->asArray() + ->all(); + } + + /** + * @param $type + * @param $goodsId + * @return array + * 获取已存储的商品sku的id + */ + public static function getOriginalIds($type, $goodsId) + { + $ids = []; + if ($type == Goods::SKU_MODE_MANUAL) { + $query = GoodsSku::find() + ->where(['is_manaul' => 1]); + } else { + $query = GoodsSku::find() + ->where(['is_manaul' => 0]); + } + $sku = $query + ->andWhere(['goods_id' => $goodsId]) + ->all(); + foreach ($sku as $value) { + $ids[] = $value->id; + } + return $ids; + } + + /** + * @param $sku + * @throws \yii\db\Exception + * 添加或更新sku数据 + */ + public static function AddOrUpdateData($sku, $type, $goodsId) + { + $goodsModel = Goods::findOne($goodsId); + if ($sku['id'] > 0) { + $goodsSku = GoodsSku::findOne($sku['id']); + $attrId = array_filter(explode(',', $goodsSku->goods_attr)); + $attr = GoodsAttr::findOne($attrId[0]); + } else { + $goodsSku = new GoodsSku(); + $attr = new GoodsAttr(); + } + if (!$attr || !$goodsSku || !$goodsModel) { + throw new \yii\db\Exception('系统异常'); + } + if ($type == Goods::SKU_MODE_MANUAL) { + $attr->attr_value = $sku['value']; + if (!$attr->save()) { + throw new \yii\db\Exception('手动属性修改失败'); + } + $goodsSku->goods_attr = (string)$attr->id; + $goodsSku->is_manaul = 1; + } else { + $goodsSku->goods_attr = implode(',', array_filter($sku['value'])); + } + $goodsSku->goods_id = $goodsId; + $goodsSku->price = $sku['price']; + $goodsSku->stock = $sku['stock']; + $goodsSku->weight = $sku['weight']; + $goodsSku->goods_sn = $goodsModel->sn; + if (!$goodsSku->save()) { + throw new \yii\db\Exception('保存失败,请检查是否有重复规格'); + } + $goods = Goods::findOne($goodsId); + $goods->sku_mode = $type; + if (!$goods->save()) { + throw new \yii\db\Exception('商品sku类型修改失败'); + } + } + + /** + * @param $type + * @param $data + * @param $goodsId + * @return bool + * @throws \Throwable + * @throws \yii\db\StaleObjectException + * 删除sku + */ + public static function deleteSku($type, $data, $goodsId) + { + if (!$data['originalIds']) { + return true; + } + if ($type == Goods::SKU_MODE_MANUAL) { + $query = GoodsSku::find() + ->where(['is_manaul' => 1]); + } else { + $query = GoodsSku::find() + ->where(['is_manaul' => 0]); + } + $sku = $query + ->andWhere(['goods_id' => $goodsId]) + ->andWhere(['in', 'id', $data['originalIds']]) + ->andWhere(['not in', 'id', $data['acceptIds']]) + ->all(); + foreach ($sku as $value) { + $value->delete(); + } + } + + /** + * @param $data + * @return bool + * @throws Exception + * 创建修改商品筛选属性操作 + */ + public static function addFilterAttributeOperating($data) + { + if (!$data['filterAttribute']) { + return true; + } + $data['filterAttribute'] = json_decode($data['filterAttribute'], true); + $oldFilterAttr = []; + $goodsFilterAttr = FilterAttr::find()->where(['goods_id' => $data['id'], 'is_delete' => FilterAttr::IS_DELETE_NO])->all(); + if ($goodsFilterAttr) { //如果商品有旧的属性 + if(count($data['filterAttribute']) == 0 && is_array($data['filterAttribute'])) { //如果传上来的是空数组,删除该商品下的全部属性 + self::delFilterAttribute($goodsFilterAttr); + return true; + } + foreach ($goodsFilterAttr as $key => $value) { //把旧的商品属性保存到一个数组 + $oldFilterAttr[$value->id] = $value->attr_value; + } + } + $newAttr = self::addFilterAttribute($data['filterAttribute'], $data['id']); //添加新的商品属性 + $delAttr = array_diff(array_keys($oldFilterAttr), array_keys($newAttr)); //找出需要删除的goodsAttrId + if (!$delAttr) { + return true; + } + foreach ($delAttr as $value) { + $model = FilterAttr::find()->where(['id' => $value, 'is_delete' => FilterAttr::IS_DELETE_NO])->One(); + if ($model) { + $model->is_delete = FilterAttr::IS_DELETE_YES; + if (!$model->save()) { + throw new Exception('goodsAttribute delete false'); + } + } + } + } + + /** + * @param $goodsFilterAttr + * @throws Exception + * 删除商品筛选属性 + */ + public static function delFilterAttribute($goodsFilterAttr) + { + foreach ($goodsFilterAttr as $key => $value) { + $value->is_delete = FilterAttr::IS_DELETE_YES; + if (!$value->save()) { + throw new Exception('goods attribute delete false'); + } + } + } + + /** + * @param $attribute + * @param $goodsId + * @return array + * @throws Exception + * 保存商品筛选属性 + */ + public static function addFilterAttribute($attribute, $goodsId) + { + $newAttr = []; + if (!$attribute) { + return []; + } + foreach ($attribute as $value) { + foreach ($value['value'] as $k => $v) { + $goodsFilterAttrModel = new FilterAttr(); + $goodsFilterAttrModel->attr_id = $value['id']; + $attr = FilterAttr::find()->where(['goods_id' => $goodsId, 'attr_id' => $value['id'], 'attr_value' => $v, 'is_delete' => FilterAttr::IS_DELETE_NO])->one(); + if ($attr) { + $newAttr[$attr->id] = $attr->attr_value; //原有的数据 + } else { + $goodsFilterAttrModel->goods_id = $goodsId; + $goodsFilterAttrModel->attr_value = $v; + if (!$goodsFilterAttrModel->save()) { + throw new Exception('goodsAttribute save false'); + } + $newAttr[$goodsFilterAttrModel->id] = $goodsFilterAttrModel->attr_value; //新增的数据 + } + } + } + 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 + * @return bool + * + */ + public static function judgeGoodsCategory($goodsModel) + { + $skus = GoodsSku::find()->where(['goods_id' => $goodsModel->id, 'is_delete' => GoodsSku::IS_DELETE_NO])->all(); + $attrId = []; + foreach ($skus as $sku) { + $attrId = array_merge(explode(',', $sku->goods_attr), $attrId); + } + $goodsAttr = array_unique(GoodsAttr::find()->select(['attr_id'])->where(['id' => $attrId, 'is_delete' => GoodsAttr::IS_DELETE_NO])->andWhere(['!=', 'attr_id', 0])->column()); + $attrArr = array_unique(Attribute::find()->select(['cat_id'])->where(['is_delete' => Attribute::IS_DELETE_NO, 'id' => $goodsAttr])->column()); + if (in_array($goodsModel->cat_id, $attrArr)) { + return true; //存在,则返回true,表示后台分类不得修改 + } + return false; //否则返回false,表示后台分类可以修改 + } + + public static function categoryBtreeList() + { + + } +} \ No newline at end of file diff --git a/antgoods123/migrations/m191119_021851_create_table_shop_category.php b/antgoods123/migrations/m191119_021851_create_table_shop_category.php new file mode 100644 index 0000000..35f536e --- /dev/null +++ b/antgoods123/migrations/m191119_021851_create_table_shop_category.php @@ -0,0 +1,42 @@ +createTable('antgoods_shop_category', [ + 'id' => $this->primaryKey(), + 'name'=>$this->string(60)->notNull()->comment('类别名称'), + 'pid'=>$this->integer(11)->defaultValue(null)->comment('父级id'), + 'goods_count'=>$this->integer(11)->defaultValue(0)->comment('商品数量'), + 'keywords'=>$this->string(100)->defaultValue(null)->comment('关键字'), + 'desc'=>$this->string(255)->defaultValue(null)->comment('描述'), + 'sort_order'=>$this->smallInteger(3)->defaultValue(0)->comment('排序'), + 'icon_type'=>$this->tinyInteger(1)->defaultValue(null)->comment('图标类型'), + 'icon'=>$this->string(64)->defaultValue(null)->comment('图标'), + 'filter_attr'=>$this->text()->comment('筛选属性'), + 'is_show'=>$this->tinyInteger(1)->defaultValue(0)->comment('是否显示,1为不显示'), + 'is_delete'=>$this->tinyInteger(1)->defaultValue(0)->comment('是否删除,1为已删除'), + 'created_at'=>$this->integer(11)->defaultValue(null)->comment('创建时间'), + 'updated_at'=>$this->integer(11)->defaultValue(null)->comment('更新时间'), + ],$tableOptions); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $this->dropTable('antgoods_shop_category'); + return true; + } +} diff --git a/antgoods123/migrations/m191119_022641_create_table_category.php b/antgoods123/migrations/m191119_022641_create_table_category.php new file mode 100644 index 0000000..60dd21e --- /dev/null +++ b/antgoods123/migrations/m191119_022641_create_table_category.php @@ -0,0 +1,39 @@ +createTable('antgoods_category', [ + 'id' => $this->primaryKey(), + 'name'=>$this->string(60)->notNull()->comment('类别名称'), + 'pid'=>$this->integer(11)->defaultValue(null)->comment('父级id'), + 'goods_count'=>$this->integer(11)->defaultValue(0)->comment('商品数量'), + 'sort_order'=>$this->smallInteger(3)->defaultValue(0)->comment('排序'), + 'icon_type'=>$this->tinyInteger(1)->defaultValue(null)->comment('图标类型'), + 'icon'=>$this->string(64)->defaultValue(null)->comment('图标'), + 'is_show'=>$this->tinyInteger(1)->defaultValue(0)->comment('是否显示,1为不显示'), + 'is_delete'=>$this->tinyInteger(1)->defaultValue(0)->comment('是否删除,1为已删除'), + 'created_at'=>$this->integer(11)->defaultValue(null)->comment('创建时间'), + 'updated_at'=>$this->integer(11)->defaultValue(null)->comment('更新时间'), + ],$tableOptions); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $this->dropTable('antgoods_category'); + return true; + } +} diff --git a/antgoods123/migrations/m191119_022939_create_table_attribute.php b/antgoods123/migrations/m191119_022939_create_table_attribute.php new file mode 100644 index 0000000..8f77f8f --- /dev/null +++ b/antgoods123/migrations/m191119_022939_create_table_attribute.php @@ -0,0 +1,36 @@ +createTable('antgoods_attribute', [ + 'id' => $this->primaryKey(), + 'name'=>$this->string(50)->notNull()->comment('属性名'), + 'value'=>$this->text()->notNull()->comment('属性值'), + 'type'=>$this->smallInteger(2)->defaultValue(null)->comment('类型'), + 'sort_order'=>$this->smallInteger(3)->defaultValue(null)->comment('排序'), + 'is_delete'=>$this->tinyInteger(1)->defaultValue(0)->comment('是否删除,1为已删除'), + 'created_at'=>$this->integer(11)->defaultValue(null)->comment('创建时间'), + 'updated_at'=>$this->integer(11)->defaultValue(null)->comment('更新时间'), + ],$tableOptions); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $this->dropTable('antgoods_attribute'); + return true; + } +} diff --git a/antgoods123/migrations/m191119_023115_create_table_goods_attr.php b/antgoods123/migrations/m191119_023115_create_table_goods_attr.php new file mode 100644 index 0000000..19a263c --- /dev/null +++ b/antgoods123/migrations/m191119_023115_create_table_goods_attr.php @@ -0,0 +1,35 @@ +createTable('antgoods_goods_attr', [ + 'id' => $this->primaryKey(), + 'goods_id'=>$this->integer(11)->notNull()->comment('商品id'), + 'attr_id'=>$this->integer(11)->notNull()->comment('属性id'), + 'attr_value'=>$this->string(50)->notNull()->comment('属性名'), + 'is_delete'=>$this->tinyInteger(1)->defaultValue(0)->comment('是否删除,1为已删除'), + 'created_at'=>$this->integer(11)->defaultValue(null)->comment('创建时间'), + 'updated_at'=>$this->integer(11)->defaultValue(null)->comment('更新时间'), + ],$tableOptions); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $this->dropTable('antgoods_goods_attr'); + return true; + } +} diff --git a/antgoods123/migrations/m191119_024029_create_table_brand.php b/antgoods123/migrations/m191119_024029_create_table_brand.php new file mode 100644 index 0000000..48984d4 --- /dev/null +++ b/antgoods123/migrations/m191119_024029_create_table_brand.php @@ -0,0 +1,33 @@ +createTable('antgoods_brand', [ + 'id' => $this->primaryKey(), + 'name'=>$this->string(50)->notNull()->comment('品牌名'), + 'is_delete'=>$this->tinyInteger(1)->defaultValue(0)->comment('是否删除,1为已删除'), + 'created_at'=>$this->integer(11)->defaultValue(null)->comment('创建时间'), + 'updated_at'=>$this->integer(11)->defaultValue(null)->comment('更新时间'), + ],$tableOptions); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $this->dropTable('antgoods_brand'); + return true; + } +} diff --git a/antgoods123/migrations/m191119_024205_create_table_goods.php b/antgoods123/migrations/m191119_024205_create_table_goods.php new file mode 100644 index 0000000..d16c1e5 --- /dev/null +++ b/antgoods123/migrations/m191119_024205_create_table_goods.php @@ -0,0 +1,27 @@ +execute($sql); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $this->dropTable("antgoods_goods"); + return true; + } +} diff --git a/antgoods123/migrations/m191119_024345_create_table_goods_sku.php b/antgoods123/migrations/m191119_024345_create_table_goods_sku.php new file mode 100644 index 0000000..227b38b --- /dev/null +++ b/antgoods123/migrations/m191119_024345_create_table_goods_sku.php @@ -0,0 +1,27 @@ +execute($sql); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $this->dropTable("antgoods_goods_sku"); + return true; + } +} diff --git a/antgoods123/migrations/m191119_025607_create_table_supplier.php b/antgoods123/migrations/m191119_025607_create_table_supplier.php new file mode 100644 index 0000000..c7d8f6c --- /dev/null +++ b/antgoods123/migrations/m191119_025607_create_table_supplier.php @@ -0,0 +1,36 @@ +createTable('antgoods_supplier', [ + 'id' => $this->primaryKey(), + 'name'=>$this->string(50)->notNull()->comment('供应商名称'), + 'full_name'=>$this->string(50)->notNull()->comment('供应商全称'), + 'phone'=>$this->string(20)->notNull()->comment('手机号码'), + 'address'=>$this->string(50)->notNull()->comment('地址'), + 'is_delete'=>$this->tinyInteger(1)->defaultValue(0)->comment('是否删除,1为已删除'), + 'created_at'=>$this->integer(11)->defaultValue(null)->comment('创建时间'), + 'updated_at'=>$this->integer(11)->defaultValue(null)->comment('更新时间'), + ],$tableOptions); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $this->dropTable('antgoods_supplier'); + return true; + } +} diff --git a/antgoods123/migrations/m191119_025843_create_table_filter_attr.php b/antgoods123/migrations/m191119_025843_create_table_filter_attr.php new file mode 100644 index 0000000..0409292 --- /dev/null +++ b/antgoods123/migrations/m191119_025843_create_table_filter_attr.php @@ -0,0 +1,35 @@ +createTable('antgoods_filter_attr', [ + 'id' => $this->primaryKey(), + 'goods_id'=>$this->integer(11)->notNull()->comment('商品id'), + 'attr_id'=>$this->integer(11)->notNull()->comment('属性id'), + 'attr_value'=>$this->string(50)->notNull()->comment('属性值'), + 'is_delete'=>$this->tinyInteger(1)->defaultValue(0)->comment('是否删除,1为已删除'), + 'created_at'=>$this->integer(11)->defaultValue(null)->comment('创建时间'), + 'updated_at'=>$this->integer(11)->defaultValue(null)->comment('更新时间'), + ],$tableOptions); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $this->dropTable('antgoods_filter_attr'); + return true; + } +} diff --git a/antgoods123/migrations/m191125_012449_update_column_icon_type_in_antgoods_category.php b/antgoods123/migrations/m191125_012449_update_column_icon_type_in_antgoods_category.php new file mode 100644 index 0000000..00fb52e --- /dev/null +++ b/antgoods123/migrations/m191125_012449_update_column_icon_type_in_antgoods_category.php @@ -0,0 +1,22 @@ +dropColumn('antgoods_category', 'icon_type'); + $this->addColumn('antgoods_category', 'icon_type', $this->tinyInteger(1)->defaultValue(1)->comment('图标类型')); + } + + public function down() + { + $this->dropColumn('antgoods_category', 'icon_type'); + $this->addColumn('antgoods_category', 'icon_type', $this->tinyInteger(1)->defaultValue(null)->comment('图标类型')); + return true; + } +} diff --git a/antgoods123/migrations/m191125_083820_drop_column_icon_type_in_table_antgoods_category.php b/antgoods123/migrations/m191125_083820_drop_column_icon_type_in_table_antgoods_category.php new file mode 100644 index 0000000..04c6a2b --- /dev/null +++ b/antgoods123/migrations/m191125_083820_drop_column_icon_type_in_table_antgoods_category.php @@ -0,0 +1,20 @@ +dropColumn('antgoods_category', 'icon_type'); + } + + public function down() + { + $this->addColumn('antgoods_category', 'icon_type', $this->tinyInteger(1)->defaultValue(null)->comment('图标类型')); + return true; + } +} diff --git a/antgoods123/migrations/m191125_084547_update_column_pid_and_icon_in_table_antgoods_category.php b/antgoods123/migrations/m191125_084547_update_column_pid_and_icon_in_table_antgoods_category.php new file mode 100644 index 0000000..055e84c --- /dev/null +++ b/antgoods123/migrations/m191125_084547_update_column_pid_and_icon_in_table_antgoods_category.php @@ -0,0 +1,26 @@ +dropColumn('antgoods_category', 'icon'); + $this->addColumn('antgoods_category', 'icon', $this->integer(11)->defaultValue(null)->comment('图标')); + $this->dropColumn('antgoods_category', 'pid'); + $this->addColumn('antgoods_category', 'pid', $this->integer(11)->defaultValue(0)->comment('父级id')); + } + + public function down() + { + $this->dropColumn('antgoods_category', 'icon'); + $this->addColumn('antgoods_category', 'icon', $this->string(64)->defaultValue(null)->comment('图标')); + $this->dropColumn('antgoods_category', 'pid'); + $this->addColumn('antgoods_category', 'pid', $this->integer(11)->defaultValue(null)->comment('父级id')); + return true; + } +} diff --git a/antgoods123/migrations/m191125_104137_drop_column_icon_type_in_table_antgoods_shop_category.php b/antgoods123/migrations/m191125_104137_drop_column_icon_type_in_table_antgoods_shop_category.php new file mode 100644 index 0000000..2f182eb --- /dev/null +++ b/antgoods123/migrations/m191125_104137_drop_column_icon_type_in_table_antgoods_shop_category.php @@ -0,0 +1,20 @@ +dropColumn('antgoods_shop_category', 'icon_type'); + } + + public function down() + { + $this->addColumn('antgoods_shop_category', 'icon_type', $this->tinyInteger(1)->defaultValue(null)->comment('图标类型')); + return true; + } +} diff --git a/antgoods123/migrations/m191125_104510_update_column_pid_and_icon_in_table_antgoods_shop_category.php b/antgoods123/migrations/m191125_104510_update_column_pid_and_icon_in_table_antgoods_shop_category.php new file mode 100644 index 0000000..b1536ac --- /dev/null +++ b/antgoods123/migrations/m191125_104510_update_column_pid_and_icon_in_table_antgoods_shop_category.php @@ -0,0 +1,26 @@ +dropColumn('antgoods_shop_category', 'icon'); + $this->addColumn('antgoods_shop_category', 'icon', $this->integer(11)->defaultValue(null)->comment('图标')); + $this->dropColumn('antgoods_shop_category', 'pid'); + $this->addColumn('antgoods_shop_category', 'pid', $this->integer(11)->defaultValue(0)->comment('父级id')); + } + + public function down() + { + $this->dropColumn('antgoods_shop_category', 'icon'); + $this->addColumn('antgoods_shop_category', 'icon', $this->string(64)->defaultValue(null)->comment('图标')); + $this->dropColumn('antgoods_shop_category', 'pid'); + $this->addColumn('antgoods_shop_category', 'pid', $this->integer(11)->defaultValue(null)->comment('父级id')); + return true; + } +} diff --git a/antgoods123/migrations/m191127_114228_add_column_is_manaul_in_table_antgoods_goods_sku.php b/antgoods123/migrations/m191127_114228_add_column_is_manaul_in_table_antgoods_goods_sku.php new file mode 100644 index 0000000..a6584d6 --- /dev/null +++ b/antgoods123/migrations/m191127_114228_add_column_is_manaul_in_table_antgoods_goods_sku.php @@ -0,0 +1,20 @@ +addColumn('antgoods_goods_sku', 'is_manaul', $this->tinyInteger(1)->notNull()->defaultValue(0)->comment('是否手动')); + } + + public function down() + { + $this->dropColumn('antgoods_goods_sku', 'is_manaul'); + return true; + } +} diff --git a/antgoods123/migrations/m191129_010349_add_column_sku_mode_in_antgoods_goods.php b/antgoods123/migrations/m191129_010349_add_column_sku_mode_in_antgoods_goods.php new file mode 100644 index 0000000..3d4b3ed --- /dev/null +++ b/antgoods123/migrations/m191129_010349_add_column_sku_mode_in_antgoods_goods.php @@ -0,0 +1,20 @@ +addColumn('antgoods_goods', 'sku_mode', $this->tinyInteger(1)->notNull()->defaultValue(1)->comment('sku类型')); + } + + public function down() + { + $this->dropColumn('antgoods_goods', 'sku_mode'); + return true; + } +} diff --git a/antgoods123/migrations/m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr.php b/antgoods123/migrations/m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr.php new file mode 100644 index 0000000..3ee066e --- /dev/null +++ b/antgoods123/migrations/m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr.php @@ -0,0 +1,26 @@ +dropColumn('antgoods_goods_attr', 'goods_id'); + $this->dropColumn('antgoods_goods_attr', 'attr_id'); + $this->addColumn('antgoods_goods_attr', 'goods_id', $this->integer(11)->notNull()->defaultValue(0)->comment('商品id')); + $this->addColumn('antgoods_goods_attr', 'attr_id', $this->integer(11)->notNull()->defaultValue(0)->comment('属性id')); + } + + public function down() + { + $this->dropColumn('antgoods_goods_attr', 'goods_id'); + $this->dropColumn('antgoods_goods_attr', 'attr_id'); + $this->addColumn('antgoods_goods_attr', 'goods_id', $this->integer(11)->notNull()->comment('商品id')); + $this->addColumn('antgoods_goods_attr', 'attr_id', $this->integer(11)->notNull()->comment('属性id')); + return true; + } +} diff --git a/antgoods123/migrations/m191130_004933_add_column_cat_id_in_table_antgoods_attribute.php b/antgoods123/migrations/m191130_004933_add_column_cat_id_in_table_antgoods_attribute.php new file mode 100644 index 0000000..f7992f5 --- /dev/null +++ b/antgoods123/migrations/m191130_004933_add_column_cat_id_in_table_antgoods_attribute.php @@ -0,0 +1,20 @@ +addColumn('antgoods_attribute', 'cat_id', $this->integer(11)->notNull()->defaultValue(0)->comment('后台商品分类id')); + } + + public function down() + { + $this->dropColumn('antgoods_attribute', 'cat_id'); + return true; + } +} diff --git a/antgoods123/migrations/m191202_082041_drop_columns_in_table_antgoods_goods_sku.php b/antgoods123/migrations/m191202_082041_drop_columns_in_table_antgoods_goods_sku.php new file mode 100644 index 0000000..52d5ca7 --- /dev/null +++ b/antgoods123/migrations/m191202_082041_drop_columns_in_table_antgoods_goods_sku.php @@ -0,0 +1,27 @@ +dropColumn('antgoods_goods_sku', 'weight'); + $this->dropColumn('antgoods_goods_sku', 'length'); + $this->dropColumn('antgoods_goods_sku', 'width'); + $this->dropColumn('antgoods_goods_sku', 'height'); + $this->dropColumn('antgoods_goods_sku', 'diameter'); + } + + public function down() + { + $this->addColumn('antgoods_goods_sku', 'weight', $this->integer(8)->defaultValue(null)->comment('重量')); + $this->addColumn('antgoods_goods_sku', 'length', $this->integer(8)->defaultValue(null)->comment('长度')); + $this->addColumn('antgoods_goods_sku', 'width', $this->integer(8)->defaultValue(null)->comment('宽度')); + $this->addColumn('antgoods_goods_sku', 'height', $this->integer(8)->defaultValue(null)->comment('高度')); + $this->addColumn('antgoods_goods_sku', 'diameter', $this->integer(8)->defaultValue(null)->comment('直径')); + } +} diff --git a/antgoods123/migrations/sql/goods.sql b/antgoods123/migrations/sql/goods.sql new file mode 100755 index 0000000..3944770 --- /dev/null +++ b/antgoods123/migrations/sql/goods.sql @@ -0,0 +1,37 @@ +DROP TABLE IF EXISTS `antgoods_goods`; +CREATE TABLE `antgoods_goods` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `pid` int(11) DEFAULT NULL COMMENT '父级id', + `cat_id` int(11) NOT NULL COMMENT '后台商品类别id', + `brand_id` int(11) NOT NULL COMMENT '品牌id', + `shop_cat_id` int(11) NOT NULL COMMENT '前端商品类别id', + `name` varchar(120) NOT NULL COMMENT '商品名称', + `sn` varchar(60) DEFAULT NULL COMMENT '商品唯一货号', + `code` varchar(50) DEFAULT NULL COMMENT '商品货码', + `supplier_id` int(11) DEFAULT NULL COMMENT '供应商id', + `weight` mediumint(8) DEFAULT NULL unique COMMENT '重量', + `length` mediumint(8) DEFAULT NULL unique COMMENT '长度', + `width` mediumint(8) DEFAULT NULL unique COMMENT '宽度', + `height` mediumint(8) DEFAULT NULL unique COMMENT '高度', + `diameter` mediumint(8) DEFAULT NULL unique COMMENT '直径', + `unit` varchar(16) DEFAULT NULL COMMENT '单位', + `sold_count` int(10) DEFAULT NULL unique COMMENT '已售数量', + `limit_count` int(10) DEFAULT NULL COMMENT '限购数量', + `stock` int(10) DEFAULT NULL COMMENT '库存', + `stock_warn` int(10) DEFAULT NULL COMMENT '库存警告', + `market_price` int(20) DEFAULT NULL unique COMMENT '市场价', + `price` int(20) DEFAULT NULL unique COMMENT '销售价', + `brief` varchar(255) DEFAULT NULL COMMENT '简介', + `description` text COMMENT '详细介绍', + `image` int(11) DEFAULT NULL COMMENT '图片id', + `model_id` int(11) DEFAULT NULL COMMENT '模型id', + `is_sale` tinyint(1) DEFAULT '0' COMMENT '该商品是否开放销售,1为是,0为否', + `sort_order` smallint(3) DEFAULT NULL COMMENT '排序', + `bouns_points` mediumint(8) DEFAULT NULL COMMENT '奖励积分', + `experience_points` mediumint(8) DEFAULT NULL COMMENT '经验值', + `is_delete` tinyint(1) DEFAULT '0' COMMENT '是否删除,1为已删除', + `express_template` int(11) DEFAULT NULL COMMENT '配送详情id', + `created_at` int(10) DEFAULT '0' COMMENT '创建时间', + `updated_at` int(10) DEFAULT '0' COMMENT '更新时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='商品表'; \ No newline at end of file diff --git a/antgoods123/migrations/sql/goods_sku.sql b/antgoods123/migrations/sql/goods_sku.sql new file mode 100755 index 0000000..a599a39 --- /dev/null +++ b/antgoods123/migrations/sql/goods_sku.sql @@ -0,0 +1,24 @@ +DROP TABLE IF EXISTS `antgoods_goods_sku`; +CREATE TABLE `antgoods_goods_sku` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `goods_id` int(11) NOT NULL COMMENT '商品id', + `goods_code` varchar(50) DEFAULT NULL COMMENT '商品条码', + `goods_sn` varchar(60) NOT NULL COMMENT '商品唯一货号', + `goods_attr` varchar(60) DEFAULT NULL COMMENT '属性匹配', + `weight` mediumint(8) DEFAULT NULL COMMENT '重量', + `length` mediumint(8) DEFAULT NULL COMMENT '长度', + `width` mediumint(8) DEFAULT NULL COMMENT '宽度', + `height` mediumint(8) DEFAULT NULL COMMENT '高度', + `diameter` mediumint(8) DEFAULT NULL COMMENT '直径', + `sold_count` int(10) DEFAULT NULL COMMENT '已售数量', + `stock` int(10) DEFAULT NULL COMMENT '库存', + `market_price` int(20) DEFAULT NULL COMMENT '市场价', + `price` int(20) DEFAULT NULL COMMENT '销售价', + `model_id` int(11) DEFAULT NULL COMMENT '模型id', + `is_sale` tinyint(1) DEFAULT '0' COMMENT '该商品是否开放销售,1为是,0为否', + `sort_order` smallint(3) DEFAULT '0' COMMENT '排序', + `is_delete` tinyint(1) DEFAULT '0' COMMENT '是否删除,1为已删除', + `created_at` int(10) DEFAULT '0' COMMENT '创建时间', + `updated_at` int(10) DEFAULT '0' COMMENT '更新时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='商品sku表'; \ No newline at end of file diff --git a/antgoods/models/.gitkeep b/antgoods123/models/.gitkeep similarity index 100% rename from antgoods/models/.gitkeep rename to antgoods123/models/.gitkeep diff --git a/antgoods123/models/ars/Attribute.php b/antgoods123/models/ars/Attribute.php new file mode 100644 index 0000000..0b077d7 --- /dev/null +++ b/antgoods123/models/ars/Attribute.php @@ -0,0 +1,111 @@ + 50], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'id', + 'name' => '规格名称', + 'value' => '规格内容(每项以逗号隔开)', + 'type' => '类型', + 'sort_order' => '排序', + 'is_delete' => '是否删除,1为已删除', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + 'cat_id' => '后台商品分类', + ]; + } + + + /** + * @author linyao + * @email 602604991@qq.com + * @created Nov 8, 2019 + * + * 行为存储创建时间和更新时间 + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => function() { + return time(); + }, + ], + ]; + } + + /** + * @return array + * 数据键值对 + */ + public static function modelColumn() + { + return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); + } + + public function beforeSave($insert) + { + if(!$this->type){ + $this->type = self::TYPE_ATTR; + } + return parent::beforeSave($insert); // TODO: Change the autogenerated stub + } + + public function getCategory() + { + return $this->hasOne(Category::className(), ['id' => 'cat_id']); + } +} diff --git a/antgoods123/models/ars/Brand.php b/antgoods123/models/ars/Brand.php new file mode 100644 index 0000000..09ef7c3 --- /dev/null +++ b/antgoods123/models/ars/Brand.php @@ -0,0 +1,82 @@ + 50], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'id', + 'name' => '品牌名', + 'is_delete' => '是否删除,1为已删除', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + ]; + } + + + /** + * @author linyao + * @email 602604991@qq.com + * @created Nov 8, 2019 + * + * 行为存储创建时间和更新时间 + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => function() { + return time(); + }, + ], + ]; + } + + public static function modelColumn() + { + return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); + } +} diff --git a/antgoods123/models/ars/Category.php b/antgoods123/models/ars/Category.php new file mode 100644 index 0000000..181da3e --- /dev/null +++ b/antgoods123/models/ars/Category.php @@ -0,0 +1,114 @@ + '显示', + self::IS_SHOW_HIDE => '隐藏' + ]; + + /** + * {@inheritdoc} + */ + public static function tableName() + { + return 'antgoods_category'; + } + + /** + * {@inheritdoc} + */ + public function rules() + { + return [ + [['name'], 'required'], + [['pid', 'goods_count', 'sort_order', 'is_show', 'is_delete', 'icon'], 'integer'], + [['name'], 'string', 'max' => 60], + [['iconImageId'], 'string'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'id', + 'name' => '类别名称', + 'pid' => '父级', + 'goods_count' => '商品数量', + 'sort_order' => '排序', + 'icon' => '图标', + 'is_show' => '是否显示', + 'is_delete' => '是否删除,1为已删除', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + ]; + } + + + /** + * @author linyao + * @email 602604991@qq.com + * @created Nov 8, 2019 + * + * 行为存储创建时间和更新时间 + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => function() { + return time(); + }, + ], + ]; + } + + /** + * @return array + * 数据键值对 + */ + public static function modelColumn() + { + return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); + } + + public function getIconFile() + { + return $this->hasOne(File::className(), ['id' => 'icon']); + } +} diff --git a/antgoods123/models/ars/FilterAttr.php b/antgoods123/models/ars/FilterAttr.php new file mode 100644 index 0000000..c6b8aa2 --- /dev/null +++ b/antgoods123/models/ars/FilterAttr.php @@ -0,0 +1,81 @@ + 50], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'id', + 'goods_id' => '商品id', + 'attr_id' => '属性id', + 'attr_value' => '属性值', + 'is_delete' => '是否删除,1为已删除', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + ]; + } + + + /** + * @author linyao + * @email 602604991@qq.com + * @created Nov 8, 2019 + * + * 行为存储创建时间和更新时间 + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => function() { + return time(); + }, + ], + ]; + } +} diff --git a/antgoods123/models/ars/Goods.php b/antgoods123/models/ars/Goods.php new file mode 100644 index 0000000..ebc748e --- /dev/null +++ b/antgoods123/models/ars/Goods.php @@ -0,0 +1,232 @@ + '不在售', + self::IS_SALE_YES => '在售' + ]; + public $ruleVerify = 0;//规则验证是否通过 + /** + * {@inheritdoc} + */ + public static function tableName() + { + return 'antgoods_goods'; + } + + /** + * {@inheritdoc} + */ + public function rules() + { + return [ + [['pid', 'cat_id', 'brand_id', 'shop_cat_id', 'supplier_id', 'weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'limit_count', 'stock', 'stock_warn', 'market_price', 'price', 'image', 'model_id', 'is_sale', 'sort_order', 'bouns_points', 'experience_points', 'is_delete', 'express_template', 'sku_mode'], 'integer'], + [['cat_id', 'brand_id', 'shop_cat_id', 'name'], 'required'], + [['sn'], 'checkExist'], + [['description', 'coverImageId', 'detailImageId'], 'string'], + [['name'], 'string', 'max' => 120], + [['sn'], 'string', 'max' => 60], + [['code'], 'string', 'max' => 50], + [['unit'], 'string', 'max' => 16], + [['brief'], 'string', 'max' => 255], + [['weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'market_price', 'price'], 'checkNegative'], + ]; + } + + /** + * @param $attribute + * @param $params + * 验证是否为负数 + */ + public function checkNegative($attribute, $params) + { + if ($this->$attribute < 0) { + $this->addError($attribute, "不得为负数"); + } + } + + /** + * @param $attribute + * @param $params + * 验证商品编号唯一 + */ + public function checkExist($attribute, $params) + { + $goods = self::find()->where([$attribute => $this->$attribute, 'is_delete' => 0])->one(); + if ($this->isNewRecord) { + if ($goods) { + $this->addError($attribute, "该商品编号已经存在"); + } + } else { + if ($goods && $goods->id != $this->id) { + $this->addError($attribute, "该商品编号已经存在"); + } + } + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'id', + 'pid' => '父级id', + 'cat_id' => '后台商品类别', + 'brand_id' => '品牌', + 'shop_cat_id' => '前端商品类别', + 'name' => '商品名称', + 'sn' => '商品唯一货号', + 'code' => '商品货码', + 'supplier_id' => '供应商', + 'weight' => '重量', + 'length' => '长度', + 'width' => '宽度', + 'height' => '高度', + 'diameter' => '直径', + 'unit' => '单位', + 'sold_count' => '已售数量', + 'limit_count' => '限购数量', + 'stock' => '库存', + 'stock_warn' => '库存警告', + 'market_price' => '市场价', + 'price' => '销售价', + 'brief' => '简介', + 'description' => '详细介绍', + 'image' => '首页图片', + 'model_id' => '模型id', + 'is_sale' => '销售状态', + 'sort_order' => '排序', + 'bouns_points' => '奖励积分', + 'experience_points' => '经验值', + 'is_delete' => '是否删除,1为已删除', + 'express_template' => '配送详情id', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + ]; + } + + + /** + * @author linyao + * @email 602604991@qq.com + * @created Nov 8, 2019 + * + * 行为存储创建时间和更新时间 + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => function() { + return time(); + }, + ], + ]; + } + + /** + * @param bool $insert + * @return bool + * 自动填入参数 + */ + public function beforeSave($insert) + { + if (!$this->sn) { + $this->sn = time() . rand(1111, 9999); + } + return parent::beforeSave($insert); // TODO: Change the autogenerated stub + } + + public function getCategory() + { + return $this->hasOne(Category::className(), ['id' => 'cat_id']); + } + + public function getShopCategory() + { + return $this->hasOne(ShopCategory::className(), ['id' => 'shop_cat_id']); + } + + public function getImageFile() + { + return $this->hasOne(File::className(), ['id' => 'image']); + } + + public function getBrand() + { + return $this->hasOne(Brand::className(), ['id' => 'brand_id']); + } + + public function getSupplier() + { + return $this->hasOne(Supplier::className(), ['id' => 'supplier_id']); + } +} diff --git a/antgoods123/models/ars/GoodsAttr.php b/antgoods123/models/ars/GoodsAttr.php new file mode 100644 index 0000000..4cb2495 --- /dev/null +++ b/antgoods123/models/ars/GoodsAttr.php @@ -0,0 +1,81 @@ + 50], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'id', + 'goods_id' => '商品id', + 'attr_id' => '属性id', + 'attr_value' => '属性名', + 'is_delete' => '是否删除,1为已删除', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + ]; + } + + + /** + * @author linyao + * @email 602604991@qq.com + * @created Nov 8, 2019 + * + * 行为存储创建时间和更新时间 + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => function() { + return time(); + }, + ], + ]; + } +} diff --git a/antgoods123/models/ars/GoodsSku.php b/antgoods123/models/ars/GoodsSku.php new file mode 100644 index 0000000..45e729a --- /dev/null +++ b/antgoods123/models/ars/GoodsSku.php @@ -0,0 +1,102 @@ + 50], + [['goods_sn', 'goods_attr'], 'string', 'max' => 60], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'id', + 'goods_id' => '商品id', + 'goods_code' => '商品条码', + 'goods_sn' => '商品唯一货号', + 'goods_attr' => '属性匹配', + 'sold_count' => '已售数量', + 'stock' => '库存', + 'market_price' => '市场价', + 'price' => '销售价', + 'model_id' => '模型id', + 'is_sale' => '该商品是否开放销售,1为是,0为否', + 'sort_order' => '排序', + 'is_delete' => '是否删除,1为已删除', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + ]; + } + + + /** + * @author linyao + * @email 602604991@qq.com + * @created Nov 8, 2019 + * + * 行为存储创建时间和更新时间 + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => function() { + return time(); + }, + ], + ]; + } +} diff --git a/antgoods123/models/ars/ShopCategory.php b/antgoods123/models/ars/ShopCategory.php new file mode 100644 index 0000000..1212ec2 --- /dev/null +++ b/antgoods123/models/ars/ShopCategory.php @@ -0,0 +1,122 @@ + '显示', + self::IS_SHOW_HIDE => '隐藏' + ]; + + /** + * {@inheritdoc} + */ + public static function tableName() + { + return 'antgoods_shop_category'; + } + + /** + * {@inheritdoc} + */ + public function rules() + { + return [ + [['name'], 'required'], + [['pid', 'goods_count', 'sort_order', 'icon', 'is_show', 'is_delete', 'iconImageId'], 'integer'], + [['filter_attr'], 'safe'], + [['name'], 'string', 'max' => 60], + [['keywords'], 'string', 'max' => 100], + [['desc'], 'string', 'max' => 255], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'id', + 'name' => '类别名称', + 'pid' => '父级', + 'goods_count' => '商品数量', + 'keywords' => '关键字', + 'desc' => '描述', + 'sort_order' => '排序', + 'icon' => '图标', + 'filter_attr' => '筛选属性', + 'is_show' => '是否显示', + 'is_delete' => '是否删除', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + ]; + } + + + /** + * @author linyao + * @email 602604991@qq.com + * @created Nov 8, 2019 + * + * 行为存储创建时间和更新时间 + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => function() { + return time(); + }, + ], + ]; + } + + /** + * @return array + * 数据键值对 + */ + public static function modelColumn() + { + return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); + } + + public function getIconFile() + { + return $this->hasOne(File::className(), ['id' => 'icon']); + } +} diff --git a/antgoods123/models/ars/Supplier.php b/antgoods123/models/ars/Supplier.php new file mode 100644 index 0000000..31bc64d --- /dev/null +++ b/antgoods123/models/ars/Supplier.php @@ -0,0 +1,96 @@ + 50], + [['phone'], 'string', 'max' => 20], + ['phone', 'filter', 'filter' => 'trim'], + ['phone','match','pattern'=>'/^[1][34578][0-9]{9}$/'], + ['phone', 'unique', 'targetClass' => '\antgoods\models\ars\Supplier', 'message' => '手机号已被使用'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'id', + 'name' => '供应商名称', + 'full_name' => '供应商全称', + 'phone' => '手机号码', + 'address' => '地址', + 'is_delete' => '是否删除,1为已删除', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + ]; + } + + + /** + * @author linyao + * @email 602604991@qq.com + * @created Nov 8, 2019 + * + * 行为存储创建时间和更新时间 + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => function() { + return time(); + }, + ], + ]; + } + + /** + * @return array + * 数据键值对 + */ + public static function modelColumn() + { + return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); + } +} diff --git a/antgoods123/models/searchs/AttributeSearch.php b/antgoods123/models/searchs/AttributeSearch.php new file mode 100644 index 0000000..dc97a43 --- /dev/null +++ b/antgoods123/models/searchs/AttributeSearch.php @@ -0,0 +1,162 @@ + 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + 'id', + 'name', + 'value', + 'sort_order', + ['attribute' => 'cat_id', + 'value' => function ($model){ + return $model->cat_id ? $model->category->name : '无限制'; + }, + ], + [ + 'class' => 'iron\grid\ActionColumn', + 'align' => 'center', + 'config' => [ + [ + 'name' => 'update', + 'icon' => 'pencil', + 'title' => '修改' + ], + [ + 'name' => 'delete', + 'icon' => 'trash', + 'title' => '删除', + 'contents' => '确定删除?' + ] + ], + ], + ]; + } + /** + * @param $params + * @return ActiveDataProvider + * 不分页的所有数据 + */ + public function allData($params) + { + $query = Attribute::find(); + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => false, + 'sort' => false + ]); + $this->load($params); + return $this->filter($query, $dataProvider); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Attribute::find()->where(['is_delete' => Attribute::IS_DELETE_NO]); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => [ + 'pageSizeLimit' => [1, 200] + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + ]); + + $this->load($params); + return $this->filter($query, $dataProvider); + } + /** + * @param $query + * @param $dataProvider + * @return ActiveDataProvider + * 条件筛选 + */ + private function filter($query, $dataProvider){ + $query->andFilterWhere(['is_delete' => Attribute::IS_DELETE_NO]); + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'type' => $this->type, + 'sort_order' => $this->sort_order, + 'is_delete' => $this->is_delete, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'value', $this->value]); + if ($this->created_at_range) { + $arr = explode(' ~ ', $this->created_at_range); + $start = strtotime($arr[0]); + $end = strtotime($arr[1]) + 3600 * 24; + $query->andFilterWhere(['between', 'created_at', $start, $end]); + } + return $dataProvider; + } +} diff --git a/antgoods123/models/searchs/BrandSearch.php b/antgoods123/models/searchs/BrandSearch.php new file mode 100644 index 0000000..a91ad40 --- /dev/null +++ b/antgoods123/models/searchs/BrandSearch.php @@ -0,0 +1,152 @@ + 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + 'id', + 'name', + [ + 'class' => 'iron\grid\ActionColumn', + 'align' => 'center', + 'config' => [ + [ + 'name' => 'update', + 'icon' => 'pencil', + 'title' => '修改' + ], + [ + 'name' => 'delete', + 'icon' => 'trash', + 'title' => '删除', + 'contents' => '确定删除?' + ] + ], + ], + ]; + } + /** + * @param $params + * @return ActiveDataProvider + * 不分页的所有数据 + */ + public function allData($params) + { + $query = Brand::find(); + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => false, + 'sort' => false + ]); + $this->load($params); + return $this->filter($query, $dataProvider); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Brand::find()->where(['is_delete' => Brand::IS_DELETE_NO]); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => [ + 'pageSizeLimit' => [1, 200] + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + ]); + + $this->load($params); + return $this->filter($query, $dataProvider); + } + /** + * @param $query + * @param $dataProvider + * @return ActiveDataProvider + * 条件筛选 + */ + private function filter($query, $dataProvider){ + $query->andFilterWhere(['is_delete' => Brand::IS_DELETE_NO]); + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'is_delete' => $this->is_delete, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + if ($this->created_at_range) { + $arr = explode(' ~ ', $this->created_at_range); + $start = strtotime($arr[0]); + $end = strtotime($arr[1]) + 3600 * 24; + $query->andFilterWhere(['between', 'created_at', $start, $end]); + } + return $dataProvider; + } +} diff --git a/antgoods123/models/searchs/CategorySearch.php b/antgoods123/models/searchs/CategorySearch.php new file mode 100644 index 0000000..1a0f1a1 --- /dev/null +++ b/antgoods123/models/searchs/CategorySearch.php @@ -0,0 +1,172 @@ + 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + 'id', + 'name', + ['attribute' => 'icon', + 'contentOptions' => [ + 'align' => 'center', + ], + 'width'=>'10%', + 'format' => 'raw', + 'value' => function ($model) { + return $model->iconFile ? + Html::img(['/'.$model->iconFile->path], ['style' => 'width:80px']) + : '
+ = Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'name', + 'value:ntext', + 'type', + 'sort_order', + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> + ++ = Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'name', + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> + ++ = Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'name', + 'pid', + 'goods_count', + 'sort_order', + 'icon_type', + 'icon', + [ + 'attribute' => 'is_show', + 'value' => function ($model) { + return $model->is_show == \antgoods\models\ars\Category::IS_SHOW_DISPLAY ? '显示':'隐藏'; + } + ], + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> + ++ = Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'name', + 'sn', + [ + 'attribute' => 'cat_id', + 'width' => '10%', + 'value' => function ($model) { + return $model->category ? $model->category->name : ''; + }, + ], + [ + 'attribute' => 'shop_cat_id', + 'width' => '10%', + 'value' => function ($model) { + return $model->shopCategory ? $model->shopCategory->name : ''; + }, + ], + [ + 'attribute' => 'brand_id', + 'width' => '10%', + 'value' => function ($model) { + return $model->brand ? $model->brand->name : ''; + }, + ], + 'code', + [ + 'attribute' => 'supplier_id', + 'width' => '10%', + 'value' => function ($model) { + return $model->supplier ? $model->supplier->name : ''; + }, + ], + 'weight', + 'length', + 'width', + 'height', + 'diameter', + 'unit', + [ + 'attribute' => 'stock', + 'width' => '5%', + 'value' => function ($model) { + if ($model->stock == -1) { + return '未开启'; + } else { + return $model->stock; + } + }, + ], + 'market_price', + 'price', + 'brief', + ['attribute' => 'image', + 'format' => 'raw', + 'value' => function ($model) { + return $model->image ? + Html::img(['/'.$model->imageFile->path], ['style' => 'width:80px']) + : '+ = Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'name', + 'keywords', + 'desc', + 'sort_order', + ['attribute' => 'icon', + 'width'=>'10%', + 'format' => 'raw', + 'value' => function ($model) { + return $model->iconFile ? + \yii\bootstrap4\Html::img(['/'.$model->iconFile->path], ['style' => 'width:80px']) + : '未设置'; + + } + ], + ['attribute' => 'filter_attr', + 'value' => $attr_str + ], + ['attribute' => 'is_show', + 'width' => '5%', + 'value' => + function ($model) { + return $model->is_show == ShopCategory::IS_SHOW_HIDE ? '隐藏' : '显示'; + }, + ], + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> + ++ = Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'name', + 'full_name', + 'phone', + 'address', + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> + +