|
|
@@ -3,22 +3,21 @@
|
|
|
namespace App\Module\Pet\Models;
|
|
|
|
|
|
use UCore\ModelCore;
|
|
|
-use App\Module\Pet\Enums\PetStatus;
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
|
/**
|
|
|
* 宠物技能模型
|
|
|
*
|
|
|
- * field start
|
|
|
- * @property int $id
|
|
|
+ * field start
|
|
|
+ * @property int $id
|
|
|
* @property string $skill_name 技能名称
|
|
|
* @property int $stamina_cost 体力消耗
|
|
|
* @property int $cool_down 冷却时间(秒)
|
|
|
* @property int $duration_time 持续时间(秒)
|
|
|
* @property string $effect_desc 效果描述
|
|
|
* @property int $min_level 最低等级要求
|
|
|
- * @property \Carbon\Carbon $created_at
|
|
|
- * @property \Carbon\Carbon $updated_at
|
|
|
+ * @property \Carbon\Carbon $created_at
|
|
|
+ * @property \Carbon\Carbon $updated_at
|
|
|
* field end
|
|
|
*/
|
|
|
class PetSkill extends ModelCore
|
|
|
@@ -35,7 +34,7 @@ class PetSkill extends ModelCore
|
|
|
*
|
|
|
* @var array
|
|
|
*/
|
|
|
- // attrlist start
|
|
|
+ // attrlist start
|
|
|
protected $fillable = [
|
|
|
'id',
|
|
|
'skill_name',
|
|
|
@@ -70,4 +69,72 @@ class PetSkill extends ModelCore
|
|
|
return $this->hasMany(PetSkillLog::class, 'skill_id');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 格式化持续时间显示
|
|
|
+ *
|
|
|
+ * @param int $seconds 秒数
|
|
|
+ * @return string 友好的时间显示
|
|
|
+ */
|
|
|
+ public static function formatDuration(int $seconds): string
|
|
|
+ {
|
|
|
+ if ($seconds <= 0) {
|
|
|
+ return '<span class="text-muted">无持续时间</span>';
|
|
|
+ }
|
|
|
+
|
|
|
+ $days = floor($seconds / 86400);
|
|
|
+ $hours = floor(($seconds % 86400) / 3600);
|
|
|
+ $minutes = floor(($seconds % 3600) / 60);
|
|
|
+ $remainingSeconds = $seconds % 60;
|
|
|
+
|
|
|
+ $parts = [];
|
|
|
+
|
|
|
+ if ($days > 0) {
|
|
|
+ $parts[] = "<span class=\"badge badge-primary\">{$days}天</span>";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($hours > 0) {
|
|
|
+ $parts[] = "<span class=\"badge badge-info\">{$hours}小时</span>";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($minutes > 0) {
|
|
|
+ $parts[] = "<span class=\"badge badge-success\">{$minutes}分钟</span>";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($remainingSeconds > 0 && empty($parts)) {
|
|
|
+ // 只有在没有更大单位时才显示秒数
|
|
|
+ $parts[] = "<span class=\"badge badge-secondary\">{$remainingSeconds}秒</span>";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($parts)) {
|
|
|
+ return '<span class="text-muted">瞬间</span>';
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = implode(' ', $parts);
|
|
|
+
|
|
|
+ // 添加原始秒数的提示
|
|
|
+ $result .= "<br><small class=\"text-muted\">({$seconds}秒)</small>";
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取格式化的持续时间
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getFormattedDurationTimeAttribute(): string
|
|
|
+ {
|
|
|
+ return self::formatDuration($this->duration_time);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取格式化的冷却时间
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getFormattedCoolDownAttribute(): string
|
|
|
+ {
|
|
|
+ return self::formatDuration($this->cool_down);
|
|
|
+ }
|
|
|
+
|
|
|
}
|