Files

270 lines
8.5 KiB
PHP
Raw Permalink Normal View History

2025-08-07 20:21:47 +08:00
<?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\Session;
use think\Validate;
/**
* 礼物
* @internal
*/
class Gift extends adminApi
{
protected $noNeedLogin = [];
protected $noNeedRight = ['gift_type_lists'];
protected $table = 'vs_gift';
public function _initialize()
{
parent::_initialize();
}
/*
* 一级分类列表
*/
public function gift_type_lists(){
$type = input('type', 1);
$giftType = [];
if($type == 1){
$giftTypeArray = model('Gift')->giftType;
$i=0;
foreach ($giftTypeArray as $key => $value) {
$giftType[$i]['id'] = $key;
$giftType[$i]['name'] = $value;
$i++;
}
}
if($type == 2){
$type_id = input('type_id', 0);
$where['delete_time'] = 0;
if(!empty($type_id)){
$where['tid'] = $type_id;
}
$giftTypeData = db::name('vs_gift_label')->where($where)->order("sort asc,id desc")->select();
2025-08-07 20:21:47 +08:00
foreach ($giftTypeData as $key => $value) {
$giftType[$key]['id'] = $value['id'];
$giftType[$key]['name'] = $value['name'];
}
}
return V(1,"成功", $giftType);
}
/**
* 礼物列表
*/
public function gift_lists(){
$page = input('page', 1);
$page_limit = input('page_limit', 30);
$search_gift_id = input('search_gift_id', '');
$search_gift_name = input('search_gift_name', '');
$search_gift_type = input('search_gift_type', '');
$search_gift_label = input('search_gift_label', '');
$where=[];
$where['delete_time'] = 0;
if($search_gift_id!==''){
$where['gid'] =$search_gift_id;
}
if($search_gift_type!==''){
$where['type'] =$search_gift_type;
}
if($search_gift_label!==''){
$where['label'] =$search_gift_label;
}
if($search_gift_name!==''){
$where['gift_name'] = ['like', '%'.$search_gift_name.'%'];
}
$count = db::name($this->table)->where($where)->count();
$lists_data = db::name($this->table)->where($where)->page($page, $page_limit)->order("sort,gid desc")->select();
$lists = [];
foreach ($lists_data as $key => $value) {
$lists[$key]['gid'] = $value['gid'];
$lists[$key]['gift_name'] = $value['gift_name'];
$lists[$key]['type'] = model('Gift')->giftType[$value['type']];
$lists[$key]['label'] = db::name('vs_gift_label')->where('id', $value['label'])->value('name');
$lists[$key]['base_image'] = $value['base_image'];
$lists[$key]['gift_price'] = $value['gift_price'];
$lists[$key]['sort'] = $value['sort'];
$lists[$key]['is_public_screen'] = $value['is_public_screen'];
$lists[$key]['is_public_server'] = $value['is_public_server'];
$lists[$key]['is_show'] = $value['is_show'];
$lists[$key]['is_can_buy'] = $value['is_can_buy'];
$lists[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
$lists[$key]['updatetime'] = date('Y-m-d H:i:s', $value['updatetime']);
}
$return_data = [
'page' =>$page,
'page_limit' => $page_limit,
'count' => $count,
'lists' => $lists
];
return V(1,"成功", $return_data);
}
/**
* 添加礼物
*/
public function add_gift(){
$gift_name = input('gift_name', '');
$type = input('type', '');
$label = input('label', '');
$gift_price = input('gift_price', '');
$base_image = input('base_image', '');
$file_type = input('file_type', 2);
$play_image = input('play_image', '');
$gift_type = input('gift_type', 1);
$is_public_screen = input('is_public_screen', 1);
$is_public_server = input('is_public_server', 1);
$is_can_buy = input('is_can_buy', 1);
$is_show = input('is_show', 1);
$sort = input('sort', 0);
if($gift_name==""){
return V(0,"礼物名称不能为空");
}
if($type == ''){
return V(0,"请选择礼物类型");
}
// if($label == ''){
// return V(0,"请选择礼物标签");
// }
if($gift_price == ''){
return V(0,"请输入礼物价格");
}
if($base_image == ''){
return V(0,"请上传礼物图片");
}
$data = [
'gift_name' => $gift_name,
'type' => $type,
'label' => $label,
'gift_price' => $gift_price,
'base_image' => $base_image,
'file_type' => $file_type,
'play_image' => $play_image,
'gift_type' => $gift_type,
'is_public_screen' => $is_public_screen,
'is_public_server' => $is_public_server,
'is_can_buy' => $is_can_buy,
'is_show' => $is_show,
'sort' => $sort,
'createtime' => time(),
'updatetime' => time()
];
$id = db::name($this->table)->insertGetId($data);
if(!$id){
return V(0,"添加失败");
}
return V(1,"成功",['id'=>$id]);
}
/*
* 礼物详情
*/
public function gift_info(){
$gid = input('gid', '');
if($gid == ''){
return V(0,"ID不能为空");
}
$gift_data = db::name($this->table)->where(['gid'=>$gid])->find();
if(!$gift_data){
return V(0,"礼物不存在");
}
return V(1,"成功", $gift_data);
}
/*
* 编辑礼物
*/
public function edit_gift(){
$gid = input('gid', '');
$gift_name = input('gift_name', '');
$type = input('type', '');
$label = input('label', '');
$gift_price = input('gift_price', '');
$base_image = input('base_image', '');
$file_type = input('file_type', '');
$play_image = input('play_image', '');
$gift_type = input('gift_type', '');
$is_public_screen = input('is_public_screen', '');
$is_public_server = input('is_public_server', '');
$is_can_buy = input('is_can_buy', '');
$is_show = input('is_show', '');
$sort = input('sort', '');
if($gid == ''){
return V(0,"ID不能为空");
}
$gift_data = db::name($this->table)->where(['gid'=>$gid])->find();
if(!$gift_data){
return V(0,"礼物不存在");
}
$gift_name = input('gift_name', '');
$data=[];
if($gift_name){
$data['gift_name'] = $gift_name;
$gift_data_to_name = db::name($this->table)->where(['gift_name'=>$gift_name,'delete_time'=>0,'gid'=>['<>',$gid]])->find();
if($gift_data_to_name){
return V(0,"礼物已存在");
}
}
if($type){
$data['type'] = $type;
}
if($label){
$data['label'] = $label;
}
if($gift_price){
$data['gift_price'] = $gift_price;
}
if($base_image){
$data['base_image'] = $base_image;
}
if($file_type){
$data['file_type'] = $file_type;
}
if($play_image){
$data['play_image'] = $play_image;
}
if($gift_type){
$data['gift_type'] = $gift_type;
}
if($is_public_screen){
$data['is_public_screen'] = $is_public_screen;
}
if($is_public_server){
$data['is_public_server'] = $is_public_server;
}
if($is_can_buy){
$data['is_can_buy'] = $is_can_buy;
}
if($is_show){
$data['is_show'] = $is_show;
}
$result = db::name($this->table)->where(['gid'=>$gid])->update($data);
if(!$result){
return V(0,"修改失败,礼物内容无更改");
}
return V(1,"成功", ['id'=>$gid]);
}
/*
* 删除礼物
*/
public function del_gift(){
$gid = input('gid', '');
if($gid == ''){
return V(0,"ID不能为空");
}
$result = db::name($this->table)->where(['gid'=>$gid])->setField(['delete_time'=>time()]);
if(!$result){
return V(0,"删除失败");
}
return V(1,"成功");
}
}