From 994df981d6a487c4aeb6eb99f39254ff911b4c68 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Wed, 4 Dec 2019 15:17:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=90=E8=B4=B9=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 4 ++- backend/views/express-template/view.php | 25 ++++++++++++++----- common/models/ars/ExpressTemplate.php | 19 +++++++++++--- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/backend/controllers/ExpressTemplateController.php b/backend/controllers/ExpressTemplateController.php index bcd97c2..40926f9 100644 --- a/backend/controllers/ExpressTemplateController.php +++ b/backend/controllers/ExpressTemplateController.php @@ -72,9 +72,11 @@ class ExpressTemplateController extends Controller { $model = new ExpressTemplate(); $model->calculation = ExpressTemplate::CALCULATION_NUMBER; + $model->basic_amount = 0; + $model->basic_price = '0.00'; if (Yii::$app->request->isPost) { - $data = Yii::$app->request->post('ExpressTemplate'); + $data = Yii::$app->request->post('ExpressTemplate');d($data);die(); if (Yii::$app->request->isAjax) { $model->load($data, ''); Yii::$app->response->format = Response::FORMAT_JSON; diff --git a/backend/views/express-template/view.php b/backend/views/express-template/view.php index 5fd222f..2c314b4 100644 --- a/backend/views/express-template/view.php +++ b/backend/views/express-template/view.php @@ -2,6 +2,7 @@ use yii\helpers\Html; use yii\widgets\DetailView; +use common\models\ars\ExpressTemplate; /* @var $this yii\web\View */ /* @var $model common\models\ars\ExpressTemplate */ @@ -22,16 +23,28 @@ $this->params['breadcrumbs'][] = $this->title; 'attributes' => [ 'id', 'name', - 'province:ntext', - 'city:ntext', - 'area:ntext', - 'calculation', + [ + 'attribute' => 'calculation', + 'value' => function ($model) { + return ExpressTemplate::$calculation[$model->calculation]; + } + ], 'basic_price', 'basic_amount', 'extra_price', 'extra_amount', - 'updated_at', - 'created_at', + 'updated_at:datetime', + 'created_at:datetime', + ['attribute' => 'city', + 'value' => function ($model) { + $array = explode(',', $model->city); + $cities = []; + foreach (\common\models\ars\City::find()->andWhere(['in', 'city_id', $array])->all() as $city) { + $cities[] = $city->name; + } + return implode(' // ', $cities); + }, + ], ], ]) ?> diff --git a/common/models/ars/ExpressTemplate.php b/common/models/ars/ExpressTemplate.php index bea17f0..1610500 100644 --- a/common/models/ars/ExpressTemplate.php +++ b/common/models/ars/ExpressTemplate.php @@ -45,13 +45,26 @@ class ExpressTemplate extends \yii\db\ActiveRecord public function rules() { return [ - [['name', 'calculation'], 'required'], - [['province', 'city', 'area'], 'string'], - [['calculation', 'basic_price', 'basic_amount', 'extra_price', 'extra_amount'], 'integer'], + [['name', 'calculation', 'basic_price', 'basic_amount'], 'required'], + [['province', 'city', 'area', 'basic_price', 'extra_price'], 'string'], + [['calculation', 'basic_amount', 'extra_amount'], 'integer'], [['name'], 'string', 'max' => 255], + [['basic_amount', 'basic_price', 'extra_price', 'extra_amount'], 'checkNegative'], ]; } + /** + * @param $attribute + * @param $params + * 验证是否为负数 + */ + public function checkNegative($attribute, $params) + { + if ($this->$attribute < 0) { + $this->addError($attribute, "不得为负数"); + } + } + /** * {@inheritdoc} */