@@ -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';
= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
- = Html::a('返回', ['index'], ['class' => 'btn btn-info']) ?>
+ = Html::a('返回', ['express-area-list', 'id' => $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);
+?>
+
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);
?>
- = Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?>
+ = Html::a('返回列表', ['express-area-list?id='.$expressTemplateModel->id], ['class' => 'btn btn-success']) ?>
= DetailView::widget([
'model' => $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 @@
+
+= $form->field($model, 'coverImageId')->hiddenInput()->label('') ?>
+= $form->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('商品封面图') ?>
+
+= $form->field($model, 'detailImageId')->hiddenInput()->label('') ?>
+= $form->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';
?>
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';
?>
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) {
- ?>
-
-
-
-= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
-
-= $form->field($model, 'calculation_type')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculationType, 'type' => "radio"]) ?>
-
-= $form->field($model, 'basic_count')->textInput() ?>
+
\ 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 @@
-= $form->field($model, 'coverImageId')->hiddenInput()->label('') ?>
-= $form->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('商品封面图') ?>
-
-= $form->field($model, 'detailImageId')->hiddenInput()->label('') ?>
-= $form->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('商品详情图') ?>
+= $form->field($model, 'is_taking')->widget(Icheck::className(), ['items' => Goods::$isTaking, 'type' => 'radio']) ?>
+
+= $form->field($model, 'is_express')->widget(Icheck::className(), ['items' => Goods::$isExpress, 'type' => 'radio']) ?>
+
+
+ = $form->field($model, 'express_type')->widget(Icheck::className(), ['items' => Goods::$expressType, 'type' => 'radio']) ?>
+
+
+ = $form->field($model, 'uniform_postage')->textInput() ?>
+
+
+
+ = $form->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']);
}