user; $moneylogs = (new UserMoneyLog()) ->where('user_id', $user->id) ->where('type', '!=', 6) ->orderBy('id', 'desc') ->get(); foreach ($moneylogs as $moneylog) { $moneylog->create_time = Tools::toDateTime($moneylog->create_time); } $moneylog_count = $moneylogs->count(); return $response->write( $this->view() ->assign('moneylogs', $moneylogs) ->assign('moneylog_count', $moneylog_count) ->fetch('user/money.tpl') ); } public function applyGiftCard(ServerRequest $request, Response $response, array $args): ResponseInterface { $giftcard_raw = $this->antiXss->xss_clean($request->getParam('giftcard')); $giftcard = (new GiftCard())->where('card', $giftcard_raw)->first(); if ($giftcard === null || $giftcard->status !== 0) { return $response->withJson([ 'ret' => 0, 'msg' => '礼品卡无效', ]); } $user = $this->user; if ($user->is_shadow_banned) { return $response->withJson([ 'ret' => 0, 'msg' => '礼品卡无效', ]); } $giftcard->status = 1; $giftcard->use_time = time(); $giftcard->use_user = $user->id; $giftcard->save(); $money_before = $user->money; $user->money += $giftcard->balance; $user->save(); (new UserMoneyLog())->add( $user->id, $money_before, (float) $user->money, $giftcard->balance, '礼品卡充值 ' . $giftcard->card ); return $response->withJson([ 'ret' => 1, 'msg' => '充值成功', ]); } public function affToBanlance(ServerRequest $request, Response $response, array $args): ResponseInterface { $amount = (float) $this->antiXss->xss_clean($request->getParam('amount')); if ($amount > $this->user->money_aff || $amount <= 0.01) { return $response->withJson([ 'ret' => 0, 'msg' => "提款金额错误", ]); } //入账 $money_before = $this->user->money; $this->user->money += $amount; $this->user->money_aff -= $amount; $this->user->save(); (new UserMoneyLog())->add( $this->user->id, $money_before, $this->user->money, $amount, '返利划转至余额', 7 ); return $response->withJson([ 'ret' => 1, 'msg' => '提现成功', ]); } public function drawToUsdt(ServerRequest $request, Response $response, array $args): ResponseInterface { $amount = (float) $this->antiXss->xss_clean($request->getParam('num')); $type = (int) $this->antiXss->xss_clean($request->getParam('type')); $usdtAddr = $this->user->usdt_addr; if ($this->user->money_aff < $_ENV['aff_draw_need']) { return $response->withJson([ 'ret' => 0, 'msg' => "不满足提现条件", ]); } if ($amount < $_ENV['aff_draw_need']) { return $response->withJson([ 'ret' => 0, 'msg' => "提现金额不能小于".$_ENV['aff_draw_need'], ]); } if (empty($usdtAddr)) { return $response->withJson([ 'ret' => 0, 'msg' => '请填写USDT提款地址', ]); } if ($amount > $this->user->money_aff || $amount <= 0.01) { return $response->withJson([ 'ret' => 0, 'msg' => "提款金额错误", ]); } $bHaveDrawWait = (new draw())->where('user_id', $this->user->id)->exists(); if ($bHaveDrawWait) { return $response->withJson([ 'ret' => 0, 'msg' => "请勿重复提交", ]); } // 扣款从aff余额 // $money_before = $this->user->money; // $this->user->money_aff -= $amount; // $this->user->save(); // 进入等待draw $modelDraw = new Draw(); $modelDraw->user_id = $this->user->id; $modelDraw->amount = $amount; $modelDraw->user_mail = $this->user->email; $modelDraw->addr = $usdtAddr; $modelDraw->addr_type = 'usdt'; $modelDraw->save(); return $response->withJson([ 'ret' => 1, 'msg' => "提现申请已提交,请等待审核。", ]); } public function cancelDraw(ServerRequest $request, Response $response, array $args): ResponseInterface { // $oModelDraw = new Draw(); // $iDrawAmount = (int) $oModelDraw->where('user_id', $this->user->id)->first()?->amount; $mDrawDel = (new Draw())->where('user_id', $this->user->id)->where('status', 0)->delete(); if (empty($mDrawDel)) { return $response->withJson([ 'ret' => 1, 'msg' => '撤销失败', ]); } // 撤销成功,退回money_aff // $money_before = $this->user->money; // $this->user->money_aff += $iDrawAmount; // $this->user->save(); return $response->withJson([ 'ret' => 1, 'msg' => '撤销成功', ]); } }