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} */