@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\service\partner;
|
||||
|
||||
use app\admin\model\shopro\commission\Agent as AgentModel;
|
||||
|
||||
/**
|
||||
* 身份文案:品酒师 / 创客V{n} / 酒道馆 / 区县
|
||||
*/
|
||||
class IdentityService
|
||||
{
|
||||
public static function build($agent)
|
||||
{
|
||||
$empty = [
|
||||
'identities' => [],
|
||||
'identity_text' => '',
|
||||
'is_partner' => false,
|
||||
'maker_level_name' => '',
|
||||
];
|
||||
if (!$agent) {
|
||||
return $empty;
|
||||
}
|
||||
$level = intval(is_array($agent) ? ($agent['level'] ?? 0) : ($agent->level ?? 0));
|
||||
$isVenue = intval(is_array($agent) ? ($agent['is_venue'] ?? 0) : ($agent->is_venue ?? 0));
|
||||
$isCounty = intval(is_array($agent) ? ($agent['is_county'] ?? 0) : ($agent->is_county ?? 0));
|
||||
|
||||
$identities = [];
|
||||
$parts = [];
|
||||
$makerLevelName = '';
|
||||
|
||||
if ($level == 1) {
|
||||
$identities[] = 'taster';
|
||||
} elseif ($level >= 2) {
|
||||
$identities[] = 'maker';
|
||||
$makerLevelName = '创客V' . ($level - 1);
|
||||
}
|
||||
if ($isVenue) {
|
||||
$identities[] = 'venue';
|
||||
}
|
||||
if ($isCounty) {
|
||||
$identities[] = 'county';
|
||||
}
|
||||
|
||||
$isPartner = in_array('maker', $identities) || in_array('venue', $identities) || in_array('county', $identities);
|
||||
|
||||
if ($isPartner) {
|
||||
$parts[] = '合伙股东';
|
||||
if ($makerLevelName) {
|
||||
$parts[] = $makerLevelName;
|
||||
}
|
||||
if ($isVenue) {
|
||||
$parts[] = '酒道馆';
|
||||
}
|
||||
if ($isCounty) {
|
||||
$parts[] = '区县代理';
|
||||
}
|
||||
} elseif ($level == 1) {
|
||||
$parts[] = '品酒师';
|
||||
}
|
||||
|
||||
return [
|
||||
'identities' => $identities,
|
||||
'identity_text' => implode(' · ', $parts),
|
||||
'is_partner' => $isPartner,
|
||||
'maker_level_name' => $makerLevelName,
|
||||
];
|
||||
}
|
||||
|
||||
public static function formatMoney($value, $scale = 2)
|
||||
{
|
||||
return number_format((float) $value, $scale, '.', '');
|
||||
}
|
||||
|
||||
public static function formatMadow($value)
|
||||
{
|
||||
return number_format((float) $value, 8, '.', '');
|
||||
}
|
||||
|
||||
public static function formatRate($value)
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
$value = PartnerConfig::get('partner_madow_base_rate', '0.00000075');
|
||||
}
|
||||
return number_format((float) $value, 8, '.', '');
|
||||
}
|
||||
|
||||
public static function attachAgent($agent, $rate = null)
|
||||
{
|
||||
if (!$agent) {
|
||||
return null;
|
||||
}
|
||||
$identity = self::build($agent);
|
||||
$madow = is_array($agent) ? ($agent['madow'] ?? 0) : ($agent->madow ?? 0);
|
||||
$released = is_array($agent) ? ($agent['voucher_released'] ?? 0) : ($agent->voucher_released ?? 0);
|
||||
$used = is_array($agent) ? ($agent['voucher_used'] ?? 0) : ($agent->voucher_used ?? 0);
|
||||
$total = is_array($agent) ? ($agent['voucher_total'] ?? 0) : ($agent->voucher_total ?? 0);
|
||||
$last = is_array($agent) ? ($agent['last_self_order_time'] ?? 0) : ($agent->last_self_order_time ?? 0);
|
||||
if ($rate === null) {
|
||||
$rate = (new RateService())->currentRate();
|
||||
}
|
||||
$available = max(0, (float) $released - (float) $used);
|
||||
|
||||
$data = is_object($agent) ? $agent->toArray() : $agent;
|
||||
return array_merge($data, $identity, [
|
||||
'is_venue' => intval($data['is_venue'] ?? 0),
|
||||
'is_county' => intval($data['is_county'] ?? 0),
|
||||
'county_code' => (string) ($data['county_code'] ?? ''),
|
||||
'direct_order_seq' => intval($data['direct_order_seq'] ?? 0),
|
||||
'madow' => self::formatMadow($madow),
|
||||
'madow_rate' => self::formatRate($rate),
|
||||
'madow_value' => self::formatMoney((float) $madow * (float) $rate),
|
||||
'voucher_total' => self::formatMoney($total),
|
||||
'voucher_released' => self::formatMoney($released),
|
||||
'voucher_used' => self::formatMoney($used),
|
||||
'voucher_available' => self::formatMoney($available),
|
||||
'active_30d' => (new ActiveService())->isActive($agent),
|
||||
'last_self_order_time' => $last ? intval($last) : 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function attachProfile($agent, $rate = null)
|
||||
{
|
||||
if (!$agent) {
|
||||
$baseRate = PartnerConfig::get('partner_madow_base_rate', '0.00000075');
|
||||
return [
|
||||
'identity_text' => '',
|
||||
'identities' => [],
|
||||
'is_partner' => false,
|
||||
'maker_level_name' => '',
|
||||
'madow' => '0.00000000',
|
||||
'madow_rate' => self::formatRate($baseRate),
|
||||
'madow_value' => '0.00',
|
||||
'voucher_available' => '0.00',
|
||||
'active_30d' => true,
|
||||
'agent_form' => self::agentFormEnabled(),
|
||||
'partner_mode' => PartnerConfig::isPartnerMode(),
|
||||
];
|
||||
}
|
||||
$full = self::attachAgent($agent, $rate);
|
||||
return [
|
||||
'identity_text' => $full['identity_text'],
|
||||
'identities' => $full['identities'],
|
||||
'is_partner' => $full['is_partner'],
|
||||
'maker_level_name' => $full['maker_level_name'],
|
||||
'madow' => $full['madow'],
|
||||
'madow_rate' => $full['madow_rate'],
|
||||
'madow_value' => $full['madow_value'],
|
||||
'voucher_available' => $full['voucher_available'],
|
||||
'active_30d' => $full['active_30d'],
|
||||
'agent_form' => self::agentFormEnabled(),
|
||||
'partner_mode' => PartnerConfig::isPartnerMode(),
|
||||
];
|
||||
}
|
||||
|
||||
protected static function agentFormEnabled()
|
||||
{
|
||||
$form = sheep_config('shop.commission.agent_form');
|
||||
if (is_array($form)) {
|
||||
return !empty($form['status']) && $form['status'] !== '0';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function findAgent($userId)
|
||||
{
|
||||
if (!$userId) {
|
||||
return null;
|
||||
}
|
||||
return AgentModel::where('user_id', $userId)->find();
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户