You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.9 KiB

  1. <?php
  2. namespace backend\models\ars;
  3. use Yii;
  4. use yii\behaviors\TimestampBehavior;
  5. /**
  6. * This is the model class for table "ats_express_template".
  7. *
  8. * @property int $id
  9. * @property string $name 名称
  10. * @property string $province 省份
  11. * @property string $city 城市
  12. * @property string $area 区域
  13. * @property int $calculation 计算方式
  14. * @property int $basic_price 基本运费
  15. * @property int $basic_amount 基本数量
  16. * @property int $extra_price 续重运费
  17. * @property int $extra_amount 续重数量
  18. * @property int $updated_at 更新时间
  19. * @property int $created_at 创建时间
  20. */
  21. class ExpressTemplate extends \yii\db\ActiveRecord
  22. {
  23. //计算方式calculation
  24. const CALCULATION_WEIGHT = 1; //按重量
  25. const CALCULATION_NUMBER = 2; //按件数
  26. public static $calculation = [
  27. self::CALCULATION_WEIGHT => '按重量',
  28. self::CALCULATION_NUMBER => '按件数'
  29. ];
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public static function tableName()
  34. {
  35. return 'ats_express_template';
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['name', 'calculation', 'basic_price', 'basic_amount'], 'required'],
  44. [['province', 'city', 'area', 'basic_price', 'extra_price', 'basic_amount', 'extra_amount'], 'string'],
  45. [['calculation'], 'integer'],
  46. [['name'], 'string', 'max' => 255],
  47. [['basic_amount', 'basic_price', 'extra_price', 'extra_amount'], 'checkNegative'],
  48. ];
  49. }
  50. /**
  51. * @param $attribute
  52. * @param $params
  53. * 验证是否为负数
  54. */
  55. public function checkNegative($attribute, $params)
  56. {
  57. if ($this->$attribute < 0) {
  58. $this->addError($attribute, "不得为负数");
  59. }
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function attributeLabels()
  65. {
  66. return [
  67. 'id' => 'id',
  68. 'name' => '名称',
  69. 'province' => '省份',
  70. 'city' => '城市',
  71. 'area' => '区域',
  72. 'calculation' => '计算方式',
  73. 'basic_price' => '基本运费',
  74. 'basic_amount' => '基本数量',
  75. 'extra_price' => '续重运费',
  76. 'extra_amount' => '续重数量',
  77. 'updated_at' => '更新时间',
  78. 'created_at' => '创建时间',
  79. ];
  80. }
  81. /**
  82. * @author linyao
  83. * @email 602604991@qq.com
  84. * @created Nov 8, 2019
  85. *
  86. * 行为存储创建时间和更新时间
  87. */
  88. public function behaviors()
  89. {
  90. return [
  91. [
  92. 'class' => TimestampBehavior::className(),
  93. 'createdAtAttribute' => 'created_at',
  94. 'updatedAtAttribute' => 'updated_at',
  95. 'value' => function() {
  96. return time();
  97. },
  98. ],
  99. ];
  100. }
  101. }