123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\FrontController;
- use App\Models\Member;
- use App\Models\Withdraw;
- use App\Models\WithdrawConfig;
- use App\Servers\RedisDataServer;
- use App\Servers\WithdrawServer;
- use Illuminate\Support\Carbon;
- class WithdrawController extends FrontController
- {
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * 获取提现配置信息
- * @return \Illuminate\Http\JsonResponse
- */
- function getWithdrawConfig()
- {
- $coin_id = request()->get('coin_id', '1');
- if (empty($coin_id)) {
- return $this->apiResponseError('缺少必要参数');
- }
- $withdraw_config = WithdrawConfig::where('id', 1)->select(['id','mix_money','proportion'])->first();
- return $this->apiResponseSuccess( '获取数据成功',$withdraw_config);
- }
- /**
- * 用户提现申请
- * @return \Illuminate\Http\JsonResponse
- */
- function setWithdraw()
- {
- //redis访问频率限制
- $m_id=request()->member['id'];
- $redis_on_name = 'add_withdraw' . $m_id;
- $redis_time = RedisDataServer::creatServer()->getData($redis_on_name);
- $time=time();
- if(!empty($redis_time) && $redis_time >$time-3){
- return $this->apiResponseError( '请不要频繁申请转账');
- }
- RedisDataServer::creatServer()->setData($redis_on_name,$time,'str',3,false);
- $pay_pass = request()->input('pay_pass', '');
- // if (empty($pay_pass)) {
- // return $this->apiResponseError('请输入支付密码');
- // }
- $member = Member::where('id', $m_id)->select(['id', 'pay_pass', 'encrypt','money'])->first();
- if (empty($member)) {
- return $this->apiResponseError( '账户信息错误');
- }
- // if (empty($member->{'pay_pass'})) {
- // return $this->apiResponseError( '请设置支付密码',[],101);
- // }
- // if (!PassServer::creatServer($pay_pass,$member->{'encrypt'})->verifyPass($member->{'pay_pass'})) {
- // return $this->apiResponseError( '支付密码错误');
- // }
- $money = request()->get('money', '');
- if (empty($money)) {
- return $this->apiResponseError('请输入提现金额');
- }
- $mix_money = WithdrawConfig::where('coin_id', 1)->value('mix_money');
- if (!empty($mix_money) && $mix_money > 0 && $mix_money>$money) {
- return $this->apiResponseError('最低提现:' . $mix_money);
- }
- $money=$money*1;
- if(!is_numeric($money) || $money<=0){
- return $this->apiResponseError('转账金额不合法');
- }
- if ($member->{'money'} < $money) {
- return $this->apiResponseError( '会员余额不足');
- }
- $ret = WithdrawServer::creatServer()->setWithdraw($member, $money);
- if (empty($ret)) {
- return $this->apiResponseError('操作失败');
- }
- return $this->apiResponseSuccess( '提现申请成功');
- }
- /**
- * 提现列表
- * @return \Illuminate\Http\JsonResponse
- */
- public function index()
- {
- $details = Withdraw::where('m_id', request()->member['id'])
- ->select(['id','created_at','status','m_id','money','service_money','withdraw_money'])
- ->orderBy('id', 'desc')
- ->paginate(20);
- foreach ($details as $key => $detail) {
- $detail['status_str'] = WithdrawServer::creatServer()->getStatusArr($detail->status);
- $detail['created_date'] = Carbon::parse($detail->created_at, config('app.timezone'))->format('Y/m/d H:i'); // 时间
- }
- return $this->apiResponseSuccess('获取数据成功', ['total' => $details->total(), 'list' => $details->items()]);
- }
- }
|