This commit is contained in:
commie
2026-02-24 21:02:17 +08:00
parent 6586f27c9e
commit c9c8a120ab
12 changed files with 345 additions and 103 deletions
+18 -4
View File
@@ -99,10 +99,11 @@ class ThaliController extends BaseController{
return $this->fail(__('Role does not exist'));
}
$role_id = $thali->role_id;
if($user->role_id >= $role_id){
if($user->role_id > $role_id){
return $this->fail(__('Your level is too high to purchase this character'));
}
$price = $thali->price;
if($quantity == 1){
$price = $thali->month_price;
}
@@ -112,7 +113,17 @@ class ThaliController extends BaseController{
if($quantity == 12){
$price = $thali->year_price;
}
$amount = $price * $quantity;
//升级
$isUpgrade=true;
//续费
if($user->role_id == $role_id){
$isUpgrade = false;
}
$amount = $price;
if($isUpgrade){
//按那个价格算,目前是按原价,剩余时间不做抵扣
}
//$amount = $price * $quantity;
if($amount <=0){
return $this->fail(__('This character group is not allowed to be sold'));
}
@@ -121,14 +132,17 @@ class ThaliController extends BaseController{
}
\support\Jwt::verify_trade_password($request->post('trade_password'));
$user = \support\Jwt::getUser();
$user->role_id = $role_id;
$user->expire_at = ($user->expire_at>time() ? $user->expire_at : time())+86400* $quantity * 30;
if($isUpgrade){
$user->expire_at = (time())+86400* $quantity * 30;
$user->role_id = $role_id;
}
$user->save();
cache('user_role_'.$user->userID,[
'role_id'=>$role_id,'expire_at'=>$user->expire_at
],$user->expire_at-time());
\app\model\User::score($user->id,-$amount,\app\enum\BalanceType::PURCHASE_ROLE,$role_id);
\app\model\User::score($user->id,-$amount,\app\enum\BalanceType::PURCHASE_ROLE,json_encode(['role_id'=>$role_id,'quantity'=>$quantity,'role_name'=>$thali->title]));
//Hook('user.roleup', $user);
// $data = [
// 'role_id' => $role_id,