121
This commit is contained in:
parent
e98e61c241
commit
bfa5e94f89
|
|
@ -795,7 +795,9 @@ class Login extends Base
|
||||||
// 获取设备信息
|
// 获取设备信息
|
||||||
$device = request()->param('device', ''); // 设备类型
|
$device = request()->param('device', ''); // 设备类型
|
||||||
$device_info = request()->param('device_info', ''); // 设备详细信息
|
$device_info = request()->param('device_info', ''); // 设备详细信息
|
||||||
|
if ($device == "") {
|
||||||
|
$device = request()->header('client');
|
||||||
|
}
|
||||||
// 获取IP和地理位置信息
|
// 获取IP和地理位置信息
|
||||||
$ip = $this->getRealIp();
|
$ip = $this->getRealIp();
|
||||||
$location = '';
|
$location = '';
|
||||||
|
|
@ -885,11 +887,11 @@ class Login extends Base
|
||||||
$redisKey = "VerificationCode:{$mobile}";
|
$redisKey = "VerificationCode:{$mobile}";
|
||||||
$redisCode = $redis->get($redisKey);
|
$redisCode = $redis->get($redisKey);
|
||||||
// if ($code != "9999") {
|
// if ($code != "9999") {
|
||||||
if (empty($redisCode) || $redisCode != $code) {
|
if (empty($redisCode) || $redisCode != $code) {
|
||||||
$logMessages[] = '验证码错误: ' . $code . ',正确验证码: ' . $redisCode;
|
$logMessages[] = '验证码错误: ' . $code . ',正确验证码: ' . $redisCode;
|
||||||
Log::error(end($logMessages));
|
Log::error(end($logMessages));
|
||||||
return $this->renderError('验证码错误');
|
return $this->renderError('验证码错误');
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// 验证通过后删除Redis中的验证码
|
// 验证通过后删除Redis中的验证码
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,14 @@ class UserLoginLog extends Model
|
||||||
->where('login_time', '<=', $today_end)
|
->where('login_time', '<=', $today_end)
|
||||||
->find();
|
->find();
|
||||||
|
|
||||||
// 如果今天已记录,则不再记录
|
// 如果今天已记录,则更新最后登录时间
|
||||||
if ($exist) {
|
if ($exist) {
|
||||||
return false;
|
return self::where('id', $exist['id'])->update([
|
||||||
|
'last_login_time' => time(),
|
||||||
|
'device' => $device,
|
||||||
|
'ip' => $ip
|
||||||
|
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加登录记录
|
// 添加登录记录
|
||||||
|
|
@ -56,6 +61,7 @@ class UserLoginLog extends Model
|
||||||
'year' => date('Y'),
|
'year' => date('Y'),
|
||||||
'month' => date('m'),
|
'month' => date('m'),
|
||||||
'week' => date('W'),
|
'week' => date('W'),
|
||||||
|
'last_login_time' => time()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,10 @@ class MiniProgramPlatform extends BasePlatform
|
||||||
*/
|
*/
|
||||||
public function pay(array $data): array
|
public function pay(array $data): array
|
||||||
{
|
{
|
||||||
$currentHour = (int)date('H');
|
$currentHour = (int) date('H');
|
||||||
$currentMinute = (int)date('i');
|
$currentMinute = (int) date('i');
|
||||||
$currentTime = $currentHour * 100 + $currentMinute;
|
$currentTime = $currentHour * 100 + $currentMinute;
|
||||||
|
|
||||||
if ($currentTime < 800 || $currentTime >= 2200) {
|
if ($currentTime < 800 || $currentTime >= 2200) {
|
||||||
return [
|
return [
|
||||||
'status' => 0,
|
'status' => 0,
|
||||||
|
|
@ -72,6 +72,11 @@ class MiniProgramPlatform extends BasePlatform
|
||||||
'msg' => '支付未开放,请在08:00-22:00范围内购买'
|
'msg' => '支付未开放,请在08:00-22:00范围内购买'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
return [
|
||||||
|
'status' => 0,
|
||||||
|
'data' => [],
|
||||||
|
'msg' => '小程序支付通道维护中,请联系客服下载app。'
|
||||||
|
];
|
||||||
$data += ['user' => null, 'price' => 0, 'title' => '', 'attach' => 'order_wxs', 'pre' => 'MH_'];
|
$data += ['user' => null, 'price' => 0, 'title' => '', 'attach' => 'order_wxs', 'pre' => 'MH_'];
|
||||||
[
|
[
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
|
|
@ -112,7 +117,10 @@ class MiniProgramPlatform extends BasePlatform
|
||||||
// 生成新的支付通知URL
|
// 生成新的支付通知URL
|
||||||
$notifyUrl = generatePayNotifyUrl($payment_type, $order_type, $user_id, $order_no, $callback_nonce_str);
|
$notifyUrl = generatePayNotifyUrl($payment_type, $order_type, $user_id, $order_no, $callback_nonce_str);
|
||||||
$is_test = $user['istest'];
|
$is_test = $user['istest'];
|
||||||
|
// $randomNumber = random_int(1, 10) / 100;
|
||||||
|
// if ($price > $randomNumber) {
|
||||||
|
// $price = $price - $randomNumber;
|
||||||
|
// }
|
||||||
// throw new \Exception('支付未开放');
|
// throw new \Exception('支付未开放');
|
||||||
// if ($is_test == 2) {
|
// if ($is_test == 2) {
|
||||||
// $price = 0.01;
|
// $price = 0.01;
|
||||||
|
|
@ -172,10 +180,10 @@ class MiniProgramPlatform extends BasePlatform
|
||||||
} else {
|
} else {
|
||||||
$error_message = '微信支付接口返回异常';
|
$error_message = '微信支付接口返回异常';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取Redis实例
|
// 获取Redis实例
|
||||||
$redis = (new \app\common\server\RedisHelper())->getRedis();
|
$redis = (new \app\common\server\RedisHelper())->getRedis();
|
||||||
|
|
||||||
// 记录到ThinkPHP的日志系统中
|
// 记录到ThinkPHP的日志系统中
|
||||||
Log::error('微信支付失败: ' . json_encode([
|
Log::error('微信支付失败: ' . json_encode([
|
||||||
'order_no' => $order_no,
|
'order_no' => $order_no,
|
||||||
|
|
@ -186,15 +194,15 @@ class MiniProgramPlatform extends BasePlatform
|
||||||
'result' => $result,
|
'result' => $result,
|
||||||
'time' => date('Y-m-d H:i:s')
|
'time' => date('Y-m-d H:i:s')
|
||||||
], JSON_UNESCAPED_UNICODE));
|
], JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
// 获取当前商户ID
|
// 获取当前商户ID
|
||||||
$merchant_id = $this->getMchId();
|
$merchant_id = $this->getMchId();
|
||||||
|
|
||||||
// 记录支付失败信息到Redis
|
// 记录支付失败信息到Redis
|
||||||
if ($merchant_id) {
|
if ($merchant_id) {
|
||||||
// 商户支付失败计数的key,使用12小时过期时间
|
// 商户支付失败计数的key,使用12小时过期时间
|
||||||
$merchant_fail_key = 'merchant:payment:fail:' . $merchant_id;
|
$merchant_fail_key = 'merchant:payment:fail:' . $merchant_id;
|
||||||
|
|
||||||
// 将失败信息存入列表
|
// 将失败信息存入列表
|
||||||
$fail_info = [
|
$fail_info = [
|
||||||
'merchant_id' => $merchant_id,
|
'merchant_id' => $merchant_id,
|
||||||
|
|
@ -202,21 +210,21 @@ class MiniProgramPlatform extends BasePlatform
|
||||||
'time' => time(),
|
'time' => time(),
|
||||||
'error' => $error_message
|
'error' => $error_message
|
||||||
];
|
];
|
||||||
|
|
||||||
// 添加到失败列表
|
// 添加到失败列表
|
||||||
$redis->rPush($merchant_fail_key, json_encode($fail_info));
|
$redis->rPush($merchant_fail_key, json_encode($fail_info));
|
||||||
|
|
||||||
// 设置过期时间为12小时
|
// 设置过期时间为12小时
|
||||||
$redis->expire($merchant_fail_key, 12 * 3600);
|
$redis->expire($merchant_fail_key, 12 * 3600);
|
||||||
|
|
||||||
// 获取当前列表长度
|
// 获取当前列表长度
|
||||||
$fail_count = $redis->lLen($merchant_fail_key);
|
$fail_count = $redis->lLen($merchant_fail_key);
|
||||||
|
|
||||||
// 如果12小时内失败次数达到10次,临时停用该商户
|
// 如果12小时内失败次数达到10次,临时停用该商户
|
||||||
if ($fail_count >= 10) {
|
if ($fail_count >= 10) {
|
||||||
// 商户临时停用标记
|
// 商户临时停用标记
|
||||||
$disable_key = 'merchant:payment:disabled:' . $merchant_id;
|
$disable_key = 'merchant:payment:disabled:' . $merchant_id;
|
||||||
|
|
||||||
// 记录停用信息
|
// 记录停用信息
|
||||||
$disable_info = [
|
$disable_info = [
|
||||||
'merchant_id' => $merchant_id,
|
'merchant_id' => $merchant_id,
|
||||||
|
|
@ -224,11 +232,11 @@ class MiniProgramPlatform extends BasePlatform
|
||||||
'disable_reason' => '12小时内支付失败次数超过10次,系统自动临时停用',
|
'disable_reason' => '12小时内支付失败次数超过10次,系统自动临时停用',
|
||||||
'auto_disabled' => true
|
'auto_disabled' => true
|
||||||
];
|
];
|
||||||
|
|
||||||
// 设置商户停用标记,默认停用12小时
|
// 设置商户停用标记,默认停用12小时
|
||||||
$redis->set($disable_key, json_encode($disable_info));
|
$redis->set($disable_key, json_encode($disable_info));
|
||||||
$redis->expire($disable_key, 12 * 3600);
|
$redis->expire($disable_key, 12 * 3600);
|
||||||
|
|
||||||
// 记录停用日志
|
// 记录停用日志
|
||||||
Log::warning('商户支付功能临时停用: ' . json_encode([
|
Log::warning('商户支付功能临时停用: ' . json_encode([
|
||||||
'merchant_id' => $merchant_id,
|
'merchant_id' => $merchant_id,
|
||||||
|
|
@ -591,50 +599,54 @@ class MiniProgramPlatform extends BasePlatform
|
||||||
*/
|
*/
|
||||||
private function switchToAlternativeMerchant(): void
|
private function switchToAlternativeMerchant(): void
|
||||||
{
|
{
|
||||||
if (empty($this->mp_miniprogram) ||
|
if (
|
||||||
empty($this->mp_miniprogram['merchants']) ||
|
empty($this->mp_miniprogram) ||
|
||||||
!is_array($this->mp_miniprogram['merchants'])) {
|
empty($this->mp_miniprogram['merchants']) ||
|
||||||
|
!is_array($this->mp_miniprogram['merchants'])
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$weixinpay_setting = getConfig('weixinpay_setting');
|
$weixinpay_setting = getConfig('weixinpay_setting');
|
||||||
if (empty($weixinpay_setting['merchants']) || !is_array($weixinpay_setting['merchants'])) {
|
if (empty($weixinpay_setting['merchants']) || !is_array($weixinpay_setting['merchants'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当前被停用的商户ID
|
// 当前被停用的商户ID
|
||||||
$current_disabled_mch_id = $this->mch_id;
|
$current_disabled_mch_id = $this->mch_id;
|
||||||
$redis = (new \app\common\server\RedisHelper())->getRedis();
|
$redis = (new \app\common\server\RedisHelper())->getRedis();
|
||||||
|
|
||||||
// 过滤出启用且未被临时停用的商户
|
// 过滤出启用且未被临时停用的商户
|
||||||
$available_merchants = array_values(array_filter($weixinpay_setting['merchants'], function ($merchant) use ($redis, $current_disabled_mch_id) {
|
$available_merchants = array_values(array_filter($weixinpay_setting['merchants'], function ($merchant) use ($redis, $current_disabled_mch_id) {
|
||||||
// 跳过当前被停用的商户
|
// 跳过当前被停用的商户
|
||||||
if ($merchant['mch_id'] == $current_disabled_mch_id) {
|
if ($merchant['mch_id'] == $current_disabled_mch_id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查商户是否被启用且在小程序配置中
|
// 检查商户是否被启用且在小程序配置中
|
||||||
if (isset($merchant['is_enabled'], $merchant['mch_id']) &&
|
if (
|
||||||
$merchant['is_enabled'] === "1" &&
|
isset($merchant['is_enabled'], $merchant['mch_id']) &&
|
||||||
in_array($merchant['mch_id'], $this->mp_miniprogram['merchants'])) {
|
$merchant['is_enabled'] === "1" &&
|
||||||
|
in_array($merchant['mch_id'], $this->mp_miniprogram['merchants'])
|
||||||
|
) {
|
||||||
|
|
||||||
// 检查商户是否被临时停用
|
// 检查商户是否被临时停用
|
||||||
$disable_key = 'merchant:payment:disabled:' . $merchant['mch_id'];
|
$disable_key = 'merchant:payment:disabled:' . $merchant['mch_id'];
|
||||||
if (!$redis->exists($disable_key)) {
|
if (!$redis->exists($disable_key)) {
|
||||||
return true; // 商户可用
|
return true; // 商户可用
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // 商户不可用
|
return false; // 商户不可用
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 如果有可用商户,随机选择一个
|
// 如果有可用商户,随机选择一个
|
||||||
if (!empty($available_merchants)) {
|
if (!empty($available_merchants)) {
|
||||||
$merchant = WxPayHelper::getRandomMerchant($available_merchants);
|
$merchant = WxPayHelper::getRandomMerchant($available_merchants);
|
||||||
$this->mp_merchant = $merchant;
|
$this->mp_merchant = $merchant;
|
||||||
$this->mch_id = $merchant['mch_id'];
|
$this->mch_id = $merchant['mch_id'];
|
||||||
$this->key = $merchant['keys'];
|
$this->key = $merchant['keys'];
|
||||||
|
|
||||||
// 记录商户切换日志
|
// 记录商户切换日志
|
||||||
Log::info('成功切换到备选商户: ' . json_encode([
|
Log::info('成功切换到备选商户: ' . json_encode([
|
||||||
'from_merchant' => $current_disabled_mch_id,
|
'from_merchant' => $current_disabled_mch_id,
|
||||||
|
|
@ -694,51 +706,51 @@ class MiniProgramPlatform extends BasePlatform
|
||||||
$basicCondition = isset($merchant['is_enabled'], $merchant['mch_id']) &&
|
$basicCondition = isset($merchant['is_enabled'], $merchant['mch_id']) &&
|
||||||
$merchant['is_enabled'] === "1" &&
|
$merchant['is_enabled'] === "1" &&
|
||||||
in_array($merchant['mch_id'], $this->mp_miniprogram['merchants']);
|
in_array($merchant['mch_id'], $this->mp_miniprogram['merchants']);
|
||||||
|
|
||||||
// 如果不满足基本条件,直接排除
|
// 如果不满足基本条件,直接排除
|
||||||
if (!$basicCondition) {
|
if (!$basicCondition) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查商户是否被临时禁用
|
// 检查商户是否被临时禁用
|
||||||
$disable_key = 'merchant:payment:disabled:' . $merchant['mch_id'];
|
$disable_key = 'merchant:payment:disabled:' . $merchant['mch_id'];
|
||||||
if ($redis->exists($disable_key)) {
|
if ($redis->exists($disable_key)) {
|
||||||
// 商户被临时禁用,记录日志
|
// 商户被临时禁用,记录日志
|
||||||
$disabled_info = $redis->get($disable_key);
|
$disabled_info = $redis->get($disable_key);
|
||||||
$disabled_info = $disabled_info ? json_decode($disabled_info, true) : [];
|
$disabled_info = $disabled_info ? json_decode($disabled_info, true) : [];
|
||||||
|
|
||||||
Log::info('加载商户时跳过被临时禁用的商户: ' . json_encode([
|
Log::info('加载商户时跳过被临时禁用的商户: ' . json_encode([
|
||||||
'merchant_id' => $merchant['mch_id'],
|
'merchant_id' => $merchant['mch_id'],
|
||||||
'disabled_time' => isset($disabled_info['disable_time']) ? date('Y-m-d H:i:s', $disabled_info['disable_time']) : '未知',
|
'disabled_time' => isset($disabled_info['disable_time']) ? date('Y-m-d H:i:s', $disabled_info['disable_time']) : '未知',
|
||||||
'reason' => $disabled_info['disable_reason'] ?? '未知原因'
|
'reason' => $disabled_info['disable_reason'] ?? '未知原因'
|
||||||
], JSON_UNESCAPED_UNICODE));
|
], JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
return false; // 商户被禁用,排除
|
return false; // 商户被禁用,排除
|
||||||
}
|
}
|
||||||
|
|
||||||
return true; // 商户可用
|
return true; // 商户可用
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 如果没有可用的未禁用商户,则使用所有启用的商户(忽略临时禁用状态)
|
// 如果没有可用的未禁用商户,则使用所有启用的商户(忽略临时禁用状态)
|
||||||
if (empty($associatedMerchants)) {
|
if (empty($associatedMerchants)) {
|
||||||
Log::warning('没有未禁用的可用商户,将加载所有启用的商户(忽略临时禁用状态)');
|
Log::warning('没有未禁用的可用商户,将加载所有启用的商户(忽略临时禁用状态)');
|
||||||
|
|
||||||
// 重新筛选商户,只考虑是否启用,忽略临时禁用状态
|
// 重新筛选商户,只考虑是否启用,忽略临时禁用状态
|
||||||
$associatedMerchants = array_values(array_filter($weixinpay_setting['merchants'], function ($merchant) {
|
$associatedMerchants = array_values(array_filter($weixinpay_setting['merchants'], function ($merchant) {
|
||||||
return isset($merchant['is_enabled'], $merchant['mch_id']) &&
|
return isset($merchant['is_enabled'], $merchant['mch_id']) &&
|
||||||
$merchant['is_enabled'] === "1" &&
|
$merchant['is_enabled'] === "1" &&
|
||||||
in_array($merchant['mch_id'], $this->mp_miniprogram['merchants']);
|
in_array($merchant['mch_id'], $this->mp_miniprogram['merchants']);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 记录被禁用但仍将使用的商户
|
// 记录被禁用但仍将使用的商户
|
||||||
foreach ($associatedMerchants as $merchant) {
|
foreach ($associatedMerchants as $merchant) {
|
||||||
$disable_key = 'merchant:payment:disabled:' . $merchant['mch_id'];
|
$disable_key = 'merchant:payment:disabled:' . $merchant['mch_id'];
|
||||||
$redis = (new \app\common\server\RedisHelper())->getRedis();
|
$redis = (new \app\common\server\RedisHelper())->getRedis();
|
||||||
|
|
||||||
if ($redis->exists($disable_key)) {
|
if ($redis->exists($disable_key)) {
|
||||||
$disabled_info = $redis->get($disable_key);
|
$disabled_info = $redis->get($disable_key);
|
||||||
$disabled_info = $disabled_info ? json_decode($disabled_info, true) : [];
|
$disabled_info = $disabled_info ? json_decode($disabled_info, true) : [];
|
||||||
|
|
||||||
Log::warning('由于没有可用商户,将使用被临时禁用的商户: ' . json_encode([
|
Log::warning('由于没有可用商户,将使用被临时禁用的商户: ' . json_encode([
|
||||||
'merchant_id' => $merchant['mch_id'],
|
'merchant_id' => $merchant['mch_id'],
|
||||||
'disabled_time' => isset($disabled_info['disable_time']) ? date('Y-m-d H:i:s', $disabled_info['disable_time']) : '未知',
|
'disabled_time' => isset($disabled_info['disable_time']) ? date('Y-m-d H:i:s', $disabled_info['disable_time']) : '未知',
|
||||||
|
|
@ -754,12 +766,12 @@ class MiniProgramPlatform extends BasePlatform
|
||||||
$this->mp_merchant = $merchant;
|
$this->mp_merchant = $merchant;
|
||||||
$this->mch_id = $merchant['mch_id'];
|
$this->mch_id = $merchant['mch_id'];
|
||||||
$this->key = $merchant['keys'];
|
$this->key = $merchant['keys'];
|
||||||
|
|
||||||
// 检查选中的商户是否被临时禁用
|
// 检查选中的商户是否被临时禁用
|
||||||
$disable_key = 'merchant:payment:disabled:' . $this->mch_id;
|
$disable_key = 'merchant:payment:disabled:' . $this->mch_id;
|
||||||
$redis = (new \app\common\server\RedisHelper())->getRedis();
|
$redis = (new \app\common\server\RedisHelper())->getRedis();
|
||||||
$isDisabled = $redis->exists($disable_key);
|
$isDisabled = $redis->exists($disable_key);
|
||||||
|
|
||||||
// 记录选择的商户
|
// 记录选择的商户
|
||||||
Log::debug('已选择支付商户: ' . json_encode([
|
Log::debug('已选择支付商户: ' . json_encode([
|
||||||
'merchant_id' => $this->mch_id,
|
'merchant_id' => $this->mch_id,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user