From 342a0f22f8b847d10c7f91112c99c91c7f99ad9e Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Thu, 5 Dec 2019 15:52:28 +0800 Subject: [PATCH 01/41] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=8F=92=E4=BB=B6=E5=8A=A0=E8=BD=BD=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/goods/models/ars/GoodsSku.php | 4 ++-- backend/modules/goods/views/goods/picture.php | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/backend/modules/goods/models/ars/GoodsSku.php b/backend/modules/goods/models/ars/GoodsSku.php index 053394a..ab0b17d 100755 --- a/backend/modules/goods/models/ars/GoodsSku.php +++ b/backend/modules/goods/models/ars/GoodsSku.php @@ -6,7 +6,7 @@ use Yii; use yii\behaviors\TimestampBehavior; /** - * This is the model class for table "goods_goods_sku". + * This is the model class for table "atg_goods_sku". * * @property int $id * @property int $goods_id 商品id @@ -38,7 +38,7 @@ class GoodsSku extends \yii\db\ActiveRecord */ public static function tableName() { - return 'goods_goods_sku'; + return 'atg_goods_sku'; } /** diff --git a/backend/modules/goods/views/goods/picture.php b/backend/modules/goods/views/goods/picture.php index eb0cec4..022f640 100755 --- a/backend/modules/goods/views/goods/picture.php +++ b/backend/modules/goods/views/goods/picture.php @@ -15,9 +15,8 @@ use yii\helpers\Url; 'maxCount' => 1, 'fillInAttribute' => 'coverImageId', 'model' => $model, - 'ruleVerify' => $model->ruleVerify, 'previewConfig' => [ - 'url' => Url::to(['image-file', 'fileidstr' => $model->coverImageId]), + 'url' => Url::to(['image-file', 'fileidstr' => $model->coverImageId, 'ruleverify' => $model->ruleVerify]), ], ])->label('商品封面图') ?> @@ -30,8 +29,7 @@ use yii\helpers\Url; 'maxCount' => 5, 'fillInAttribute' => 'detailImageId', 'model' => $model, - 'ruleVerify' => $model->ruleVerify, 'previewConfig' => [ - 'url' => Url::to(['image-file', 'fileidstr' => $model->detailImageId]), + 'url' => Url::to(['image-file', 'fileidstr' => $model->detailImageId, 'ruleverify' => $model->ruleVerify]), ], ])->label('商品详情图') ?> From 9c55344af384cd686ce54616edfe1b95b36e051b Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Thu, 5 Dec 2019 19:21:09 +0800 Subject: [PATCH 02/41] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E9=80=BB=E8=BE=91=EF=BC=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=85=B6=E4=B8=AD=E6=97=A0=E7=94=A8=E7=9A=84=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=88=9B=E5=BB=BA=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E4=BB=B7=E6=A0=BC=E6=95=B0=E6=8D=AE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ra_price_in_table_ats_express_template.php | 32 +++++++++++++++++ ...5_092942_create_table_ats_express_area.php | 36 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 backend/modules/shop/migrations/m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template.php create mode 100644 backend/modules/shop/migrations/m191205_092942_create_table_ats_express_area.php diff --git a/backend/modules/shop/migrations/m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template.php b/backend/modules/shop/migrations/m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template.php new file mode 100644 index 0000000..a0859df --- /dev/null +++ b/backend/modules/shop/migrations/m191205_092426_drop_columns_province_city_area_basic_price_basic_count_extra_count_extra_price_in_table_ats_express_template.php @@ -0,0 +1,32 @@ +dropColumn('ats_express_template', 'province'); + $this->dropColumn('ats_express_template', 'city'); + $this->dropColumn('ats_express_template', 'area'); + $this->dropColumn('ats_express_template', 'extra_price'); + $this->dropColumn('ats_express_template', 'basic_price'); + $this->dropColumn('ats_express_template', 'basic_count'); + $this->dropColumn('ats_express_template', 'extra_count'); + } + + public function down() + { + $this->addColumn('ats_express_template', 'province', $this->text()->comment('省份')); + $this->addColumn('ats_express_template', 'city', $this->text()->comment('城市')); + $this->addColumn('ats_express_template', 'area', $this->text()->comment('区域')); + $this->addColumn('ats_express_template', 'extra_price', $this->integer(20)->defaultValue(null)->comment('续重运费')); + $this->addColumn('ats_express_template', 'basic_price', $this->integer(20)->defaultValue(null)->comment('基本运费')); + $this->addColumn('ats_express_template', 'basic_count', $this->integer(20)->defaultValue(null)->comment('基本数量')); + $this->addColumn('ats_express_template', 'extra_count', $this->integer(20)->defaultValue(null)->comment('续重数量')); + return true; + } +} diff --git a/backend/modules/shop/migrations/m191205_092942_create_table_ats_express_area.php b/backend/modules/shop/migrations/m191205_092942_create_table_ats_express_area.php new file mode 100644 index 0000000..bd50a85 --- /dev/null +++ b/backend/modules/shop/migrations/m191205_092942_create_table_ats_express_area.php @@ -0,0 +1,36 @@ +createTable('ats_express_area', [ + 'id' => $this->primaryKey(), + 'province' => $this->text()->comment('省份'), + 'city' => $this->text()->comment('城市'), + 'area' => $this->text()->comment('区域'), + 'express_template' => $this->integer(11)->defaultValue(null)->comment('运费模板id'), + 'extra_price' => $this->integer(20)->defaultValue(null)->comment('续重运费'), + 'basic_price' => $this->integer(20)->defaultValue(null)->comment('基本运费'), + 'basic_count' => $this->integer(20)->defaultValue(null)->comment('基本数量'), + 'extra_count' => $this->integer(20)->defaultValue(null)->comment('续重数量'), + 'updated_at'=>$this->integer(11)->defaultValue(null)->comment('更新时间'), + 'created_at'=>$this->integer(11)->defaultValue(null)->comment('创建时间'), + ],$tableOptions); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $this->dropTable('ats_express_area'); + return true; + } +} From ea705c35bb2a18fd6298e3237b6474903330d3c5 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Thu, 5 Dec 2019 19:23:39 +0800 Subject: [PATCH 03/41] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E6=A8=A1=E6=9D=BFmodel=E4=B8=AD=E7=9A=84=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/models/ars/ExpressTemplate.php | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/backend/modules/shop/models/ars/ExpressTemplate.php b/backend/modules/shop/models/ars/ExpressTemplate.php index ce4fd07..27bd453 100644 --- a/backend/modules/shop/models/ars/ExpressTemplate.php +++ b/backend/modules/shop/models/ars/ExpressTemplate.php @@ -10,15 +10,8 @@ use yii\behaviors\TimestampBehavior; * * @property int $id * @property string $name 名称 - * @property string $province 省份 - * @property string $city 城市 - * @property string $area 区域 - * @property int $extra_price 续重运费 * @property int $updated_at 更新时间 * @property int $created_at 创建时间 - * @property int $basic_price 基本运费 - * @property int $basic_count 基本数量 - * @property int $extra_count 续重数量 * @property int $calculation_type 计算方式 */ class ExpressTemplate extends \yii\db\ActiveRecord @@ -46,10 +39,8 @@ class ExpressTemplate extends \yii\db\ActiveRecord { return [ [['name'], 'required'], - [['province', 'city', 'area'], 'string'], [['calculation_type'], 'integer'], - [['name'], 'string', 'max' => 255], - [['extra_price', 'basic_price', 'basic_count', 'extra_count'], 'safe'] + [['name'], 'string', 'max' => 255] ]; } @@ -61,15 +52,8 @@ class ExpressTemplate extends \yii\db\ActiveRecord return [ 'id' => 'id', 'name' => '名称', - 'province' => '省份', - 'city' => '城市', - 'area' => '区域', - 'extra_price' => '续重运费', 'updated_at' => '更新时间', 'created_at' => '创建时间', - 'basic_price' => '基本运费', - 'basic_count' => '基本数量', - 'extra_count' => '续重数量', 'calculation_type' => '计算方式', ]; } From b0c2940cdfb844af055d1d629c92407e22a6c82a Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Thu, 5 Dec 2019 19:24:55 +0800 Subject: [PATCH 04/41] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E6=A8=A1=E6=9D=BFsearch=E4=B8=AD=E7=9A=84=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/models/searchs/ExpressTemplateSearch.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/backend/modules/shop/models/searchs/ExpressTemplateSearch.php b/backend/modules/shop/models/searchs/ExpressTemplateSearch.php index 8cee01c..73fe403 100755 --- a/backend/modules/shop/models/searchs/ExpressTemplateSearch.php +++ b/backend/modules/shop/models/searchs/ExpressTemplateSearch.php @@ -26,8 +26,8 @@ class ExpressTemplateSearch extends ExpressTemplate public function rules() { return [ - [['id', 'calculation_type', 'basic_price', 'basic_count', 'extra_price', 'extra_count', 'updated_at', 'created_at'], 'integer'], - [['name', 'province', 'city', 'area'], 'safe'], + [['id', 'calculation_type', 'updated_at', 'created_at'], 'integer'], + [['name'], 'safe'], ['created_at_range','safe'], ]; } @@ -122,18 +122,11 @@ class ExpressTemplateSearch extends ExpressTemplate $query->andFilterWhere([ 'id' => $this->id, 'calculation_type' => $this->calculation_type, - 'basic_price' => $this->basic_price, - 'basic_count' => $this->basic_count, - 'extra_price' => $this->extra_price, - 'extra_count' => $this->extra_count, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at, ]); - $query->andFilterWhere(['like', 'name', $this->name]) - ->andFilterWhere(['like', 'province', $this->province]) - ->andFilterWhere(['like', 'city', $this->city]) - ->andFilterWhere(['like', 'area', $this->area]); + $query->andFilterWhere(['like', 'name', $this->name]); if ($this->created_at_range) { $arr = explode(' ~ ', $this->created_at_range); $start = strtotime($arr[0]); From 02fae18bb5a63c64ab0a1bbdd6a5fc983b102d58 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Thu, 5 Dec 2019 19:25:52 +0800 Subject: [PATCH 05/41] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E4=BB=B7=E6=A0=BCmodel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/shop/models/ars/ExpressArea.php | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 backend/modules/shop/models/ars/ExpressArea.php diff --git a/backend/modules/shop/models/ars/ExpressArea.php b/backend/modules/shop/models/ars/ExpressArea.php new file mode 100644 index 0000000..16497c2 --- /dev/null +++ b/backend/modules/shop/models/ars/ExpressArea.php @@ -0,0 +1,85 @@ + 'id', + 'province' => '省份', + 'city' => '城市', + 'area' => '区域', + 'express_template' => '运费模板id', + 'extra_price' => '续重运费', + 'basic_price' => '基本运费', + 'basic_count' => '基本数量', + 'extra_count' => '续重数量', + 'updated_at' => '更新时间', + 'created_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(); + }, + ], + ]; + } +} From 5f40462c7455c1cfb8ad71e730388947c5c104a1 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 10:21:43 +0800 Subject: [PATCH 06/41] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=98=E5=8C=96gridv?= =?UTF-8?q?iew=E6=8F=92=E4=BB=B6=EF=BC=8C=E5=BC=80=E5=8F=91=E8=BF=90?= =?UTF-8?q?=E8=B4=B9=E5=8C=BA=E5=9F=9F=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 20 ++++++ .../models/searchs/ExpressTemplateSearch.php | 23 +++++++ .../express-template/express_area_list.php | 33 ++++++++++ vendor/iron/grid/GridView.php | 63 ++++++++++++++++--- 4 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 backend/modules/shop/views/express-template/express_area_list.php diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 460be98..4f6e9a0 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -4,6 +4,7 @@ namespace backend\modules\shop\controllers; use backend\modules\shop\models\ars\City; use backend\modules\shop\models\ars\Province; +use backend\modules\shop\models\searchs\ExpressAreaSearch; use Yii; use backend\modules\shop\models\ars\ExpressTemplate; use backend\modules\shop\models\searchs\ExpressTemplateSearch; @@ -13,6 +14,7 @@ use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\web\Response; use yii\widgets\ActiveForm; +use backend\modules\shop\models\ars\ExpressArea; /** * ExpressTemplateController implements the CRUD actions for ExpressTemplate model. @@ -213,4 +215,22 @@ class ExpressTemplateController extends Controller 'columns' => $searchModel->columns() ]); } + + /** + * @return string + * 运费区域列表 + */ + public function actionExpressAreaList($id) + { + $expressTemplate = ExpressTemplate::findOne($id); + $searchModel = new ExpressAreaSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $id); + + return $this->render('express_area_list', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns(), + 'expressTemplate' => $expressTemplate + ]); + } } diff --git a/backend/modules/shop/models/searchs/ExpressTemplateSearch.php b/backend/modules/shop/models/searchs/ExpressTemplateSearch.php index 73fe403..a1e4b16 100755 --- a/backend/modules/shop/models/searchs/ExpressTemplateSearch.php +++ b/backend/modules/shop/models/searchs/ExpressTemplateSearch.php @@ -57,6 +57,29 @@ class ExpressTemplateSearch extends ExpressTemplate [ 'class' => 'iron\grid\ActionColumn', 'align' => 'center', + 'config' => [ + [ + 'name' => 'view', + 'icon' => 'list', + 'title' => '详情', + ], + [ + 'name' => 'update', + 'icon' => 'pencil', + 'title' => '修改' + ], + [ + 'name' => 'express-area-list', + 'icon' => 'hard-drive', + 'title' => '配送区域' + ], + [ + 'name' => 'delete', + 'icon' => 'trash', + 'title' => '删除', + 'contents' => '确定删除?' + ] + ], ], ]; } diff --git a/backend/modules/shop/views/express-template/express_area_list.php b/backend/modules/shop/views/express-template/express_area_list.php new file mode 100644 index 0000000..465718b --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_list.php @@ -0,0 +1,33 @@ +title = '运费区域模板:'.$expressTemplate->name; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+ $dataProvider, + 'filter' => $this->render("_search", ['model' => $searchModel]), + 'batch' => [ + [ + "label" => "删除", + "url" => "express-area/deletes" + ], + ], + 'columns' => $columns, + 'batchTemplate' => '', + 'create' => '', + 'export' => '', + 'content' => Html::a('创建', ['index'], ['class' => 'btn btn-default']). + Html::a('返回', ['index'], ['class' => 'btn btn-default']) + ]); + ?> +
+
\ No newline at end of file diff --git a/vendor/iron/grid/GridView.php b/vendor/iron/grid/GridView.php index 5b42816..809a4ad 100644 --- a/vendor/iron/grid/GridView.php +++ b/vendor/iron/grid/GridView.php @@ -219,16 +219,11 @@ class GridView extends BaseListView
{batch} - 添加 + {create} -
- - -
+ {export} + {content}
{filter} @@ -263,6 +258,25 @@ HTML;
HTML; + public $export =<< + + +
+HTML; + public $create =<<添加 +HTML; + /** + * @var + * 表单头部内容 + */ + public $content; + + /** * 初始化 grid view. @@ -445,6 +459,12 @@ SCRIPT; return $this->renderFilter(); case '{batch}': return $this->renderBatch(); + case '{export}': + return $this->renderExport(); + case '{create}': + return $this->renderCreate(); + case '{content}': + return $this->renderContent(); default: return false; } @@ -694,4 +714,31 @@ SCRIPT; ]); } + /** + * 渲染导出部分 + * @return string + */ + protected function renderExport() + { + return $this->export; + } + + /** + * 渲染创建部分 + * @return string + */ + protected function renderCreate() + { + return $this->create; + } + + /** + * 渲染表单头部内容 + * @return string + */ + protected function renderContent() + { + return Html::tag('div', $this->content, ['class' => 'btn-group']); + } + } From fc72e148d11602f8ac4d4119e0f9d2bab32ba53d Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 14:43:05 +0800 Subject: [PATCH 07/41] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=88=97=E8=A1=A8=EF=BC=8C=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=88=9B=E5=BB=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 79 +++++++++- .../express-template/express_area_create.php | 50 ++++++ .../express-template/express_area_form.php | 145 ++++++++++++++++++ .../express-template/express_area_update.php | 51 ++++++ 4 files changed, 323 insertions(+), 2 deletions(-) create mode 100755 backend/modules/shop/views/express-template/express_area_create.php create mode 100755 backend/modules/shop/views/express-template/express_area_form.php create mode 100755 backend/modules/shop/views/express-template/express_area_update.php diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 4f6e9a0..7b23bb4 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -108,7 +108,7 @@ class ExpressTemplateController extends Controller $provinces = Province::find()->cache(0)->all(); foreach ($provinces as $k => $v) { $data[$k]['province'] = $v->name; - $cities = City::find()->cache(0) + $cities = City::find() ->where(['province_id' => $v->province_id]) ->all(); foreach ($cities as $city) { @@ -153,7 +153,7 @@ class ExpressTemplateController extends Controller $provinces = Province::find()->cache(0)->all(); foreach ($provinces as $k => $v) { $data[$k]['province'] = $v->name; - $cities = City::find()->cache(0) + $cities = City::find() ->where(['province_id' => $v->province_id]) ->all(); foreach ($cities as $city) { @@ -233,4 +233,79 @@ class ExpressTemplateController extends Controller 'expressTemplate' => $expressTemplate ]); } + + /** + * @return array|mixed|string|Response + * 运费区域模板区域创建方法 + */ + public function actionExpressAreaCreate() + { + $expressTemplateId = Yii::$app->request->get('expressTemplateId'); + $expressTemplateModel = ExpressTemplate::findOne($expressTemplateId); + $model = new ExpressArea(); + $model->basic_count = 1; + $model->basic_price = '0.00'; + $model->express_template = $expressTemplateModel->id; + + if (Yii::$app->request->isPost) { + $data = Yii::$app->request->post('ExpressArea'); + if (Yii::$app->request->isAjax) { + $model->load($data, ''); + Yii::$app->response->format = Response::FORMAT_JSON; + $data = ActiveForm::validate($model); + $data['status'] = 2; + return $data; + } + if (Yii::$app->request->post('area') == null) { + return $this->redirect(Yii::$app->request->referrer . '?status=1'); + } + $cityIds = array_keys(Yii::$app->request->post('area')); + $data['city'] = implode(',', $cityIds); + $model->load($data, ''); + $model->basic_price *= 100; + $model->extra_price *= 100; + if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { + $model->basic_count *= 10; + $model->extra_count *= 10; + } else { + $model->basic_count *= 1; + $model->extra_count *= 1; + } + $model->save(); + return $this->redirect('express-area-list?id='.$model->express_template); + } + $data = []; + $expressAreas = ExpressArea::find()->select(['city'])->where(['express_template' => $expressTemplateModel->id])->all(); + $expressAresCityIdArr = []; + if ($expressAreas) { + foreach ($expressAreas as $expressAreaCity) { + $cityIdArr = explode(',', $expressAreaCity->city); + $expressAresCityIdArr = array_unique(array_merge($cityIdArr, $expressAresCityIdArr)); + } + } + $provinces = Province::find()->cache(0)->all(); + $j = 0; + foreach ($provinces as $k => $v) { + $cities = City::find() + ->where(['province_id' => $v->province_id]) + ->andWhere(['not in', 'city_id', $expressAresCityIdArr]) + ->all(); + if ($cities) { + $data[$j]['province'] = $v->name; + foreach ($cities as $city) { + $data[$j]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; + } + $j++; + } + } + if (empty($data)) { + Yii::$app->session->setFlash('error', '已无地区选择'); + return $this->redirect('express-area-list?id='.$expressTemplateModel->id); + } + return $this->render('express_area_create', [ + 'model' => $model, + 'data' => $data, + 'expressTemplateModel' => $expressTemplateModel + ]); + } } diff --git a/backend/modules/shop/views/express-template/express_area_create.php b/backend/modules/shop/views/express-template/express_area_create.php new file mode 100755 index 0000000..fb35a2e --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_create.php @@ -0,0 +1,50 @@ +title = '创建运费模板'; +$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +Yii::$app->params['bsVersion'] = '4.x'; +?> +
+
+ + ['class' => 'container-fluid']]); + + echo TabsX::widget([ + 'bordered' => true, + 'items' => [ + [ + 'label' => ' 基本信息', + 'content' => $this->render('_form', [ + 'model' => $model, + 'form' => $form, + ]), + ], + [ + 'label' => ' 选择配送区域', + 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => [] + ]), + ], + ], + 'position' => TabsX::POS_ABOVE, + 'encodeLabels' => false + ]); + ?> + +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
+ + + +
+
diff --git a/backend/modules/shop/views/express-template/express_area_form.php b/backend/modules/shop/views/express-template/express_area_form.php new file mode 100755 index 0000000..940b46f --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_form.php @@ -0,0 +1,145 @@ + + +request->get('status'); +if ($status == 1) { + ?> + + + +field($model, 'name')->textInput(['maxlength' => true]) ?> + +field($model, 'calculation_type')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculationType, 'type' => "radio"]) ?> + +field($model, 'basic_count')->textInput() ?> + +field($model, 'basic_price')->textInput() ?> + +field($model, 'extra_count')->textInput() ?> + +field($model, 'extra_price')->textInput() ?> + +registerJs($js) + +?> \ No newline at end of file diff --git a/backend/modules/shop/views/express-template/express_area_update.php b/backend/modules/shop/views/express-template/express_area_update.php new file mode 100755 index 0000000..13c0193 --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_update.php @@ -0,0 +1,51 @@ +title = '编辑运费模板: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update '; +Yii::$app->params['bsVersion'] = '4.x'; +?> +
+
+ + ['class' => 'container-fluid']]); + + echo TabsX::widget([ + 'bordered' => true, + 'items' => [ + [ + 'label' => ' 基本信息', + 'content' => $this->render('_form', [ + 'model' => $model, + 'form' => $form, + ]), + ], + [ + 'label' => ' 选择配送区域', + 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => $cities + ]), + ], + ], + 'position' => TabsX::POS_ABOVE, + 'encodeLabels' => false + ]); + ?> + +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
+ + + +
+
From 33b775e7c4737f6904f847c36e182e4fa998cbdc Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 14:43:27 +0800 Subject: [PATCH 08/41] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=88=9B=E5=BB=BA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/views/express-template/express_area_create.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/modules/shop/views/express-template/express_area_create.php b/backend/modules/shop/views/express-template/express_area_create.php index fb35a2e..d9068a5 100755 --- a/backend/modules/shop/views/express-template/express_area_create.php +++ b/backend/modules/shop/views/express-template/express_area_create.php @@ -7,8 +7,8 @@ use kartik\tabs\TabsX; /* @var $this yii\web\View */ /* @var $model backend\modules\shop\models\ars\ExpressTemplate */ -$this->title = '创建运费模板'; -$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; +$this->title = '创建区域运费模板'; +$this->params['breadcrumbs'][] = ['label' => '运费区域模板', 'url' => ['express_area_list', ['id' => $expressTemplateModel->id]]]; $this->params['breadcrumbs'][] = $this->title; Yii::$app->params['bsVersion'] = '4.x'; ?> @@ -23,9 +23,10 @@ Yii::$app->params['bsVersion'] = '4.x'; 'items' => [ [ 'label' => ' 基本信息', - 'content' => $this->render('_form', [ + 'content' => $this->render('express_area_form', [ 'model' => $model, 'form' => $form, + 'expressTemplateModel' => $expressTemplateModel ]), ], [ @@ -41,7 +42,7 @@ Yii::$app->params['bsVersion'] = '4.x';
'btn btn-success']) ?> - 'btn btn-info']) ?> + $expressTemplateModel->id], ['class' => 'btn btn-info']) ?>
From b89e598846d83bb9c78d18718457f38dc683f722 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 14:43:49 +0800 Subject: [PATCH 09/41] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=88=9B=E5=BB=BA=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/shop/models/ars/ExpressArea.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/modules/shop/models/ars/ExpressArea.php b/backend/modules/shop/models/ars/ExpressArea.php index 16497c2..403799b 100644 --- a/backend/modules/shop/models/ars/ExpressArea.php +++ b/backend/modules/shop/models/ars/ExpressArea.php @@ -37,7 +37,9 @@ class ExpressArea extends \yii\db\ActiveRecord { return [ [['province', 'city', 'area'], 'string'], - [['express_template', 'extra_price', 'basic_price', 'basic_count', 'extra_count'], 'integer'], + [['express_template'], 'integer'], + [['extra_price', 'basic_price', 'basic_count', 'extra_count'], 'safe'], + [['extra_price', 'basic_price', 'basic_count', 'extra_count'], 'number'], ]; } From 61808a7cb6d112c14ee4b2b8373508ff76c330fd Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 14:44:04 +0800 Subject: [PATCH 10/41] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E8=A1=A8=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../express-template/express_area_form.php | 76 +++++++++++-------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/backend/modules/shop/views/express-template/express_area_form.php b/backend/modules/shop/views/express-template/express_area_form.php index 940b46f..7864334 100755 --- a/backend/modules/shop/views/express-template/express_area_form.php +++ b/backend/modules/shop/views/express-template/express_area_form.php @@ -19,9 +19,7 @@ if ($status == 1) { -field($model, 'name')->textInput(['maxlength' => true]) ?> - -field($model, 'calculation_type')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculationType, 'type' => "radio"]) ?> +field($model, 'express_template')->textInput(['maxlength' => true]) ?> field($model, 'basic_count')->textInput() ?> @@ -35,18 +33,18 @@ if ($status == 1) { $js=<<calculation_type}-1;//初始的计算方式0:计重 1:计件 function updateTypeChangeCalType(type){//当切换计算方式 @@ -62,10 +60,10 @@ function updateTypeChangeCalType(type){//当切换计算方式 $("." + index).children("label").html(value) }); - $("#expresstemplate-basic_count").val(udfVal[type][0])//重置初始值 - $("#expresstemplate-basic_price").val(udfVal[type][1]) - $("#expresstemplate-extra_count").val(0) - $("#expresstemplate-extra_price").val(udfVal[type][1]) + $("#expressarea-basic_count").val(udfVal[type][0])//重置初始值 + $("#expressarea-basic_price").val(udfVal[type][1]) + $("#expressarea-extra_count").val(0) + $("#expressarea-extra_price").val(udfVal[type][1]) calType = type; } function changeCalType(type){//当切换计算方式 @@ -74,44 +72,55 @@ function changeCalType(type){//当切换计算方式 $("." + index).children("label").html(value) }); - if(!$("#expresstemplate-basic_count").val()){ - $("#expresstemplate-basic_count").val(udfVal[type][0])//重置初始值 + if(!$("#expressarea-basic_count").val()){ + $("#expressarea-basic_count").val(udfVal[type][0])//重置初始值 } - if(!$("#expresstemplate-basic_price").val()){ - $("#expresstemplate-basic_price").val(udfVal[type][1]) + if(!$("#expressarea-basic_price").val()){ + $("#expressarea-basic_price").val(udfVal[type][1]) } - if(!$("#expresstemplate-extra_count").val()){ - $("#expresstemplate-extra_count").val(0) + if(!$("#expressarea-extra_count").val()){ + $("#expressarea-extra_count").val(0) } - if(!$("#expresstemplate-extra_price").val()){ - $("#expresstemplate-extra_price").val(udfVal[type][1]) + if(!$("#expressarea-extra_price").val()){ + $("#expressarea-extra_price").val(udfVal[type][1]) } calType = type; } $(document).ready(function(){ - $("#expresstemplate-basic_count").blur(function(){ + $("#expressarea-basic_count").blur(function(){ + if(isNaN($(this).val())){ + $(this).val(1) + } if (calType == 0) { if($(this).val() < 0.1){ - $(this).val(0.1) + $(this).val(1) } var basiccount = $(this).val(); - $(this).val(Math.floor(basiccount * 10) / 10); + // $(this).val(Math.floor(basiccount * 10) / 10); + $(this).val(basiccount.toString().match(/^\d+(?:\.\d{0,1})?/)); } else{ if($(this).val() < 1){ $(this).val(1) } var basiccount = $(this).val(); - $(this).val(Math.floor(basiccount * 1) / 1); + // $(this).val(Math.floor(basiccount * 1) / 1); + $(this).val(basiccount.toString().match(/^\d+(?:\.\d{0,0})?/)); } }) - $("#expresstemplate-basic_price").blur(function(){ + $("#expressarea-basic_price").blur(function(){ + if(isNaN($(this).val())){ + $(this).val("0.00") + } if($(this).val().indexOf('-') != -1){ $(this).val("0.00") } var basicPrice = $(this).val(); $(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); }) - $("#expresstemplate-extra_count").blur(function(){ + $("#expressarea-extra_count").blur(function(){ + if(isNaN($(this).val())){ + $(this).val(0) + } if (calType == 0) { if($(this).val() < 0){ $(this).val(0) @@ -126,7 +135,10 @@ $(document).ready(function(){ $(this).val(Math.floor(basiccount * 1) / 1); } }) - $("#expresstemplate-extra_price").blur(function(){ + $("#expressarea-extra_price").blur(function(){ + if(isNaN($(this).val())){ + $(this).val("0.00") + } if($(this).val().indexOf('-') != -1){ $(this).val("0.00") } @@ -134,7 +146,7 @@ $(document).ready(function(){ $(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); }) - $("input:radio[name='ExpressTemplate[calculation_type]']").on('ifChecked', function(event){ + $("input:radio[name='ExpressArea[calculation_type]']").on('ifChecked', function(event){ updateTypeChangeCalType($(this).val()-1) }) changeCalType(calType) From 69a511ef1791a255c9b0259ba8e72263d1792e5e Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 14:44:29 +0800 Subject: [PATCH 11/41] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=88=97=E8=A1=A8=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/shop/views/express-template/express_area_list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/modules/shop/views/express-template/express_area_list.php b/backend/modules/shop/views/express-template/express_area_list.php index 465718b..1f59fb9 100644 --- a/backend/modules/shop/views/express-template/express_area_list.php +++ b/backend/modules/shop/views/express-template/express_area_list.php @@ -25,7 +25,7 @@ $this->params['breadcrumbs'][] = $this->title; 'batchTemplate' => '', 'create' => '', 'export' => '', - 'content' => Html::a('创建', ['index'], ['class' => 'btn btn-default']). + 'content' => Html::a('创建', ['express-area-create', 'expressTemplateId' => $expressTemplate->id], ['class' => 'btn btn-default']). Html::a('返回', ['index'], ['class' => 'btn btn-default']) ]); ?> From cd778c7b404830e016017e98021d0f2b5b2fe08b Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 14:44:53 +0800 Subject: [PATCH 12/41] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E6=A3=80=E7=B4=A2=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/models/searchs/ExpressAreaSearch.php | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 backend/modules/shop/models/searchs/ExpressAreaSearch.php diff --git a/backend/modules/shop/models/searchs/ExpressAreaSearch.php b/backend/modules/shop/models/searchs/ExpressAreaSearch.php new file mode 100644 index 0000000..7604eef --- /dev/null +++ b/backend/modules/shop/models/searchs/ExpressAreaSearch.php @@ -0,0 +1,160 @@ + 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + 'id', + ['attribute' => 'city', + 'value' => function ($model) { + $array = explode(',', $model->city); + $cities = []; + foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', $array])->all() as $city) { + $cities[] = $city->name; + } + return implode(' // ', $cities); + }, + ], + 'express_template', + //'extra_price', + //'basic_price', + //'basic_count', + //'extra_count', + //'updated_at', + //'created_at', + [ + 'class' => 'iron\grid\ActionColumn', + 'align' => 'center', + ], + ]; + } + /** + * @param $params + * @return ActiveDataProvider + * 不分页的所有数据 + */ + public function allData($params) + { + $query = ExpressArea::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, $expressTemplateId) + { + $query = ExpressArea::find()->where(['express_template' => $expressTemplateId]); + + // 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){ + 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, + 'express_template' => $this->express_template, + 'extra_price' => $this->extra_price, + 'basic_price' => $this->basic_price, + 'basic_count' => $this->basic_count, + 'extra_count' => $this->extra_count, + 'updated_at' => $this->updated_at, + 'created_at' => $this->created_at, + ]); + + $query->andFilterWhere(['like', 'province', $this->province]) + ->andFilterWhere(['like', 'city', $this->city]) + ->andFilterWhere(['like', 'area', $this->area]); + 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; + } +} From 1547d81c67d023418023b13f8c00f3072643fdb2 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 15:43:05 +0800 Subject: [PATCH 13/41] =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E6=9B=B4=E6=96=B0=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 7b23bb4..61e7773 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -308,4 +308,59 @@ class ExpressTemplateController extends Controller 'expressTemplateModel' => $expressTemplateModel ]); } + + /** + * @return array|mixed|string|Response + * 运费区域模板区域更新方法 + */ + public function actionExpressAreaUpdate($id) + { + $expressTemplateId = Yii::$app->request->get('expressTemplateId'); + $expressTemplateModel = ExpressTemplate::findOne($expressTemplateId); + $model = ExpressArea::findOne($id); + $model->basic_price /= 100; + $model->extra_price /= 100; + if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { + $model->basic_count /= 10; + $model->extra_count /= 10; + } + $data = Yii::$app->request->post('ExpressArea'); + if ($data) { + if (Yii::$app->request->post('area') == null) { + return $this->redirect(Yii::$app->request->referrer . '&status=1'); + } + $cityIds = array_keys(Yii::$app->request->post('area')); + $data['city'] = implode(',', $cityIds); + $model->load($data, ''); + $model->save(); + return $this->redirect('express-area-list?id='.$model->express_template); + } + $data = []; + $expressAreas = ExpressArea::find()->select(['city'])->where(['express_template' => $expressTemplateModel->id])->andWhere(['!=', 'id', $id])->all(); + $expressAresCityIdArr = []; + if ($expressAreas) { + foreach ($expressAreas as $expressAreaCity) { + $cityIdArr = explode(',', $expressAreaCity->city); + $expressAresCityIdArr = array_unique(array_merge($cityIdArr, $expressAresCityIdArr)); + } + } + $provinces = Province::find()->cache(0)->all(); + $j = 0; + foreach ($provinces as $k => $v) { + $cities = City::find() + ->where(['province_id' => $v->province_id]) + ->andWhere(['not in', 'city_id', $expressAresCityIdArr]) + ->all(); + if ($cities) { + $data[$j]['province'] = $v->name; + foreach ($cities as $city) { + $data[$j]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; + } + $j++; + } + } + return $this->render('express_area_update', [ + 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city), 'expressTemplateModel' => $expressTemplateModel + ]); + } } From 4e06b660cea08ad87df3984326e57b112081bf09 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 15:43:24 +0800 Subject: [PATCH 14/41] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=88=97=E8=A1=A8=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/models/searchs/ExpressAreaSearch.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/backend/modules/shop/models/searchs/ExpressAreaSearch.php b/backend/modules/shop/models/searchs/ExpressAreaSearch.php index 7604eef..dea69ac 100644 --- a/backend/modules/shop/models/searchs/ExpressAreaSearch.php +++ b/backend/modules/shop/models/searchs/ExpressAreaSearch.php @@ -6,6 +6,8 @@ use yii\base\Model; use yii\data\ActiveDataProvider; use yii\helpers\ArrayHelper; use backend\modules\shop\models\ars\ExpressArea; +use yii; +use yii\bootstrap4\Html; /** * ExpressAreaSearch represents the model behind the search form of `backend\modules\shop\models\ars\ExpressArea`. @@ -63,16 +65,23 @@ class ExpressAreaSearch extends ExpressArea return implode(' // ', $cities); }, ], - 'express_template', - //'extra_price', - //'basic_price', - //'basic_count', - //'extra_count', - //'updated_at', - //'created_at', [ 'class' => 'iron\grid\ActionColumn', 'align' => 'center', + 'template' => '{express-area-update}', + 'buttons' => [ + 'express-area-update' => function ($url, $model, $key) { + $options = [ + 'title' => Yii::t('yii', '修改'), + 'aria-label' => Yii::t('yii', '修改'), + 'data-method' => 'post', + 'class' => 'oi oi-pencil', + + ]; + return Html::a('', $url . '&expressTemplateId=' . $model->express_template, $options); + }, + ], + 'config' => [], ], ]; } From 509ffc6afbe0a6c55150922c662bdab30acb72c9 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 15:44:03 +0800 Subject: [PATCH 15/41] =?UTF-8?q?=E5=BC=80=E5=8F=91=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=BF=90=E8=B4=B9=E5=8C=BA=E5=9F=9F=E7=BC=96=E8=BE=91=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/views/express-template/express_area_update.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/modules/shop/views/express-template/express_area_update.php b/backend/modules/shop/views/express-template/express_area_update.php index 13c0193..0019efb 100755 --- a/backend/modules/shop/views/express-template/express_area_update.php +++ b/backend/modules/shop/views/express-template/express_area_update.php @@ -7,10 +7,10 @@ use kartik\tabs\TabsX; /* @var $this yii\web\View */ /* @var $model backend\modules\shop\models\ars\ExpressTemplate */ -$this->title = '编辑运费模板: ' . $model->name; +$this->title = '编辑区域运费模板'; $this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; -$this->params['breadcrumbs'][] = 'Update '; +$this->params['breadcrumbs'][] = ['label' => '区域运费模板:'.$expressTemplateModel->name, 'url' => ['express-area-list', 'id' => $expressTemplateModel->id]]; +$this->params['breadcrumbs'][] = '编辑区域运费模板'; Yii::$app->params['bsVersion'] = '4.x'; ?>
@@ -24,9 +24,10 @@ Yii::$app->params['bsVersion'] = '4.x'; 'items' => [ [ 'label' => ' 基本信息', - 'content' => $this->render('_form', [ + 'content' => $this->render('express_area_form', [ 'model' => $model, 'form' => $form, + 'expressTemplateModel' => $expressTemplateModel ]), ], [ From 7560af34f11efa2036d62bec29f9628ab9849067 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 17:03:42 +0800 Subject: [PATCH 16/41] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=9F=8E=E5=B8=82?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 1 + .../shop/models/searchs/ExpressAreaSearch.php | 22 +++++++++++++++---- .../express-template/express_area_update.php | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 61e7773..488385f 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -359,6 +359,7 @@ class ExpressTemplateController extends Controller $j++; } } + return $this->render('express_area_update', [ 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city), 'expressTemplateModel' => $expressTemplateModel ]); diff --git a/backend/modules/shop/models/searchs/ExpressAreaSearch.php b/backend/modules/shop/models/searchs/ExpressAreaSearch.php index dea69ac..c9cb7a3 100644 --- a/backend/modules/shop/models/searchs/ExpressAreaSearch.php +++ b/backend/modules/shop/models/searchs/ExpressAreaSearch.php @@ -2,6 +2,8 @@ namespace backend\modules\shop\models\searchs; +use backend\modules\shop\models\ars\City; +use backend\modules\shop\models\ars\Province; use yii\base\Model; use yii\data\ActiveDataProvider; use yii\helpers\ArrayHelper; @@ -57,12 +59,24 @@ class ExpressAreaSearch extends ExpressArea 'id', ['attribute' => 'city', 'value' => function ($model) { - $array = explode(',', $model->city); + $expressAreas = ExpressArea::findOne($model->id); + $expressAresCityIdArr = explode(',', $expressAreas->city); $cities = []; - foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', $array])->all() as $city) { - $cities[] = $city->name; + $provinces = Province::find()->cache(0)->all(); + foreach ($provinces as $k => $v) { + $cityId = City::find() + ->select(['city_id']) + ->where(['province_id' => $v->province_id]) + ->column(); + if (empty(array_diff($cityId, $expressAresCityIdArr))) { + $cities[] = $v->name; + }else{ + foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', array_diff($cityId, array_diff($cityId, $expressAresCityIdArr))])->all() as $city) { + $cities[] = $city->name; + } + } } - return implode(' // ', $cities); + return implode(' , ', $cities); }, ], [ diff --git a/backend/modules/shop/views/express-template/express_area_update.php b/backend/modules/shop/views/express-template/express_area_update.php index 0019efb..60c0704 100755 --- a/backend/modules/shop/views/express-template/express_area_update.php +++ b/backend/modules/shop/views/express-template/express_area_update.php @@ -43,7 +43,7 @@ Yii::$app->params['bsVersion'] = '4.x';
'btn btn-success']) ?> - 'btn btn-info']) ?> + $expressTemplateModel->id], ['class' => 'btn btn-info']) ?>
From 773719d5b230a4c9d54e3a658cbb8f0dc9847d7f Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 19:10:59 +0800 Subject: [PATCH 17/41] =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E8=A7=86=E5=9B=BE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 24 +++++++++ .../express-template/express_area_view.php | 51 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100755 backend/modules/shop/views/express-template/express_area_view.php diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 488385f..6f29c2b 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -332,6 +332,15 @@ class ExpressTemplateController extends Controller $cityIds = array_keys(Yii::$app->request->post('area')); $data['city'] = implode(',', $cityIds); $model->load($data, ''); + $model->basic_price *= 100; + $model->extra_price *= 100; + if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { + $model->basic_count *= 10; + $model->extra_count *= 10; + } else { + $model->basic_count *= 1; + $model->extra_count *= 1; + } $model->save(); return $this->redirect('express-area-list?id='.$model->express_template); } @@ -364,4 +373,19 @@ class ExpressTemplateController extends Controller 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city), 'expressTemplateModel' => $expressTemplateModel ]); } + + /** + * @param $id + * @return string + * 运费区域模板区域查看方法 + */ + public function actionExpressAreaView($id) + { + $expressTemplateId = Yii::$app->request->get('expressTemplateId'); + $expressTemplateModel = ExpressTemplate::findOne($expressTemplateId); + return $this->render('express_area_view', [ + 'model' => ExpressArea::findOne($id), + 'expressTemplateModel' => $expressTemplateModel + ]); + } } diff --git a/backend/modules/shop/views/express-template/express_area_view.php b/backend/modules/shop/views/express-template/express_area_view.php new file mode 100755 index 0000000..f2d6f8a --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_view.php @@ -0,0 +1,51 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Express Templates', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

