146 行
3.7 KiB
PHP
146 行
3.7 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model\shopro\partner;
|
|
|
|
use app\admin\model\shopro\Common;
|
|
use app\admin\model\shopro\user\User as UserModel;
|
|
use app\admin\model\shopro\order\Order as OrderModel;
|
|
use addons\shopro\service\partner\PartnerConfig;
|
|
|
|
class Reward extends Common
|
|
{
|
|
protected $name = 'shopro_partner_reward';
|
|
|
|
protected $type = [
|
|
'ext' => 'json',
|
|
];
|
|
|
|
protected $append = [
|
|
'status_text',
|
|
'reward_type_text',
|
|
'role_text',
|
|
'skip_reason',
|
|
'skip_reason_text',
|
|
'formula',
|
|
'wallet_type',
|
|
'wallet_type_text',
|
|
];
|
|
|
|
public function statusList()
|
|
{
|
|
return [
|
|
-2 => '已退回',
|
|
-1 => '已取消',
|
|
0 => '待入账',
|
|
1 => '已入账',
|
|
];
|
|
}
|
|
|
|
public function rewardTypeList()
|
|
{
|
|
return PartnerConfig::rewardTypeMap();
|
|
}
|
|
|
|
public function roleList()
|
|
{
|
|
return [
|
|
'taster' => '品酒师',
|
|
'maker' => '创客',
|
|
'venue' => '酒道馆',
|
|
'county' => '区县',
|
|
'system' => '平台',
|
|
];
|
|
}
|
|
|
|
public function getRewardTypeTextAttr($value, $data)
|
|
{
|
|
return PartnerConfig::rewardTypeText($data['reward_type'] ?? '');
|
|
}
|
|
|
|
public function getRoleTextAttr($value, $data)
|
|
{
|
|
$role = $data['role'] ?? '';
|
|
$list = $this->roleList();
|
|
return $list[$role] ?? $role;
|
|
}
|
|
|
|
public function getSkipReasonAttr($value, $data)
|
|
{
|
|
$ext = $data['ext'] ?? [];
|
|
if (is_string($ext)) {
|
|
$ext = json_decode($ext, true) ?: [];
|
|
}
|
|
return $ext['skip_reason'] ?? '';
|
|
}
|
|
|
|
public function getSkipReasonTextAttr($value, $data)
|
|
{
|
|
$reason = $this->getSkipReasonAttr(null, $data);
|
|
return $reason ? PartnerConfig::skipReasonText($reason) : '';
|
|
}
|
|
|
|
public function getFormulaAttr($value, $data)
|
|
{
|
|
$ext = $data['ext'] ?? [];
|
|
if (is_string($ext)) {
|
|
$ext = json_decode($ext, true) ?: [];
|
|
}
|
|
return $ext['formula'] ?? '';
|
|
}
|
|
|
|
public function getMadowAttr($value)
|
|
{
|
|
return \addons\shopro\service\partner\IdentityService::formatMadow($value);
|
|
}
|
|
|
|
public function getWalletTypeAttr($value, $data)
|
|
{
|
|
$ext = $data['ext'] ?? [];
|
|
if (is_string($ext)) {
|
|
$ext = json_decode($ext, true) ?: [];
|
|
}
|
|
if (!empty($ext['wallet_type'])) {
|
|
return $ext['wallet_type'];
|
|
}
|
|
$rewardType = $data['reward_type'] ?? '';
|
|
if (in_array($rewardType, ['voucher_grant', 'voucher_release'], true)) {
|
|
return 'voucher';
|
|
}
|
|
if ($rewardType === 'madow_share') {
|
|
return 'madow';
|
|
}
|
|
if (intval($data['user_id'] ?? 0) === 0) {
|
|
return 'system';
|
|
}
|
|
return PartnerConfig::rewardWalletType();
|
|
}
|
|
|
|
public function getWalletTypeTextAttr($value, $data)
|
|
{
|
|
$type = $this->getWalletTypeAttr(null, $data);
|
|
$map = [
|
|
'money' => '钱包余额',
|
|
'commission' => '佣金钱包',
|
|
'voucher' => '消费补贴券',
|
|
'madow' => '分红dmepa',
|
|
'system' => '平台留存',
|
|
];
|
|
return $map[$type] ?? '钱包余额';
|
|
}
|
|
|
|
public function buyer()
|
|
{
|
|
return $this->belongsTo(UserModel::class, 'buyer_id', 'id')->field('id, nickname, avatar, mobile');
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(UserModel::class, 'user_id', 'id')->field('id, nickname, avatar, mobile');
|
|
}
|
|
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(OrderModel::class, 'order_id', 'id');
|
|
}
|
|
}
|