Browse Source

修改运费模板字段

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
994df981d6
  1. 4
      backend/controllers/ExpressTemplateController.php
  2. 25
      backend/views/express-template/view.php
  3. 19
      common/models/ars/ExpressTemplate.php

4
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;

25
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);
},
],
],
]) ?>

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

Loading…
Cancel
Save