Lottery.php 4.7 KB

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