+ 'btn btn-success']) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'name', + [ + 'attribute' => 'calculation_type', + 'value' => function ($model) { + return ExpressTemplate::$calculationType[$model->calculation_type]; + } + ], + 'basic_price', + 'basic_count', + 'extra_price', + 'extra_count', + 'updated_at:datetime', + 'created_at:datetime', + ['attribute' => 'city', + 'value' => function ($model) { + $array = explode(',', $model->city); + $cities = []; + foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', $array])->all() as $city) { + $cities[] = $city->name; + } + return implode(' // ', $cities); + }, + ], + ], + ]) ?> + +
From c9a1ce54c23c091343c848f6eee5bc266019d3d3 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 19:14:23 +0800 Subject: [PATCH 18/41] =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=9F=BA=E6=9C=AC=E9=85=8D=E7=BD=AE=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/shop/models/ars/ExpressArea.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backend/modules/shop/models/ars/ExpressArea.php b/backend/modules/shop/models/ars/ExpressArea.php index 403799b..259201a 100644 --- a/backend/modules/shop/models/ars/ExpressArea.php +++ b/backend/modules/shop/models/ars/ExpressArea.php @@ -22,6 +22,20 @@ use yii\behaviors\TimestampBehavior; */ class ExpressArea extends \yii\db\ActiveRecord { + public static $formList = [ + 1 => [ + "basic_count"=>"基本重量(KG)", + "basic_price"=>"基本运费(元)", + "extra_count"=>"续重重量(KG)", + "extra_price"=>"续重运费(元)" + ], + 2 => [ + "basic_count"=>"基本数量(件)", + "basic_price"=>"基本运费(元)", + "extra_count"=>"续重数量(件)", + "extra_price"=>"续重运费(元)" + ] + ]; /** * {@inheritdoc} */ From 858020f9e14f91e79c9df222e17e94f13f2d3379 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 19:14:40 +0800 Subject: [PATCH 19/41] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/models/searchs/ExpressAreaSearch.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/modules/shop/models/searchs/ExpressAreaSearch.php b/backend/modules/shop/models/searchs/ExpressAreaSearch.php index c9cb7a3..1521c92 100644 --- a/backend/modules/shop/models/searchs/ExpressAreaSearch.php +++ b/backend/modules/shop/models/searchs/ExpressAreaSearch.php @@ -82,7 +82,7 @@ class ExpressAreaSearch extends ExpressArea [ 'class' => 'iron\grid\ActionColumn', 'align' => 'center', - 'template' => '{express-area-update}', + 'template' => '{express-area-view} {express-area-update}', 'buttons' => [ 'express-area-update' => function ($url, $model, $key) { $options = [ @@ -94,6 +94,16 @@ class ExpressAreaSearch extends ExpressArea ]; return Html::a('', $url . '&expressTemplateId=' . $model->express_template, $options); }, + 'express-area-view' => function ($url, $model, $key) { + $options = [ + 'title' => Yii::t('yii', '查看'), + 'aria-label' => Yii::t('yii', '查看'), + 'data-method' => 'post', + 'class' => 'oi oi-list', + + ]; + return Html::a('', $url . '&expressTemplateId=' . $model->express_template, $options); + }, ], 'config' => [], ], From 62f32a086b109f396231dbec36c885dc7e4d6459 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 19:16:01 +0800 Subject: [PATCH 20/41] =?UTF-8?q?=E4=BF=AE=E5=A4=8Djs=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E6=9C=BA=E5=88=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/views/express-template/express_area_form.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/modules/shop/views/express-template/express_area_form.php b/backend/modules/shop/views/express-template/express_area_form.php index 7864334..74b97d9 100755 --- a/backend/modules/shop/views/express-template/express_area_form.php +++ b/backend/modules/shop/views/express-template/express_area_form.php @@ -71,7 +71,7 @@ function changeCalType(type){//当切换计算方式 $.each(formList[type],function(index,value){ //更改文字标题 $("." + index).children("label").html(value) }); - + if(!$("#expressarea-basic_count").val()){ $("#expressarea-basic_count").val(udfVal[type][0])//重置初始值 } @@ -103,8 +103,7 @@ $(document).ready(function(){ $(this).val(1) } var basiccount = $(this).val(); - // $(this).val(Math.floor(basiccount * 1) / 1); - $(this).val(basiccount.toString().match(/^\d+(?:\.\d{0,0})?/)); + $(this).val(Math.floor(basiccount * 1) / 1); } }) $("#expressarea-basic_price").blur(function(){ From 4094b2fdde1bdae00defe32dc56ccdb1abe23cfa Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 19:16:45 +0800 Subject: [PATCH 21/41] =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E8=A7=86=E5=9B=BE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../express-template/express_area_view.php | 71 +++++++++++++++---- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/backend/modules/shop/views/express-template/express_area_view.php b/backend/modules/shop/views/express-template/express_area_view.php index f2d6f8a..31d353e 100755 --- a/backend/modules/shop/views/express-template/express_area_view.php +++ b/backend/modules/shop/views/express-template/express_area_view.php @@ -1,5 +1,8 @@ title = $model->name; -$this->params['breadcrumbs'][] = ['label' => 'Express Templates', 'url' => ['index']]; +$this->title = $model->id; +$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => '运费区域模板:'.$expressTemplateModel->name, 'url' => ['express-area-list?id='.$expressTemplateModel->id]]; $this->params['breadcrumbs'][] = $this->title; \yii\web\YiiAsset::register($this); ?>

- 'btn btn-success']) ?> + id], ['class' => 'btn btn-success']) ?>

