fuc-new/src/Controllers/User/MoneyController.php
hellcat 1fe8673f62 1
2025-10-01 13:34:29 +08:00

215 lines
6.1 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace App\Controllers\User;
use App\Controllers\BaseController;
use App\Models\GiftCard;
use App\Models\UserMoneyLog;
use App\Models\Payback;
use App\Models\Draw;
use App\Utils\Tools;
use Exception;
use Psr\Http\Message\ResponseInterface;
use Slim\Http\Response;
use Slim\Http\ServerRequest;
use function time;
final class MoneyController extends BaseController
{
/**
* @throws Exception
*/
public function index(ServerRequest $request, Response $response, array $args): ResponseInterface
{
$user = $this->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' => '撤销成功',
]);
}
}