WithdrawController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\FrontController;
  4. use App\Models\Member;
  5. use App\Models\Withdraw;
  6. use App\Models\WithdrawConfig;
  7. use App\Servers\RedisDataServer;
  8. use App\Servers\WithdrawServer;
  9. use Illuminate\Support\Carbon;
  10. class WithdrawController extends FrontController
  11. {
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. /**
  17. * 获取提现配置信息
  18. * @return \Illuminate\Http\JsonResponse
  19. */
  20. function getWithdrawConfig()
  21. {
  22. $coin_id = request()->get('coin_id', '1');
  23. if (empty($coin_id)) {
  24. return $this->apiResponseError('缺少必要参数');
  25. }
  26. $withdraw_config = WithdrawConfig::where('id', 1)->select(['id','mix_money','proportion'])->first();
  27. return $this->apiResponseSuccess( '获取数据成功',$withdraw_config);
  28. }
  29. /**
  30. * 用户提现申请
  31. * @return \Illuminate\Http\JsonResponse
  32. */
  33. function setWithdraw()
  34. {
  35. //redis访问频率限制
  36. $m_id=request()->member['id'];
  37. $redis_on_name = 'add_withdraw' . $m_id;
  38. $redis_time = RedisDataServer::creatServer()->getData($redis_on_name);
  39. $time=time();
  40. if(!empty($redis_time) && $redis_time >$time-3){
  41. return $this->apiResponseError( '请不要频繁申请转账');
  42. }
  43. RedisDataServer::creatServer()->setData($redis_on_name,$time,'str',3,false);
  44. $pay_pass = request()->input('pay_pass', '');
  45. // if (empty($pay_pass)) {
  46. // return $this->apiResponseError('请输入支付密码');
  47. // }
  48. $member = Member::where('id', $m_id)->select(['id', 'pay_pass', 'encrypt','money'])->first();
  49. if (empty($member)) {
  50. return $this->apiResponseError( '账户信息错误');
  51. }
  52. // if (empty($member->{'pay_pass'})) {
  53. // return $this->apiResponseError( '请设置支付密码',[],101);
  54. // }
  55. // if (!PassServer::creatServer($pay_pass,$member->{'encrypt'})->verifyPass($member->{'pay_pass'})) {
  56. // return $this->apiResponseError( '支付密码错误');
  57. // }
  58. $money = request()->get('money', '');
  59. if (empty($money)) {
  60. return $this->apiResponseError('请输入提现金额');
  61. }
  62. $mix_money = WithdrawConfig::where('coin_id', 1)->value('mix_money');
  63. if (!empty($mix_money) && $mix_money > 0 && $mix_money>$money) {
  64. return $this->apiResponseError('最低提现:' . $mix_money);
  65. }
  66. $money=$money*1;
  67. if(!is_numeric($money) || $money<=0){
  68. return $this->apiResponseError('转账金额不合法');
  69. }
  70. if ($member->{'money'} < $money) {
  71. return $this->apiResponseError( '会员余额不足');
  72. }
  73. $ret = WithdrawServer::creatServer()->setWithdraw($member, $money);
  74. if (empty($ret)) {
  75. return $this->apiResponseError('操作失败');
  76. }
  77. return $this->apiResponseSuccess( '提现申请成功');
  78. }
  79. /**
  80. * 提现列表
  81. * @return \Illuminate\Http\JsonResponse
  82. */
  83. public function index()
  84. {
  85. $details = Withdraw::where('m_id', request()->member['id'])
  86. ->select(['id','created_at','status','m_id','money','service_money','withdraw_money'])
  87. ->orderBy('id', 'desc')
  88. ->paginate(20);
  89. foreach ($details as $key => $detail) {
  90. $detail['status_str'] = WithdrawServer::creatServer()->getStatusArr($detail->status);
  91. $detail['created_date'] = Carbon::parse($detail->created_at, config('app.timezone'))->format('Y/m/d H:i'); // 时间
  92. }
  93. return $this->apiResponseSuccess('获取数据成功', ['total' => $details->total(), 'list' => $details->items()]);
  94. }
  95. }