WithdrawValidate.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\validate;
  20. use app\common\enum\WithdrawEnum;
  21. use app\common\model\User;
  22. use app\common\service\ConfigService;
  23. use app\common\validate\BaseValidate;
  24. /**
  25. * 提现验证器
  26. * Class WithdrawValidate
  27. * @package app\shopapi\validate
  28. */
  29. class WithdrawValidate extends BaseValidate
  30. {
  31. protected $rule = [
  32. 'id' => 'require',
  33. 'type' => 'require|in:1,2,3,4,5',
  34. 'money' => 'require|gt:0|checkMoney',
  35. 'account' => 'requireIf:type,3|requireIf:type,4|requireIf:type,5',
  36. 'real_name' => 'requireIf:type,3|requireIf:type,4|requireIf:type,5|chs',
  37. 'money_qr_code' => 'requireIf:type,4|requireIf:type,5',
  38. 'bank' => 'requireIf:type,3',
  39. 'subbank' => 'requireIf:type,3',
  40. ];
  41. protected $message = [
  42. 'id.require' => '参数缺失',
  43. 'type.require' => '请选择提现类型',
  44. 'type.in' => '提现类型状态值错误',
  45. 'money.require' => '请输入提现金额',
  46. 'money.gt' => '提现金额须大于0',
  47. 'account.requireIf' => '请输入提现账号',
  48. 'real_name.requireIf' => '请输入真实姓名',
  49. 'real_name.chs' => '真实姓名须为中文',
  50. 'money_qr_code.requireIf' => '请上传收款码',
  51. 'bank.requireIf' => '请输入提现银行',
  52. 'subbank.requireIf' => '请输入银行支行',
  53. ];
  54. /**
  55. * @notes 提现申请场景
  56. * @return WithdrawValidate
  57. * @author Tab
  58. * @date 2021/8/6 17:15
  59. */
  60. public function sceneApply()
  61. {
  62. return $this->only(['type', 'money', 'account', 'real_name', 'money_qr_code', 'bank', 'subbank']);
  63. }
  64. /**
  65. * @notes 提现申请详情场景
  66. * @return WithdrawValidate
  67. * @author Tab
  68. * @date 2021/8/6 19:02
  69. */
  70. public function sceneDetail()
  71. {
  72. return $this->only(['id']);
  73. }
  74. /**
  75. * @notes 校验提现金额
  76. * @param $value
  77. * @param $rule
  78. * @param $data
  79. * @return bool|string
  80. * @author Tab
  81. * @date 2021/8/6 17:22
  82. */
  83. protected function checkMoney($value, $rule, $data)
  84. {
  85. // 可提现金额是否充足
  86. $user_earnings = User::where('id', $data['user_id'])->value('user_earnings');
  87. $user_earnings = is_null($user_earnings) ? 0 : $user_earnings;
  88. if ($value > $user_earnings){
  89. return '可提现金额不足';
  90. }
  91. // 最低提现金额
  92. $min_withdraw = ConfigService::get('config', 'withdraw_min_money', WithdrawEnum::DEFAULT_MIN_MONEY);
  93. if($value < $min_withdraw){
  94. return '最低提现'.$min_withdraw.'元';
  95. }
  96. // 最高提现金额
  97. $max_withdraw = ConfigService::get('config', 'withdraw_max_money', WithdrawEnum::DEFAULT_MAX_MONEY);
  98. if ($value > $max_withdraw){
  99. return '最高提现'.$max_withdraw.'元';
  100. }
  101. return true;
  102. }
  103. }