This commit is contained in:
parent
1530ff82bd
commit
f24d88bec2
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace app\controller\api;
|
namespace app\controller\api;
|
||||||
|
|
||||||
|
use app\dao\SignDao;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
|
|
||||||
use App\Utils\ApiResponseApp;
|
use App\Utils\ApiResponseApp;
|
||||||
|
@ -42,7 +43,7 @@ class SignController
|
||||||
for ($day = 1; $day <= $days_in_month; $day++) {
|
for ($day = 1; $day <= $days_in_month; $day++) {
|
||||||
$res['sign_info'][$day]=0;
|
$res['sign_info'][$day]=0;
|
||||||
}
|
}
|
||||||
$res['today_sign']=0;
|
$res['today_sign']=SignDao::search_Sign_today($user_id);
|
||||||
$res['sign_days']=0;
|
$res['sign_days']=0;
|
||||||
$res['next_days']=7;
|
$res['next_days']=7;
|
||||||
$res['next_score']=500;
|
$res['next_score']=500;
|
||||||
|
@ -61,10 +62,7 @@ class SignController
|
||||||
|
|
||||||
//这里需要根据 业务逻辑判断 能不能签到
|
//这里需要根据 业务逻辑判断 能不能签到
|
||||||
$user_id=$request->data['id'];
|
$user_id=$request->data['id'];
|
||||||
$Signlog=new Signlog();
|
SignDao::Sign($user_id);
|
||||||
// 获取当前月份的天数
|
|
||||||
$Signlog->userid=$user_id;
|
|
||||||
$Signlog->save();
|
|
||||||
return ApiResponseApp::success([]);
|
return ApiResponseApp::success([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
namespace app\controller\api;
|
namespace app\controller\api;
|
||||||
|
|
||||||
|
use app\dao\UserDao;
|
||||||
|
use app\dao\UserRewardDao;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
|
|
||||||
use App\Utils\ApiResponseApp;
|
use App\Utils\ApiResponseApp;
|
||||||
|
use app\model\User;
|
||||||
|
|
||||||
use App\model\Reward;
|
use App\model\Reward;
|
||||||
use hg\apidoc\annotation as Apidoc;
|
use hg\apidoc\annotation as Apidoc;
|
||||||
|
@ -40,8 +42,15 @@ class TurntableController
|
||||||
*/
|
*/
|
||||||
public function lottery(Request $request)
|
public function lottery(Request $request)
|
||||||
{
|
{
|
||||||
|
$user_id = $request->data['id'];
|
||||||
return ApiResponseApp::success(4,'恭喜抽中1.00');
|
$user = User::find($user_id);
|
||||||
|
if($user->money<10){
|
||||||
|
return ApiResponseApp::error([],'账户余额不足');
|
||||||
|
}
|
||||||
|
//TODO 这里好像还需要写是否完成今天的任务
|
||||||
|
UserRewardDao::lottery($user_id,-10);
|
||||||
|
UserRewardDao::winning($user_id,1);
|
||||||
|
return ApiResponseApp::success(1,'恭喜抽中1.00');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ use Tinywan\Jwt\JwtToken;
|
||||||
use App\model\User;
|
use App\model\User;
|
||||||
use App\Utils\ApiResponseApp;
|
use App\Utils\ApiResponseApp;
|
||||||
use App\dao\UserDao;
|
use App\dao\UserDao;
|
||||||
|
use app\dao\UserRewardDao;
|
||||||
|
use app\model\UserReward;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Apidoc\Title("用户控制器")
|
* @Apidoc\Title("用户控制器")
|
||||||
*/
|
*/
|
||||||
|
@ -80,8 +83,9 @@ class UserController
|
||||||
if (User::where('invite_code', $invitation)->count() == 0) {
|
if (User::where('invite_code', $invitation)->count() == 0) {
|
||||||
return ApiResponseApp::error([], "代理不存在");
|
return ApiResponseApp::error([], "代理不存在");
|
||||||
} else {
|
} else {
|
||||||
$f_id = User::where('invite_code', $invitation)->first('id');
|
$f = User::where('invite_code', $invitation)->first();
|
||||||
$ff_id = User::where('f_id', $$f_id)->first('id');
|
$f_id=$f->id;
|
||||||
|
$ff_id = $f->f_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$user = new User();
|
$user = new User();
|
||||||
|
@ -95,6 +99,9 @@ class UserController
|
||||||
$user->invite_code = Random::str_random(5);
|
$user->invite_code = Random::str_random(5);
|
||||||
$user->password = password_hash($password, PASSWORD_DEFAULT);
|
$user->password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
$user->save();
|
$user->save();
|
||||||
|
$user_new=User::where('username', $username)->first();
|
||||||
|
var_dump($user_new);
|
||||||
|
UserRewardDao::Register_for_free($user_new->id);
|
||||||
return ApiResponseApp::success([], '注册成功');
|
return ApiResponseApp::success([], '注册成功');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,85 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace app\dao;
|
|
||||||
|
|
||||||
use App\model\Users;
|
|
||||||
use App\model\BankLog;
|
|
||||||
use plugin\admin\app\model\User;
|
|
||||||
|
|
||||||
class BankDao {
|
|
||||||
/**
|
|
||||||
* 转账函数
|
|
||||||
*
|
|
||||||
* @param int $senderAccountId - 发送账户ID
|
|
||||||
* @param int $receiverAccountId - 接收账户手机号
|
|
||||||
* @param float $amount - 转账金额
|
|
||||||
* @return array - 返回转账结果
|
|
||||||
*/
|
|
||||||
public static function transfer($senderAccountId, $receiverAccountId, $amount) {
|
|
||||||
// 假设账户数据存储在一个简单的数组或数据库中
|
|
||||||
// 模拟账户余额数据(实际应用中应查询数据库)
|
|
||||||
$senderAccount=Users::where('id',$senderAccountId)->first();
|
|
||||||
$receiverAccount=Users::where('phone',$receiverAccountId)->first();
|
|
||||||
|
|
||||||
// 检查接收账户是否存在
|
|
||||||
if (!isset($receiverAccount)) {
|
|
||||||
return ['status' => 'error', 'message' => '接收账户不存在'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查转账金额是否合法
|
|
||||||
if ($amount <= 0) {
|
|
||||||
return ['status' => 'error', 'message' => '时间币必须大于0'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查发送账户余额是否足够
|
|
||||||
if ($senderAccount->timecoin < $amount) {
|
|
||||||
return ['status' => 'error', 'message' => '时间币余额不足'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 执行转账操作
|
|
||||||
self::add($senderAccount->id,$amount-$amount*2,"赠送给 $receiverAccountId 时间币 $amount");
|
|
||||||
self::add($receiverAccount->id,$amount,"收到 $senderAccount->phone 赠予 时间币 $amount");
|
|
||||||
|
|
||||||
return [
|
|
||||||
'status' => 'success',
|
|
||||||
'message' => '转账成功',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 增加时间币 传入负数就是减法
|
|
||||||
*
|
|
||||||
* @param [type] $userid 用户id
|
|
||||||
* @param [type] $amount 金额
|
|
||||||
* @param [type] $remark 备注
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function add($userid, $amount,$remark) {
|
|
||||||
$user = Users::where('id',$userid)->first();
|
|
||||||
$log=new BankLog();
|
|
||||||
$log->userid=$userid;
|
|
||||||
$log->money=$amount;
|
|
||||||
$log->remark=$remark;
|
|
||||||
$log->save();
|
|
||||||
$user->timecoin+=$amount;
|
|
||||||
$user->Save();
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 减少用户时间币 好像废弃了
|
|
||||||
*
|
|
||||||
* @param [type] $userid 用户id
|
|
||||||
* @param [type] $amount 金额
|
|
||||||
* @param [type] $remark 备注
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function subtraction($userid, $amount,$remark) {
|
|
||||||
$user = Users::where('id',$userid)->first('timecoin');
|
|
||||||
$log=new BankLog();
|
|
||||||
$log->userid=$userid;
|
|
||||||
$log->money=$amount;
|
|
||||||
$log->remark=$remark;
|
|
||||||
$log->save();
|
|
||||||
$user->timecoin-=$amount;
|
|
||||||
$user->Save();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\dao;
|
||||||
|
|
||||||
|
use App\model\Signlog;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SignDao {
|
||||||
|
/**
|
||||||
|
* 签到函数
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function Sign($user_id) {
|
||||||
|
$Signlog=new Signlog();
|
||||||
|
$Signlog->userid=$user_id;
|
||||||
|
$Signlog->save();
|
||||||
|
UserRewardDao::sing($user_id,30);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 查询今天是否签到
|
||||||
|
* 0没签到1签到
|
||||||
|
*/
|
||||||
|
public static function search_Sign_today($user_id){
|
||||||
|
$today = date('Y-m-d');
|
||||||
|
$is_sign=Signlog::where('userid',$user_id)->where('created_at', '>=', $today." 00:00:00")->count();
|
||||||
|
return $is_sign==0?0:1;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 查询当月签到数据
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function search_Sign_tomon($user_id){
|
||||||
|
$startTime = date('Y-m-01',time());//获取该月份的第一天
|
||||||
|
$endTime = date('Y-m-t',time());//获取该月份的最后一天
|
||||||
|
$mon_data=Signlog::whereBetween('created_at', [$startTime." 00:00:00", $endTime." 23:59:59"])->orderBy('created_at','DESC')->get();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ class UserRewardDao
|
||||||
*/
|
*/
|
||||||
public static function Register_for_free($userid)
|
public static function Register_for_free($userid)
|
||||||
{
|
{
|
||||||
self::f_bounty($userid, 4, 30, '注册赠送');
|
self::f_bounty($userid, 4, 88, '注册赠送');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 挂机获得的奖励
|
* 挂机获得的奖励
|
||||||
|
@ -32,6 +32,27 @@ class UserRewardDao
|
||||||
{
|
{
|
||||||
self::base($userid, 5, $money, '加粉赏金');
|
self::base($userid, 5, $money, '加粉赏金');
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 抽奖
|
||||||
|
*/
|
||||||
|
public static function lottery($userid, $money)
|
||||||
|
{
|
||||||
|
self::base($userid, 9, $money, '抽奖');
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 中奖
|
||||||
|
*/
|
||||||
|
public static function winning($userid, $money)
|
||||||
|
{
|
||||||
|
self::base($userid, 8, $money, '中奖');
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 签到
|
||||||
|
*/
|
||||||
|
public static function sing($userid, $money)
|
||||||
|
{
|
||||||
|
self::base($userid, 7, $money, '签到');
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 转账函数
|
* 转账函数
|
||||||
*/
|
*/
|
||||||
|
@ -63,7 +84,8 @@ class UserRewardDao
|
||||||
//父父分红
|
//父父分红
|
||||||
$ff_dividend = floor($money * 0.1);
|
$ff_dividend = floor($money * 0.1);
|
||||||
$user = User::find($userid);
|
$user = User::find($userid);
|
||||||
if ($user->f_id != 0&&$money>0) {
|
//分红大于0才会记录 这里还有类型 有些类型需要分红吗
|
||||||
|
if ($user->f_id != 0&&$money>0&&$f_dividend>0&&$ff_dividend>0) {
|
||||||
$f = User::find($user->f_id);
|
$f = User::find($user->f_id);
|
||||||
self::base($f->id, 5, $f_dividend, '加粉赏金');
|
self::base($f->id, 5, $f_dividend, '加粉赏金');
|
||||||
if ($user->ff_id != 0) {
|
if ($user->ff_id != 0) {
|
||||||
|
@ -85,7 +107,7 @@ class UserRewardDao
|
||||||
{
|
{
|
||||||
// 初始化查询对象
|
// 初始化查询对象
|
||||||
if ($status == 0) {
|
if ($status == 0) {
|
||||||
$query = UserReward::where('user_id', $userid);
|
$query = UserReward::where('user_id', $userid)->orderBy('id','DESC');
|
||||||
} else {
|
} else {
|
||||||
$query = UserReward::where('status', $status)->where('user_id', $userid);
|
$query = UserReward::where('status', $status)->where('user_id', $userid);
|
||||||
}
|
}
|
||||||
|
@ -98,19 +120,18 @@ class UserRewardDao
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// 今天:查询今天的记录
|
// 今天:查询今天的记录
|
||||||
$startOfDay = strtotime('today'); // 今天的开始时间(00:00:00)
|
$today = date('Y-m-d');
|
||||||
return $query->where('created_at', '>=', $startOfDay)->get();
|
return $query->where('created_at', '>=', $today." 00:00:00")->orderBy('id','DESC')->get();
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// 昨天:查询昨天的记录
|
// 昨天:查询昨天的记录
|
||||||
$startOfYesterday = strtotime('yesterday'); // 昨天的开始时间(00:00:00)
|
$endOfYesterday = date('Y-m-d', strtotime('-1 day'));
|
||||||
$endOfYesterday = strtotime('today') - 1; // 昨天的结束时间(23:59:59)
|
return $query->whereBetween('created_at', [$endOfYesterday." 00:00:00", $endOfYesterday." 23:59:59"])->orderBy('id','DESC')->get();
|
||||||
return $query->whereBetween('created_at', [$startOfYesterday, $endOfYesterday])->get();
|
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
// 最近七天:查询过去七天的记录
|
// 最近七天:查询过去七天的记录
|
||||||
$sevenDaysAgo = strtotime('-7 days'); // 七天前的时间戳
|
$sevenDaysAgo = date('Y-m-d', strtotime('-7 days'));
|
||||||
return $query->where('created_at', '>=', $sevenDaysAgo)->get();
|
return $query->where('created_at', '>=', $sevenDaysAgo." 23:59:59")->orderBy('id','DESC')->get();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// 如果没有匹配的时间段,返回空结果或其他处理方式
|
// 如果没有匹配的时间段,返回空结果或其他处理方式
|
||||||
|
|
|
@ -13,7 +13,7 @@ use support\Model;
|
||||||
* @property float $before 操作前的积分余额
|
* @property float $before 操作前的积分余额
|
||||||
* @property float $after 操作后的积分余额
|
* @property float $after 操作后的积分余额
|
||||||
* @property string $memo 奖励类型或备注信息
|
* @property string $memo 奖励类型或备注信息
|
||||||
* @property int $status 操作类型 1提现扣款 2人工调整 3提现返还 4注册赠送 5加粉赏金 6任务佣金
|
* @property int $status 操作类型 1提现扣款 2人工调整 3提现返还 4注册赠送 5加粉赏金 6任务佣金 8是中奖 9是抽奖
|
||||||
* @property string $uu_id 用户唯一标识符 这里好像是对应的用户邀请码
|
* @property string $uu_id 用户唯一标识符 这里好像是对应的用户邀请码
|
||||||
* @property string|null $admin_name 管理员名称(如果管理员操作)
|
* @property string|null $admin_name 管理员名称(如果管理员操作)
|
||||||
* @property string $createtime2 创建时间的格式化日期(YYYY-MM-DD HH:MM:SS)
|
* @property string $createtime2 创建时间的格式化日期(YYYY-MM-DD HH:MM:SS)
|
||||||
|
|
Loading…
Reference in New Issue