159 行
5.1 KiB
PHP
159 行
5.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model\shopro\commission;
|
|
|
|
use app\admin\model\shopro\Common;
|
|
use app\admin\model\shopro\user\User;
|
|
|
|
class Agent extends Common
|
|
{
|
|
protected $pk = 'user_id';
|
|
|
|
protected $name = 'shopro_commission_agent';
|
|
|
|
protected $type = [
|
|
'become_time' => 'timestamp',
|
|
'apply_info' => 'json',
|
|
'child_agent_level_1' => 'json',
|
|
'child_agent_level_all' => 'json',
|
|
];
|
|
protected $append = [
|
|
'status_text',
|
|
'pending_reward',
|
|
'identity_text',
|
|
'identities',
|
|
'is_guest',
|
|
'has_purchased',
|
|
'is_partner',
|
|
'is_advanced',
|
|
'maker_level_name',
|
|
'role_names',
|
|
'custom_role_names',
|
|
'voucher_available',
|
|
'active_30d',
|
|
'madow_value',
|
|
];
|
|
|
|
// 分销商状态 AGENT_STATUS
|
|
const AGENT_STATUS_NORMAL = 'normal'; // 正常
|
|
const AGENT_STATUS_PENDING = 'pending'; // 审核中 不分佣、不打款、没有团队信息
|
|
const AGENT_STATUS_FREEZE = 'freeze'; // 冻结 正常记录分佣、不打款,记录业绩和团队信息 冻结解除后立即打款
|
|
const AGENT_STATUS_FORBIDDEN = 'forbidden'; // 禁用 不分佣、不记录业绩和团队信息
|
|
const AGENT_STATUS_NEEDINFO = 'needinfo'; // 需要完善表单资料 临时状态
|
|
const AGENT_STATUS_REJECT = 'reject'; // 审核驳回, 重新修改 临时状态
|
|
const AGENT_STATUS_NULL = NULL; // 未满足成为分销商条件
|
|
|
|
|
|
// 分销商升级锁 UPGRADE_LOCK
|
|
const UPGRADE_LOCK_OPEN = 1; // 禁止分销商升级
|
|
const UPGRADE_LOCK_CLOSE = 0; // 允许分销商升级
|
|
|
|
public function statusList()
|
|
{
|
|
return [
|
|
'normal' => '正常',
|
|
'pending' => '审核中',
|
|
'freeze' => '冻结',
|
|
'forbidden' => '禁用',
|
|
'reject' => '拒绝'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 可用分销商
|
|
*/
|
|
public function scopeAvaliable($query)
|
|
{
|
|
return $query->where('status', 'in', [self::AGENT_STATUS_NORMAL, self::AGENT_STATUS_FREEZE]);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id', 'id')->field('id, nickname, avatar, mobile, total_consume, parent_user_id');
|
|
}
|
|
|
|
public function levelInfo()
|
|
{
|
|
return $this->belongsTo(Level::class, 'level', 'level')->field(['level', 'name', 'image', 'commission_rules']);
|
|
}
|
|
|
|
public function getPendingRewardAttr($value, $data)
|
|
{
|
|
$amount = Reward::pending()->where('agent_id', $data['user_id'])->sum('commission');
|
|
return number_format($amount, 2, '.', '');
|
|
}
|
|
|
|
public function getIdentityTextAttr($value, $data)
|
|
{
|
|
return \addons\shopro\service\partner\IdentityService::build($data)['identity_text'];
|
|
}
|
|
|
|
public function getIdentitiesAttr($value, $data)
|
|
{
|
|
return \addons\shopro\service\partner\IdentityService::build($data)['identities'];
|
|
}
|
|
|
|
public function getIsGuestAttr($value, $data)
|
|
{
|
|
return \addons\shopro\service\partner\IdentityService::build($data)['is_guest'] ?? false;
|
|
}
|
|
|
|
public function getHasPurchasedAttr($value, $data)
|
|
{
|
|
return \addons\shopro\service\partner\IdentityService::build($data)['has_purchased'] ?? false;
|
|
}
|
|
|
|
public function getIsPartnerAttr($value, $data)
|
|
{
|
|
return \addons\shopro\service\partner\IdentityService::build($data)['is_partner'];
|
|
}
|
|
|
|
public function getIsAdvancedAttr($value, $data)
|
|
{
|
|
return \addons\shopro\service\partner\IdentityService::build($data)['is_advanced'] ?? false;
|
|
}
|
|
|
|
public function getMakerLevelNameAttr($value, $data)
|
|
{
|
|
return \addons\shopro\service\partner\IdentityService::build($data)['maker_level_name'];
|
|
}
|
|
|
|
public function getRoleNamesAttr($value, $data)
|
|
{
|
|
return \addons\shopro\service\partner\IdentityService::build($data)['role_names'] ?? \addons\shopro\service\partner\PartnerConfig::roleNames();
|
|
}
|
|
|
|
public function getCustomRoleNamesAttr($value, $data)
|
|
{
|
|
return $this->getRoleNamesAttr($value, $data);
|
|
}
|
|
|
|
public function getVoucherAvailableAttr($value, $data)
|
|
{
|
|
$released = (float) ($data['voucher_released'] ?? 0);
|
|
$used = (float) ($data['voucher_used'] ?? 0);
|
|
return number_format(max(0, $released - $used), 2, '.', '');
|
|
}
|
|
|
|
public function getActive_30dAttr($value, $data)
|
|
{
|
|
return (new \addons\shopro\service\partner\ActiveService())->isActive($data);
|
|
}
|
|
|
|
public function getMadowValueAttr($value, $data)
|
|
{
|
|
$rate = (new \addons\shopro\service\partner\RateService())->currentRate();
|
|
return \addons\shopro\service\partner\IdentityService::formatMoney((float) ($data['madow'] ?? 0) * (float) $rate);
|
|
}
|
|
|
|
public function levelStatusInfo()
|
|
{
|
|
return $this->belongsTo(Level::class, 'level_status', 'level');
|
|
}
|
|
|
|
public function upgradeLevel()
|
|
{
|
|
return $this->belongsTo(Level::class, 'level_status', 'level');
|
|
}
|
|
}
|