表情包功能上传
This commit is contained in:
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