文件
xionggeshop/addons/shopro_huifu/library/Bridge.php

83 行
2.3 KiB
PHP

<?php
namespace addons\shopro_huifu\library;
use addons\shopro\library\split\Config as SplitConfig;
use addons\shopro\model\Order;
use think\Db;
class Bridge
{
public static function isEnabled()
{
if (!is_file(ADDON_PATH . 'shopro_huifu/info.ini')) {
return false;
}
$info = parse_ini_file(ADDON_PATH . 'shopro_huifu/info.ini');
if (empty($info['state'])) {
return false;
}
$config = HuifuConfig::getInstance();
return $config->get('status', '1') === '1';
}
public static function isHuifuMiniProgramChannel($platform = 'wxMiniProgram')
{
if (!self::isEnabled() || $platform !== 'wxMiniProgram') {
return false;
}
return HuifuConfig::getInstance()->get('miniprogram_channel', 'yansongda') === 'huifu';
}
public static function shouldHandlePay($params)
{
return self::isHuifuMiniProgramChannel($params['platform'] ?? '')
&& ($params['payment'] ?? '') === 'wechat'
&& ($params['prepay_type'] ?? '') === 'order';
}
public static function shouldHandleRefund($order)
{
return self::isEnabled() && $order && $order['pay_type'] === 'huifu_wechat';
}
public static function shouldHandleSplit($order)
{
if (!self::isEnabled() || !$order) {
return false;
}
if ($order['pay_type'] !== 'huifu_wechat') {
return false;
}
$splitConfig = new SplitConfig();
if (!$splitConfig->isEnable()) {
return false;
}
$mode = $splitConfig->getMode();
if ($mode === 'wallet') {
return false;
}
if (in_array($mode, ['huifu', 'both'])) {
return true;
}
$provider = $splitConfig->all()['split_provider'] ?? 'auto';
if ($provider === 'huifu') {
return true;
}
if ($provider === 'auto' && self::isHuifuMiniProgramChannel($order['platform'] ?? 'wxMiniProgram')) {
return true;
}
return false;
}
public static function getMiniProgramAppId()
{
$row = Db::name('shopro_config')->where('name', 'wxMiniProgram')->find();
if (!$row) {
return '';
}
$value = json_decode($row['value'], true);
return $value['app_id'] ?? '';
}
}