|
|
<?php
namespace backend\models\ars;
use Yii; use yii\behaviors\TimestampBehavior;
/** * This is the model class for table "ats_express_template". * * @property int $id * @property string $name 名称 * @property string $province 省份 * @property string $city 城市 * @property string $area 区域 * @property int $calculation 计算方式 * @property int $basic_price 基本运费 * @property int $basic_amount 基本数量 * @property int $extra_price 续重运费 * @property int $extra_amount 续重数量 * @property int $updated_at 更新时间 * @property int $created_at 创建时间 */ class ExpressTemplate extends \yii\db\ActiveRecord { //计算方式calculation
const CALCULATION_WEIGHT = 1; //按重量
const CALCULATION_NUMBER = 2; //按件数
public static $calculation = [ self::CALCULATION_WEIGHT => '按重量', self::CALCULATION_NUMBER => '按件数' ]; /** * {@inheritdoc} */ public static function tableName() { return 'ats_express_template'; }
/** * {@inheritdoc} */ public function rules() { return [ [['name', 'calculation', 'basic_price', 'basic_amount'], 'required'], [['province', 'city', 'area', 'basic_price', 'extra_price', 'basic_amount', 'extra_amount'], 'string'], [['calculation'], '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} */ public function attributeLabels() { return [ 'id' => 'id', 'name' => '名称', 'province' => '省份', 'city' => '城市', 'area' => '区域', 'calculation' => '计算方式', 'basic_price' => '基本运费', 'basic_amount' => '基本数量', 'extra_price' => '续重运费', 'extra_amount' => '续重数量', '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(); }, ], ]; } }
|