Withdraw.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\api\validate;
  3. use think\Validate;
  4. class Withdraw extends Validate
  5. {
  6. protected $rule = [
  7. 'type' => 'require|in:wechat,alipay,bank',
  8. 'amount' => 'require|float|gt:0',
  9. 'account_id' => 'require|integer|gt:0',
  10. 'withdraw_sn' => 'require',
  11. 'status' => 'integer|in:-3,-2,-1,0,1,2',
  12. 'page' => 'integer|egt:1',
  13. 'page_size' => 'integer|between:1,100',
  14. 'year_month' => 'checkYearMonth',
  15. ];
  16. protected $message = [
  17. 'type.require' => '请选择提现类型',
  18. 'type.in' => '请选择正确的提现类型',
  19. 'amount.require' => '请输入提现金额',
  20. 'amount.float' => '请输入正确的提现金额',
  21. 'amount.gt' => '请输入正确的提现金额',
  22. 'account_id.require' => '请选择提现账户',
  23. 'account_id.integer' => '账户ID必须为整数',
  24. 'account_id.gt' => '请选择正确的提现账户',
  25. 'withdraw_sn.require' => '未找到您的提现信息',
  26. 'status.integer' => '状态必须为整数',
  27. 'status.in' => '请选择正确的状态',
  28. 'page.integer' => '页码必须为整数',
  29. 'page.egt' => '页码必须大于等于1',
  30. 'page_size.integer' => '分页大小必须为整数',
  31. 'page_size.between' => '分页大小必须在1-100之间',
  32. 'year_month.checkYearMonth' => '年月格式错误,请使用YYYY-MM格式,如2025-08',
  33. ];
  34. protected $scene = [
  35. 'index' => ['status', 'page', 'page_size', 'year_month'],
  36. 'apply' => ['type', 'amount', 'account_id'],
  37. 'transfer' => ['type', 'withdraw_sn'],
  38. 'retry' => ['type', 'withdraw_sn'],
  39. 'cancel' => ['type', 'withdraw_sn'],
  40. ];
  41. /**
  42. * 验证年月格式 (YYYY-MM)
  43. * @param string $value
  44. * @param string $rule
  45. * @param array $data
  46. * @return bool|string
  47. */
  48. protected function checkYearMonth($value, $rule, $data)
  49. {
  50. if (empty($value)) {
  51. return true; // 允许为空
  52. }
  53. // 验证格式 YYYY-MM
  54. if (!preg_match('/^\d{4}-\d{2}$/', $value)) {
  55. return '年月格式错误,请使用YYYY-MM格式,如2025-08';
  56. }
  57. list($year, $month) = explode('-', $value);
  58. $year = (int)$year;
  59. $month = (int)$month;
  60. // 验证年份范围(不限制具体范围,只要是4位数字即可)
  61. if ($year < 1000 || $year > 9999) {
  62. return '年份必须是4位数字';
  63. }
  64. // 验证月份范围
  65. if ($month < 1 || $month > 12) {
  66. return '月份必须在01-12之间';
  67. }
  68. return true;
  69. }
  70. }