adjustUserWallet.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\adminapi\validate\user;
  20. use app\common\{
  21. model\User,
  22. validate\BaseValidate
  23. };
  24. /**
  25. * 调整用户钱包验证器
  26. * Class AdjustUserEarnings
  27. * @package app\adminapi\validate\user
  28. */
  29. class adjustUserWallet extends BaseValidate
  30. {
  31. protected $rule = [
  32. 'user_id' => 'require',
  33. 'type' => 'require|in:1,2,3',
  34. 'action' => 'require|in:0,1',
  35. 'num' => 'require|gt:0|checkNum',
  36. 'remark' => 'max:128',
  37. ];
  38. protected $message = [
  39. 'id.require' => '请选择用户',
  40. 'type.require' => '请选择变动类型',
  41. 'type.in' => '变动类型错误',
  42. 'action.require' => '请选择调整类型',
  43. 'action.in' => '调整类型错误',
  44. 'num.require' => '请输入调整数量',
  45. 'num.gt' => '调整余额必须大于零',
  46. 'remark' => '备注不可超过128个符号',
  47. ];
  48. protected function checkNum($vaule,$rule,$data){
  49. $user = User::find($data['user_id']);
  50. if(empty($user)){
  51. return '用户不存在';
  52. }
  53. if ($user['user_delete']) {
  54. return '用户已注销,不能操作';
  55. }
  56. if(1 == $data['action']){
  57. return true;
  58. }
  59. switch ($data['type']){
  60. case 1:
  61. $surplusMoeny = $user->user_money - $vaule;
  62. if($surplusMoeny < 0){
  63. return '用户可用余额仅剩'.$user->user_money;
  64. }
  65. break;
  66. case 2:
  67. $surplusMoeny = $user->user_earnings - $vaule;
  68. if($surplusMoeny < 0){
  69. return '用户可提现金额仅剩'.$user->user_earnings;
  70. }
  71. break;
  72. case 3:
  73. $surplusIntegral = $user->user_integral - $vaule;
  74. if($surplusIntegral < 0){
  75. return '用户积分仅剩'.$user->user_earnings;
  76. }
  77. break;
  78. }
  79. return true;
  80. }
  81. }