表情包功能上传
This commit is contained in:
170
application/adminapi/controller/RoomEmoji.php
Normal file
170
application/adminapi/controller/RoomEmoji.php
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
<?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 = ['room_user_log','room_flow'];
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
application/api/controller/RoomEmoji.php
Normal file
22
application/api/controller/RoomEmoji.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\controller;
|
||||||
|
|
||||||
|
use app\common\controller\BaseCom;
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
class RoomEmoji extends BaseCom
|
||||||
|
{
|
||||||
|
//表情类型列表
|
||||||
|
public function type_list(){
|
||||||
|
$reslut = model('RoomEmoji')->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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
67
application/api/model/RoomEmoji.php
Normal file
67
application/api/model/RoomEmoji.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\model;
|
||||||
|
|
||||||
|
use app\common\controller\Push;
|
||||||
|
use think\Cache;
|
||||||
|
use think\Db;
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class RoomEmoji extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'vs_room_emoji';
|
||||||
|
protected $table_type = 'vs_room_emoji_type';
|
||||||
|
private $redis;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user