|
@@ -390,7 +390,26 @@ class User extends Authenticatable implements JWTSubject
|
|
|
|
|
|
public function incrementData(int $data): bool
|
|
public function incrementData(int $data): bool
|
|
{// 添加用户流量
|
|
{// 添加用户流量
|
|
- $this->transfer_enable += $data;
|
|
|
|
|
|
+
|
|
|
|
+ //用户的 剩余流量
|
|
|
|
+ $totalTransfer = $this->transfer_enable;
|
|
|
|
+ $usedTransfer = $this->u + $this->d;
|
|
|
|
+ $unusedTraffic = $totalTransfer - $usedTransfer; // 计算剩余流量
|
|
|
|
+
|
|
|
|
+ // 如果剩余流量为负数,将其设置为0
|
|
|
|
+ if ($unusedTraffic < 0) {
|
|
|
|
+ $unusedTraffic = 0;
|
|
|
|
+ $this->d = 0;
|
|
|
|
+ $this->u = 0;
|
|
|
|
+ }
|
|
|
|
+ // 用户的使用流量超过总流量就
|
|
|
|
+ if ($unusedTraffic > $totalTransfer) {
|
|
|
|
+ $unusedTraffic = 0;
|
|
|
|
+ $this->d = 0;
|
|
|
|
+ $this->u = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->transfer_enable = $data + $unusedTraffic;
|
|
|
|
|
|
return $this->save();
|
|
return $this->save();
|
|
}
|
|
}
|