From 0451444b85e62b629f2c783584cccd180eef3e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=92=8A?= Date: Wed, 22 Oct 2025 10:38:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E6=83=85=E5=8C=85=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/adminapi/controller/RoomEmoji.php | 170 ++++++++++++++++++ application/api/controller/RoomEmoji.php | 22 +++ application/api/model/RoomEmoji.php | 67 +++++++ 3 files changed, 259 insertions(+) create mode 100644 application/adminapi/controller/RoomEmoji.php create mode 100644 application/api/controller/RoomEmoji.php create mode 100644 application/api/model/RoomEmoji.php diff --git a/application/adminapi/controller/RoomEmoji.php b/application/adminapi/controller/RoomEmoji.php new file mode 100644 index 0000000..d548b47 --- /dev/null +++ b/application/adminapi/controller/RoomEmoji.php @@ -0,0 +1,170 @@ +table) + ->where($where) + ->count(); + $list = Db::name($this->table) + ->where($where) + ->order('sort desc,id desc') + ->page($page, $limit) + ->select(); + foreach ($list as &$item) { + $item['createtime'] = date('Y-m-d H:i:s', $item['createtime']); + $item['status_str'] = $item['status'] == 1 ? '显示' : '隐藏'; + } + $return_data = [ + 'page' => $page, + 'limit' => $limit, + 'total' => $total, + 'list' => $list + ]; + return V(1,"成功", $return_data); + } + //添加房间表情 + function add_emoji(){ + $pid = input('pid', 0, 'intval'); + $name = input('name', '', 'trim'); + $img = input('image', '', 'trim'); + $animate_image = input('animate_image', '', 'trim'); + $sort = input('sort', 0, 'intval'); + $type_id = input('type_id', 0); + $status = input('status', 1, 'intval'); + if (!$name) { + return V(0, '请输入表情名称'); + } + if (!$img) { + return V(0, '请上传表情图片'); + } + if (!$type_id) { + return V(0, '请选择表情类型'); + } + $data = [ + 'pid' => $pid, + 'name' => $name, + 'image' => $img, + 'animate_image' => $animate_image, + 'sort' => $sort, + 'type_id' => $type_id, + 'status' => $status, + 'createtime' => time(), + ]; + $res = Db::name($this->table)->insert($data); + if ($res) { + return V(1, '添加成功'); + } + } + //房间表情修改 + function edit_emoji(){ + $id = input('id', 0, 'intval'); + $name = input('name', '', 'trim'); + $img = input('image', '', 'trim'); + $animate_image = input('animate_image', '', 'trim'); + $sort = input('sort', 0, 'intval'); + $type_id = input('type_id', 0); + $status = input('status', 1, 'intval'); + if (!$id) { + return V(0, '请选择要修改的表情'); + } + if($name){ + $data['name'] = $name; + } + if($img){ + $data['image'] = $img; + } + if($animate_image){ + $data['animate_image'] = $animate_image; + } + if($sort){ + $data['sort'] = $sort; + } + if($type_id){ + $data['type_id'] = $type_id; + } + $data['status'] = $status; + $res = Db::name($this->table)->where('id',$id)->update($data); + if ($res) { + return V(1, '修改成功'); + } + } + //房间表情删除 + function del_emoji(){ + $id = input('id', 0, 'intval'); + if (!$id) { + return V(0, '请选择要删除的表情'); + } + $res = Db::name($this->table)->where('id',$id)->update( + ['deletetime' => time()] + ); + if ($res) { + return V(1, '删除成功'); + } + } + //表情详情 + function emoji_detail(){ + $id = input('id', 0, 'intval'); + if (!$id) { + return V(0, '请选择要查看的表情'); + } + $detail = Db::name($this->table)->where('id',$id)->find(); + if (!$detail) { + return V(0, '表情不存在'); + } + return V(1,"成功", $detail); + } + + //表情类型列表 + function emoji_type_list(){ + $emoji_type = Db::name($this->table_type) + ->field('id,type_name') + ->where(['deletetime'=>0,'status'=>1]) + ->order('sort desc,id desc') + ->select(); + return V(1,"成功", $emoji_type); + } + +} \ No newline at end of file diff --git a/application/api/controller/RoomEmoji.php b/application/api/controller/RoomEmoji.php new file mode 100644 index 0000000..058e5b4 --- /dev/null +++ b/application/api/controller/RoomEmoji.php @@ -0,0 +1,22 @@ +getRoomEmojiType(); + return V($reslut['code'], $reslut['msg'], $reslut['data']); + } + //表情列表 + public function emoji_list(){ + $type_id = input('type_id', ""); + $pid = input('pid', ""); + $reslut = model('RoomEmoji')->getRoomEmoji($type_id,$pid,true); + return V($reslut['code'], $reslut['msg'], $reslut['data']); + } +} \ No newline at end of file diff --git a/application/api/model/RoomEmoji.php b/application/api/model/RoomEmoji.php new file mode 100644 index 0000000..b18577c --- /dev/null +++ b/application/api/model/RoomEmoji.php @@ -0,0 +1,67 @@ +redis = \think\Cache::store('redis')->handler(); + } + //获取房间表情包类型 + public function getRoomEmojiType(){ + $list = db($this->table_type)->field('id,type_name')->where(['status'=>1,'deletetime'=>0])->select(); + return ['code' => 1, 'msg' => '创建成功', 'data' => $list]; + } + + //获取房间表情包 + public function getRoomEmoji($type_id=0,$pid=0, $isTree = false){ + $where = []; + if($type_id){ + $where['type_id'] = $type_id; + } + if($pid!=""){ + $where['pid'] = $pid; + } + $list = db($this->table) + ->field('id,pid,type_id,name,image,animate_image') + ->where(['status'=>1,'deletetime'=>0]) + ->where($where) + ->order('sort desc,id desc') + ->select(); + if ($isTree && !empty($list) && empty($pid)) { + $list = $this->buildTree($list); + } + return ['code' => 1, 'msg' => '成功', 'data' => $list]; + } + + /** + * 将扁平数据转换为树状结构 + * @param array $data 数据列表 + * @param int $pid 父级ID + * @return array + */ + private function buildTree($data, $pid = 0) + { + $tree = []; + foreach ($data as $item) { + if ($item['pid'] == $pid) { + $children = $this->buildTree($data, $item['id']); + if (!empty($children)) { + $item['children'] = $children; + } + $tree[] = $item; + } + } + return $tree; + } +} \ No newline at end of file