Files
webman_duanju/app/czg/app/controller/CashController.php
2025-08-14 17:19:26 +08:00

94 lines
2.5 KiB
PHP

<?php
namespace app\czg\app\controller;
use app\api\model\CommonInfo;
use app\api\model\WithDraw;
use app\common\controller\Frontend;
use app\exception\SysException;
use app\utils\RedisUtils;
use support\think\Cache;
use app\api\model\Cash as CashModel;
class CashController extends Frontend
{
protected array $noNeedLogin = ['*'];
public function canCash()
{
$user_id = $this->auth->getUser()['user_id'];
$comm = CommonInfo::where(['type' => 928])->find()->value;
if($comm == 0) {
$this->success('ok', true);
}
$redis_can_cash = Cache::get('cash:canCash:' . $user_id);
if($redis_can_cash) {
$this->success('ok', true);
}
}
private function checkCanCash($userId)
{
$canCash = RedisUtils::isCanCash($userId);
if (!$canCash) {
$val = (new CommonInfo())->getByCode(928)['value'];
if ($val == '1') {
throw new SysException("您未观看激励广告,请先观看");
}
}
}
/**
* 提现接口
*/
public function withdraw()
{
$amount = $this->request->get('amount');
$isAlipay = $this->request->get('isAlipay/d');
$userId = $this->getUserId();
self::checkCanCash($userId);
$info = (new CommonInfo())->getByCode(930);
if (!$info) {
$this->error("当前时间段未开启提现功能");
}
$timeScope = explode('~', $info['value']); // 如 08:30~17:30
$today = date('Y-m-d');
// 拼接今日的开始和结束时间
$beginTime = strtotime($today . ' ' . $timeScope[0]);
$endTime = strtotime($today . ' ' . $timeScope[1]);
$now = time();
// 判断是否在时间范围内
if ($now < $beginTime || $now > $endTime) {
throw new SysException("提现时间为每天" . $info['value']);
}
debounce("withdraw:".$userId, 30);
runWithLock("lock:withdraw:{$userId}", 300, function () use ($userId, $amount, $isAlipay) {
WithDraw::goWithDraw($userId, $amount, '', false, $isAlipay == 1);
});
$this->success('提现成功,将在三个工作日内到账,请耐心等待!');
}
/**
* 查询提现记录列表
*/
public function selectPayDetails()
{
$get = $this->request->get();
$cashOut[ 'user_id'] = $this->auth->user_id;
return $this->ApiDataReturn(CashModel::selectPayDetails($cashOut, $get, true, $this->auth->getUser()));
}
}