文件

204 行
5.1 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace addons\shopro\library\commission;
use addons\shopro\model\commission\Config as ConfigModel;
use addons\shopro\model\User;
use think\Model;
use fast\Http;
/**
*
*/
class Config
{
protected $config = [];
public function __construct()
{
$this->config = ConfigModel::column('value', 'name');
}
// 覆盖默认分销设置
public function setConfig($config)
{
foreach ($config as $name => $value) {
$this->config[$name] = $value;
}
}
// 获取绑定推广关系的事件节点
public function getInviteLockEvent()
{
return $this->config['invite_lock'];
}
// 获取成为分销商的条件
public function getBecomeAgentEvent()
{
return json_decode($this->config['become_agent'], true);
}
// 分销商是否需要审核
public function isAgentCheck()
{
return boolval($this->config['agent_check']);
}
// 分销商升级审核
public function isUpgradeCheck()
{
return boolval($this->config['upgrade_check']);
}
// 分销商允许越级升级
public function isUpgradeJump()
{
return boolval($this->config['upgrade_jump']);
}
// 是否需要完善分销商表单信息
public function needAgentForm()
{
return boolval($this->config['agent_form']);
}
// 获取申请资料表单信息
public function getAgentForm()
{
if ($this->needAgentForm()) {
return json_decode($this->config['agent_form'], true);
}
return false;
}
// 申请协议
public function getApplyProtocol()
{
if ($this->config['apply_protocol']) {
return json_decode($this->config['apply_protocol'], true);
}
return null;
}
// 分销层级
public function getCommissionLevel()
{
return intval($this->config['commission_level']);
}
// 是否允许分销内购
public function isSelfBuy()
{
return boolval($this->config['self_buy']);
}
// 是否显示升级条件
public function isUpgradeDisplay()
{
return boolval($this->config['upgrade_display']);
}
// 佣金结算价格类型 pay_price=支付金额 goods_price=商品价格 (都不含运费 因为运费对于平台和用户没有实际价值)
public function getCommissionPriceType()
{
return $this->config['commission_price_type'];
}
// 佣金结算节点 payed=支付后
public function getCommissionEvent()
{
return $this->config['commission_event'];
}
// 退款是否扣除分销业绩
public function getRefundCommissionOrder()
{
return boolval($this->config['refund_commission_order']);
}
// 退款是否扣除佣金
public function getRefundCommissionReward()
{
return boolval($this->config['refund_commission_reward']);
}
// 分佣模式(兼容旧配置,新逻辑请用下方独立开关)
public function getCommissionMode()
{
return $this->config['commission_mode'] ?? 'chain';
}
public function isDifferentialMode()
{
return $this->getCommissionMode() === 'differential';
}
/** 关系链分佣(commission_1/2/3) */
public function isChainCommissionEnable()
{
if (isset($this->config['chain_commission_enable'])) {
return boolval($this->config['chain_commission_enable']);
}
return $this->getCommissionMode() !== 'differential';
}
/** 级差奖 */
public function isDifferentialCommissionEnable()
{
if (isset($this->config['differential_commission_enable'])) {
return boolval($this->config['differential_commission_enable']);
}
return $this->isDifferentialMode();
}
// 复购返现开关
public function isRepurchaseEnable()
{
return boolval($this->config['repurchase_enable'] ?? 0);
}
public function isRepurchaseSelfEnable()
{
return boolval($this->config['repurchase_self_enable'] ?? 0);
}
public function getRepurchaseRate()
{
return floatval($this->config['repurchase_rate'] ?? 0);
}
public function getRepurchaseSelfRate()
{
return floatval($this->config['repurchase_self_rate'] ?? 0);
}
public function isManagementAwardEnable()
{
return boolval($this->config['management_award_enable'] ?? 1);
}
public function isRepurchaseReferrerEnable()
{
return boolval($this->config['repurchase_referrer_enable'] ?? 1);
}
public function getRepurchaseSelfType()
{
$type = $this->config['repurchase_self_type'] ?? 'rate';
return in_array($type, ['fixed', 'rate']) ? $type : 'rate';
}
public function getRepurchaseSelfAmount()
{
return floatval($this->config['repurchase_self_amount'] ?? 0);
}
// 邀请码功能开关(暂时关闭,保留分销二维码/海报 spm 分享)
public function isInviteCodeEnable()
{
return false;
// return boolval($this->config['invite_code_enable'] ?? 0);
}
}