255 || !Db::name('attachment')->where('url', $voucher)->where('admin_id', (int)$adminId)->where('category', 'recharge')->where('mimetype', 'in', ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/bmp'])->find()) { throw new \RuntimeException('请上传本次支付凭证图片'); } $amount = bcadd($amount, '0', 2); Db::startTrans(); try { $user = Db::name('user')->where('id', (int)$userId)->lock(true)->find(); if (!$user) { throw new \RuntimeException('充值用户不存在'); } if (Db::name('admin_recharge')->where('request_id', $requestId)->find()) { throw new \RuntimeException('该充值请求已提交,请勿重复充值'); } $balance = bcadd((string)$user['money'], $amount, 2); if (bccomp($balance, '99999999.99', 2) > 0) { throw new \RuntimeException('充值后余额超出允许范围'); } $now = time(); Db::name('user')->where('id', (int)$userId)->update(['money' => $balance, 'updatetime' => $now]); $logId = Db::name('wallet_log')->insertGetId([ 'user_type' => 'user', 'user_id' => (int)$userId, 'type' => 'recharge', 'amount' => $amount, 'balance' => $balance, 'order_id' => 0, 'remark' => '后台人工充值', 'createtime' => $now, ]); Db::name('admin_recharge')->insert([ 'wallet_log_id' => $logId, 'admin_id' => (int)$adminId, 'voucher' => $voucher, 'request_id' => $requestId, 'createtime' => $now, ]); Db::commit(); return ['wallet_log_id' => $logId, 'balance' => $balance]; } catch (\Throwable $e) { Db::rollback(); throw $e; } } }