feat(commission): 支持计奖商品参与设置、独立分成与多规格规则,完善团队中心与微信快捷登录
这个提交包含在:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户