| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Module\GameItems\Logics;
- use App\Module\GameItems\Models\ItemUserOutputCounter;
- /**
- * 用户产出计数逻辑类
- */
- class UserOutputCounter
- {
- /**
- * 增加计数
- *
- * @param ItemUserOutputCounter $counter 用户产出计数模型
- * @param int $count 增加的数量
- * @return bool
- */
- public function incrementCount(ItemUserOutputCounter $counter, int $count = 1): bool
- {
- $counter->current_count += $count;
- return $counter->save();
- }
- /**
- * 重置计数
- *
- * @param ItemUserOutputCounter $counter 用户产出计数模型
- * @return bool
- */
- public function resetCount(ItemUserOutputCounter $counter): bool
- {
- $counter->current_count = 0;
- $counter->last_reset_time = now();
- return $counter->save();
- }
- /**
- * 检查是否达到限制
- *
- * @param ItemUserOutputCounter $counter 用户产出计数模型
- * @return bool
- */
- public function isLimitReached(ItemUserOutputCounter $counter): bool
- {
- $limit = $counter->outputLimit;
- if (!$limit) {
- return false;
- }
- return $counter->current_count >= $limit->max_quantity;
- }
- }
|