Files

221 lines
7.2 KiB
PHP
Raw Permalink Normal View History

2025-08-07 20:21:47 +08:00
<?php
namespace app\adminapi\model;
use think\Model;
use think\Session;
use think\Db;
class Guild extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $name = 'vs_guild';
public function getList($where = [], $page = 1, $limit = 10)
{
$list = $this->where($where)->page($page, $limit)->select();
$list = collection($list)->toArray();
return $list;
}
public function getCount($where = [])
{
return $this->where($where)->count();
}
public function getOne($where = [])
{
$one = $this->where($where)->find();
return $one;
}
public function add($data)
{
$res = $this->save($data);
if (!$res) {
return false;
}
$guild_id = $this->id;
return $guild_id;
}
public function edit($where = [], $data = [])
{
$res = $this->where($where)->update($data);
return $res;
}
public function del($where = [])
{
$res = $this->where($where)->delete();
return $res;
}
//软删除
public function setDel($where = []){
$res = $this->where($where)->setField('delete_time',time());
if(!$res){
return false;
}
return $res;
}
//靓号处理
public function getGuildSpecialId(){
$code = $this->order('guild_special_id desc')->value('guild_special_id');
if(empty($code)){
$code = 10000;
}
$code = $code + 1;
$vip_code = db::name('vip_code')->where(['type' => 3, 'status' => 1,'is_use' => 1])->field('code')->select();
if (empty($vip_code)) {
return $code;
}
if (in_array($code, (array)$vip_code)) {
return $code + 2;
}
return $code;
}
/*
* 通过用户ID 获取公会信息
*
*/
public function getGuildByUserId($user_id){
$guild = db::name('vs_guild_user')
->alias('g')
->join('vs_guild gg','g.guild_id = gg.id')
->field('gg.*')
2025-10-20 09:59:39 +08:00
->where(['g.user_id' => $user_id,'g.status' => 1,'g.delete_time' => 0])
2025-08-07 20:21:47 +08:00
->find();
return $guild;
}
/*
*
*工会当日流水
*/
2025-12-26 18:07:06 +08:00
// public function getTodayMoney($guild_id,$stoday="",$etoday=""){
// //获取所有工会房间ID
// $guild_user_data = db::name('vs_guild_user')->where('guild_id', $guild_id)->where(['apply_time'=>['>',0],'status'=>1])->field('room_id,apply_time,quit_time')->select();
// $transaction = 0;
// foreach ($guild_user_data as $k => $v) {
// if(empty($stoday) && empty($etoday)){
// $stoday_seach = strtotime(date('Y-m-d 00:00:00',time()));
// $etoday_seach = strtotime(date('Y-m-d 23:59:59',time()));
// }else{
// $stoday_seach = strtotime($stoday);
// $etoday_seach = strtotime($etoday);
// }
// if($v['apply_time'] && $stoday_seach < $v['apply_time']){
// $stoday_seach = $v['apply_time'];
// }
// if($v['quit_time'] && ($etoday > $v['quit_time'])){
// $etoday_seach = $v['quit_time'];
// }
// $transaction_one = db::name('vs_give_gift')
// ->where('from_id',$v['room_id'])
// ->where(['from'=>['in',[2,3,6]],'createtime' => ['between', [$stoday_seach, $etoday_seach]]])
// ->sum('total_price');
// $transaction += $transaction_one;
// }
// return $transaction;
// }
2025-08-07 20:21:47 +08:00
public function getTodayMoney($guild_id,$stoday="",$etoday=""){
2025-12-26 18:07:06 +08:00
$where = [];
$where['guild_id'] = $guild_id;
if(empty($stoday) && empty($etoday)){
$where['day'] = date('Y-m-d');
}else{
if(!empty($stoday)){
$where['createtime'] = ['>=',strtotime($stoday)];
2025-08-07 20:21:47 +08:00
}
2025-12-26 18:07:06 +08:00
if(!empty($etime)){
$where['createtime'] = ['<',strtotime($etoday)];
2025-08-07 20:21:47 +08:00
}
2025-12-26 18:07:06 +08:00
if(!empty($stime) && !empty($etime)){
$where['createtime'] = [['>=',strtotime($stoday)],['<',strtotime($etoday)]];
2025-08-07 20:21:47 +08:00
}
}
2025-12-26 18:07:06 +08:00
$guild_flow = db::name('vs_guild_flow')
->where($where)
->sum('flow_price');
return $guild_flow;
}
//获取公会流水
public function getGuildFlow($guild_id=0,$room_id=0,$stoday="",$etoday=""){
$where = [];
if($guild_id!=0) {
$where['guild_id'] = $guild_id;
}
if($room_id!=0){
$where['room_id'] = $room_id;
}
if(!empty($stoday)){
$where['createtime'] = ['>=',strtotime($stoday)];
}
if(!empty($etime)){
$where['createtime'] = ['<',strtotime($etoday)];
}
if(!empty($stime) && !empty($etime)){
$where['createtime'] = [['>=',strtotime($stoday)],['<',strtotime($etoday)]];
}
$guild_flow = db::name('vs_guild_flow')->where($where)->sum('flow_price');
return $guild_flow;
2025-08-07 20:21:47 +08:00
}
2025-12-22 09:44:34 +08:00
/*
*
*工会幸运流水
*/
public function getTodayMoneyLuckyCoin($guild_id,$stoday="",$etoday=""){
//获取所有工会房间ID
$guild_user_data = db::name('vs_guild_user')->where('guild_id', $guild_id)->where(['apply_time'=>['>',0],'status'=>1])->field('room_id,apply_time,createtime,quit_time')->select();
$transaction = 0;
foreach ($guild_user_data as $k => $v) {
2025-12-26 18:07:06 +08:00
$stoday_seach = strtotime("2025-12-21 00:00:00");
$etoday_seach = time();
if(!empty($stoday)){
2025-12-22 09:44:34 +08:00
$stoday_seach = strtotime($stoday);
2025-12-26 18:07:06 +08:00
}
if(!empty($etoday)){
2025-12-22 09:44:34 +08:00
$etoday_seach = strtotime($etoday);
}
if($v['apply_time'] && $stoday_seach < $v['apply_time']){
$stoday_seach = $v['apply_time'];
}
if($v['quit_time'] && ($etoday > $v['quit_time'])){
$etoday_seach = $v['quit_time'];
}
$transaction_one = db::name('vs_room_luck_value')
->where('room_id',$v['room_id'])
2025-12-26 18:07:06 +08:00
->where(['createtime'=>['>=',$stoday_seach]])
->where(['createtime'=>['<',$etoday_seach]])
2025-12-22 09:44:34 +08:00
->sum('luck_value');
$transaction += $transaction_one;
}
return $transaction;
}
2025-08-07 20:21:47 +08:00
/*
* 工会个人流水
*/
public function getUserMoney($guild_id,$user_id,$stoday="",$etoday=""){
if(empty($stoday)){
$stoday = strtotime(date('Y-m-d 00:00:00'));
}
if(empty($etoday)){
$etoday = strtotime(date('Y-m-d 23:59:59'));
}
//获取所有工会房间ID
$room_ids = db::name('vs_guild_user')->where('guild_id', $guild_id)->field('room_id')->select();
$room_ids = array_column($room_ids, 'room_id');
$transaction =0;
$transaction = db::name('vs_give_gift')
->whereIn('from_id',$room_ids)
->where(['from'=>['in',[2,3,6]],'createtime' => ['between', [$stoday, $etoday]]])
->sum('total_price');
return $transaction;
}
}