$model, 'attributes' => [ 'id', - 'name', [ - 'attribute' => 'calculation_type', + 'attribute' => 'basic_count', + 'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['basic_count'], 'value' => function ($model) { - return ExpressTemplate::$calculationType[$model->calculation_type]; + $expressTemplateModel = ExpressTemplate::findOne($model->express_template); + if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { + return $model->basic_count /= 10; + } else { + return $model->basic_count; + } + } + ], + [ + 'attribute' => 'basic_price', + 'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['basic_price'], + 'value' => function ($model) { + return $model->basic_price /= 100; + } + ], + [ + 'attribute' => 'extra_count', + 'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['extra_count'], + 'value' => function ($model) { + $expressTemplateModel = ExpressTemplate::findOne($model->express_template); + if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { + return $model->extra_count /= 10; + } else { + return $model->extra_count; + } + } + ], + [ + 'attribute' => 'extra_price', + 'label' => ExpressArea::$formList[$expressTemplateModel->calculation_type]['extra_price'], + 'value' => function ($model) { + return $model->extra_price /= 100; } ], - 'basic_price', - 'basic_count', - 'extra_price', - 'extra_count', 'updated_at:datetime', 'created_at:datetime', ['attribute' => 'city', 'value' => function ($model) { - $array = explode(',', $model->city); + $expressAreas = ExpressArea::findOne($model->id); + $expressAresCityIdArr = explode(',', $expressAreas->city); $cities = []; - foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', $array])->all() as $city) { - $cities[] = $city->name; + $provinces = Province::find()->cache(0)->all(); + foreach ($provinces as $k => $v) { + $cityId = City::find() + ->select(['city_id']) + ->where(['province_id' => $v->province_id]) + ->column(); + if (empty(array_diff($cityId, $expressAresCityIdArr))) { + $cities[] = $v->name; + }else{ + foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', array_diff($cityId, array_diff($cityId, $expressAresCityIdArr))])->all() as $city) { + $cities[] = $city->name; + } + } } - return implode(' // ', $cities); + return implode(' , ', $cities); }, ], ], From fc782e23cd5d878083e28d697d1a70c6a6f4be7a Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 09:56:08 +0800 Subject: [PATCH 22/41] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6id=E5=B0=86=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E6=96=87=E4=BB=B6=E4=BF=9D=E5=AD=98=E5=9C=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E6=96=B9=E6=B3=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/file/logic/file/FileManager.php | 14 ++++---- backend/modules/goods/views/goods/express.php | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) create mode 100755 backend/modules/goods/views/goods/express.php diff --git a/backend/modules/file/logic/file/FileManager.php b/backend/modules/file/logic/file/FileManager.php index 80d2f26..ba555a7 100755 --- a/backend/modules/file/logic/file/FileManager.php +++ b/backend/modules/file/logic/file/FileManager.php @@ -15,7 +15,7 @@ class FileManager const TYPE_WORD = 4;//word文本 const TYPE_TXT = 5;//txt文本 - public static $extension = [ + private $extension = [ self::TYPE_IMAGE => ['jpg', 'png', 'jpeg'], self::TYPE_VIDEO => ['mp4'], self::TYPE_EXCEL => [], @@ -29,16 +29,14 @@ class FileManager * @return array * 根据文件拓展名在$extension中查找对应的文件类型,若不存在则返回false */ - public function searchType($array, $keyword) + public function searchType($keyword) { - foreach($array as $key => $value){ - foreach ($value as $k => $v) { - if($v == $keyword){ - return ['status' => true, 'info' => '操作成功', 'type' => $key]; - } + foreach($this->extension as $key => $type){ + if (in_array($keyword, $type)) { + return $key; } } - return ['status' => false, 'info' => '操作失败']; + return 0; } /** diff --git a/backend/modules/goods/views/goods/express.php b/backend/modules/goods/views/goods/express.php new file mode 100755 index 0000000..022f640 --- /dev/null +++ b/backend/modules/goods/views/goods/express.php @@ -0,0 +1,35 @@ + +field($model, 'coverImageId')->hiddenInput()->label('') ?> +field($model, 'coverImagePath')->widget(\iron\widgets\Upload::className(), [ + 'url' => 'upload', + 'deleteUrl' => 'img-id-del', + 'dragdropWidth'=> 800, + 'afterSave' => 'save-file', + 'maxCount' => 1, + 'fillInAttribute' => 'coverImageId', + 'model' => $model, + 'previewConfig' => [ + 'url' => Url::to(['image-file', 'fileidstr' => $model->coverImageId, 'ruleverify' => $model->ruleVerify]), + ], +])->label('商品封面图') ?> + +field($model, 'detailImageId')->hiddenInput()->label('') ?> +field($model, 'detailImagePath')->widget(\iron\widgets\Upload::className(), [ + 'url' => 'upload', + 'deleteUrl' => 'img-id-del', + 'dragdropWidth'=> 800, + 'afterSave' => 'save-file', + 'maxCount' => 5, + 'fillInAttribute' => 'detailImageId', + 'model' => $model, + 'previewConfig' => [ + 'url' => Url::to(['image-file', 'fileidstr' => $model->detailImageId, 'ruleverify' => $model->ruleVerify]), + ], +])->label('商品详情图') ?> From a331ef25753d26ef925e84cf59b4677d9da49741 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 09:57:21 +0800 Subject: [PATCH 23/41] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=88=86=E7=B1=BB=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/goods/controllers/CategoryController.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/backend/modules/goods/controllers/CategoryController.php b/backend/modules/goods/controllers/CategoryController.php index 7cf5a09..305db28 100755 --- a/backend/modules/goods/controllers/CategoryController.php +++ b/backend/modules/goods/controllers/CategoryController.php @@ -201,10 +201,7 @@ class CategoryController extends Controller $model->user_id = Yii::$app->user->identity->id; $model->name = $file_name; $file_manager = new \backend\modules\file\logic\file\FileManager(); - $type_res = $file_manager->searchType(\backend\modules\file\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); - if ($type_res['status']) { - $model->type = $type_res['type']; - } + $model->type = $file_manager->searchType(pathinfo($data['path'])['extension']); $model->alias = $data['alias']; $model->path = $data['path']; $model->save(); From 67c8ca9f71c65a2de115dfced8615a57a97375be Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 09:59:01 +0800 Subject: [PATCH 24/41] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=89=A9=E6=B5=81?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=88=9B=E5=BB=BA=E6=9B=B4=E6=94=B9=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/goods/controllers/GoodsController.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/modules/goods/controllers/GoodsController.php b/backend/modules/goods/controllers/GoodsController.php index e0d4833..26b63ec 100755 --- a/backend/modules/goods/controllers/GoodsController.php +++ b/backend/modules/goods/controllers/GoodsController.php @@ -96,7 +96,11 @@ class GoodsController extends Controller $model = new Goods(); $model->is_sale = Goods::IS_SALE_YES; $model->stock = -1; + $model->is_taking = Goods::IS_TAKING_NO; + $model->is_express = Goods::IS_EXPRESS_YES; + $model->express_type = Goods::EXPRESS_TYPE_EXPRESS_TEMPLAGE; if ($model->load(Yii::$app->request->post()) && $model->validate()) { + $model->uniform_postage *= 100; //商品封面图和商品详情图上传保存处理 $res = GoodsManager::updateGoods(Yii::$app->request->post(), $model); if ($res['status']) { @@ -126,12 +130,14 @@ class GoodsController extends Controller $cover_image_old_id_str = $model->image; $detail_image_old_id_str = $model->detailImageId; if ($model->load(Yii::$app->request->post()) && $model->validate()) { + $model->uniform_postage *= 100; //商品封面图和商品详情图上传保存处理 $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'); } } + $model->uniform_postage /= 100; $attributeModel = GoodsManager::getAttribute($id); $checkAttr = GoodsManager::getSkuInfo($id); $filterAttributeModel = GoodsManager::getFilterAttribute($id); @@ -211,10 +217,7 @@ class GoodsController extends Controller $model->user_id = Yii::$app->user->identity->id; $model->name = $file_name; $file_manager = new \backend\modules\file\logic\file\FileManager(); - $type_res = $file_manager->searchType(\backend\modules\file\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); - if ($type_res['status']) { - $model->type = $type_res['type']; - } + $model->type = $file_manager->searchType(pathinfo($data['path'])['extension']); $model->alias = $data['alias']; $model->path = $data['path']; $model->save(); From 9457ad634d0661553c0d0cf5b2445983de2ae40b Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:00:08 +0800 Subject: [PATCH 25/41] =?UTF-8?q?=E5=95=86=E5=93=81=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=A1=A8=E5=88=9B=E5=BB=BA=E6=98=AF=E5=90=A6=E8=87=AA=E6=8F=90?= =?UTF-8?q?=EF=BC=8C=E6=98=AF=E5=90=A6=E5=BF=AB=E9=80=92=E5=8F=91=E8=B4=A7?= =?UTF-8?q?=EF=BC=8C=E5=BF=AB=E9=80=92=E8=BF=90=E8=B4=B9=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E7=BB=9F=E4=B8=80=E9=82=AE=E8=B4=B9=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ype_uniform_postage_in_table_atg_goods.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 backend/modules/goods/migrations/m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods.php diff --git a/backend/modules/goods/migrations/m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods.php b/backend/modules/goods/migrations/m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods.php new file mode 100644 index 0000000..4f06e33 --- /dev/null +++ b/backend/modules/goods/migrations/m191207_004848_add_columns_is_taking_is_express_express_type_uniform_postage_in_table_atg_goods.php @@ -0,0 +1,26 @@ +addColumn('atg_goods', 'is_taking', $this->tinyInteger(1)->defaultValue(0)->notNull()->comment('是否自提')); + $this->addColumn('atg_goods', 'is_express', $this->tinyInteger(1)->defaultValue(0)->notNull()->comment('是否快递发货')); + $this->addColumn('atg_goods', 'express_type', $this->tinyInteger(2)->defaultValue(0)->comment('快递运费方式')); + $this->addColumn('atg_goods', 'uniform_postage', $this->integer(20)->defaultValue(0)->comment('统一邮费')); + } + + public function down() + { + $this->dropColumn('atg_goods', 'is_taking'); + $this->dropColumn('atg_goods', 'is_express'); + $this->dropColumn('atg_goods', 'express_type'); + $this->dropColumn('atg_goods', 'uniform_postage'); + return true; + } +} From 584bbd97426dcac8a6c307db40352cf6298e0b4a Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:00:32 +0800 Subject: [PATCH 26/41] =?UTF-8?q?=E5=95=86=E5=93=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0=E7=89=A9=E6=B5=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/views/express-template/update.php | 36 +++---------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/backend/modules/shop/views/express-template/update.php b/backend/modules/shop/views/express-template/update.php index 13c0193..8e086e9 100755 --- a/backend/modules/shop/views/express-template/update.php +++ b/backend/modules/shop/views/express-template/update.php @@ -14,38 +14,10 @@ $this->params['breadcrumbs'][] = 'Update '; Yii::$app->params['bsVersion'] = '4.x'; ?>
-
- ['class' => 'container-fluid']]); + render('_form', [ + 'model' => $model, + 'isCreate' => false + ]) ?> - echo TabsX::widget([ - 'bordered' => true, - 'items' => [ - [ - 'label' => ' 基本信息', - 'content' => $this->render('_form', [ - 'model' => $model, - 'form' => $form, - ]), - ], - [ - 'label' => ' 选择配送区域', - 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => $cities - ]), - ], - ], - 'position' => TabsX::POS_ABOVE, - 'encodeLabels' => false - ]); - ?> - -
- 'btn btn-success']) ?> - 'btn btn-info']) ?> -
- - - -
From 953d1f26f022f360d653302de2553699e4f24105 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:00:48 +0800 Subject: [PATCH 27/41] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0=E7=89=A9=E6=B5=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/views/express-template/create.php | 36 +++---------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/backend/modules/shop/views/express-template/create.php b/backend/modules/shop/views/express-template/create.php index fb35a2e..14ec692 100755 --- a/backend/modules/shop/views/express-template/create.php +++ b/backend/modules/shop/views/express-template/create.php @@ -13,38 +13,10 @@ $this->params['breadcrumbs'][] = $this->title; Yii::$app->params['bsVersion'] = '4.x'; ?>
-
- ['class' => 'container-fluid']]); + render('_form', [ + 'model' => $model, + 'isCreate' => true + ]) ?> - echo TabsX::widget([ - 'bordered' => true, - 'items' => [ - [ - 'label' => ' 基本信息', - 'content' => $this->render('_form', [ - 'model' => $model, - 'form' => $form, - ]), - ], - [ - 'label' => ' 选择配送区域', - 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => [] - ]), - ], - ], - 'position' => TabsX::POS_ABOVE, - 'encodeLabels' => false - ]); - ?> - -
- 'btn btn-success']) ?> - 'btn btn-info']) ?> -
- - - -
From e73256899be7d02136520e7254bcbed4f79c1d63 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:01:30 +0800 Subject: [PATCH 28/41] =?UTF-8?q?=E8=BF=90=E8=B4=B9=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E5=88=A0=E9=99=A4=E5=9F=BA=E6=9C=AC=E6=95=B0?= =?UTF-8?q?=E9=87=8F=EF=BC=8C=E5=9F=BA=E6=9C=AC=E8=B4=B9=E7=94=A8=EF=BC=8C?= =?UTF-8?q?=E7=BB=AD=E9=87=8D=E6=95=B0=E9=87=8F=EF=BC=8C=E7=BB=AD=E9=87=8D?= =?UTF-8?q?=E8=B4=B9=E7=94=A8=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/views/express-template/_form.php | 145 ++---------------- 1 file changed, 16 insertions(+), 129 deletions(-) diff --git a/backend/modules/shop/views/express-template/_form.php b/backend/modules/shop/views/express-template/_form.php index 940b46f..c919f92 100755 --- a/backend/modules/shop/views/express-template/_form.php +++ b/backend/modules/shop/views/express-template/_form.php @@ -2,144 +2,31 @@ use blobt\widgets\Icheck; use backend\modules\shop\models\ars\ExpressTemplate; +use yii\bootstrap4\ActiveForm; +use yii\bootstrap4\Html; /* @var $this yii\web\View */ /* @var $model backend\modules\shop\models\ars\ExpressTemplate */ /* @var $form yii\widgets\ActiveForm */ ?> -request->get('status'); -if ($status == 1) { - ?> - - - -field($model, 'name')->textInput(['maxlength' => true]) ?> - -field($model, 'calculation_type')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculationType, 'type' => "radio"]) ?> - -field($model, 'basic_count')->textInput() ?> +
-field($model, 'basic_price')->textInput() ?> + -field($model, 'extra_count')->textInput() ?> + field($model, 'name')->textInput(['maxlength' => true]) ?> -field($model, 'extra_price')->textInput() ?> - -field($model, 'calculation_type')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculationType, 'type' => "radio"]); + } + ?> - $.each(formList[type],function(index,value){ //更改文字标题 - $("." + index).children("label").html(value) - }); - - $("#expresstemplate-basic_count").val(udfVal[type][0])//重置初始值 - $("#expresstemplate-basic_price").val(udfVal[type][1]) - $("#expresstemplate-extra_count").val(0) - $("#expresstemplate-extra_price").val(udfVal[type][1]) - calType = type; -} -function changeCalType(type){//当切换计算方式 +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
- $.each(formList[type],function(index,value){ //更改文字标题 - $("." + index).children("label").html(value) - }); - - if(!$("#expresstemplate-basic_count").val()){ - $("#expresstemplate-basic_count").val(udfVal[type][0])//重置初始值 - } - if(!$("#expresstemplate-basic_price").val()){ - $("#expresstemplate-basic_price").val(udfVal[type][1]) - } - if(!$("#expresstemplate-extra_count").val()){ - $("#expresstemplate-extra_count").val(0) - } - if(!$("#expresstemplate-extra_price").val()){ - $("#expresstemplate-extra_price").val(udfVal[type][1]) - } - calType = type; -} -$(document).ready(function(){ - $("#expresstemplate-basic_count").blur(function(){ - if (calType == 0) { - if($(this).val() < 0.1){ - $(this).val(0.1) - } - var basiccount = $(this).val(); - $(this).val(Math.floor(basiccount * 10) / 10); - } else{ - if($(this).val() < 1){ - $(this).val(1) - } - var basiccount = $(this).val(); - $(this).val(Math.floor(basiccount * 1) / 1); - } - }) - $("#expresstemplate-basic_price").blur(function(){ - if($(this).val().indexOf('-') != -1){ - $(this).val("0.00") - } - var basicPrice = $(this).val(); - $(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); - }) - $("#expresstemplate-extra_count").blur(function(){ - if (calType == 0) { - if($(this).val() < 0){ - $(this).val(0) - } - var basiccount = $(this).val(); - $(this).val(Math.floor(basiccount * 10) / 10); - } else{ - if($(this).val() < 0){ - $(this).val(0) - } - var basiccount = $(this).val(); - $(this).val(Math.floor(basiccount * 1) / 1); - } - }) - $("#expresstemplate-extra_price").blur(function(){ - if($(this).val().indexOf('-') != -1){ - $(this).val("0.00") - } - var basicPrice = $(this).val(); - $(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); - }) - - $("input:radio[name='ExpressTemplate[calculation_type]']").on('ifChecked', function(event){ - updateTypeChangeCalType($(this).val()-1) - }) - changeCalType(calType) -}) -JS; -$this->registerJs($js) + -?> \ No newline at end of file +
\ No newline at end of file From 7a063925f59db6ffc7c33c8ca5bf537e5598b7dc Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:02:35 +0800 Subject: [PATCH 29/41] =?UTF-8?q?=E8=BF=90=E8=B4=B9=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=88=A0=E9=99=A4=E7=9C=81=E5=B8=82=E5=8C=BA?= =?UTF-8?q?=E5=9F=9F=EF=BC=8C=E5=9F=BA=E6=9C=AC=E6=95=B0=E9=87=8F=EF=BC=8C?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E8=B4=B9=E7=94=A8=EF=BC=8C=E7=BB=AD=E9=87=8D?= =?UTF-8?q?=E6=95=B0=E9=87=8F=EF=BC=8C=E7=BB=AD=E9=87=8D=E8=B4=B9=E7=94=A8?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/shop/models/ars/ExpressTemplate.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/modules/shop/models/ars/ExpressTemplate.php b/backend/modules/shop/models/ars/ExpressTemplate.php index 27bd453..b0ef8b7 100644 --- a/backend/modules/shop/models/ars/ExpressTemplate.php +++ b/backend/modules/shop/models/ars/ExpressTemplate.php @@ -79,4 +79,13 @@ class ExpressTemplate extends \yii\db\ActiveRecord ], ]; } + + /** + * @return array + * 数据键值对 + */ + public static function modelColumn() + { + return $column = self::find()->select(['name'])->indexBy('id')->column(); + } } From f6dc5c426e3efdfb1d1e6104cf72ff3b0abea28f Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:03:25 +0800 Subject: [PATCH 30/41] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=88=9B=E5=BB=BA=E5=92=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=9B=A0=E5=88=A0=E9=99=A4=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E9=80=BB=E8=BE=91=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 74 ++----------------- 1 file changed, 6 insertions(+), 68 deletions(-) diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 6f29c2b..2e56221 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -73,52 +73,13 @@ class ExpressTemplateController extends Controller public function actionCreate() { $model = new ExpressTemplate(); - $model->calculation_type = ExpressTemplate::CALCULATION_TYPE_NUMBER; - $model->basic_count = 1; - $model->basic_price = '0.00'; - if (Yii::$app->request->isPost) { - $data = Yii::$app->request->post('ExpressTemplate'); - if (Yii::$app->request->isAjax) { - $model->load($data, ''); - Yii::$app->response->format = Response::FORMAT_JSON; - $data = ActiveForm::validate($model); - $data['status'] = 2; - return $data; - } - if (Yii::$app->request->post('area') == null) { - return $this->redirect(Yii::$app->request->referrer . '?status=1'); - } - $cityIds = array_keys(Yii::$app->request->post('area')); - $data['city'] = implode(',', $cityIds); - $model->load($data, ''); - $model->basic_price *= 100; - $model->extra_price *= 100; - if ($model->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { - $model->basic_count *= 10; - $model->extra_count *= 10; - } else { - $model->basic_count *= 1; - $model->extra_count *= 1; - } - $model->save(); + if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect('index'); } - $data = []; - $provinces = Province::find()->cache(0)->all(); - foreach ($provinces as $k => $v) { - $data[$k]['province'] = $v->name; - $cities = City::find() - ->where(['province_id' => $v->province_id]) - ->all(); - foreach ($cities as $city) { - $data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; - } - } return $this->render('create', [ 'model' => $model, - 'data' => $data ]); } @@ -132,36 +93,13 @@ class ExpressTemplateController extends Controller public function actionUpdate($id) { $model = $this->findModel($id); - $model->basic_price /= 100; - $model->extra_price /= 100; - if ($model->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { - $model->basic_count /= 10; - $model->extra_count /= 10; - } - $data = Yii::$app->request->post('ExpressTemplate'); - if ($data) { - if (Yii::$app->request->post('area') == null) { - return $this->redirect(Yii::$app->request->referrer . '&status=1'); - } - $cityIds = array_keys(Yii::$app->request->post('area')); - $data['city'] = implode(',', $cityIds); - $model->load($data, ''); - $model->save(); - return $this->render('view', ['model' => ExpressTemplate::findOne($model->id)]); - } - $data = []; - $provinces = Province::find()->cache(0)->all(); - foreach ($provinces as $k => $v) { - $data[$k]['province'] = $v->name; - $cities = City::find() - ->where(['province_id' => $v->province_id]) - ->all(); - foreach ($cities as $city) { - $data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; - } + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); } + return $this->render('update', [ - 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city) + 'model' => $model, ]); } From 757a43f65c3453a872d1925de87af366f88daba8 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:04:39 +0800 Subject: [PATCH 31/41] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=9B=B4=E6=96=B0=E9=A1=B5=E9=9D=A2=E5=92=8C?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/goods/views/goods/create.php | 6 ++++++ backend/modules/goods/views/goods/update.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/backend/modules/goods/views/goods/create.php b/backend/modules/goods/views/goods/create.php index a2f1131..1d87807 100755 --- a/backend/modules/goods/views/goods/create.php +++ b/backend/modules/goods/views/goods/create.php @@ -42,6 +42,12 @@ Yii::$app->params['bsVersion'] = '4.x'; 'attrValue' => [], ]), ], + [ + 'label' => ' 物流信息', + 'content' => $this->render('express', ['model' => $model, + 'form' => $form, + ]), + ], [ 'label' => ' 详情上传', 'content' => $this->render('new_editor', ['model' => $model, diff --git a/backend/modules/goods/views/goods/update.php b/backend/modules/goods/views/goods/update.php index da346ef..25ac202 100755 --- a/backend/modules/goods/views/goods/update.php +++ b/backend/modules/goods/views/goods/update.php @@ -44,6 +44,12 @@ Yii::$app->params['bsVersion'] = '4.x'; 'goodsModel' => $model, ]), ], + [ + 'label' => ' 物流信息', + 'content' => $this->render('express', ['model' => $model, + 'form' => $form, + ]), + ], [ 'label' => ' 详情上传', 'content' => $this->render('new_editor', ['model' => $model, From b1ab7d94e04156bf17bb0098192bc6762b34574e Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:05:17 +0800 Subject: [PATCH 32/41] =?UTF-8?q?=E5=BC=80=E5=8F=91=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=89=A9=E6=B5=81=E4=BF=A1=E6=81=AF=E7=BC=96=E8=BE=91=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/goods/views/goods/express.php | 79 ++++++++++++------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/backend/modules/goods/views/goods/express.php b/backend/modules/goods/views/goods/express.php index 022f640..c97839e 100755 --- a/backend/modules/goods/views/goods/express.php +++ b/backend/modules/goods/views/goods/express.php @@ -1,35 +1,60 @@ -field($model, 'coverImageId')->hiddenInput()->label('') ?> -field($model, 'coverImagePath')->widget(\iron\widgets\Upload::className(), [ - 'url' => 'upload', - 'deleteUrl' => 'img-id-del', - 'dragdropWidth'=> 800, - 'afterSave' => 'save-file', - 'maxCount' => 1, - 'fillInAttribute' => 'coverImageId', - 'model' => $model, - 'previewConfig' => [ - 'url' => Url::to(['image-file', 'fileidstr' => $model->coverImageId, 'ruleverify' => $model->ruleVerify]), - ], -])->label('商品封面图') ?> - -field($model, 'detailImageId')->hiddenInput()->label('') ?> -field($model, 'detailImagePath')->widget(\iron\widgets\Upload::className(), [ - 'url' => 'upload', - 'deleteUrl' => 'img-id-del', - 'dragdropWidth'=> 800, - 'afterSave' => 'save-file', - 'maxCount' => 5, - 'fillInAttribute' => 'detailImageId', - 'model' => $model, - 'previewConfig' => [ - 'url' => Url::to(['image-file', 'fileidstr' => $model->detailImageId, 'ruleverify' => $model->ruleVerify]), - ], -])->label('商品详情图') ?> +field($model, 'is_taking')->widget(Icheck::className(), ['items' => Goods::$isTaking, 'type' => 'radio']) ?> + +field($model, 'is_express')->widget(Icheck::className(), ['items' => Goods::$isExpress, 'type' => 'radio']) ?> + +
+ field($model, 'express_type')->widget(Icheck::className(), ['items' => Goods::$expressType, 'type' => 'radio']) ?> + +
+ field($model, 'uniform_postage')->textInput() ?> +
+ +
+ field($model, 'express_template')->widget(Select2::className(), ["items" => ExpressTemplate::modelColumn()]) ?> +
+
+ +registerJs($js); + +?> \ No newline at end of file From 3f8f09bf36a5a95c11338dc80397d5618728e363 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:06:21 +0800 Subject: [PATCH 33/41] =?UTF-8?q?=E5=95=86=E5=93=81=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E8=87=AA=E6=8F=90,?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=BF=AB=E9=80=92=E5=8F=91=E8=B4=A7,?= =?UTF-8?q?=E5=BF=AB=E9=80=92=E8=BF=90=E8=B4=B9=E6=96=B9=E5=BC=8F,?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E9=82=AE=E8=B4=B9=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/goods/models/ars/Goods.php | 40 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/backend/modules/goods/models/ars/Goods.php b/backend/modules/goods/models/ars/Goods.php index beaa058..7ec96dc 100755 --- a/backend/modules/goods/models/ars/Goods.php +++ b/backend/modules/goods/models/ars/Goods.php @@ -47,6 +47,10 @@ use backend\modules\goods\models\ars\Supplier; * @property int $created_at 创建时间 * @property int $updated_at 更新时间 * @property int $sku_mode sku类型 + * @property int $is_taking 是否自提 + * @property int $is_express 是否快递发货 + * @property int $express_type 快递运费方式 + * @property int $uniform_postage 统一邮费 */ class Goods extends \yii\db\ActiveRecord { @@ -62,9 +66,31 @@ class Goods extends \yii\db\ActiveRecord //该商品是否开放销售is_sale const IS_SALE_NO = 0;//否 const IS_SALE_YES = 1;//是 - //sku类型 + //类型sku const SKU_MODE_ATTR = 1;//SKU类型属性 const SKU_MODE_MANUAL = 2;//SKU类型手写 + //是否自提is_taking + const IS_TAKING_NO = 0; //否 + const IS_TAKING_YES = 1; //是 + //是否快递发货is_express + const IS_EXPRESS_NO = 0; //否 + const IS_EXPRESS_YES = 1; //是 + //快递运费计算方式express_type + const EXPRESS_TYPE_UNIFORM_POSTAGE = 1; //统一邮费 + const EXPRESS_TYPE_EXPRESS_TEMPLAGE = 2; //运费模板 + + public static $isTaking = [ + self::IS_TAKING_NO => '否', + self::IS_TAKING_YES => '是' + ]; + public static $isExpress = [ + self::IS_EXPRESS_NO => '否', + self::IS_EXPRESS_YES => '是' + ]; + public static $expressType = [ + self::EXPRESS_TYPE_UNIFORM_POSTAGE => '统一邮费', + self::EXPRESS_TYPE_EXPRESS_TEMPLAGE => '运费模板' + ]; public static $isSale = [ self::IS_SALE_NO => '不在售', self::IS_SALE_YES => '在售' @@ -84,7 +110,7 @@ class Goods extends \yii\db\ActiveRecord 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'], + [['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', 'is_taking', 'is_express', 'express_type'], 'integer'], [['cat_id', 'brand_id', 'shop_cat_id', 'name'], 'required'], [['sn'], 'checkExist'], [['description', 'coverImageId', 'detailImageId'], 'string'], @@ -93,7 +119,8 @@ class Goods extends \yii\db\ActiveRecord [['code'], 'string', 'max' => 50], [['unit'], 'string', 'max' => 16], [['brief'], 'string', 'max' => 255], - [['weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'market_price', 'price'], 'checkNegative'], + [['weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'market_price', 'price', 'uniform_postage'], 'checkNegative'], + [['uniform_postage'], 'safe'] ]; } @@ -164,9 +191,14 @@ class Goods extends \yii\db\ActiveRecord 'bouns_points' => '奖励积分', 'experience_points' => '经验值', 'is_delete' => '是否删除,1为已删除', - 'express_template' => '配送详情id', + 'express_template' => '配送详情', 'created_at' => '创建时间', 'updated_at' => '更新时间', + 'sku_mode' => 'sku类型', + 'is_taking' => '是否自提', + 'is_express' => '是否快递发货', + 'express_type' => '快递运费方式', + 'uniform_postage' => '统一邮费', ]; } From 9eb9bdf90e8c1fdbfae2e2e0db7ecfe2d2e93c48 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:06:48 +0800 Subject: [PATCH 34/41] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=8E=A7=E5=88=B6=E5=99=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/goods/controllers/ShopCategoryController.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/backend/modules/goods/controllers/ShopCategoryController.php b/backend/modules/goods/controllers/ShopCategoryController.php index 70d1515..c0feeec 100755 --- a/backend/modules/goods/controllers/ShopCategoryController.php +++ b/backend/modules/goods/controllers/ShopCategoryController.php @@ -212,10 +212,7 @@ class ShopCategoryController extends Controller $model->user_id = Yii::$app->user->identity->id; $model->name = $file_name; $file_manager = new \backend\modules\file\logic\file\FileManager(); - $type_res = $file_manager->searchType(\backend\modules\file\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); - if ($type_res['status']) { - $model->type = $type_res['type']; - } + $model->type = $file_manager->searchType(pathinfo($data['path'])['extension']); $model->alias = $data['alias']; $model->path = $data['path']; $model->save(); From 7a869f6d761a057babc3f7f15540fac96917842a Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:40:28 +0800 Subject: [PATCH 35/41] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=88=97=E8=A1=A8=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F=E8=B5=84=E6=BA=90=EF=BC=8C?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=AF=A6=E6=83=85=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/models/searchs/ExpressTemplateSearch.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/modules/shop/models/searchs/ExpressTemplateSearch.php b/backend/modules/shop/models/searchs/ExpressTemplateSearch.php index a1e4b16..09beeed 100755 --- a/backend/modules/shop/models/searchs/ExpressTemplateSearch.php +++ b/backend/modules/shop/models/searchs/ExpressTemplateSearch.php @@ -52,17 +52,18 @@ class ExpressTemplateSearch extends ExpressTemplate 'width' => '2%', 'align' => 'center' ], - 'id', - 'name', + 'id', + 'name', + [ + 'attribute' => 'calculation_type', + 'value' => function ($model) { + return ExpressTemplate::$calculationType[$model->calculation_type]; + } + ], [ 'class' => 'iron\grid\ActionColumn', 'align' => 'center', 'config' => [ - [ - 'name' => 'view', - 'icon' => 'list', - 'title' => '详情', - ], [ 'name' => 'update', 'icon' => 'pencil', From 77b08b6a7e135381bf1465a6d06a957f308dceb4 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 11:25:09 +0800 Subject: [PATCH 36/41] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E7=BC=96=E8=BE=91=E6=96=B9=E6=B3=95=E4=B8=8D?= =?UTF-8?q?=E5=90=88=E7=90=86=E5=A4=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controllers/ExpressTemplateController.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 2e56221..c704b50 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -253,9 +253,8 @@ class ExpressTemplateController extends Controller */ public function actionExpressAreaUpdate($id) { - $expressTemplateId = Yii::$app->request->get('expressTemplateId'); - $expressTemplateModel = ExpressTemplate::findOne($expressTemplateId); $model = ExpressArea::findOne($id); + $expressTemplateModel = ExpressTemplate::findOne($model->express_template); $model->basic_price /= 100; $model->extra_price /= 100; if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { @@ -319,10 +318,10 @@ class ExpressTemplateController extends Controller */ public function actionExpressAreaView($id) { - $expressTemplateId = Yii::$app->request->get('expressTemplateId'); - $expressTemplateModel = ExpressTemplate::findOne($expressTemplateId); + $expressAreaModel = ExpressArea::findOne($id); + $expressTemplateModel = ExpressTemplate::findOne($expressAreaModel->express_template); return $this->render('express_area_view', [ - 'model' => ExpressArea::findOne($id), + 'model' => $expressAreaModel, 'expressTemplateModel' => $expressTemplateModel ]); } From f576c0eec013e6dc2632d0a4a515bb3c73cc0f2b Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 11:25:47 +0800 Subject: [PATCH 37/41] =?UTF-8?q?=E5=B0=86=E5=88=97=E8=A1=A8tamplate-butto?= =?UTF-8?q?n=E7=94=A8=E6=B3=95=E6=94=B9=E4=B8=BAconfig=E7=94=A8=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/models/searchs/ExpressAreaSearch.php | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/backend/modules/shop/models/searchs/ExpressAreaSearch.php b/backend/modules/shop/models/searchs/ExpressAreaSearch.php index 1521c92..6efd306 100644 --- a/backend/modules/shop/models/searchs/ExpressAreaSearch.php +++ b/backend/modules/shop/models/searchs/ExpressAreaSearch.php @@ -82,30 +82,24 @@ class ExpressAreaSearch extends ExpressArea [ 'class' => 'iron\grid\ActionColumn', 'align' => 'center', - 'template' => '{express-area-view} {express-area-update}', - 'buttons' => [ - 'express-area-update' => function ($url, $model, $key) { - $options = [ - 'title' => Yii::t('yii', '修改'), - 'aria-label' => Yii::t('yii', '修改'), - 'data-method' => 'post', - 'class' => 'oi oi-pencil', - - ]; - return Html::a('', $url . '&expressTemplateId=' . $model->express_template, $options); - }, - 'express-area-view' => function ($url, $model, $key) { - $options = [ - 'title' => Yii::t('yii', '查看'), - 'aria-label' => Yii::t('yii', '查看'), - 'data-method' => 'post', - 'class' => 'oi oi-list', - - ]; - return Html::a('', $url . '&expressTemplateId=' . $model->express_template, $options); - }, + 'config' => [ + [ + 'name' => 'express-area-view', + 'icon' => 'list', + 'title' => '详情', + ], + [ + 'name' => 'express-area-update', + 'icon' => 'pencil', + 'title' => '修改' + ], +// [ +// 'name' => 'delete', +// 'icon' => 'trash', +// 'title' => '删除', +// 'contents' => '确定删除?' +// ] ], - 'config' => [], ], ]; } From 7ef8cbb3331245946d6e8ea89b68e435d531f46f Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 11:28:25 +0800 Subject: [PATCH 38/41] =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=88=A0=E9=99=A4=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controllers/ExpressTemplateController.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index c704b50..bac843f 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -325,4 +325,12 @@ class ExpressTemplateController extends Controller 'expressTemplateModel' => $expressTemplateModel ]); } + + public function actionExpressAreaDelete($id) + { + $expressAreaModel = ExpressArea::findOne($id); + $expressTemplateId = $expressAreaModel->express_template; + $expressAreaModel->delete(); + return $this->redirect('express-area-list?id='.$expressTemplateId); + } } From a873e80f044c37cc3c31b66ca53207cd9c26f7d3 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 11:28:44 +0800 Subject: [PATCH 39/41] =?UTF-8?q?=E8=BF=90=E8=B4=B9=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/models/searchs/ExpressAreaSearch.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/modules/shop/models/searchs/ExpressAreaSearch.php b/backend/modules/shop/models/searchs/ExpressAreaSearch.php index 6efd306..0893957 100644 --- a/backend/modules/shop/models/searchs/ExpressAreaSearch.php +++ b/backend/modules/shop/models/searchs/ExpressAreaSearch.php @@ -93,12 +93,12 @@ class ExpressAreaSearch extends ExpressArea 'icon' => 'pencil', 'title' => '修改' ], -// [ -// 'name' => 'delete', -// 'icon' => 'trash', -// 'title' => '删除', -// 'contents' => '确定删除?' -// ] + [ + 'name' => 'express-area-delete', + 'icon' => 'trash', + 'title' => '删除', + 'contents' => '确定删除?' + ] ], ], ]; From a29c58273e9164210938d8185b2d9ce2911daf73 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 15:18:16 +0800 Subject: [PATCH 40/41] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/file/logic/file/FileManager.php | 65 +++-- .../goods/controllers/GoodsController.php | 9 +- .../goods/logic/goods/GoodsManager.php | 256 +++++++++--------- 3 files changed, 179 insertions(+), 151 deletions(-) diff --git a/backend/modules/file/logic/file/FileManager.php b/backend/modules/file/logic/file/FileManager.php index ba555a7..35edc15 100755 --- a/backend/modules/file/logic/file/FileManager.php +++ b/backend/modules/file/logic/file/FileManager.php @@ -5,10 +5,13 @@ namespace backend\modules\file\logic\file; use backend\modules\file\models\ars\File; use backend\modules\file\models\ars\TemFile; +use yii\web\HttpException; +use yii; class FileManager { //数据表ats_file和ats_tem_file的类型字段type + const TYPE_NONE = 0;//不存在 const TYPE_IMAGE = 1;//图片 const TYPE_VIDEO = 2;//影视 const TYPE_EXCEL = 3;//excel表单 @@ -24,10 +27,9 @@ class FileManager ]; /** - * @param $array * @param $keyword - * @return array - * 根据文件拓展名在$extension中查找对应的文件类型,若不存在则返回false + * @return int|string + * 根据文件拓展名在$extension中查找对应的文件类型,若不存在则返回self::TYPE_NONE */ public function searchType($keyword) { @@ -36,40 +38,45 @@ class FileManager return $key; } } - return 0; + return self::TYPE_NONE; } /** - * @param $temFIleIdArr + * @param $temFileIdArr * @param $ownId * @param $ownType - * @return array + * @return array|bool + * @throws \Exception * 根据临时文件id将临时文件保存在文件中 */ - public function saveTemFileToFile($temFIleIdArr, $ownId, $ownType) + public function saveTemFileToFile($temFileIdArr, $ownId, $ownType) { - if(!$temFIleIdArr || !$ownId) { - return ['status' => false, 'info' => '参数错误']; + if(empty($temFileIdArr) || !$ownId) { + return false; } - $firstFileId = 0; - foreach ($temFIleIdArr as $key => $value) { - $temFile = TemFile::findOne($value); + $tra = Yii::$app->db->beginTransaction(); + try { + $firstFileId = 0; + foreach ($temFileIdArr as $key => $value) { + $temFile = TemFile::findOne($value); - if(!$temFile) { - return ['status' => false, 'info' => '存在查找不到的文件']; - } + if (!$temFile) { + throw new \Exception('存在查找不到的文件'); + } - $res = self::saveNewFile($temFile, $ownId, $ownType); - if(!$res['status']) { - return ['status' => false, 'info' => '存在文件保存失败']; - } - if($key == 0) { - $firstFileId = $res['file_id']; + $res = self::saveNewFile($temFile, $ownId, $ownType); + if ($key == 0) { + $firstFileId = $res['file_id']; + } } - } - return ['status' => true, 'info' => '保存成功', 'first_file_id' => $firstFileId]; + $tra->commit(); + return ['status' => true, 'info' => '保存成功', 'first_file_id' => $firstFileId]; + } catch (\Exception $e) { + $tra->rollBack(); + throw new \Exception($e->getMessage()); + } } /** @@ -77,6 +84,7 @@ class FileManager * @param $ownId * @param $ownType * @return array + * @throws HttpException * 创建新的文件 */ private function saveNewFile($temFile, $ownId, $ownType) @@ -91,13 +99,14 @@ class FileManager if($newFile->save()) { return ['status' => true, 'info' => '操作成功', 'file_id' => $newFile->id]; } else { - return ['status' => false, 'info' => '操作失败']; + throw new HttpException('500', 'File保存失败'); } } /** * @param $fileIdArr - * @return array + * @return bool + * @throws HttpException * 删除file表中的文件 */ public function deleteFile($fileIdArr) @@ -107,12 +116,12 @@ class FileManager $fileModel = File::findOne($value); if($fileModel){ $fileModel->is_delete = File::IS_DELETE_YES; - if($fileModel->save()){ - return ['status' => false, 'info' => '操作失败']; + if(!$fileModel->save()){ + throw new HttpException('500', '文件删除失败'); } } } } - return ['status' => true, 'info' => '操作成功']; + return true; } } \ No newline at end of file diff --git a/backend/modules/goods/controllers/GoodsController.php b/backend/modules/goods/controllers/GoodsController.php index 26b63ec..9284c30 100755 --- a/backend/modules/goods/controllers/GoodsController.php +++ b/backend/modules/goods/controllers/GoodsController.php @@ -11,6 +11,7 @@ use Yii; use backend\modules\goods\models\ars\Goods; use backend\modules\goods\models\searchs\GoodsSearch; use yii\web\Controller; +use yii\web\HttpException; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use backend\modules\goods\logic\goods\GoodsManager; @@ -100,7 +101,9 @@ class GoodsController extends Controller $model->is_express = Goods::IS_EXPRESS_YES; $model->express_type = Goods::EXPRESS_TYPE_EXPRESS_TEMPLAGE; if ($model->load(Yii::$app->request->post()) && $model->validate()) { - $model->uniform_postage *= 100; + if ($model->uniform_postage) { + $model->uniform_postage *= 100; + } //商品封面图和商品详情图上传保存处理 $res = GoodsManager::updateGoods(Yii::$app->request->post(), $model); if ($res['status']) { @@ -130,7 +133,9 @@ class GoodsController extends Controller $cover_image_old_id_str = $model->image; $detail_image_old_id_str = $model->detailImageId; if ($model->load(Yii::$app->request->post()) && $model->validate()) { - $model->uniform_postage *= 100; + if ($model->uniform_postage) { + $model->uniform_postage *= 100; + } //商品封面图和商品详情图上传保存处理 $res = GoodsManager::updateGoods(Yii::$app->request->post(), $model, $cover_image_old_id_str, $detail_image_old_id_str); if ($res['status']) { diff --git a/backend/modules/goods/logic/goods/GoodsManager.php b/backend/modules/goods/logic/goods/GoodsManager.php index ce534c8..eb0de2f 100755 --- a/backend/modules/goods/logic/goods/GoodsManager.php +++ b/backend/modules/goods/logic/goods/GoodsManager.php @@ -10,6 +10,7 @@ use backend\modules\goods\models\ars\GoodsSku; use backend\modules\goods\models\ars\Goods; use backend\modules\goods\models\ars\FilterAttr; use backend\modules\goods\models\ars\Category; +use yii\web\HttpException; class GoodsManager { @@ -19,36 +20,44 @@ class GoodsManager * @param array $oldFileIdArr * @param int $fileType * @return array + * @throws \Exception * 保存新文件,删除不需要的文件操作 */ public static function saveFile($newFileIdArr, $goodsModel, $oldFileIdArr = [], $fileType = 1) { - //需要新建的文件id - $createFileIdArr = array_diff($newFileIdArr, $oldFileIdArr); + $tra = Yii::$app->db->beginTransaction(); + try { + //需要新建的文件id + $createFileIdArr = array_diff($newFileIdArr, $oldFileIdArr); - //创建文件 - $class = new \backend\modules\file\logic\file\FileManager(); - $createFileRes = $class->saveTemFileToFile($createFileIdArr, $goodsModel->id, $fileType); + //创建文件 + $class = new \backend\modules\file\logic\file\FileManager(); + $createFileRes = $class->saveTemFileToFile($createFileIdArr, $goodsModel->id, $fileType); - //需要删除的文件id - $delFileIdArr = array_diff($oldFileIdArr, $newFileIdArr); + //需要删除的文件id + $delFileIdArr = array_diff($oldFileIdArr, $newFileIdArr); - //删除文件 - $class->deleteFile($delFileIdArr); + //删除文件 + $class->deleteFile($delFileIdArr); - //记录第一张图片id - $firstFileId = 0; + //记录第一张图片id + $firstFileId = 0; - //查看修改数组是否为空 - if (!$newFileIdArr[0]) { - $firstFileId = null; - }else { - if ($createFileRes['status']) { - $firstFileId = $createFileRes['first_file_id']; + //查看修改数组是否为空 + if (!$newFileIdArr[0]) { + $firstFileId = null; + } else { + if ($createFileRes['status']) { + $firstFileId = $createFileRes['first_file_id']; + } } - } - return ['status' => true, 'info' => '操作成功', 'first_file_id' => $firstFileId]; + $tra->commit(); + return ['status' => true, 'info' => '操作成功', 'first_file_id' => $firstFileId]; + } catch (\Exception $e) { + $tra->rollBack(); + throw new \Exception($e->getMessage()); + } } /** @@ -57,7 +66,7 @@ class GoodsManager * @param null $coverImageOldIdStr * @param null $detailImageOldIdStr * @return array - * @throws \Throwable + * @throws \Exception * 创建修改商品操作 */ public static function updateGoods($data, $model, $coverImageOldIdStr = null, $detailImageOldIdStr = null) @@ -67,19 +76,15 @@ class GoodsManager $tra = Yii::$app->db->beginTransaction(); try { if (!$model->save()) { - throw new Exception(''); + 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('图片保存失败'); - } + 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]); @@ -87,60 +92,71 @@ class GoodsManager return ['status' => true]; } catch (\yii\base\Exception $e) { $tra->rollBack(); - return ['status' => false, 'info' => $e->getMessage()]; + throw new \Exception($e->getMessage()); } } /** * @param $data * @return bool - * @throws Exception + * @throws \Exception * 创建修改商品属性操作 */ - public static function addAttributeOperating($data) + private 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); + $tra = Yii::$app->db->beginTransaction(); + try { + if (!$data['attribute']) { + $tra->commit(); return true; } - foreach ($goodsAttr as $key => $value) { //把旧的商品属性保存到一个数组 - $oldAttr[$value->id] = $value->attr_value; + $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); + $tra->commit(); + 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'); + $newAttr = self::addAttribute($data['attribute'], $data['id']); //添加新的商品属性 + $delAttr = array_diff(array_keys($oldAttr), array_keys($newAttr)); //找出需要删除的goodsAttrId + if (!$delAttr) { + $tra->commit(); + 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'); + } } } + $tra->commit(); + return true; + } catch (\Exception $e) { + $tra->rollBack(); + throw new \Exception($e->getMessage()); } } /** * @param $goodsAttr - * @throws Exception + * @throws \Exception * 删除商品属性 */ - public static function delAttribute($goodsAttr) + private 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'); + throw new \Exception('goods attribute delete false'); } } } @@ -149,10 +165,10 @@ class GoodsManager * @param $attribute * @param $goodsId * @return array - * @throws Exception + * @throws \Exception * 保存商品属性 */ - public static function addAttribute($attribute, $goodsId) + private static function addAttribute($attribute, $goodsId) { $newAttr = []; if (!$attribute) { @@ -169,7 +185,7 @@ class GoodsManager $goodsAttrModel->goods_id = $goodsId; $goodsAttrModel->attr_value = $v; if (!$goodsAttrModel->save()) { - throw new Exception('goodsAttribute save false'); + throw new \Exception('goodsAttribute save false'); } $newAttr[$goodsAttrModel->id] = $goodsAttrModel->attr_value; //新增的数据 } @@ -306,29 +322,18 @@ class GoodsManager if ($attribute && $attribute->type == Attribute::TYPE_ATTR) { $ret['name'] = $attribute->name; $ret['id'] = $attribute->id; - $ret['attrValue'] = self::getAttrValue($attribute->id, $id); + $ret['attrValue'] = GoodsAttr::find() + ->select(['id', 'attr_value']) + ->where(['goods_id' => $id]) + ->andWhere(['attr_id' => $attribute->id]) + ->asArray() + ->all(); $attributes[] = $ret; } } return $attributes; } - /** - * @param $attrId - * @param $goodsId - * @return GoodsAttr[]|GoodsSku[]|array|File[]|\backend\modules\file\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 @@ -356,45 +361,53 @@ class GoodsManager /** * @param $sku - * @throws \yii\db\Exception + * @param $type + * @param $goodsId + * @throws \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('手动属性修改失败'); + $tra = Yii::$app->db->beginTransaction(); + try { + $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(); } - $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类型修改失败'); + if (!$attr || !$goodsSku || !$goodsModel) { + throw new \Exception('参数错误'); + } + if ($type == Goods::SKU_MODE_MANUAL) { + $attr->attr_value = $sku['value']; + if (!$attr->save()) { + throw new \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 \Exception('保存失败,请检查是否有重复规格'); + } + $goods = Goods::findOne($goodsId); + $goods->sku_mode = $type; + if (!$goods->save()) { + throw new \Exception('商品sku类型修改失败'); + } + } catch (\Exception $e) { + $tra->rollBack(); + throw new \Exception($e->getMessage()); } } @@ -433,9 +446,10 @@ class GoodsManager * @param $data * @return bool * @throws Exception + * @throws HttpException * 创建修改商品筛选属性操作 */ - public static function addFilterAttributeOperating($data) + private static function addFilterAttributeOperating($data) { if (!$data['filterAttribute']) { return true; @@ -462,7 +476,7 @@ class GoodsManager if ($model) { $model->is_delete = FilterAttr::IS_DELETE_YES; if (!$model->save()) { - throw new Exception('goodsAttribute delete false'); + throw new \Exception('goodsAttribute delete false'); } } } @@ -470,15 +484,15 @@ class GoodsManager /** * @param $goodsFilterAttr - * @throws Exception + * @throws HttpException * 删除商品筛选属性 */ - public static function delFilterAttribute($goodsFilterAttr) + private 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'); + throw new \Exception('goods attribute delete false'); } } } @@ -487,10 +501,10 @@ class GoodsManager * @param $attribute * @param $goodsId * @return array - * @throws Exception + * @throws \Exception * 保存商品筛选属性 */ - public static function addFilterAttribute($attribute, $goodsId) + private static function addFilterAttribute($attribute, $goodsId) { $newAttr = []; if (!$attribute) { @@ -507,7 +521,7 @@ class GoodsManager $goodsFilterAttrModel->goods_id = $goodsId; $goodsFilterAttrModel->attr_value = $v; if (!$goodsFilterAttrModel->save()) { - throw new Exception('goodsAttribute save false'); + throw new \Exception('goodsAttribute save false'); } $newAttr[$goodsFilterAttrModel->id] = $goodsFilterAttrModel->attr_value; //新增的数据 } @@ -549,7 +563,7 @@ class GoodsManager /** * @param $goodsModel * @return bool - * + * 判断该商品的sku是否存在已选属性,存在则返回true,表示不得删除 */ public static function judgeGoodsCategory($goodsModel) { From 8f0d66c18b3278dc0ac5e2082a0a8a1c107b1d25 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 15:43:15 +0800 Subject: [PATCH 41/41] =?UTF-8?q?=E5=BC=80=E5=8F=91=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=BF=90=E8=B4=B9=E6=A8=A1=E6=9D=BF=E5=88=A0=E9=99=A4=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index bac843f..7b712cb 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -2,19 +2,20 @@ namespace backend\modules\shop\controllers; -use backend\modules\shop\models\ars\City; -use backend\modules\shop\models\ars\Province; +use backend\modules\shop\models\ars\City; +use backend\modules\shop\models\ars\Province; use backend\modules\shop\models\searchs\ExpressAreaSearch; use Yii; -use backend\modules\shop\models\ars\ExpressTemplate; -use backend\modules\shop\models\searchs\ExpressTemplateSearch; -use yii\caching\Cache; +use backend\modules\shop\models\ars\ExpressTemplate; +use backend\modules\shop\models\searchs\ExpressTemplateSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\web\Response; use yii\widgets\ActiveForm; use backend\modules\shop\models\ars\ExpressArea; +use backend\modules\goods\models\ars\Goods; + /** * ExpressTemplateController implements the CRUD actions for ExpressTemplate model. @@ -112,7 +113,13 @@ class ExpressTemplateController extends Controller */ public function actionDelete($id) { - $this->findModel($id)->delete(); + if (Goods::find()->where(['express_template' => $id])->count() == 0) { + $expressTemplateModel = $this->findModel($id); + ExpressArea::deleteAll(['express_template' => $expressTemplateModel->id]); + $expressTemplateModel->delete(); + } else { + Yii::$app->session->setFlash('error', '该模板已被使用'); + } return $this->redirect(['index']); }