2025-02-16 19:34:37 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\dao;
|
|
|
|
|
|
|
|
|
|
use App\model\UserReward;
|
|
|
|
|
use App\model\BankLog;
|
|
|
|
|
use app\model\User;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户收益明细控制类
|
|
|
|
|
*/
|
|
|
|
|
class UserRewardDao
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 注册赠送金额
|
|
|
|
|
*/
|
|
|
|
|
public static function Register_for_free($userid)
|
|
|
|
|
{
|
2025-02-16 22:00:51 +08:00
|
|
|
|
self::f_bounty($userid, 4, 30, '注册赠送');
|
2025-02-16 19:34:37 +08:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 挂机获得的奖励
|
|
|
|
|
*/
|
2025-02-16 21:20:18 +08:00
|
|
|
|
public static function Onhookincome($userid, $money)
|
2025-02-16 19:34:37 +08:00
|
|
|
|
{
|
2025-02-16 22:00:51 +08:00
|
|
|
|
self::f_bounty($userid, 6, $money, '挂机收益');
|
2025-02-16 19:34:37 +08:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 加粉赏金奖励
|
|
|
|
|
*/
|
2025-02-16 21:20:18 +08:00
|
|
|
|
public static function bounty($userid, $money)
|
2025-02-16 19:34:37 +08:00
|
|
|
|
{
|
|
|
|
|
self::base($userid, 5, $money, '加粉赏金');
|
|
|
|
|
}
|
|
|
|
|
/**
|
2025-02-16 22:00:51 +08:00
|
|
|
|
* 转账函数
|
2025-02-16 19:34:37 +08:00
|
|
|
|
*/
|
2025-02-16 22:00:51 +08:00
|
|
|
|
public static function base($userid, $status, $money, $memo)
|
2025-02-16 19:34:37 +08:00
|
|
|
|
{
|
|
|
|
|
$UserReward = new UserReward();
|
|
|
|
|
$user = User::find($userid);
|
|
|
|
|
$UserReward->user_id = $user->id;
|
|
|
|
|
$UserReward->username = $user->username;
|
|
|
|
|
$UserReward->uu_id = $user->invite_code;
|
|
|
|
|
$UserReward->status = $status;
|
|
|
|
|
$UserReward->money = $money;
|
|
|
|
|
$UserReward->before = $user->money;
|
|
|
|
|
$UserReward->after = $user->money + $money;
|
|
|
|
|
$UserReward->memo = $memo;
|
|
|
|
|
$UserReward->createtime2 = date('Y-m-d H:i:s');
|
|
|
|
|
$user->money = $UserReward->after;
|
|
|
|
|
$user->save();
|
|
|
|
|
$UserReward->save();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 父级 父父级分红
|
2025-02-16 22:00:51 +08:00
|
|
|
|
* 函数
|
2025-02-16 19:34:37 +08:00
|
|
|
|
*/
|
2025-02-16 21:20:18 +08:00
|
|
|
|
public static function f_bounty($userid, $status, $money, $memo)
|
|
|
|
|
{
|
2025-02-16 19:34:37 +08:00
|
|
|
|
//父分红
|
2025-02-16 21:20:18 +08:00
|
|
|
|
$f_dividend = floor($money * 0.2);
|
2025-02-16 19:34:37 +08:00
|
|
|
|
//父父分红
|
2025-02-16 21:20:18 +08:00
|
|
|
|
$ff_dividend = floor($money * 0.1);
|
2025-02-16 19:34:37 +08:00
|
|
|
|
$user = User::find($userid);
|
2025-02-16 22:00:51 +08:00
|
|
|
|
if ($user->f_id != 0&&$money>0) {
|
2025-02-16 21:20:18 +08:00
|
|
|
|
$f = User::find($user->f_id);
|
2025-02-16 19:34:37 +08:00
|
|
|
|
self::base($f->id, 5, $f_dividend, '加粉赏金');
|
2025-02-16 21:20:18 +08:00
|
|
|
|
if ($user->ff_id != 0) {
|
|
|
|
|
$ff = User::find($user->ff_id);
|
|
|
|
|
self::base($ff->id, 5, $ff_dividend, '加粉赏金');
|
|
|
|
|
}
|
2025-02-16 19:34:37 +08:00
|
|
|
|
}
|
2025-02-16 22:00:51 +08:00
|
|
|
|
self::base($userid, $status, $money, $memo);
|
2025-02-16 19:34:37 +08:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 搜索函数
|
|
|
|
|
*
|
|
|
|
|
* @param int $userid 用户ID
|
|
|
|
|
* @param int $status 类型
|
|
|
|
|
* @param int $time 时间段(0: 全部时间,1: 今天,2: 昨天,3: 最近七天)
|
|
|
|
|
* @return mixed 返回查询结果(可以是数组或查询对象)
|
|
|
|
|
*/
|
|
|
|
|
public static function search($userid, $status, int $time)
|
|
|
|
|
{
|
|
|
|
|
// 初始化查询对象
|
|
|
|
|
if ($status == 0) {
|
|
|
|
|
$query = UserReward::where('user_id', $userid);
|
|
|
|
|
} else {
|
|
|
|
|
$query = UserReward::where('status', $status)->where('user_id', $userid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch ($time) {
|
|
|
|
|
case 0:
|
|
|
|
|
// 全部时间:查询没有时间限制的记录
|
|
|
|
|
return $query->get();
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
// 今天:查询今天的记录
|
|
|
|
|
$startOfDay = strtotime('today'); // 今天的开始时间(00:00:00)
|
|
|
|
|
return $query->where('created_at', '>=', $startOfDay)->get();
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
// 昨天:查询昨天的记录
|
|
|
|
|
$startOfYesterday = strtotime('yesterday'); // 昨天的开始时间(00:00:00)
|
|
|
|
|
$endOfYesterday = strtotime('today') - 1; // 昨天的结束时间(23:59:59)
|
|
|
|
|
return $query->whereBetween('created_at', [$startOfYesterday, $endOfYesterday])->get();
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
// 最近七天:查询过去七天的记录
|
|
|
|
|
$sevenDaysAgo = strtotime('-7 days'); // 七天前的时间戳
|
|
|
|
|
return $query->where('created_at', '>=', $sevenDaysAgo)->get();
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// 如果没有匹配的时间段,返回空结果或其他处理方式
|
|
|
|
|
return $query->get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|