From f24d88bec2b18e81d1016e84fbfb814069e92b6e Mon Sep 17 00:00:00 2001 From: lingling <1077478963@qq.com> Date: Mon, 17 Feb 2025 11:49:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/SignController.php | 8 +- app/controller/api/TurntableController.php | 15 +++- app/controller/api/UserController.php | 11 ++- app/dao/BankDao.php | 85 ---------------------- app/dao/SignDao.php | 39 ++++++++++ app/dao/UserRewardDao.php | 41 ++++++++--- app/model/UserReward.php | 2 +- 7 files changed, 95 insertions(+), 106 deletions(-) delete mode 100644 app/dao/BankDao.php create mode 100644 app/dao/SignDao.php diff --git a/app/controller/api/SignController.php b/app/controller/api/SignController.php index 512ee6f..1dbc122 100644 --- a/app/controller/api/SignController.php +++ b/app/controller/api/SignController.php @@ -2,6 +2,7 @@ namespace app\controller\api; +use app\dao\SignDao; use support\Request; use App\Utils\ApiResponseApp; @@ -42,7 +43,7 @@ class SignController for ($day = 1; $day <= $days_in_month; $day++) { $res['sign_info'][$day]=0; } - $res['today_sign']=0; + $res['today_sign']=SignDao::search_Sign_today($user_id); $res['sign_days']=0; $res['next_days']=7; $res['next_score']=500; @@ -61,10 +62,7 @@ class SignController //这里需要根据 业务逻辑判断 能不能签到 $user_id=$request->data['id']; - $Signlog=new Signlog(); - // 获取当前月份的天数 - $Signlog->userid=$user_id; - $Signlog->save(); + SignDao::Sign($user_id); return ApiResponseApp::success([]); } diff --git a/app/controller/api/TurntableController.php b/app/controller/api/TurntableController.php index 02a0af5..cc76aac 100644 --- a/app/controller/api/TurntableController.php +++ b/app/controller/api/TurntableController.php @@ -2,10 +2,12 @@ namespace app\controller\api; +use app\dao\UserDao; +use app\dao\UserRewardDao; use support\Request; use App\Utils\ApiResponseApp; - +use app\model\User; use App\model\Reward; use hg\apidoc\annotation as Apidoc; @@ -40,8 +42,15 @@ class TurntableController */ public function lottery(Request $request) { - - return ApiResponseApp::success(4,'恭喜抽中1.00'); + $user_id = $request->data['id']; + $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'); } } diff --git a/app/controller/api/UserController.php b/app/controller/api/UserController.php index 7e9b4d9..5306975 100644 --- a/app/controller/api/UserController.php +++ b/app/controller/api/UserController.php @@ -11,6 +11,9 @@ use Tinywan\Jwt\JwtToken; use App\model\User; use App\Utils\ApiResponseApp; use App\dao\UserDao; +use app\dao\UserRewardDao; +use app\model\UserReward; + /** * @Apidoc\Title("用户控制器") */ @@ -80,8 +83,9 @@ class UserController if (User::where('invite_code', $invitation)->count() == 0) { return ApiResponseApp::error([], "代理不存在"); } else { - $f_id = User::where('invite_code', $invitation)->first('id'); - $ff_id = User::where('f_id', $$f_id)->first('id'); + $f = User::where('invite_code', $invitation)->first(); + $f_id=$f->id; + $ff_id = $f->f_id; } } $user = new User(); @@ -95,6 +99,9 @@ class UserController $user->invite_code = Random::str_random(5); $user->password = password_hash($password, PASSWORD_DEFAULT); $user->save(); + $user_new=User::where('username', $username)->first(); + var_dump($user_new); + UserRewardDao::Register_for_free($user_new->id); return ApiResponseApp::success([], '注册成功'); } /** diff --git a/app/dao/BankDao.php b/app/dao/BankDao.php deleted file mode 100644 index 181cca4..0000000 --- a/app/dao/BankDao.php +++ /dev/null @@ -1,85 +0,0 @@ -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(); - } -} diff --git a/app/dao/SignDao.php b/app/dao/SignDao.php new file mode 100644 index 0000000..e34c678 --- /dev/null +++ b/app/dao/SignDao.php @@ -0,0 +1,39 @@ +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(); + + } +} diff --git a/app/dao/UserRewardDao.php b/app/dao/UserRewardDao.php index 430a5dc..2555bc9 100644 --- a/app/dao/UserRewardDao.php +++ b/app/dao/UserRewardDao.php @@ -16,7 +16,7 @@ class UserRewardDao */ 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, '加粉赏金'); } + /** + * 抽奖 + */ + 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); $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); self::base($f->id, 5, $f_dividend, '加粉赏金'); if ($user->ff_id != 0) { @@ -85,7 +107,7 @@ class UserRewardDao { // 初始化查询对象 if ($status == 0) { - $query = UserReward::where('user_id', $userid); + $query = UserReward::where('user_id', $userid)->orderBy('id','DESC'); } else { $query = UserReward::where('status', $status)->where('user_id', $userid); } @@ -98,19 +120,18 @@ class UserRewardDao case 1: // 今天:查询今天的记录 - $startOfDay = strtotime('today'); // 今天的开始时间(00:00:00) - return $query->where('created_at', '>=', $startOfDay)->get(); + $today = date('Y-m-d'); + return $query->where('created_at', '>=', $today." 00:00:00")->orderBy('id','DESC')->get(); case 2: // 昨天:查询昨天的记录 - $startOfYesterday = strtotime('yesterday'); // 昨天的开始时间(00:00:00) - $endOfYesterday = strtotime('today') - 1; // 昨天的结束时间(23:59:59) - return $query->whereBetween('created_at', [$startOfYesterday, $endOfYesterday])->get(); + $endOfYesterday = date('Y-m-d', strtotime('-1 day')); + return $query->whereBetween('created_at', [$endOfYesterday." 00:00:00", $endOfYesterday." 23:59:59"])->orderBy('id','DESC')->get(); case 3: // 最近七天:查询过去七天的记录 - $sevenDaysAgo = strtotime('-7 days'); // 七天前的时间戳 - return $query->where('created_at', '>=', $sevenDaysAgo)->get(); + $sevenDaysAgo = date('Y-m-d', strtotime('-7 days')); + return $query->where('created_at', '>=', $sevenDaysAgo." 23:59:59")->orderBy('id','DESC')->get(); default: // 如果没有匹配的时间段,返回空结果或其他处理方式 diff --git a/app/model/UserReward.php b/app/model/UserReward.php index 5caa5e6..1fa2cc9 100644 --- a/app/model/UserReward.php +++ b/app/model/UserReward.php @@ -13,7 +13,7 @@ use support\Model; * @property float $before 操作前的积分余额 * @property float $after 操作后的积分余额 * @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|null $admin_name 管理员名称(如果管理员操作) * @property string $createtime2 创建时间的格式化日期(YYYY-MM-DD HH:MM:SS)