代码初始化
This commit is contained in:
396
application/adminapi/controller/Decorate.php
Normal file
396
application/adminapi/controller/Decorate.php
Normal file
@@ -0,0 +1,396 @@
|
||||
<?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 Decorate extends adminApi
|
||||
{
|
||||
|
||||
protected $noNeedLogin = [];
|
||||
protected $noNeedRight = [];
|
||||
|
||||
protected $table = 'vs_decorate';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 装扮列表
|
||||
*/
|
||||
public function decorate_lists(){
|
||||
$admin_id = Session::get('admin_id');
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 30);
|
||||
$name = input('name', '');
|
||||
$type = input('type', '');
|
||||
$where = ['delete_time'=>0];
|
||||
if($name){
|
||||
$where['name'] = ['like', '%'.$name.'%'];
|
||||
}
|
||||
if($type){
|
||||
$where['type'] = $type;
|
||||
}
|
||||
$count = db::name($this->table)->where($where)->count();
|
||||
$lists = db::name($this->table)->where($where)->order('did desc')->page($page, $page_limit)->select();
|
||||
$return_list = [];
|
||||
foreach ($lists as $k=>$v){
|
||||
$return_list[$k]['id'] = $v['did'];
|
||||
$return_list[$k]['name'] = $v['title'];
|
||||
$return_list[$k]['type'] = $v['type'];
|
||||
$return_list[$k]['type_str'] = model('api/Decorate')->TypeArray[$v['type']];
|
||||
$return_list[$k]['base_image'] = $v['base_image'];
|
||||
$return_list[$k]['file_type'] = $v['file_type'];
|
||||
$return_list[$k]['file_type_str'] = $v['file_type'] ? "SVGA" : "MP4";
|
||||
$return_list[$k]['play_image'] = $v['play_image'];
|
||||
$return_list[$k]['show_status'] = $v['show_status'];
|
||||
$return_list[$k]['is_buy'] = $v['is_buy'];
|
||||
$return_list[$k]['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
|
||||
$return_list[$k]['admin_name'] = db::name('admin')->where(['id'=>$v['admin_id']])->value('nickname')??"--";
|
||||
|
||||
}
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'lists' => $return_list
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
|
||||
/*
|
||||
* 添加装扮
|
||||
*
|
||||
*/
|
||||
public function add_decorate(){
|
||||
$admin_id = Session::get('admin_id');
|
||||
$title = input('title', '');
|
||||
$type = input('type', '');
|
||||
$show_status = input('show_status', 1);
|
||||
$is_buy = input('is_buy', 1);
|
||||
$base_image = input('base_image', '');
|
||||
$file_type = input('file_type', 2);
|
||||
$play_image = input('play_image', '');
|
||||
//靓号
|
||||
$special_num = input('special_num', '');
|
||||
if($title==""){
|
||||
return V(0,"参数错");
|
||||
}
|
||||
if($type==""){
|
||||
return V(0,"参数错");
|
||||
}
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'type' => $type,
|
||||
'show_status' => $show_status,
|
||||
'is_buy' => $is_buy,
|
||||
'base_image' => $base_image,
|
||||
'file_type' => $file_type,
|
||||
'play_image' => $play_image,
|
||||
'special_num' => $special_num,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time(),
|
||||
'admin_id' => $admin_id
|
||||
];
|
||||
$id = db::name($this->table)->insertGetId($data);
|
||||
if(!$id){
|
||||
return V(0,"添加失败");
|
||||
}
|
||||
return V(1,"成功",['id'=>$id]);
|
||||
|
||||
}
|
||||
/*
|
||||
* 装扮详情
|
||||
*/
|
||||
public function decorate_info(){
|
||||
$did = input('id', '');
|
||||
if($did == ''){
|
||||
return V(0,"ID不能为空");
|
||||
}
|
||||
$decorate_data = db::name($this->table)->where(['did'=>$did])->find();
|
||||
if(!$decorate_data){
|
||||
return V(0,"装扮不存在");
|
||||
}
|
||||
return V(1,"成功", $decorate_data);
|
||||
}
|
||||
/*
|
||||
* 修改装扮
|
||||
*/
|
||||
public function edit_decorate(){
|
||||
$did = input('id', '');
|
||||
if($did == ''){
|
||||
return V(0,"ID不能为空");
|
||||
}
|
||||
$title = input('title', '');
|
||||
$type = input('type', '');
|
||||
$show_status = input('show_status', 1);
|
||||
$is_buy = input('is_buy', 1);
|
||||
$base_image = input('base_image', '');
|
||||
$file_type = input('file_type', 2);
|
||||
$play_image = input('play_image', '');
|
||||
$special_num = input('special_num', '');
|
||||
$data = [];
|
||||
if($title!=""){
|
||||
$data['title'] = $title;
|
||||
}
|
||||
if($type!=""){
|
||||
$data['type'] = $type;
|
||||
}
|
||||
if($show_status!=""){
|
||||
$data['show_status'] = $show_status;
|
||||
}
|
||||
if($is_buy!=""){
|
||||
$data['is_buy'] = $is_buy;
|
||||
}
|
||||
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($special_num!=""){
|
||||
$data['special_num'] = $special_num;
|
||||
}
|
||||
$data['updatetime'] = time();
|
||||
$res = db::name($this->table)->where(['did'=>$did])->update($data);
|
||||
if(!$res){
|
||||
return V(0,"修改失败");
|
||||
}
|
||||
return V(1,"成功");
|
||||
}
|
||||
/*
|
||||
* 道具类型
|
||||
*/
|
||||
public function type_array(){
|
||||
$list = model('api/Decorate')->TypeArray;
|
||||
$type_array = [];
|
||||
$i=0;
|
||||
foreach ($list as $key => $value) {
|
||||
$type_array[$i]['id'] = $key;
|
||||
$type_array[$i]['name'] = $value;
|
||||
$i++;
|
||||
}
|
||||
return V(1,"成功", $type_array);
|
||||
}
|
||||
/*
|
||||
* 删除装扮
|
||||
*/
|
||||
public function delete_decorate(){
|
||||
$did = input('id', '');
|
||||
if($did == ''){
|
||||
return V(0,"ID不能为空");
|
||||
}
|
||||
$res = db::name($this->table)->where(['did'=>$did])->update(['delete_time'=>time()]);
|
||||
if(!$res){
|
||||
return V(0,"删除失败");
|
||||
}
|
||||
return V(1,"成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 价格设置列表
|
||||
*/
|
||||
public function price_list(){
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 10);
|
||||
$where['is_delete'] =1;
|
||||
$where['did'] = input('did', '');
|
||||
if($where['did']==""){
|
||||
return V(0,"参数错");
|
||||
}
|
||||
$count = db::name("vs_decorate_price")->where($where)->count();
|
||||
$lists = db::name("vs_decorate_price")->where($where)->order('id desc')->page($page, $page_limit)->select();
|
||||
$return_list = [];
|
||||
foreach ($lists as $k=>$v){
|
||||
$return_list[$k]['id'] = $v['id'];
|
||||
$return_list[$k]['day'] = $v['day'];
|
||||
$return_list[$k]['original_price'] = $v['original_price'];
|
||||
$return_list[$k]['price'] = $v['price'];
|
||||
$return_list[$k]['discount'] = $v['discount'];
|
||||
$return_list[$k]['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
|
||||
$return_list[$k]['admin_name'] = db::name('admin')->where(['id'=>$v['admin_id']])->value('nickname')??"--";
|
||||
}
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'lists' => $return_list
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
/**
|
||||
* 添加价格设置
|
||||
*/
|
||||
public function add_price(){
|
||||
$admin_id = Session::get('admin_id');
|
||||
$did = input('did', '');
|
||||
$day = input('day', '');
|
||||
$original_price = input('original_price', '');
|
||||
$price = input('price', '');
|
||||
if($did==""){
|
||||
return V(0,"参数错");
|
||||
}
|
||||
if($day==""){
|
||||
return V(0,"参数错");
|
||||
}
|
||||
if($original_price==""){
|
||||
return V(0,"参数错");
|
||||
}
|
||||
if($price==""){
|
||||
return V(0,"参数错");
|
||||
}
|
||||
$decorate_data = db::name($this->table)->where(['did'=>$did,'day'=>$day])->find();
|
||||
if($decorate_data){
|
||||
return V(0,"该价格已存在");
|
||||
}
|
||||
//计算折扣取整
|
||||
$discount = round($price/$original_price, 2)*10;
|
||||
$data = [
|
||||
'did' => $did,
|
||||
'day' => $day,
|
||||
'original_price' => $original_price,
|
||||
'price' => $price,
|
||||
'discount' => $discount,
|
||||
'createtime' => time(),
|
||||
'admin_id' => $admin_id
|
||||
];
|
||||
$id = db::name('vs_decorate_price')->insertGetId($data);
|
||||
if(!$id){
|
||||
return V(0,"添加失败");
|
||||
}
|
||||
return V(1,"成功",['id'=>$id]);
|
||||
}
|
||||
/*
|
||||
* 修改价格设置
|
||||
*/
|
||||
public function edit_price(){
|
||||
$id = input('id', '');
|
||||
if($id == ''){
|
||||
return V(0,"ID不能为空");
|
||||
}
|
||||
$day = input('day', '');
|
||||
$original_price = input('original_price', '');
|
||||
$price = input('price', '');
|
||||
$discount = round($price/$original_price, 2)*10;;
|
||||
$data = [
|
||||
'day' => $day,
|
||||
'original_price' => $original_price,
|
||||
'price' => $price,
|
||||
'discount' => $discount,
|
||||
'updatetime' => time()
|
||||
];
|
||||
$res = db::name('vs_decorate_price')->where(['id'=>$id])->update($data);
|
||||
if(!$res){
|
||||
return V(0,"修改失败");
|
||||
}
|
||||
return V(1,"成功");
|
||||
}
|
||||
/*
|
||||
* 删除价格设置
|
||||
*/
|
||||
public function delete_price(){
|
||||
$id = input('id', '');
|
||||
if($id == ''){
|
||||
return V(0,"ID不能为空");
|
||||
}
|
||||
$res = db::name('vs_decorate_price')->where(['id'=>$id])->delete();
|
||||
if(!$res){
|
||||
return V(0,"删除失败");
|
||||
}
|
||||
return V(1,"成功");
|
||||
}
|
||||
/*
|
||||
* 用户装扮列表
|
||||
*/
|
||||
public function user_decorate_list(){
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 10);
|
||||
$user_id = input('user_id', '');
|
||||
$did = input('did', '');
|
||||
$type = input('type', '');
|
||||
$where = [];
|
||||
if($user_id!=""){
|
||||
$where['user_id'] = $user_id;
|
||||
}
|
||||
if($did!=""){
|
||||
$where['did'] = $did;
|
||||
}
|
||||
if($type!=""){
|
||||
$where['type'] = $type;
|
||||
}
|
||||
$count = db::name("vs_user_decorate")->where($where)->count();
|
||||
$lists = db::name("vs_user_decorate")->where($where)->order('udid desc')->page($page, $page_limit)->select();
|
||||
$return_list = [];
|
||||
foreach ($lists as $k=>$v){
|
||||
$return_list[$k]['id'] = $v['udid'];
|
||||
$return_list[$k]['user_name'] = $v['user_id']."-".db::name('user')->where(['id'=>$v['user_id']])->value('nickname');
|
||||
$return_list[$k]['type'] = model('api/Decorate')->TypeArray[$v['type']];
|
||||
if($v['type'] >= 6){
|
||||
$return_list[$k]['name'] = $v['special_num'];
|
||||
|
||||
}else{
|
||||
$return_list[$k]['name'] = db::name('vs_decorate')->where(['did'=>$v['did']])->value('title');
|
||||
}
|
||||
$return_list[$k]['base_image'] = db::name('vs_decorate')->where(['did'=>$v['did']])->value('base_image');
|
||||
$return_list[$k]['is_using'] = $v['is_using'];
|
||||
$return_list[$k]['is_using_str'] = $v['is_using']==1?"使用中":"未使用";
|
||||
if($v['is_perpetual']==1){
|
||||
$return_list[$k]['end_time'] = "永久";
|
||||
}else{
|
||||
$return_list[$k]['end_time'] = date('Y-m-d H:i:s', $v['end_time']);
|
||||
}
|
||||
}
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'lists' => $return_list,
|
||||
'type_array' => model('api/Decorate')->TypeArray
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
|
||||
/*
|
||||
* 赠送装扮
|
||||
*/
|
||||
public function give_decorate(){
|
||||
$user_id = input('user_id', '');
|
||||
$decorate_id = input('decorate_id', '');
|
||||
$day = input('day', '');
|
||||
$user = db::name('user')->where(['id'=>$user_id])->find();
|
||||
if(!$user){
|
||||
return V(0,"用户不存在");
|
||||
}
|
||||
$decorate = db::name('vs_decorate')->where(['did'=>$decorate_id])->find();
|
||||
if(!$decorate){
|
||||
return V(0,"装扮不存在");
|
||||
}
|
||||
$decorate_price = db::name('vs_decorate_price')->where(['did'=>$decorate_id,'day'=>$day,'is_delete'=>1])->find();
|
||||
if(!$decorate_price){
|
||||
return V(0,"该装扮天数不存在");
|
||||
}
|
||||
$result = model('api/Decorate')->pay_decorate($user_id,$decorate_id,$day,2);
|
||||
if($result['code'] == 1){
|
||||
return V(1,"成功");
|
||||
}else{
|
||||
return V(0,$result['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user