101 lines
2.8 KiB
PHP
101 lines
2.8 KiB
PHP
<?php
|
|
require_once('models/Emoji.php');
|
|
|
|
use models\Emoji;
|
|
class EmojiController extends BaseAuthedController
|
|
{
|
|
// public function getEmojiList(){
|
|
// $this->_rspData(array(
|
|
// 'data' => array(
|
|
// array(
|
|
// 'item_id'=>200001,
|
|
// 'state'=>1,
|
|
// )
|
|
// ),
|
|
// 'use_emoji' => array(200001)
|
|
// ));
|
|
// }
|
|
|
|
public function getEmojiList(){
|
|
$list = Emoji::emojiList();
|
|
$uses = Emoji::getUseEmoji();
|
|
$temp = array_map(function ($val){
|
|
return $val['item_id'];
|
|
},$uses);
|
|
$data = array();
|
|
foreach ($list as $val){
|
|
if(in_array($val, $temp)){
|
|
array_push($data,
|
|
array(
|
|
'item_id'=>$val,
|
|
'state'=>1,
|
|
)
|
|
);
|
|
}else{
|
|
array_push($data,
|
|
array(
|
|
'item_id'=>$val,
|
|
'state'=>0,
|
|
)
|
|
);
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'data' => $data,
|
|
'use_emoji' => $uses
|
|
));
|
|
}
|
|
|
|
public function setEmoji(){
|
|
$itemId = getReqVal('item_id', '');
|
|
$slotId = getReqVal('slot_id', 0);
|
|
if(! in_array($itemId,Emoji::emojiList())){
|
|
$this->_rspErr(1, 'item_id parameter error');
|
|
return;
|
|
}
|
|
if($slotId < 1 || $slotId > 6){
|
|
$this->_rspErr(1, 'slot_id parameter error');
|
|
return;
|
|
}
|
|
$uses = Emoji::getUseEmoji();
|
|
$temp = array_map(function ($val){
|
|
return $val['item_id'];
|
|
},$uses);
|
|
if(in_array($itemId,$temp)){
|
|
$this->_rspErr(1, 'The emoji has been used');
|
|
return;
|
|
}
|
|
if ($uses){
|
|
foreach ($uses as &$val){
|
|
if ($val['slot_id'] == $slotId){
|
|
$val['item_id'] = $itemId;
|
|
}
|
|
}
|
|
}else{
|
|
array_push($uses,array(
|
|
'item_id' => $itemId,
|
|
"slot_id" => $slotId
|
|
));
|
|
}
|
|
|
|
Emoji::updateEmoji( json_encode($uses));
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function cancel(){
|
|
$slotId = getReqVal('slot_id', 0);
|
|
if($slotId < 1 || $slotId > 6){
|
|
$this->_rspErr(1, 'slot_id parameter error');
|
|
return;
|
|
}
|
|
$uses = Emoji::getUseEmoji();
|
|
|
|
foreach ($uses as &$val){
|
|
if ($val['slot_id'] == $slotId){
|
|
$val['item_id'] = 0;
|
|
}
|
|
}
|
|
Emoji::updateEmoji(json_encode($uses));
|
|
$this->_rspOk();
|
|
}
|
|
} |