mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-03 02:58:42 +00:00
🔧 Fixed bugs
This commit is contained in:
@@ -19,7 +19,6 @@ use App\Utils\Payments\PayJs;
|
||||
use App\Utils\Payments\PayPal;
|
||||
use App\Utils\Payments\Stripe;
|
||||
use App\Utils\Payments\THeadPay;
|
||||
use Auth;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -90,6 +89,7 @@ class PaymentController extends Controller
|
||||
{
|
||||
$goods_id = $request->input('goods_id');
|
||||
$coupon_sn = $request->input('coupon_sn');
|
||||
$coupon = null;
|
||||
self::$method = $request->input('method');
|
||||
$credit = $request->input('amount');
|
||||
$pay_type = $request->input('pay_type');
|
||||
@@ -126,12 +126,11 @@ class PaymentController extends Controller
|
||||
|
||||
// 使用优惠券
|
||||
if ($coupon_sn) {
|
||||
$ret = (new CouponService($coupon_sn))->search($goods); // 检查券合规性
|
||||
$coupon = (new CouponService($coupon_sn))->search($goods); // 检查券合规性
|
||||
|
||||
if (! $ret instanceof Coupon) {
|
||||
return $ret;
|
||||
if (! $coupon instanceof Coupon) {
|
||||
return $coupon;
|
||||
}
|
||||
$coupon = $ret;
|
||||
|
||||
// 计算实际应支付总价
|
||||
$amount = $coupon->type === 2 ? $goods->price * $coupon->value / 100 : $goods->price - $coupon->value;
|
||||
@@ -149,7 +148,7 @@ class PaymentController extends Controller
|
||||
if (Order::uid()->whereStatus(0)->exists()) {
|
||||
return Response::json(['status' => 'fail', 'message' => '订单创建失败:尚有未支付的订单,请先去支付']);
|
||||
}
|
||||
} elseif (Auth::getUser()->credit < $amount) { // 验证账号余额是否充足
|
||||
} elseif (auth()->user()->credit < $amount) { // 验证账号余额是否充足
|
||||
return Response::json(['status' => 'fail', 'message' => '您的余额不足,请先充值']);
|
||||
}
|
||||
|
||||
@@ -169,7 +168,7 @@ class PaymentController extends Controller
|
||||
'sn' => date('ymdHis').random_int(100000, 999999),
|
||||
'user_id' => auth()->id(),
|
||||
'goods_id' => $credit ? null : $goods_id,
|
||||
'coupon_id' => $coupon->id ?? null,
|
||||
'coupon_id' => $coupon?->id,
|
||||
'origin_amount' => $credit ?: ($goods->price ?? 0),
|
||||
'amount' => $amount,
|
||||
'pay_type' => $pay_type,
|
||||
|
||||
@@ -416,16 +416,16 @@ class UserController extends Controller
|
||||
return Response::json(['status' => 'fail', 'title' => trans('common.failed'), 'message' => trans('user.coupon.error.unknown')]);
|
||||
}
|
||||
|
||||
$ret = (new CouponService($coupon_sn))->search($good); // 检查券合规性
|
||||
$coupon = (new CouponService($coupon_sn))->search($good); // 检查券合规性
|
||||
|
||||
if (! $ret instanceof Coupon) {
|
||||
return $ret;
|
||||
if (! $coupon instanceof Coupon) {
|
||||
return $coupon;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => $ret->name,
|
||||
'type' => $ret->type,
|
||||
'value' => $ret->type === 2 ? $ret->value : Helpers::getPriceTag($ret->value),
|
||||
'name' => $coupon->name,
|
||||
'type' => $coupon->type,
|
||||
'value' => $coupon->type === 2 ? $coupon->value : Helpers::getPriceTag($coupon->value),
|
||||
];
|
||||
|
||||
return Response::json(['status' => 'success', 'data' => $data, 'message' => trans('common.applied', ['attribute' => trans('model.coupon.attribute')])]);
|
||||
|
||||
@@ -21,7 +21,7 @@ class CouponService
|
||||
$this->user = Auth::getUser();
|
||||
}
|
||||
|
||||
public function search(Goods $goods): JsonResponse|bool
|
||||
public function search(Goods $goods): JsonResponse|Coupon
|
||||
{ // 寻找合适的券
|
||||
$coupons = Coupon::whereSn($this->code)->whereIn('type', [1, 2])->orderByDesc('priority')->get();
|
||||
if ($coupons->isNotEmpty()) {
|
||||
@@ -31,11 +31,9 @@ class CouponService
|
||||
return $coupon;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret ?? $this->failedReturn(trans('common.failed'), trans('user.coupon.error.unknown'));
|
||||
}
|
||||
|
||||
return $this->failedReturn(trans('common.failed'), trans('user.coupon.error.unknown'));
|
||||
return $ret ?? $this->failedReturn(trans('common.failed'), trans('user.coupon.error.unknown'));
|
||||
}
|
||||
|
||||
private function check(Goods $goods, Coupon $coupon): JsonResponse|bool
|
||||
|
||||
@@ -40,19 +40,19 @@ class IP
|
||||
$source++;
|
||||
}
|
||||
} else {
|
||||
while ($source <= 10 && $ret === null) { // 中文ipv6
|
||||
while ($source <= 9 && $ret === null) { // 中文ipv6
|
||||
$ret = match ($source) {
|
||||
0 => self::userAgentInfo($ip),
|
||||
1 => self::baiduBce($ip),
|
||||
2 => self::TenAPI($ip),
|
||||
3 => self::TaoBao($ip),
|
||||
4 => self::fkcoder($ip),
|
||||
5 => self::ipApi($ip),
|
||||
6 => self::juHe($ip),
|
||||
7 => self::Baidu($ip),
|
||||
8 => self::ipGeoLocation($ip),
|
||||
9 => self::ip2Region($ip),
|
||||
10 => self::IPIP($ip),
|
||||
0 => self::baiduBce($ip),
|
||||
1 => self::TenAPI($ip),
|
||||
2 => self::TaoBao($ip),
|
||||
3 => self::fkcoder($ip),
|
||||
4 => self::ipApi($ip),
|
||||
5 => self::juHe($ip),
|
||||
6 => self::Baidu($ip),
|
||||
7 => self::ipGeoLocation($ip),
|
||||
8 => self::ip2Region($ip),
|
||||
9 => self::IPIP($ip),
|
||||
//10 => self::userAgentInfo($ip), // 无法查外网的ip
|
||||
};
|
||||
$source++;
|
||||
}
|
||||
@@ -125,8 +125,8 @@ class IP
|
||||
$url = "https://qifu-api.baidubce.com/ip/geo/v1/district?ip=$ip";
|
||||
}
|
||||
$response = Http::timeout(15)->get($url);
|
||||
$data = $response->json();
|
||||
if ($response->ok()) {
|
||||
$data = $response->json();
|
||||
if ($data['code'] === 'Success') {
|
||||
return [
|
||||
'country' => $data['data']['country'],
|
||||
@@ -141,7 +141,7 @@ class IP
|
||||
|
||||
Log::error('【baiduBce】IP查询失败:'.$data['msg'] ?? '');
|
||||
} else {
|
||||
Log::error('【baiduBce】查询无效:'.$ip);
|
||||
Log::error('【baiduBce】查询无效:'.$ip.var_export($data, true));
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -264,7 +264,7 @@ class IP
|
||||
];
|
||||
}
|
||||
|
||||
Log::error('【userAgentInfo】IP查询失败:'.$data['desc'] ?? '');
|
||||
Log::error('【userAgentInfo】IP查询失败:'.$data ?? '');
|
||||
} else {
|
||||
Log::error('【userAgentInfo】查询无效:'.$ip);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Config;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
return new class extends Migration
|
||||
@@ -13,11 +14,13 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
foreach (self::$newConfigs as $config) {
|
||||
Config::insert(['name' => $config]);
|
||||
}
|
||||
foreach (self::$dropConfigs as $config) {
|
||||
Config::destroy(['name' => $config]);
|
||||
if (Config::exists()) {
|
||||
foreach (self::$newConfigs as $config) {
|
||||
Config::insert(['name' => $config]);
|
||||
}
|
||||
foreach (self::$dropConfigs as $config) {
|
||||
Config::destroy(['name' => $config]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user