UpdateHbForm.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace hd\models\hb;
  3. use hd\models\BaseForm;
  4. /**
  5. * 更新红包表单模型
  6. *
  7. * 仅暴露允许更新的字段,避免被恶意修改 shopId/mainId 等敏感字段。
  8. */
  9. class UpdateHbForm extends BaseForm
  10. {
  11. /** @var int 红包ID */
  12. public $id;
  13. /** @var int 红包状态(-1 作废,0 未使用,1 已使用) */
  14. public $status;
  15. /** @var float 红包金额 */
  16. public $amount;
  17. /** @var float 最低消费金额 */
  18. public $minConsume;
  19. /** @var int 生效时间 */
  20. public $beginTime;
  21. /** @var int 失效时间 */
  22. public $endTime;
  23. /** @var int 预期失效时间 */
  24. public $willTime;
  25. /** @var int 有效天数 */
  26. public $duration;
  27. /** @var string 备注 */
  28. public $remark;
  29. /** @var int 订单ID */
  30. public $orderId;
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['id'], 'required', 'message' => '红包ID不能为空'],
  38. [['id'], 'integer', 'min' => 1, 'tooSmall' => '红包ID参数错误'],
  39. [['status'], 'in', 'range' => [-1, 0, 1], 'message' => '红包状态不正确'],
  40. [['beginTime', 'endTime', 'willTime'], 'integer', 'min' => 0, 'tooSmall' => '{attribute}必须大于等于0'],
  41. [['duration'], 'integer', 'min' => 0, 'max' => 3650, 'tooSmall' => '有效天数必须大于等于0', 'tooBig' => '有效天数过大'],
  42. [['amount'], 'number', 'min' => 0.01, 'tooSmall' => '{attribute}不能小于0.01'],
  43. [['minConsume'], 'number', 'min' => 0.00, 'tooSmall' => '{attribute}不能小于0'],
  44. [['remark'], 'default', 'value' => ''],
  45. [['remark'], 'filter', 'filter' => 'trim'],
  46. [['remark'], 'string'],
  47. //[['orderId'], 'default', 'value' => 0],
  48. [['orderId'], 'integer', 'min' => 1],
  49. [['orderId'], 'required', 'when' => function ($model) {
  50. return $model->status == 0;
  51. }, 'message' => '订单ID不能为空'],
  52. ];
  53. }
  54. /**
  55. * 获取属性标签
  56. * @return array
  57. */
  58. public function attributeLabels()
  59. {
  60. return [
  61. 'id' => '红包ID',
  62. 'status' => '红包状态',
  63. 'amount' => '红包金额',
  64. 'minConsume' => '最低消费金额',
  65. 'beginTime' => '生效时间',
  66. 'endTime' => '失效时间',
  67. 'willTime' => '预期失效时间',
  68. 'duration' => '有效天数',
  69. 'remark' => '备注',
  70. 'orderId' => '订单ID',
  71. ];
  72. }
  73. }