54 lines
1.1 KiB
PHP
54 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 文件功能:礼物/鲜花模型
|
||
|
|
* 存储各种礼物的名称、图标、金币消耗、魅力增量等信息。
|
||
|
|
* 后台可完整 CRUD 管理,前端名片弹窗中展示可送的礼物列表。
|
||
|
|
*
|
||
|
|
* @author ChatRoom Laravel
|
||
|
|
*
|
||
|
|
* @version 1.0.0
|
||
|
|
*/
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
class Gift extends Model
|
||
|
|
{
|
||
|
|
/** @var string 表名 */
|
||
|
|
protected $table = 'gifts';
|
||
|
|
|
||
|
|
/** @var array 可批量赋值字段 */
|
||
|
|
protected $fillable = [
|
||
|
|
'name',
|
||
|
|
'emoji',
|
||
|
|
'image',
|
||
|
|
'cost',
|
||
|
|
'charm',
|
||
|
|
'sort_order',
|
||
|
|
'is_active',
|
||
|
|
];
|
||
|
|
|
||
|
|
/** @var array 类型转换 */
|
||
|
|
protected $casts = [
|
||
|
|
'cost' => 'integer',
|
||
|
|
'charm' => 'integer',
|
||
|
|
'sort_order' => 'integer',
|
||
|
|
'is_active' => 'boolean',
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取所有启用的礼物列表(按排序字段排列)
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
||
|
|
*/
|
||
|
|
public static function activeList()
|
||
|
|
{
|
||
|
|
return static::where('is_active', true)
|
||
|
|
->orderBy('sort_order')
|
||
|
|
->orderBy('cost')
|
||
|
|
->get();
|
||
|
|
}
|
||
|
|
}
|