824 lines
32 KiB
PHP
824 lines
32 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model;
|
|
|
|
use think\Db;
|
|
use think\Model;
|
|
|
|
class Guild extends Model
|
|
{
|
|
//公会列表
|
|
public function guild_list($id, $guild_name, $order, $sort, $page = 1, $limit = 20,$jie_shan=2)
|
|
{
|
|
$map = [];
|
|
if (!empty($id)) {
|
|
$map[] = ['a.id|a.guild_special_id', '=', $id];
|
|
}
|
|
$start_time = input('start', '');
|
|
$end_time = input('end', '');
|
|
if(empty($start_time)) {
|
|
$start_time = strtotime(date('Ymd'));
|
|
|
|
} else {
|
|
$start_time = strtotime($start_time);
|
|
}
|
|
if(empty($end_time)) {
|
|
$end_time = time();
|
|
} else {
|
|
$end_time = strtotime($end_time);
|
|
}
|
|
$build_sql = db::name('room_guild_charm_count_day')
|
|
->field('guild_id,SUM(amount) as total_gift_total_price')
|
|
->where('add_time', 'between', [$start_time, $end_time])
|
|
->group('guild_id')->buildSql();
|
|
|
|
if($jie_shan==2){
|
|
$map[] = ['is_delete', '=', 1];
|
|
}else{
|
|
$map[] = ['is_delete', '=', 2];
|
|
}
|
|
|
|
|
|
$list = db::name('guild')->alias('a')
|
|
->join($build_sql.'b', 'a.id = b.guild_id', 'LEFT')
|
|
->field('a.id, a.guild_name, a.base64_guild_name, a.cover, b.total_gift_total_price, a.add_time,a.update_time,a.is_show,a.guild_special_id')
|
|
->where($map)->order('b.total_gift_total_price', 'desc')->page($page, $limit)->select();
|
|
foreach ($list as $k => &$v) {
|
|
|
|
$v['guild_name'] = mb_convert_encoding(base64_decode($v['base64_guild_name']), 'UTF-8', 'UTF-8');
|
|
$v['cover'] = localpath_to_netpath($v['cover']);
|
|
$v['total_gift_total_price'] = empty($v['total_gift_total_price']) ? 0 : $v['total_gift_total_price'];
|
|
}
|
|
$data = [];
|
|
$data['count'] = db::name('guild')->alias('a')->where($map)->count();
|
|
$data['list'] = $list;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
//编辑公会
|
|
public function edit_guild($data)
|
|
{
|
|
if (empty($data)) {
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
|
|
$user_info = db::name('user')->find($data['uid']);
|
|
if(!$user_info){
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
|
|
$guild_info = db::name('guild')->find($data['id']);
|
|
if (empty($guild_info)) {
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
|
|
Db::startTrans();
|
|
try {
|
|
//是否修改会长
|
|
if($data['uid'] != $guild_info['uid']){
|
|
$map = [];
|
|
$map[] = ['uid', '=', $data['uid']];
|
|
$map[] = ['status', '=', 1];
|
|
$map[] = ['is_delete', '=', 1];
|
|
$guild_infos = db::name('user_guild')->where($map)->find();
|
|
if($guild_infos){
|
|
return ['code' => 201, 'msg' => '该用户已加入公会', 'data' => null];
|
|
}
|
|
if(empty($user_info['real_name']) || empty($user_info['card_id'])) {
|
|
return ['code' => 201, 'msg' => '请先实名认证', 'data' => null];
|
|
}
|
|
//将之前会长退出公会
|
|
$update_data = [];
|
|
$update_data['is_delete'] = 2;
|
|
$update_data['update_time'] = time();
|
|
$reslut = db::name('user_guild')->where('uid',$guild_info['uid'])->update($update_data);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
|
|
}
|
|
|
|
$update_data = [];
|
|
$update_data['is_deacon'] = 2;
|
|
$update_data['update_time'] = time();
|
|
$reslut = db::name('user')->where('uid', $guild_info['uid'])->update($update_data);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
|
|
}
|
|
|
|
//新会长进入公会
|
|
//该用户是否有房间
|
|
$rid = 0;
|
|
$room_info = db::name('room')->where('room_owner_uid',$data['uid'])->find();
|
|
if($room_info){
|
|
$rid = $room_info['rid'];
|
|
}
|
|
//加入公会
|
|
$insert_data = [];
|
|
$insert_data['uid'] = $data['uid'];
|
|
$insert_data['guild_id'] = $data['id'];
|
|
$insert_data['rid'] = $rid;
|
|
$insert_data['card_id'] = $user_info['card_id'];
|
|
$insert_data['status'] = 1;
|
|
$insert_data['add_time'] = time();
|
|
$insert_data['is_deacon'] = 1;
|
|
$insert_data['is_show_room'] = 1;
|
|
$reslut = db::name('user_guild')->insertGetId($insert_data);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
|
|
}
|
|
|
|
$update_data = [];
|
|
$update_data['is_deacon'] = 1;
|
|
$update_data['update_time'] = time();
|
|
$reslut = db::name('user')->where('uid', $data['uid'])->update($update_data);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
|
|
$data['guild_special_id'] = trim($data['guild_special_id']);
|
|
if(!empty($data['guild_special_id'])){
|
|
if(!preg_match("/^[1-9][0-9]*$/" ,$data['guild_special_id']) || ($data['guild_special_id'] <= 1000)){
|
|
return ['code' => 201, 'msg' => '请输入至少4位正整数!', 'data' => null];
|
|
}
|
|
if(!empty($data['guild_special_id'])){
|
|
$is_exists = db::name('guild')->where([['id','<>',$data['id']]])->where(['guild_special_id|uid'=>trim($data['guild_special_id'])])->find();
|
|
if($is_exists){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '该靓号已经存在其它公会!', 'data' => null];
|
|
}
|
|
}
|
|
}else{
|
|
$data['guild_special_id'] = "";
|
|
}
|
|
|
|
|
|
$update_data = [];
|
|
$update_data['uid'] = $data['uid'];
|
|
$update_data['guild_name'] = $data['guild_name'];
|
|
$update_data['base64_guild_name'] = base64_encode($data['guild_name']);
|
|
$update_data['cover'] = $data['cover'];
|
|
$update_data['money'] = $data['money'];
|
|
$update_data['update_time'] = time();
|
|
$update_data['guild_special_id'] = $data['guild_special_id'];
|
|
$update_data['intro'] = trim($data['intro']);
|
|
|
|
$reslut = db::name('guild')->where(['id' => $data['id']])->update($update_data);
|
|
if (!$reslut) {
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
|
|
}
|
|
|
|
Db::commit();
|
|
return ['code' => 200, 'msg' => '修改成功', 'data' => null];
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
dump($e);
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
|
|
}
|
|
|
|
|
|
}
|
|
//添加公会
|
|
public function add_guild($data)
|
|
{
|
|
$user_info = db::name('user')->find($data['uid']);
|
|
if(!$user_info){
|
|
return ['code' => 201, 'msg' => '该用户不存在', 'data' => null];
|
|
}
|
|
if(empty($user_info['real_name']) || empty($user_info['card_id'])) {
|
|
return ['code' => 201, 'msg' => '请先实名认证', 'data' => null];
|
|
}
|
|
$map = [];
|
|
$map[] = ['uid', '=', $data['uid']];
|
|
$map[] = ['status', '=', 1];
|
|
$map[] = ['is_delete', '=', 1];
|
|
$guild_info = db::name('user_guild')->where($map)->find();
|
|
if($guild_info){
|
|
return ['code' => 201, 'msg' => '该用户已有公会', 'data' => null];
|
|
}
|
|
|
|
Db::startTrans();
|
|
try {
|
|
|
|
|
|
$data['guild_special_id'] = trim($data['guild_special_id']);
|
|
if(!empty($data['guild_special_id'])){
|
|
if(!preg_match("/^[1-9][0-9]*$/" ,$data['guild_special_id']) || ($data['guild_special_id'] <= 1000)){
|
|
return ['code' => 201, 'msg' => '请输入至少4位正整数!', 'data' => null];
|
|
}
|
|
if(!empty($data['guild_special_id'])){
|
|
$is_exists = db::name('guild')->where(['guild_special_id|uid'=>trim($data['guild_special_id'])])->find();
|
|
if($is_exists){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '该靓号已经存在其它公会!', 'data' => null];
|
|
}
|
|
}
|
|
}else{
|
|
$data['guild_special_id'] = "";
|
|
}
|
|
|
|
|
|
//添加公会
|
|
$add_data = [];
|
|
$add_data['uid'] = $data['uid'];
|
|
$add_data['guild_name'] = $data['guild_name'];
|
|
$add_data['base64_guild_name'] = base64_encode($data['guild_name']);
|
|
$add_data['cover'] = $data['cover'];
|
|
$add_data['money'] = 0;
|
|
$add_data['num'] = 1;
|
|
$add_data['add_time'] = time();
|
|
$add_data['guild_special_id'] = $data['guild_special_id'];
|
|
$add_data['intro'] = trim($data['intro']);
|
|
$guild_id = db::name('guild')->insertGetId($add_data);
|
|
if (!$guild_id) {
|
|
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
|
|
}
|
|
|
|
//该用户是否有房间
|
|
$rid = 0;
|
|
$room_info = db::name('room')->where('room_owner_uid',$data['uid'])->find();
|
|
if($room_info){
|
|
$rid = $room_info['rid'];
|
|
}
|
|
|
|
//加入公会
|
|
$insert_data = [];
|
|
$insert_data['uid'] = $data['uid'];
|
|
$insert_data['guild_id'] = $guild_id;
|
|
$insert_data['rid'] = $rid;
|
|
$insert_data['card_id'] = $user_info['card_id'];
|
|
$insert_data['status'] = 1;
|
|
$insert_data['add_time'] = time();
|
|
$insert_data['is_deacon'] = 1;
|
|
$insert_data['is_show_room'] = 1;
|
|
$reslut = db::name('user_guild')->insertGetId($insert_data);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
|
|
}
|
|
|
|
$update_data = [];
|
|
$update_data['is_deacon'] = 1;
|
|
$update_data['update_time'] = time();
|
|
$reslut = db::name('user')->where('uid', $data['uid'])->update($update_data);
|
|
if(!$reslut){
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
|
|
}
|
|
|
|
Db::commit();
|
|
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
dump($e);
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//获取公会信息
|
|
public function guild_info($id)
|
|
{
|
|
if (empty($id)) {
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
$gift_info = db::name('guild')->where(['id' => $id])->find();
|
|
$gift_info['http_base_image'] = localpath_to_netpath($gift_info['cover']);
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $gift_info];
|
|
}
|
|
|
|
//删除公会
|
|
public function del_guild($id)
|
|
{
|
|
if (empty($id)) {
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
$gid_info = db::name('guild')->where('id', $id)->find();
|
|
if(!$gid_info){
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
|
|
$reslut = db::name('guild')->where(['id' => $id])->update(['is_delete' => 2, 'update_time' => time()]);
|
|
if (!$reslut) {
|
|
return ['code' => 201, 'msg' => '删除失败', 'data' => null];
|
|
} else {
|
|
return ['code' => 200, 'msg' => '删除成功', 'data' => null];
|
|
}
|
|
}
|
|
|
|
//批量删除公会
|
|
public function batch_delete_guild($data){
|
|
if(empty($data)){
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
|
|
$gid_list = [];
|
|
foreach ($data as $k => $v){
|
|
$gid_list[] = $v['gid'];
|
|
}
|
|
|
|
$map = [];
|
|
$map[] = ['id', 'in', $gid_list];
|
|
$date = [];
|
|
$date['is_delete'] = 2;
|
|
$date['delete_time'] = time();
|
|
$reslut = db::name('guild')->where($map)->update($date);
|
|
if($reslut){
|
|
return ['code' => 200, 'msg' => '删除成功', 'data' => null];
|
|
}else{
|
|
return ['code' => 201, 'msg' => '删除失败', 'data' => null];
|
|
}
|
|
|
|
}
|
|
|
|
//公会用户详情
|
|
public function get_user_guild_list($id, $uid, $order, $sort, $page = 1, $limit = 20){
|
|
$map = [];
|
|
|
|
if(!empty($uid)){
|
|
$map[] = ['a.uid', '=', $uid];
|
|
}
|
|
// dump($id);exit;
|
|
$map[] = ['a.guild_id', '=', $id];
|
|
$map[] = ['a.status', '=', 1];
|
|
$map[] = ['a.is_delete', '=', 1];
|
|
|
|
$list = db::name('user_guild')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.*,b.nick_name,b.base64_nick_name')->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');
|
|
}
|
|
$data = [];
|
|
$data['count'] = db::name('user_guild')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.*')->where($map)->count();
|
|
$data['list'] = $list;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
|
|
}
|
|
|
|
//设置显示状态
|
|
public function set_is_show($id, $is_show)
|
|
{
|
|
$info = Db::name('guild')->find($id);
|
|
if(empty($info)) {
|
|
return ['code' => 201, 'msg' => '数据不存在', 'data' => ''];
|
|
}
|
|
$result = Db::name('guild')->where('id', $id)->update(['is_show' => $is_show, 'update_time' => time()]);
|
|
return ['code' => 200, 'msg' => '设置成功', 'data' => ''];
|
|
}
|
|
|
|
//用户公会信息
|
|
public function user_guild_info($id){
|
|
$user_guild_info = db::name('user_guild')->where('id', $id)->where('status', 1)->where('is_delete', 1)->find();
|
|
if(!$user_guild_info){
|
|
return ['code' => 201, 'msg' => '该用户信息不存在', 'data' => null];
|
|
}
|
|
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $user_guild_info];
|
|
|
|
}
|
|
|
|
//编辑用户公会信息
|
|
public function edit_user_guild($data){
|
|
if(empty($data['id'])){
|
|
return ['code' => 201, 'msg' => '参数错误', 'data' => ''];
|
|
}
|
|
|
|
$user_guild_info = db::name('user_guild')->where('id', $data['id'])->where('status', 1)->where('is_delete', 1)->find();
|
|
if(!$user_guild_info){
|
|
return ['code' => 201, 'msg' => '该用户信息不存在', 'data' => null];
|
|
}
|
|
|
|
if($user_guild_info['is_deacon'] == 1){
|
|
// return ['code' => 201, 'msg' => '无法修改会长信息', 'data' => null];
|
|
}
|
|
|
|
$update = [];
|
|
$update['is_show_room'] = $data['is_show_room'];
|
|
$update['update_time'] = time();
|
|
$result = db::name('user_guild')->where('id', $data['id'])->update($update);
|
|
if($result){
|
|
return ['code' => 200, 'msg' => '编辑成功', 'data' => null];
|
|
}else{
|
|
return ['code' => 201, 'msg' => '编辑失败', 'data' => null];
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//公会排行列表
|
|
public function get_guild_rank_list($id, $start, $end, $order, $sort, $page = 1, $limit = 20)
|
|
{
|
|
$map = [];
|
|
if (!empty($id)) {
|
|
$map[] = ['a.id', '=', $id];
|
|
}
|
|
$where = [];
|
|
if(!empty($start)) {
|
|
$where[] = ['add_time', '>=', strtotime($start)];
|
|
}
|
|
if(!empty($end)) {
|
|
$where[] = ['add_time', '<=', strtotime($end)];
|
|
}
|
|
|
|
$map[] = ['a.is_delete', '=', 1];
|
|
|
|
$build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price,add_time')->where($where)->group('guild_id')->buildSql();
|
|
|
|
$list = db::name('guild')->alias('a')->join($build_sql.'b', 'a.id = b.guild_id', 'LEFT')->field('a.*,b.total_gift_total_price')->where($map)->order($order, $sort)->page($page, $limit)->select();
|
|
foreach ($list as $k => &$v) {
|
|
$v['guild_name'] = mb_convert_encoding(base64_decode($v['base64_guild_name']), 'UTF-8', 'UTF-8');
|
|
$v['cover'] = localpath_to_netpath($v['cover']);
|
|
if(empty($v['total_gift_total_price'])){
|
|
$v['total_gift_total_price'] = 0;
|
|
}
|
|
}
|
|
$data = [];
|
|
$data['count'] = db::name('guild')->alias('a')->join($build_sql.'b', 'a.id = b.guild_id', 'LEFT')->where($map)->count();
|
|
$data['list'] = $list;
|
|
// $totalRowData = Db::name('guild')->alias('a')->join($build_sql.'b', 'a.id = b.guild_id', 'LEFT')->field('total_gift_total_price')->where($map)->find();
|
|
|
|
// $data['totalRow'] = $totalRowData;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
|
|
//公会用户列表
|
|
public function get_guild_user_rank_list($guild_id, $uid, $start, $end, $order, $sort, $page = 1, $limit = 20)
|
|
{
|
|
$map = [];
|
|
if (!empty($uid)) {
|
|
$map[] = ['a.uid', '=', $uid];
|
|
}
|
|
$where = [];
|
|
if(!empty($start)) {
|
|
$where[] = ['add_time', '>=', strtotime($start)];
|
|
}
|
|
if(!empty($end)) {
|
|
$where[] = ['add_time', '<=', strtotime($end)];
|
|
}
|
|
|
|
$map[] = ['a.guild_id', '=', $guild_id];
|
|
$map[] = ['a.status', '=', 1];
|
|
$map[] = ['a.is_delete', '=', 1];
|
|
|
|
$build_sql = db::name('user_guild_charm_count_day')->field('uid,SUM(amount) as total_gift_total_price,add_time')->where($where)->group('uid')->buildSql();
|
|
|
|
$list = db::name('user_guild')->alias('a')->join($build_sql.'b', 'a.uid = b.uid', 'LEFT')->join('yy_user c', 'a.uid = c.uid')->field('a.*,b.total_gift_total_price,c.base64_nick_name,c.head_pic')->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']);
|
|
if(empty($v['total_gift_total_price'])){
|
|
$v['total_gift_total_price'] = 0;
|
|
}
|
|
}
|
|
$data = [];
|
|
$data['count'] = db::name('user_guild')->alias('a')->join($build_sql.'b', 'a.uid = b.uid', 'LEFT')->join('yy_user c', 'a.uid = c.uid')->where($map)->count();
|
|
$data['list'] = $list;
|
|
// $totalRowData = Db::name('guild')->alias('a')->join($build_sql.'b', 'a.id = b.guild_id', 'LEFT')->field('total_gift_total_price')->where($map)->find();
|
|
|
|
// $data['totalRow'] = $totalRowData;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
|
|
|
|
//公会房间列表
|
|
public function get_guild_room_rank_list($guild_id, $room_number, $start, $end, $order, $sort, $page = 1, $limit = 20)
|
|
{
|
|
$map = [];
|
|
if (!empty($room_number)) {
|
|
$map[] = ['c.room_number', '=', $room_number];
|
|
}
|
|
$where = [];
|
|
if(!empty($start)) {
|
|
$where[] = ['add_time', '>=', strtotime($start)];
|
|
}
|
|
if(!empty($end)) {
|
|
$where[] = ['add_time', '<=', strtotime($end)];
|
|
}
|
|
|
|
$map[] = ['a.guild_id', '=', $guild_id];
|
|
$map[] = ['a.status', '=', 1];
|
|
$map[] = ['a.is_delete', '=', 1];
|
|
$map[] = ['a.rid', '>', 0];
|
|
|
|
$build_sql = db::name('room_guild_charm_count_day')->field('rid,SUM(amount) as total_gift_total_price,add_time')->where($where)->group('rid')->buildSql();
|
|
|
|
$list = db::name('user_guild')->alias('a')->join($build_sql.'b', 'a.rid = b.rid', 'LEFT')->join('yy_room c', 'a.rid = c.rid')->field('a.*,b.total_gift_total_price,c.base64_room_name,c.room_cover,c.room_number')->where($map)->order($order, $sort)->page($page, $limit)->select();
|
|
foreach ($list as $k => &$v) {
|
|
$v['room_name'] = mb_convert_encoding(base64_decode($v['base64_room_name']), 'UTF-8', 'UTF-8');
|
|
$v['room_cover'] = localpath_to_netpath($v['room_cover']);
|
|
if(empty($v['total_gift_total_price'])){
|
|
$v['total_gift_total_price'] = 0;
|
|
}
|
|
}
|
|
$data = [];
|
|
$data['count'] = db::name('user_guild')->alias('a')->join($build_sql.'b', 'a.rid = b.rid', 'LEFT')->join('yy_room c', 'a.rid = c.rid')->where($map)->count();
|
|
$data['list'] = $list;
|
|
// $totalRowData = Db::name('guild')->alias('a')->join($build_sql.'b', 'a.id = b.guild_id', 'LEFT')->field('total_gift_total_price')->where($map)->find();
|
|
|
|
// $data['totalRow'] = $totalRowData;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
|
|
//获取列表
|
|
public function give_guild_subsidy_list($guild_id, $uid, $is_fa, $order, $sort, $page, $limit, $belong_week){
|
|
$map = [];
|
|
if(!empty($guild_id)){
|
|
$map[] = ['guild_id', '=', $guild_id];
|
|
}
|
|
if(!empty($uid)){
|
|
$map[] = ['guild_uid_id', '=', $uid];
|
|
}
|
|
|
|
if(!empty($is_fa)){
|
|
$map[] = ['is_fa', '=', $is_fa];
|
|
}
|
|
|
|
// if(!empty($is_delete)){
|
|
// $map[] = ['is_delete', '=', $is_delete];
|
|
// }
|
|
|
|
|
|
// if(!empty($start)){
|
|
// $now_time = strtotime($start);
|
|
// $last_week = strtotime('-1 week last sunday', $now_time);
|
|
// $map[] = ['last_week_time', '=', $last_week];
|
|
// }else{
|
|
// $now_time = time();
|
|
// $last_week = strtotime('-1 week last sunday', $now_time);
|
|
// $map[] = ['last_week_time', '=', $last_week];
|
|
// }
|
|
|
|
if(!empty($belong_week)){
|
|
$map[] = ['belong_week', '=', $belong_week];
|
|
}
|
|
|
|
|
|
|
|
|
|
$map[] = ['type', '=', 1];
|
|
$list = db::name('guild_week_earnings_log')->where($map)->order($order, $sort)->page($page, $limit)->select();
|
|
foreach ($list as $k => &$v){
|
|
$guild_info = db::name('guild')->find($v['guild_id']);
|
|
$v['guild_name'] = mb_convert_encoding(base64_decode($guild_info['base64_guild_name']), 'UTF-8', 'UTF-8');
|
|
$user_info = db::name('user')->find($v['guild_uid_id']);
|
|
$v['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
|
}
|
|
|
|
$data = [];
|
|
$data['count'] = db::name('guild_week_earnings_log')->where($map)->count();
|
|
|
|
$totalRowData = db::name('guild_week_earnings_log')->field('SUM(change_value) as change_value,SUM(earnings) as earnings')->where($map)->find();
|
|
$data['totalRow'] = $totalRowData;
|
|
|
|
|
|
$data['list'] = $list;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
|
|
//批量结算
|
|
// public function batch_give_guild_subsidy($data){
|
|
// if(empty($data)){
|
|
// return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
// }
|
|
|
|
// $gid_list = [];
|
|
// foreach ($data as $k => $v){
|
|
// if(in_array($v['is_delete'], [2])) {
|
|
// ['code' => 201, 'msg' => '批量结算中包含已发放的', 'data' => null];
|
|
// }
|
|
// $gid_list[] = $v['id'];
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// try {
|
|
// Db::startTrans();
|
|
// $map = [];
|
|
// $map[] = ['id', 'in', $gid_list];
|
|
// $map[] = ['is_delete', '=', 1];
|
|
// $list = db::name('user_guild_week_earnings')->where($map)->select();
|
|
// if(!empty($list)){
|
|
// foreach ($list as $k => $v){
|
|
// if($v['user_earnings'] > 0){
|
|
// $reslut = model('admin/User')->change_user_money_by_uid($v['uid'], $v['user_earnings'], 1, 39, '公会补贴收益', $v['uid'], 0, 0);
|
|
// if ($reslut['code'] == 201) {
|
|
// Db::rollback();
|
|
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
|
// }
|
|
// }
|
|
// $reslut = db::name('user_guild_week_earnings')->where('id', $v['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
|
// if (!$reslut) {
|
|
// Db::rollback();
|
|
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// // 提交事务
|
|
// Db::commit();
|
|
// return ['code' => 200, 'msg' => "发放成功", 'data' => null];
|
|
// } catch (\Exception $e) {
|
|
// // 回滚事务
|
|
// // dump($e);
|
|
// Db::rollback();
|
|
// return ['code' => 201, 'msg' => "发放失败", 'data' => null];
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
public function batch_give_guild_subsidy(){
|
|
|
|
$week_start = date('Y-m-d', strtotime("last week Monday"));
|
|
$week_end = date('Y-m-d', strtotime("last week Sunday"));
|
|
$balance_week = $week_start."-".$week_end;
|
|
|
|
|
|
// $week_start = date('Y-m-d', strtotime("this week Monday"));
|
|
// $week_end = date('Y-m-d', strtotime("this week Sunday"));
|
|
// $balance_week = $week_start."-".$week_end;
|
|
|
|
|
|
|
|
$is_had_deal = db::name('guild_week_earnings_log')->where(['is_delete'=>1,'belong_week'=>$balance_week,'is_fa'=>2])->find();
|
|
if(empty($is_had_deal)){
|
|
return ['code' => 201, 'msg' => "没有要结算的工资", 'data' => null];
|
|
}
|
|
|
|
|
|
try {
|
|
db::name('guild_week_earnings_log')->where(['is_delete'=>1,'belong_week'=>$balance_week,'is_fa'=>2])->update(['is_delete'=>2,'update_time'=>time()]);
|
|
|
|
|
|
|
|
//推入队列
|
|
$redis = connectionRedis();
|
|
$redis->rPush('balance_guild_wages_date',$balance_week);
|
|
|
|
//推入事务逻辑
|
|
// $data = model('api/RoomWages')->batch_give_guild_subsidy($balance_week);
|
|
|
|
// if($data['code'] != 200){
|
|
// return ['code' => 200, 'msg' =>$data['msg'], 'data' => null];
|
|
// }
|
|
|
|
return ['code' => 200, 'msg' => "发放成功", 'data' => null];
|
|
} catch (\Exception $e) {
|
|
// 回滚事务
|
|
Db::rollback();
|
|
|
|
return ['code' => 201, 'msg' => "发放失败", 'data' => null];
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//补贴详情
|
|
public function get_give_guild_subsidy_info($id){
|
|
if(empty($id)){
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
|
|
$user_guild_week_earnings = db::name('user_guild_week_earnings')->where('id', $id)->find();
|
|
if(!$user_guild_week_earnings){
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $user_guild_week_earnings];
|
|
}
|
|
|
|
//修改补贴
|
|
public function edit_give_room_subsidy($id, $user_earnings){
|
|
if(empty($id)){
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
|
|
$user_guild_week_earnings = db::name('user_guild_week_earnings')->where('id', $id)->find();
|
|
if(!$user_guild_week_earnings){
|
|
return ['code' => 201, 'msg' => '参数异常', 'data' => null];
|
|
}
|
|
|
|
if($user_earnings < 0){
|
|
return ['code' => 201, 'msg' => '收益不能小于0', 'data' => null];
|
|
}
|
|
|
|
if($user_guild_week_earnings['is_delete'] == 2){
|
|
return ['code' => 201, 'msg' => '该收益已结算,无法编辑', 'data' => null];
|
|
}
|
|
|
|
$update = [];
|
|
$update['user_earnings'] = $user_earnings;
|
|
$update['update_time'] = time();
|
|
$reslut = db::name('user_guild_week_earnings')->where('id', $id)->update($update);
|
|
if($reslut){
|
|
return ['code' => 200, 'msg' => '编辑成功', 'data' => null];
|
|
}else{
|
|
return ['code' => 201, 'msg' => '编辑失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//解散公会
|
|
public function diss_guild($guild_id){
|
|
$guild_info = db::name('guild')->where(['id'=>$guild_id,'is_delete'=>1])->find();
|
|
if(empty($guild_info)){
|
|
return ['code' => 201, 'msg' => '公会不存在!', 'data' => null];
|
|
}
|
|
try {
|
|
Db::startTrans();
|
|
//成员解散
|
|
db::name('user_guild')->where(['guild_id'=>$guild_id,'status'=>1,'is_delete'=>1])->update(['is_delete'=>2,'quit_type'=>3,'quit_time'=>time()]);
|
|
|
|
//退会
|
|
$update_data = [];
|
|
$update_data['is_deacon'] = 2;
|
|
$update_data['update_time'] = time();
|
|
$reslut = db::name('user')->where('uid', $guild_info['uid'])->update($update_data);
|
|
|
|
//解散公会
|
|
db::name('guild')->where('id',$guild_id)->update(['is_delete'=>2,'is_show'=>2,'num'=>0,'guild_special_id'=>""]);
|
|
|
|
Db::commit();
|
|
return ['code' => 200, 'msg' => '解散成功!', 'data' => null];
|
|
}catch (\Exception $e) {
|
|
// 回滚事务
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '解散失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//公会合并
|
|
public function guild_combine($cancel_guild_id,$join_guild_id){
|
|
$guild_info1 = db::name('guild')->where(['id'=>$cancel_guild_id,'is_delete'=>1])->find();
|
|
if(empty($guild_info1)){
|
|
return ['code' => 201, 'msg' => '被解散公会不存在!', 'data' => null];
|
|
}
|
|
$guild_info2 = db::name('guild')->where(['id'=>$join_guild_id,'is_delete'=>1])->find();
|
|
if(empty($guild_info2)){
|
|
return ['code' => 201, 'msg' => '并入公会不存在!', 'data' => null];
|
|
}
|
|
try {
|
|
Db::startTrans();
|
|
//a公会成员人数统计
|
|
$num = db::name('user_guild')->where(['guild_id'=>$cancel_guild_id,'status'=>1,'is_delete'=>1])->count("*");
|
|
|
|
//将a公会成员加入b公会
|
|
$s_date = date('Y-m-d H:i:s');
|
|
db::name('user_guild')->where(['guild_id'=>$cancel_guild_id,'status'=>1,'is_delete'=>1])->update(['guild_id'=>$join_guild_id,'is_deacon'=>2,'remarks'=>"{$s_date}公会id:{$cancel_guild_id}合并到公会id:{$join_guild_id}"]);
|
|
db::name('guild')->where(['id'=>$join_guild_id,'is_delete'=>1])->inc('num',$num)->update(['update_time'=>time()]);
|
|
|
|
|
|
//取消a公会 工会长身份
|
|
$update_data = [];
|
|
$update_data['is_deacon'] = 2;
|
|
$update_data['update_time'] = time();
|
|
$reslut = db::name('user')->where('uid', $guild_info1['uid'])->update($update_data);
|
|
db::name('guild')->where(['id'=>$cancel_guild_id])->update(['guild_special_id'=>"",'num'=>0,'is_delete'=>2,'is_show'=>2]);
|
|
|
|
Db::commit();
|
|
|
|
return ['code' => 200, 'msg' => '合并成功!', 'data' => null];
|
|
}catch (\Exception $e) {
|
|
Db::rollback();
|
|
return ['code' => 201, 'msg' => '合并失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|