功能:送花/礼物系统完整开发
- 新增 Gift 模型和 gifts 数据表(7种默认花卉,各有图片/金币/魅力配置) - 7张花卉图片生成并存放于 public/images/gifts/ - 名片弹窗新增送礼物 UI:图片选择列表、金币/魅力标注、数量选择 - sendFlower 控制器方法:按 gift_id 查找礼物、扣金币、加魅力、广播消息 - 聊天消息渲染支持显示礼物图片(含弹跳动画效果) - 后台可在 gifts 表中管理花卉类型(名称、图标、图片、金币、魅力、排序、启禁用)
This commit is contained in:
53
app/Models/Gift.php
Normal file
53
app/Models/Gift.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user