SendHbRuleItemForm.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace hd\models\hb;
  3. use hd\models\BaseForm;
  4. /**
  5. * 充值送红包规则项表单模型
  6. */
  7. class SendHbRuleItemForm extends BaseForm
  8. {
  9. /** @var int 红包金额 */
  10. public $hbAmount;
  11. /** @var int 红包张数 */
  12. public $hbNum;
  13. /** @var int 最低消费金额(0 表示不限制) */
  14. public $miniCost;
  15. /** @var int 有效天数(0 表示永不过期) */
  16. public $duration;
  17. /** @var int 生效类型
  18. * 1: 日期 2: 天数
  19. */
  20. public $effectiveType;
  21. /** @var string 生效日期 */
  22. public $effectiveDate;
  23. /** @var int 生效天数 */
  24. public $effectiveDays;
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['miniCost', 'duration'], 'default', 'value' => 0],
  32. [['hbAmount'], 'required', 'message' => '请填写红包金额'],
  33. // 注意:不要对字段做 intval 过滤,避免 "abc" 被转成 0 导致校验绕过
  34. [['hbAmount'], 'number', 'min' => 0.01, 'tooSmall' => '{attribute}必须大于等于0.01'],
  35. [['hbNum', 'miniCost'], 'integer', 'message' => '{attribute}必须为正整数', 'min' => 0, 'tooSmall' => '{attribute}不能小于0'],
  36. [['duration'], 'integer', 'min' => 0, 'max' => 3650, 'tooSmall' => '{attribute}不能小于0', 'tooBig' => '{attribute}过大'],
  37. [['effectiveType'], 'in', 'range' => [1, 2]],
  38. [['effectiveDate'], 'default', 'value' => null],
  39. [['effectiveDate'], 'filter', 'filter' => function($value) {
  40. return $value === '0000-00-00' ? null : $value;
  41. }],
  42. [['effectiveDate'], 'datetime', 'format' => 'php:Y-m-d'],
  43. [['effectiveDays'], 'integer', 'min' => 0, 'max' => 365, 'tooSmall' => '{attribute}不能小于0', 'tooBig' => '{attribute}过大'],
  44. ];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function attributeLabels()
  50. {
  51. return [
  52. 'hbAmount' => '红包金额',
  53. 'hbNum' => '红包数量',
  54. 'miniCost' => '最低消费金额',
  55. 'duration' => '有效天数',
  56. 'effectiveType' => '生效类型',
  57. 'effectiveDate' => '生效日期',
  58. 'effectiveDays' => '生效天数',
  59. ];
  60. }
  61. }