改进 返回用户组价格
This commit is contained in:
parent
1dbf28e048
commit
5fc80dfe60
@ -87,11 +87,11 @@ public function getBirthdayFromIdCard(string|null $id_card = null): Carbon
|
|||||||
}
|
}
|
||||||
|
|
||||||
$bir = substr($id_card, 6, 8);
|
$bir = substr($id_card, 6, 8);
|
||||||
$year = (int) substr($bir, 0, 4);
|
$year = (int)substr($bir, 0, 4);
|
||||||
$month = (int) substr($bir, 4, 2);
|
$month = (int)substr($bir, 4, 2);
|
||||||
$day = (int) substr($bir, 6, 2);
|
$day = (int)substr($bir, 6, 2);
|
||||||
|
|
||||||
return Carbon::parse($year.'-'.$month.'-'.$day);
|
return Carbon::parse($year . '-' . $month . '-' . $day);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasBalance(string $amount = '0.01'): bool
|
public function hasBalance(string $amount = '0.01'): bool
|
||||||
@ -162,13 +162,26 @@ public function startTransfer(self $to, string $amount, string|null $description
|
|||||||
return $this->balance;
|
return $this->balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCostPrice(string $price): string
|
||||||
|
{
|
||||||
|
$this->load('user_group');
|
||||||
|
|
||||||
|
if (!$this->user_group) {
|
||||||
|
return $price;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->user_group->getCostPrice($price);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 扣除费用
|
* 扣除费用
|
||||||
*
|
*
|
||||||
* @param string|null $amount
|
* @param string|null $amount
|
||||||
* @param string $description
|
* @param string $description
|
||||||
* @param bool $fail
|
* @param bool $fail
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function reduce(string|null $amount = '0', string $description = '消费', bool $fail = false, array $options = []): string
|
public function reduce(string|null $amount = '0', string $description = '消费', bool $fail = false, array $options = []): string
|
||||||
@ -177,7 +190,7 @@ public function reduce(string|null $amount = '0', string $description = '消费'
|
|||||||
return $this->balance;
|
return $this->balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache::lock('user_balance_'.$this->id, 10)->block(10, function () use ($amount, $fail, $description, $options) {
|
Cache::lock('user_balance_' . $this->id, 10)->block(10, function () use ($amount, $fail, $description, $options) {
|
||||||
$this->refresh();
|
$this->refresh();
|
||||||
|
|
||||||
if ($this->balance < $amount) {
|
if ($this->balance < $amount) {
|
||||||
@ -210,10 +223,11 @@ public function reduce(string|null $amount = '0', string $description = '消费'
|
|||||||
/**
|
/**
|
||||||
* 增加余额
|
* 增加余额
|
||||||
*
|
*
|
||||||
* @param string|null $amount
|
* @param string|null $amount
|
||||||
* @param string $payment
|
* @param string $payment
|
||||||
* @param string $description
|
* @param string $description
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function charge(string|null $amount = '0', string $payment = 'console', string $description = '充值', array $options = []): string
|
public function charge(string|null $amount = '0', string $payment = 'console', string $description = '充值', array $options = []): string
|
||||||
@ -222,7 +236,7 @@ public function charge(string|null $amount = '0', string $payment = 'console', s
|
|||||||
return $this->balance;
|
return $this->balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache::lock('user_balance_'.$this->id, 10)->block(10, function () use ($amount, $description, $payment, $options) {
|
Cache::lock('user_balance_' . $this->id, 10)->block(10, function () use ($amount, $description, $payment, $options) {
|
||||||
$this->refresh();
|
$this->refresh();
|
||||||
$this->balance = bcadd($this->balance, $amount, 4);
|
$this->balance = bcadd($this->balance, $amount, 4);
|
||||||
$this->save();
|
$this->save();
|
||||||
|
@ -60,4 +60,15 @@ public function setTempGroup(User $user, self $group, Carbon $expired_at): User
|
|||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCostPrice(string $price): string
|
||||||
|
{
|
||||||
|
if ($this->exempt) {
|
||||||
|
return '0';
|
||||||
|
} else if ($this->discount !== 100 && $this->discount !== null) {
|
||||||
|
$price = bcmul($price, bcdiv($this->discount, '100', 4), 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $price;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user