Files
mier-php/application/admin/model/Nobility.php
2025-08-11 10:22:05 +08:00

252 lines
9.8 KiB
PHP

<?php
namespace app\admin\model;
use think\Db;
use think\Model;
class Nobility extends Model
{
//列表
public function get_nobility_list($order, $sort, $page = 1, $limit = 20)
{
$map = [];
$map[] = ['is_delete', '=', 1];
$list = db::name('nobility')->where($map)->order($order, $sort)->page($page, $limit)->select();
foreach ($list as $k => &$v) {
$v['image'] = localpath_to_netpath($v['image']);
}
$data = [];
$data['count'] = db::name('nobility')->where($map)->count();
$data['list'] = $list;
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
}
//编辑
public function edit_nobility($data)
{
if (empty($data)) {
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
}
$nobility_info = db::name('nobility')->find($data['lid']);
if (empty($nobility_info)) {
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
}
$update_data = [];
// $update_data['level'] = $data['level'];
$update_data['name'] = $data['name'];
$update_data['image'] = $data['image'];
// $update_data['change_value'] = $data['change_value'];
// $update_data['images'] = $data['images'];
$update_data['pay_price'] = $data['pay_price'];
$update_data['renew_price'] = $data['renew_price'];
$update_data['pay_coin'] = $data['pay_coin'];
$update_data['renew_coin'] = $data['renew_coin'];
// $update_data['play_image'] = $data['play_image'];
// $update_data['is_public_server'] = $data['is_public_server'];
// $update_data['is_kick'] = $data['is_kick'];
// $update_data['is_show_rank'] = $data['is_show_rank'];
// $update_data['is_freedom_micro'] = $data['is_freedom_micro'];
// $update_data['is_look_visitor'] = $data['is_look_visitor'];
$update_data['day_num'] = $data['day_num'];
$update_data['update_time'] = time();
$reslut = db::name('nobility')->where(['lid' => $data['lid']])->update($update_data);
if (!$reslut) {
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
} else {
return ['code' => 200, 'msg' => '修改成功', 'data' => null];
}
}
//获取信息
public function nobility_info($lid)
{
if (empty($lid)) {
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
}
$gift_info = db::name('nobility')->where(['lid' => $lid])->find();
$gift_info['image'] = localpath_to_netpath($gift_info['image']);
// $gift_info['images'] = localpath_to_netpath($gift_info['images']);
// $gift_info['http_play_image'] = localpath_to_netpath($gift_info['play_image']);
return ['code' => 200, 'msg' => '获取成功', 'data' => $gift_info];
}
//权限列表
public function get_nobility_power_list($order, $sort, $page = 1, $limit = 20)
{
$map = [];
$list = db::name('nobility_power')->where($map)->order($order, $sort)->page($page, $limit)->select();
foreach ($list as $k => &$v) {
$v['image'] = localpath_to_netpath($v['image']);
}
$data = [];
$data['count'] = db::name('nobility_power')->where($map)->count();
$data['list'] = $list;
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
}
//获取信息
public function nobility_power_info($id)
{
if (empty($id)) {
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
}
$gift_info = db::name('nobility_power')->where(['id' => $id])->find();
$gift_info['image'] = localpath_to_netpath($gift_info['image']);
$gift_info['images'] = localpath_to_netpath($gift_info['images']);
return ['code' => 200, 'msg' => '获取成功', 'data' => $gift_info];
}
//编辑
public function edit_nobility_power($data)
{
if (empty($data)) {
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
}
$nobility_info = db::name('nobility_power')->find($data['id']);
if (empty($nobility_info)) {
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
}
$update_data = [];
$update_data['name'] = $data['name'];
$update_data['image'] = $data['image'];
$update_data['images'] = $data['images'];
$update_data['content'] = $data['content'];
$update_data['update_time'] = time();
$reslut = db::name('nobility_power')->where(['id' => $data['id']])->update($update_data);
if (!$reslut) {
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
} else {
return ['code' => 200, 'msg' => '修改成功', 'data' => null];
}
}
//用户爵位列表
public function get_user_nobility_list($order, $sort, $page = 1, $limit = 20)
{
$map = [];
$map[] = ['a.is_delete', '=', 1];
$map[] = ['a.status', '=', 1];
$list = db::name('user_nobility')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_nobility c', 'c.lid = a.lid')->field('a.id, b.uid, b.nick_name, b.base64_nick_name, b.head_pic, c.name, a.add_time, a.update_time')->where($map)->order($order, $sort)->page($page, $limit)->select();
foreach ($list as $k => &$v) {
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
}
$data = [];
$data['count'] = db::name('user_nobility')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_nobility c', 'c.lid = a.lid')->field('a.id')->where($map)->count();
$data['list'] = $list;
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
}
//列表
public function get_nobility_decorate_list($lid, $order, $sort, $page = 1, $limit = 20)
{
$map = [];
$map[] = ['a.is_delete', '=', 1];
$map[] = ['a.lid', '=', $lid];
$banner_list = db::name('nobility_decorate')->alias('a')->join('yy_decorate b', 'a.did = b.did')->field('a.*,b.title,b.type,b.base_image')->where($map)->order($order, $sort)->select();
foreach ($banner_list as $k => &$v){
$v['base_image'] = localpath_to_netpath($v['base_image']);
}
$data = [];
$data['count'] = db::name('nobility_decorate')->alias('a')->join('yy_decorate b', 'a.did = b.did')->field('a.*,b.title,b.type,b.base_image')->where($map)->count();
$data['list'] = $banner_list;
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
}
//获取
public function nobility_decorate_info($id)
{
if (empty($id)) {
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
}
$report_type = db::name('nobility_decorate')->find($id);
$report_type['decorate_id'] = $report_type['did'];
return ['code' => 200, 'msg' => '获取成功', 'data' => $report_type];
}
//添加
public function add_nobility_decorate($lid, $did, $day_num)
{
if(empty($lid) || empty($did)){
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
}
// if($day_num < 1){
// return ['code' => 201, 'msg' => '天数不能小于1天', 'data' => null];
// }
$decorate_info = db::name('decorate')->where('did', $did)->find();
// if($decorate_info['type'] == 2){
// $type = 4;
// }else if($decorate_info['type'] == 2){
// $type = 2;
// }else if($decorate_info['type'] == 3){
// $type = 3;
// }elseif($decorate_info['type'] == 4){
// $type = 6;
// }
$arr = [];
$arr['lid'] = $lid;
$arr['did'] = $did;
$arr['type'] = $decorate_info['type'];
// $arr['day_num'] = $day_num;
$arr['add_time'] = time();
$arr['update_time'] = time();
$add = db::name('nobility_decorate')->insert($arr);
if ($add) {
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
} else {
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
}
}
//修改
public function edit_nobility_decorate($id, $did, $day_num = 0)
{
if (empty($id)) {
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
}
// if($day_num < 1){
// return ['code' => 201, 'msg' => '天数不能小于1天', 'data' => null];
// }
$decorate_info = db::name('decorate')->where('did', $did)->find();
// if($decorate_info['type'] == 1){
// $type = 4;
// }else if($decorate_info['type'] == 2){
// $type = 2;
// }else if($decorate_info['type'] == 3){
// $type = 3;
// }elseif($decorate_info['type'] == 4){
// $type = 6;
// }
$type = $decorate_info['type'];
$upd = db::name('nobility_decorate')->where(['id' => $id])->update(['did' => $did, 'type' => $type, 'day_num' => $day_num, 'update_time' => time()]);
if ($upd) {
return ['code' => 200, 'msg' => '修改成功', 'data' => null];
} else {
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
}
}
//删除
public function del_nobility_decorate($id)
{
$del = db::name('nobility_decorate')->where(['id' => $id])->update(['is_delete' => 2, 'update_time' => time()]);
if ($del) {
return ['code' => 200, 'msg' => '删除成功', 'data' => null];
} else {
return ['code' => 201, 'msg' => '删除失败', 'data' => null];
}
}
}