feat(commission): 支持计奖商品参与设置、独立分成与多规格规则,完善团队中心与微信快捷登录
这个提交包含在:
@@ -7,9 +7,11 @@ namespace addons\shopro\service\partner;
|
||||
*/
|
||||
class MakerDiffReward
|
||||
{
|
||||
public function run($order, $buyerId, $chain, ActiveService $active)
|
||||
public function run($order, $buyerId, $chain, ActiveService $active, $rules = null)
|
||||
{
|
||||
$bonus = PartnerConfig::makerBonus();
|
||||
$bonus = (!empty($rules['maker_bonus']) && is_array($rules['maker_bonus']))
|
||||
? $rules['maker_bonus']
|
||||
: PartnerConfig::makerBonus();
|
||||
$seen = 0;
|
||||
$paid = [];
|
||||
|
||||
|
||||
@@ -7,11 +7,17 @@ namespace addons\shopro\service\partner;
|
||||
*/
|
||||
class MakerPeerReward
|
||||
{
|
||||
public function run($order, $buyerId, $chain, $diffResult, ActiveService $active)
|
||||
public function run($order, $buyerId, $chain, $diffResult, ActiveService $active, $rules = null)
|
||||
{
|
||||
$bonus = PartnerConfig::makerBonus();
|
||||
$peerRate = (float) PartnerConfig::get('partner_maker_peer_rate', 0.10);
|
||||
$overRate = (float) PartnerConfig::get('partner_maker_overtaken_rate', 0.05);
|
||||
$bonus = (!empty($rules['maker_bonus']) && is_array($rules['maker_bonus']))
|
||||
? $rules['maker_bonus']
|
||||
: PartnerConfig::makerBonus();
|
||||
$peerRate = (isset($rules['maker_peer_rate']) && is_numeric($rules['maker_peer_rate']))
|
||||
? (float) $rules['maker_peer_rate']
|
||||
: (float) PartnerConfig::get('partner_maker_peer_rate', 0.10);
|
||||
$overRate = (isset($rules['maker_overtaken_rate']) && is_numeric($rules['maker_overtaken_rate']))
|
||||
? (float) $rules['maker_overtaken_rate']
|
||||
: (float) PartnerConfig::get('partner_maker_overtaken_rate', 0.05);
|
||||
$minAmount = (float) PartnerConfig::get('partner_peer_min_amount', 0.10);
|
||||
if ($minAmount <= 0) {
|
||||
$minAmount = 0.10;
|
||||
|
||||
@@ -167,8 +167,143 @@ class PartnerConfig
|
||||
];
|
||||
}
|
||||
|
||||
public static function dailyTypes()
|
||||
public static function defaultRules()
|
||||
{
|
||||
return ['venue_share', 'county_share', 'madow_share', 'voucher_release'];
|
||||
return [
|
||||
'push3_amounts' => self::push3Amounts(),
|
||||
'maker_bonus' => self::makerBonus(),
|
||||
'maker_peer_rate' => (float) self::get('partner_maker_peer_rate', 0.10),
|
||||
'maker_overtaken_rate' => (float) self::get('partner_maker_overtaken_rate', 0.05),
|
||||
'venue_split' => (float) self::get('partner_venue_split', 50),
|
||||
'county_full' => (float) self::get('partner_county_full', 100),
|
||||
'venue_peer_rate' => (float) self::get('partner_venue_peer_rate', 0.10),
|
||||
'county_peer_rate' => (float) self::get('partner_county_peer_rate', 0.10),
|
||||
'voucher_times' => (float) self::get('partner_voucher_times', 1.5),
|
||||
'voucher_days' => (int) self::get('partner_voucher_days', 365),
|
||||
'venue_share' => (float) self::get('partner_venue_share_per_order', 100),
|
||||
'county_share' => (float) self::get('partner_county_share_per_order', 50),
|
||||
'is_custom' => false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定商品/规格的生效分成规则(优先独立规则,未设置项回退默认规则)
|
||||
*/
|
||||
public static function getEffectiveRules($goodsId, $skuPriceId = 0)
|
||||
{
|
||||
$rules = self::defaultRules();
|
||||
$goodsId = intval($goodsId);
|
||||
if ($goodsId <= 0) {
|
||||
return $rules;
|
||||
}
|
||||
|
||||
try {
|
||||
$cg = \think\Db::name('shopro_commission_goods')->where('goods_id', $goodsId)->find();
|
||||
if (!$cg || intval($cg['status'] ?? 0) !== 1) {
|
||||
// 未参与计奖
|
||||
$rules['status'] = 0;
|
||||
return $rules;
|
||||
}
|
||||
$rules['status'] = 1;
|
||||
$rules['commission_order_status'] = intval($cg['commission_order_status'] ?? 1);
|
||||
$selfRules = intval($cg['self_rules'] ?? 0);
|
||||
$rules['self_rules'] = $selfRules;
|
||||
|
||||
if ($selfRules !== 1 && $selfRules !== 2) {
|
||||
return $rules; // 默认规则
|
||||
}
|
||||
|
||||
$raw = $cg['commission_rules'] ?? '';
|
||||
$custom = is_array($raw) ? $raw : (json_decode($raw, true) ?: []);
|
||||
if (empty($custom)) {
|
||||
return $rules;
|
||||
}
|
||||
|
||||
// 多规格支持:优先匹配特定规格配置
|
||||
$skuKey = intval($skuPriceId);
|
||||
if ($skuKey > 0 && isset($custom[$skuKey]) && is_array($custom[$skuKey])) {
|
||||
$custom = $custom[$skuKey];
|
||||
} elseif ($skuKey > 0 && isset($custom['sku_' . $skuKey]) && is_array($custom['sku_' . $skuKey])) {
|
||||
$custom = $custom['sku_' . $skuKey];
|
||||
}
|
||||
|
||||
if (isset($custom['push3_amounts']) && is_array($custom['push3_amounts']) && count($custom['push3_amounts']) >= 3) {
|
||||
$rules['push3_amounts'] = array_map('floatval', array_values($custom['push3_amounts']));
|
||||
}
|
||||
if (isset($custom['maker_bonus']) && is_array($custom['maker_bonus'])) {
|
||||
$mb = [];
|
||||
foreach ($custom['maker_bonus'] as $lvl => $val) {
|
||||
$mb[intval($lvl)] = floatval($val);
|
||||
}
|
||||
$rules['maker_bonus'] = $mb;
|
||||
}
|
||||
if (isset($custom['maker_peer_rate']) && is_numeric($custom['maker_peer_rate'])) {
|
||||
$rules['maker_peer_rate'] = floatval($custom['maker_peer_rate']);
|
||||
}
|
||||
if (isset($custom['maker_overtaken_rate']) && is_numeric($custom['maker_overtaken_rate'])) {
|
||||
$rules['maker_overtaken_rate'] = floatval($custom['maker_overtaken_rate']);
|
||||
}
|
||||
if (isset($custom['venue_split']) && is_numeric($custom['venue_split'])) {
|
||||
$rules['venue_split'] = floatval($custom['venue_split']);
|
||||
}
|
||||
if (isset($custom['county_full']) && is_numeric($custom['county_full'])) {
|
||||
$rules['county_full'] = floatval($custom['county_full']);
|
||||
}
|
||||
if (isset($custom['venue_peer_rate']) && is_numeric($custom['venue_peer_rate'])) {
|
||||
$rules['venue_peer_rate'] = floatval($custom['venue_peer_rate']);
|
||||
}
|
||||
if (isset($custom['county_peer_rate']) && is_numeric($custom['county_peer_rate'])) {
|
||||
$rules['county_peer_rate'] = floatval($custom['county_peer_rate']);
|
||||
}
|
||||
if (isset($custom['voucher_times']) && is_numeric($custom['voucher_times'])) {
|
||||
$rules['voucher_times'] = floatval($custom['voucher_times']);
|
||||
}
|
||||
if (isset($custom['voucher_days']) && is_numeric($custom['voucher_days'])) {
|
||||
$rules['voucher_days'] = intval($custom['voucher_days']);
|
||||
}
|
||||
if (isset($custom['venue_share']) && is_numeric($custom['venue_share'])) {
|
||||
$rules['venue_share'] = floatval($custom['venue_share']);
|
||||
}
|
||||
if (isset($custom['county_share']) && is_numeric($custom['county_share'])) {
|
||||
$rules['county_share'] = floatval($custom['county_share']);
|
||||
}
|
||||
|
||||
$rules['is_custom'] = true;
|
||||
return $rules;
|
||||
} catch (\Exception $e) {
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析订单中主计奖商品的生效分成规则
|
||||
*/
|
||||
public static function getOrderEffectiveRules($order)
|
||||
{
|
||||
$default = self::defaultRules();
|
||||
$items = $order['items'] ?? [];
|
||||
if (empty($items) && !empty($order['id'])) {
|
||||
$fresh = \app\admin\model\shopro\order\Order::with(['items'])->where('id', $order['id'])->find();
|
||||
if ($fresh) {
|
||||
$items = $fresh['items'] ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
// 优先寻找设置了独立分成规则的计奖商品
|
||||
foreach ($items as $item) {
|
||||
$ext = is_array($item['ext'] ?? null) ? $item['ext'] : (json_decode($item['ext'] ?? '', true) ?: []);
|
||||
if (isset($ext['is_commission']) && !$ext['is_commission']) {
|
||||
continue;
|
||||
}
|
||||
$goodsId = intval($item['goods_id'] ?? 0);
|
||||
$skuId = intval($item['goods_sku_price_id'] ?? 0);
|
||||
$rules = self::getEffectiveRules($goodsId, $skuId);
|
||||
if (!empty($rules['is_custom'])) {
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,16 +40,19 @@ class PartnerRewardService
|
||||
$parentChain = $chainService->collect($buyerId, false);
|
||||
$selfChain = $chainService->collect($buyerId, true);
|
||||
|
||||
// 动态解析商品独立分成规则与全局默认配置
|
||||
$orderRules = PartnerConfig::getOrderEffectiveRules($order);
|
||||
|
||||
$parent = $parentChain[0] ?? null;
|
||||
(new Push3Reward())->run($order, $buyerId, $parent, $active);
|
||||
(new Push3Reward())->run($order, $buyerId, $parent, $active, $orderRules);
|
||||
|
||||
$diff = (new MakerDiffReward())->run($order, $buyerId, $parentChain, $active);
|
||||
(new MakerPeerReward())->run($order, $buyerId, $parentChain, $diff, $active);
|
||||
$diff = (new MakerDiffReward())->run($order, $buyerId, $parentChain, $active, $orderRules);
|
||||
(new MakerPeerReward())->run($order, $buyerId, $parentChain, $diff, $active, $orderRules);
|
||||
|
||||
$team = (new TeamSplitReward())->run($order, $buyerId, $selfChain, $active);
|
||||
(new PeerShareReward())->run($order, $buyerId, $selfChain, $team, $active);
|
||||
$team = (new TeamSplitReward())->run($order, $buyerId, $selfChain, $active, $orderRules);
|
||||
(new PeerShareReward())->run($order, $buyerId, $selfChain, $team, $active, $orderRules);
|
||||
|
||||
(new VoucherService())->grant($order, $buyerId);
|
||||
(new VoucherService())->grant($order, $buyerId, $orderRules);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -7,10 +7,14 @@ namespace addons\shopro\service\partner;
|
||||
*/
|
||||
class PeerShareReward
|
||||
{
|
||||
public function run($order, $buyerId, $chain, $teamResult, ActiveService $active)
|
||||
public function run($order, $buyerId, $chain, $teamResult, ActiveService $active, $rules = null)
|
||||
{
|
||||
$venueRate = (float) PartnerConfig::get('partner_venue_peer_rate', 0.10);
|
||||
$countyRate = (float) PartnerConfig::get('partner_county_peer_rate', 0.10);
|
||||
$venueRate = (isset($rules['venue_peer_rate']) && is_numeric($rules['venue_peer_rate']))
|
||||
? (float) $rules['venue_peer_rate']
|
||||
: (float) PartnerConfig::get('partner_venue_peer_rate', 0.10);
|
||||
$countyRate = (isset($rules['county_peer_rate']) && is_numeric($rules['county_peer_rate']))
|
||||
? (float) $rules['county_peer_rate']
|
||||
: (float) PartnerConfig::get('partner_county_peer_rate', 0.10);
|
||||
|
||||
if (!empty($teamResult['venue'])) {
|
||||
$this->peer($order, $buyerId, $chain, $teamResult['venue'], 'is_venue', 'venue_peer', 'venue', $venueRate, $active, '酒道馆');
|
||||
|
||||
@@ -9,7 +9,7 @@ use app\admin\model\shopro\commission\Agent as AgentModel;
|
||||
*/
|
||||
class Push3Reward
|
||||
{
|
||||
public function run($order, $buyerId, $parent, ActiveService $active)
|
||||
public function run($order, $buyerId, $parent, ActiveService $active, $rules = null)
|
||||
{
|
||||
if (!$parent) {
|
||||
PartnerRewardService::writeSkip($order, $buyerId, 0, 'push3', 'taster', 'no_parent', '暂无推荐人,不计提推荐开拓奖');
|
||||
@@ -35,7 +35,9 @@ class Push3Reward
|
||||
$agent->direct_order_seq = intval($agent->direct_order_seq) + 1;
|
||||
$agent->save();
|
||||
|
||||
$amounts = PartnerConfig::push3Amounts();
|
||||
$amounts = (!empty($rules['push3_amounts']) && is_array($rules['push3_amounts']))
|
||||
? $rules['push3_amounts']
|
||||
: PartnerConfig::push3Amounts();
|
||||
$seq = intval($agent->direct_order_seq);
|
||||
$amount = $amounts[($seq - 1) % 3];
|
||||
|
||||
|
||||
@@ -7,10 +7,14 @@ namespace addons\shopro\service\partner;
|
||||
*/
|
||||
class TeamSplitReward
|
||||
{
|
||||
public function run($order, $buyerId, $chain, ActiveService $active)
|
||||
public function run($order, $buyerId, $chain, ActiveService $active, $rules = null)
|
||||
{
|
||||
$venueSplit = (float) PartnerConfig::get('partner_venue_split', 50);
|
||||
$countyFull = (float) PartnerConfig::get('partner_county_full', 100);
|
||||
$venueSplit = (isset($rules['venue_split']) && is_numeric($rules['venue_split']))
|
||||
? (float) $rules['venue_split']
|
||||
: (float) PartnerConfig::get('partner_venue_split', 50);
|
||||
$countyFull = (isset($rules['county_full']) && is_numeric($rules['county_full']))
|
||||
? (float) $rules['county_full']
|
||||
: (float) PartnerConfig::get('partner_county_full', 100);
|
||||
$result = ['venue' => null, 'county' => null];
|
||||
|
||||
$venue = $this->nearest($chain, 'is_venue', $active);
|
||||
|
||||
@@ -123,15 +123,19 @@ class VoucherService
|
||||
}
|
||||
}
|
||||
|
||||
public function grant($order, $buyerId)
|
||||
public function grant($order, $buyerId, $rules = null)
|
||||
{
|
||||
$exists = VoucherPlan::where('order_id', $order['id'])->find();
|
||||
if ($exists) {
|
||||
return $exists;
|
||||
}
|
||||
|
||||
$times = (float) PartnerConfig::get('partner_voucher_times', 1.5);
|
||||
$days = intval(PartnerConfig::get('partner_voucher_days', 365));
|
||||
$times = (isset($rules['voucher_times']) && is_numeric($rules['voucher_times']))
|
||||
? (float) $rules['voucher_times']
|
||||
: (float) PartnerConfig::get('partner_voucher_times', 1.5);
|
||||
$days = (isset($rules['voucher_days']) && is_numeric($rules['voucher_days']))
|
||||
? intval($rules['voucher_days'])
|
||||
: intval(PartnerConfig::get('partner_voucher_days', 365));
|
||||
$days = $days > 0 ? $days : 365;
|
||||
$rewardService = new PartnerRewardService();
|
||||
$qualifiedPayFee = $rewardService->getQualifiedPayFee($order);
|
||||
|
||||
在新工单中引用
屏蔽一个用户