Files
midi-php/application/adminapi/controller/RoomEmoji.php
2025-10-22 10:57:30 +08:00

170 lines
4.6 KiB
PHP

<?php
namespace app\adminapi\controller;
use app\admin\model\AdminLog;
use app\common\controller\adminApi;
use think\Config;
use think\Db;
use think\Hook;
use think\Model;
use think\Session;
use think\Validate;
/**
* 房间
* @internal
*/
class RoomEmoji extends adminApi
{
protected $noNeedLogin = [];
protected $noNeedRight = ['emoji_list','add_emoji','edit_emoji','del_emoji','emoji_detail','emoji_type_list'];
protected $table = 'vs_room_emoji';
protected $table_type = 'vs_room_emoji_type';
public function _initialize()
{
parent::_initialize();
}
//房间表情列表
function emoji_list(){
$id = input('id', '', 'intval');
$name = input('name', '', 'trim');
$page = input('page', 1, 'intval');
$limit = input('limit', 10, 'intval');
$where = [];
if ($id) {
$where['id'] = $id;
}
if ($name) {
$where['name'] = ['like', '%' . $name . '%'];
}
$total = Db::name($this->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);
}
}