房间表情功能-前端-接口提交
This commit is contained in:
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')
|
||||||
|
->where(['status'=>1,'deletetime'=>0])
|
||||||
|
->where($where)
|
||||||
|
->order('sort asc,id asc')
|
||||||
|
->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