Lottery.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\api\validate;
  3. use think\Validate;
  4. use app\common\Enum\LotteryEnum;
  5. class Lottery extends Validate
  6. {
  7. public function __construct(array $rules = [], $message = [], $field = [])
  8. {
  9. // 动态设置枚举值
  10. $this->rule['record_status'] = 'require|in:' . implode(',', LotteryEnum::getDrawStatusList());
  11. parent::__construct($rules, $message, $field);
  12. }
  13. /**
  14. * 验证规则
  15. */
  16. protected $rule = [
  17. 'lottery_id' => 'require|integer|gt:0',
  18. 'lottery_id_optional' => 'integer|gt:0', // 可选的lottery_id
  19. 'page' => 'integer|egt:1',
  20. 'pageSize' => 'integer|between:1,100',
  21. 'status' => 'integer|in:0,1,2,3',
  22. 'type' => 'array|length:1,10', // 奖品类型,数组且每个元素为整型
  23. 'type.*' => 'integer|length:1,10', // 奖品类型,数组且每个元素为整型
  24. 'win_record_id' => 'require|integer|gt:0',
  25. 'receiver_name' => 'require|length:2,20|chsAlphaNum',
  26. 'receiver_mobile' => 'require|regex:/^1[3-9]\d{9}$/',
  27. 'receiver_address' => 'require|length:10,200',
  28. 'province' => 'length:1,50',
  29. 'city' => 'length:1,50',
  30. 'district' => 'length:1,50',
  31. 'detail_address' => 'require|length:5,100',
  32. 'order_id' => 'require|integer|gt:0',
  33. 'draw_record_id' => 'require|integer|gt:0'
  34. ];
  35. /**
  36. * 提示消息
  37. */
  38. protected $message = [
  39. 'lottery_id.require' => '活动ID不能为空',
  40. 'lottery_id.integer' => '活动ID必须是整数',
  41. 'lottery_id.gt' => '活动ID必须大于0',
  42. 'lottery_id_optional.integer' => '活动ID必须是整数',
  43. 'lottery_id_optional.gt' => '活动ID必须大于0',
  44. 'page.integer' => '页码必须是整数',
  45. 'page.egt' => '页码必须大于等于1',
  46. 'pageSize.integer' => '每页数量必须是整数',
  47. 'pageSize.between' => '每页数量必须在1-100之间',
  48. 'status.integer' => '状态必须是整数',
  49. 'status.in' => '状态值不正确',
  50. 'record_status.integer' => '状态必须是整数',
  51. 'record_status.in' => '状态值不正确',
  52. 'type.array' => '奖品类型必须是数组格式',
  53. 'type.*.integer' => '奖品类型数组中的每个元素必须是整型',
  54. 'type.*.length' => '奖品类型数组中的每个元素长度必须在1-10之间',
  55. 'win_record_id.require' => '中奖记录ID不能为空',
  56. 'win_record_id.integer' => '中奖记录ID必须是整数',
  57. 'win_record_id.gt' => '中奖记录ID必须大于0',
  58. 'receiver_name.require' => '收货人姓名不能为空',
  59. 'receiver_name.length' => '收货人姓名长度必须在2-20个字符之间',
  60. 'receiver_name.chsAlphaNum' => '收货人姓名只能包含中文、字母和数字',
  61. 'receiver_mobile.require' => '收货人手机号不能为空',
  62. 'receiver_mobile.regex' => '收货人手机号格式不正确',
  63. 'receiver_address.require' => '收货地址不能为空',
  64. 'receiver_address.length' => '收货地址长度必须在10-200个字符之间',
  65. 'province.length' => '省份名称不能超过50个字符',
  66. 'city.length' => '城市名称不能超过50个字符',
  67. 'district.length' => '区县名称不能超过50个字符',
  68. 'detail_address.require' => '详细地址不能为空',
  69. 'detail_address.length' => '详细地址长度必须在5-100个字符之间',
  70. 'order_id.require' => '订单ID不能为空',
  71. 'order_id.integer' => '订单ID必须是整数',
  72. 'order_id.gt' => '订单ID必须大于0',
  73. 'draw_record_id.require' => '抽奖记录ID不能为空',
  74. 'draw_record_id.integer' => '抽奖记录ID必须是整数',
  75. 'draw_record_id.gt' => '抽奖记录ID必须大于0'
  76. ];
  77. /**
  78. * 验证场景
  79. */
  80. protected $scene = [
  81. // 获取活动列表(所有参数都可选)
  82. 'activityList' => ['page', 'limit', 'status'],
  83. // 获取活动详情(lottery_id必填)
  84. 'activityDetail' => ['lottery_id'],
  85. // 执行抽奖(lottery_id必填)
  86. 'draw' => ['lottery_id'],
  87. // 获取用户抽奖机会(lottery_id必填)
  88. 'getUserChances' => ['lottery_id'],
  89. // 获取用户抽奖记录( 可选,page和pageSize可选)
  90. 'getDrawRecords' => ['lottery_id_optional', 'page', 'pageSize', 'record_status'],
  91. // 获取用户中奖记录(page和pageSize可选)
  92. 'getWinRecords' => ['page', 'pageSize'],
  93. // 设置中奖记录收货地址(所有地址相关字段必填)
  94. 'setWinRecordAddress' => ['win_record_id', 'receiver_name', 'receiver_mobile', 'receiver_address'],
  95. // 设置详细收货地址(包含省市区)
  96. 'setDetailAddress' => ['win_record_id', 'receiver_name', 'receiver_mobile', 'province', 'city', 'district', 'detail_address'],
  97. // 获取活动排行榜(lottery_id必填,page和pageSize可选)
  98. 'getRanking' => ['lottery_id', 'page', 'pageSize'],
  99. // 获取奖品列表(lottery_id可选,page、pageSize、type可选)
  100. 'getPrizes' => ['lottery_id_optional', 'page', 'pageSize', 'type'],
  101. // 获取订单完成后分发抽奖机会
  102. 'getLotteryChanceByOrder' => ['order_id'],
  103. // 获取抽奖记录详情
  104. 'getDrawRecordDetail' => ['draw_record_id']
  105. ];
  106. }