public function recharge($param)
{
    if (empty($param['userId']) || empty($param['money']) || empty($param['type']) || empty($param['img']) || empty($param['paypassword'])) {
        new Exception("参数错误");
    }


    $user = \app\admin\model\User::where(['id' => $param['userId']])->find();
    if (!$user || ($user['paypassword'] != $param['paypassword'])) {
        new Exception("支付密码错误", 0);
    }


    $orderSn = getordersn('CZ');
    Db::startTrans();
    try {
        $rechargeModel = new Recharge();

        $userId = $param['userId']; // 或者其他用户标识
        $cacheKey = "submit_limit:" . $userId;
        $lastSubmitTime = cache($cacheKey);

        if ($lastSubmitTime && (time() - $lastSubmitTime < 5)) { // 5秒内限制
            // 返回错误,防止重复提交
            new Exception("请稍后再试", 0);
        } else {
            // 处理请求
            $rechargeModel->save([
                'orderNo' => $orderSn,
                'user_id' => $param['userId'],
                'payid' => $param['payid'],
                'type' => $param['type'],
                'money' => $param['money'],
                'status' => 2,
                'payPic' => $param['img'],
                'remark' => $param['remark'] ?? '',
            ]);
            Db::commit();
            cache($cacheKey, time(), 10); // 设置缓存,10秒有效
        }



        new Exception("充值提交成功", 1, ['order_id' => $orderSn]);
    } catch (\think\Exception $e) {
        Db::rollback();
        new Exception($e->getMessage());
    }
}


点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部
{__SCRIPT__}