·设为首页收藏本站📧邮箱修改🎁免费下载专区💎积分✅卡密📒收藏夹👽聊天室
12下一页
返回列表 发布新帖

过年了,帝国CMS发红包功能让大家乐呵呵

118 17
发表于 昨天 15:39 | 查看全部 阅读模式

马上注册,免费下载更多dz插件网资源。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
过年了,帝国CMS发红包功能让大家乐呵呵。直接上干货。代码走起
  1. if($enews=="hongbao"){//红包if($user['zt']=="nologin"){echo json_encode(['msg' => '未登陆不能领取'], JSON_UNESCAPED_UNICODE);exit;        }// 获取 POST 数据$userid = (int)$_POST['userid']; // 发红包的人userid$username = RepPostStr($_POST['username']); // 发红包的人$fusername = RepPostStr($_POST['fusername']); // 领红包的人$fuserid = (int)$_POST['fuserid']; // 领红包的人ID$amount = (int)$_POST['amount']; // 红包总金额$recipients = (int)$_POST['recipients']; // 红包个数$hongbao_id = RepPostStr($_POST['hongbaoid']) ? RepPostStr($_POST['hongbaoid']) : uniqid(); // 获取红包标识符// 检查参数有效性if ($amount <= 0 || $recipients <= 0) {    echo json_encode(['msg' => '无效的参数'], JSON_UNESCAPED_UNICODE);    exit;}// 检查红包是否存在$hongbao_state = $empire->fetch1("select hongbao_id,remaining_points, recipients, total_amount from {$dbtbpre}hongbao_info where hongbao_id ='$hongbao_id'");if (empty($hongbao_state['hongbao_id'])) {// 插入新红包$time=time();//获取当前时间$empire->query("insert into {$dbtbpre}hongbao_info(hongbao_id,sender_userid,sender_username,total_amount,recipients,remaining_points,time) values('$hongbao_id','$userid','$username','$amount','$recipients','$remainingPoints','$time');");$remainingPoints = $amount;}else{$remainingPoints = $hongbao_state['remaining_points'];        }// 检查用户是否已经领取过该红包$alreadyClaimed=$empire->gettotal("select count(*) as total from {$dbtbpre}hongbao_history where hongbao_id ='$hongbao_id' and receiver_userid ='$fuserid'");if ($alreadyClaimed > 0) {    $info = ['msg' => '您已经领取过了', 'hongbao_id' => $hongbao_id, 'remainingPoints' => $remainingPoints, 'amount' => $amount, 'fusername' => $fusername];    echo json_encode($info, JSON_UNESCAPED_UNICODE);    exit;}// 检查红包是否已经被领取超过了指定次数$totalClaimed = $empire->fetch1("select count(*) as total_claimed from {$dbtbpre}hongbao_history where hongbao_id ='$hongbao_id'");if ($totalClaimed['total_claimed'] >= $recipients) {$info = ['msg' => '红包已被领取完', 'hongbao_id' => $hongbao_id, 'remainingPoints' => $remainingPoints, 'amount' => $amount, 'fusername' => $fusername,'title' =>'红包次数检查'];echo json_encode($info, JSON_UNESCAPED_UNICODE);exit;}// 计算随机分配的积分$minPoints = 1; // 最小积分$maxPoints = min($remainingPoints, ceil($amount / $recipients)); // 最大积分$randomPoints = rand($minPoints, $maxPoints);// 如果这是最后一个领取者,将剩余的积分全部分配给该用户if ($recipients - $totalClaimed['total_claimed'] == 1) {$randomPoints =$remainingPoints;}// 更新剩余积分$newRemainingPoints = $remainingPoints - $randomPoints;// 更新红包状态$sql = $empire->query("update {$dbtbpre}hongbao_info set remaining_points =$newRemainingPoints where hongbao_id ='$hongbao_id'"); // 插入领取记录$time=time();//获取当前时间// 检查剩余积分是否为0$updatedHongbaoState = $empire->fetch1("select remaining_points from {$dbtbpre}hongbao_info where hongbao_id = '$hongbao_id'");if ((int)$updatedHongbaoState['remaining_points'] <0 ||(int)$randomPoints<=0) {$info = ['msg' => '红包已被领取完', 'hongbao_id' => $hongbao_id, 'remainingPoints' => (int)$updatedHongbaoState['remaining_points'], 'amount' => $amount, 'fusername' => $fusername,'title' =>'点数金额检查'];echo json_encode($info, JSON_UNESCAPED_UNICODE);exit;} else {        $empire->query("insert into {$dbtbpre}hongbao_history(hongbao_id,receiver_userid,receiver_username,userid,username,points,total_amount,recipients,ip,duankou,time) values('$hongbao_id','$fuserid','$fusername','$userid','$username','$randomPoints','$amount','$recipients','$ip','$duankou','$time');");         // 更新用户积分$sql = $empire->query("update {$dbtbpre}enewsmember set userfen = userfen - $randomPoints where userid = '$userid'"); // 扣除打赏者积分$sql1 = $empire->query("update {$dbtbpre}enewsmember set userfen = userfen + $randomPoints where userid = '$fuserid'"); // 领取红包增加积分$info = ['msg' => '获得 ' . $randomPoints . ' 元', 'hongbao_id' => $hongbao_id, 'remainingPoints' =>(int)$randomPoints, 'amount' => $amount, 'fusername' => $fusername];echo json_encode($info, JSON_UNESCAPED_UNICODE);exit;}}if($enews=="chahongbao"){//红包查询$hongbao_id = RepPostStr($_POST['hongbaoid']); // 获取红包标识符$sql=$empire->query("select * from {$dbtbpre}hongbao_history where hongbao_id='$hongbao_id' order by id");while($r=$empire->fetch($sql)){$memberrr = fetch_memcache0("select userpic from {$dbtbpre}enewsmemberadd where userid='$r[receiver_userid]' order by userid desc limit 1", 'Memcached', 'chatpublic', 3600*24*1);    $memberrr = $memberrr[0]; $receiveruserpic=$memberrr['userpic']?$memberrr['userpic']:'/e/extend/pcpinglun/assets/nouserpic.gif';$receiveruserpic=$public_r['add_pcurl'].$receiveruserpic;        $date[]= array(    'receiver_username'=>$r['receiver_username'],    'receiver_userid'=>$r['receiver_userid'],        'username'=>$r['username'],        'totalamount'=>$r['total_amount'],        'recipients'=>$r['recipients'],    'userid'=>$r['userid'],        'points'=>$r['points'],        'ip'=>$r['ip'],        'hongbao_id'=>$hongbao_id,    'time'=>date('Y-m-d H:i:s',$r['time']),    'headerimg'=>$userpic,        'receiver_headerimg'=>$receiveruserpic,    );}if (empty($date)) {$response = ['code' => 400,'msg' => '还没有人领取红包','hongbao_id' => $hongbao_id];}else{$response = ['code' => 200,'data' => $date];}echo json_encode($response);exit;        }if($enews=="sendredbaojilu"){//全网红包记录$num=(int)$_POST['num']?(int)$_POST['num']:'15';//前端传来的请求多少条$value=fetch_memcache0("select * from {$dbtbpre}hongbao_history order by id desc limit $num",'Memcached','hongbaohistoryall',3600);$jiangall=fetch_memcache0("select count(*) as total from {$dbtbpre}hongbao_history",'Memcached','listjiang',3600);$hongbaohistoryall=$jiangall[0]['total'];//红包领取总数$jiangallm=fetch_memcache0("select count(*) as total from {$dbtbpre}hongbao_info",'Memcached','listjiang',3600);$hongbaoall=$jiangallm[0]['total'];//红包发放总数foreach ($value as $r){$date[]= array('hongbao_id'=>$r['hongbao_id'],'receiver_userid'=>$r['receiver_userid'],'receiver_username'=>$r['receiver_username'],'userid'=>$r['userid'],'username'=>$r['username'],'points'=>$r['points'],'total_amount'=>$r['total_amount'],'ip'=>$r['ip'],'ipcity'=>citychatip($r['ip']),'time'=>date('Y-m-d H:i:s',$r['time']),'recipients'=>$r['recipients'],);}$response = ['code' => 200,'hongbaohistoryall'=>$hongbaohistoryall,//红包领取总数'hongbaoall'=>$hongbaoall,//红包发放总数'data'=> $date];$data = json_encode($response);echo $data;exit;}
复制代码
  1. /********创建红包的信息表CREATE TABLE `[!db.pre!]hongbao_info` (`id` INT(11) NOT NULL AUTO_INCREMENT,`hongbao_id` VARCHAR(32) NOT NULL,`sender_userid` INT(11) NOT NULL,`sender_username` VARCHAR(255) NOT NULL,`total_amount` DECIMAL(10,2) NOT NULL,`recipients` INT(11) NOT NULL,`remaining_points` DECIMAL(10,2) DEFAULT 0.00,`time` int(11) NOT NULL COMMENT '时间',PRIMARY KEY (`id`),UNIQUE KEY `hongbao_id` (`hongbao_id`),KEY `time` (`time`),KEY `sender_userid` (`sender_userid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;*******创建红包的信息表*******************//********创建领取红包的记录表CREATE TABLE `[!db.pre!]hongbao_history` (`id` INT(11) NOT NULL AUTO_INCREMENT,`hongbao_id` VARCHAR(32) NOT NULL,`receiver_userid` INT(11) NOT NULL,`receiver_username` VARCHAR(255) NOT NULL,`userid` INT(11) NOT NULL,`username` VARCHAR(255) NOT NULL,`points` DECIMAL(10,2) NOT NULL,`total_amount` DECIMAL(10,2) NOT NULL,`recipients` INT(11) NOT NULL,`ip` VARCHAR(32) NOT NULL,`duankou` INT(11) NOT NULL,`time` int(11) NOT NULL COMMENT '时间', PRIMARY KEY (`id`),KEY `hongbao_id` (`hongbao_id`),KEY `time` (`time`),KEY `receiver_userid` (`receiver_userid`),KEY `userid` (`userid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;*******创建领取红包的记录表*******************/
复制代码
至于在什么地方使用那取决于你了,小编是用在聊天室的。聊天室前端先生成一个临时的红包ID。待WebSocket双向通讯接收到后端通知在更新为真实的红包ID。(快速响应,异步处理,前端逻辑与后端解耦,分布式架构支持,功能扩展便利)
我要说一句 收起回复
创宇盾启航版免费网站防御网站加速服务

评论17

CrystαlLv.8 发表于 昨天 15:40 | 查看全部
有撒用哦!
我要说一句 收起回复
浅生Lv.8 发表于 昨天 15:40 | 查看全部
天天嚷着有啥用!你倒是分享点干货出来再说。本不想回复的,看到喷子有点多。难道我不可以发个帖子领取点金币么?
我要说一句 收起回复
婷姐Lv.8 发表于 昨天 15:41 | 查看全部
谢谢老板
我要说一句 收起回复
拾光Lv.8 发表于 昨天 15:42 | 查看全部
感谢老板
我要说一句 收起回复
TyCodingLv.8 发表于 昨天 15:42 | 查看全部
感谢老板
我要说一句 收起回复
TyCodingLv.8 发表于 昨天 15:43 | 查看全部
收藏  只要是技术流发 都值得收藏起来

哪怕现在用不到  也值得啊
我要说一句 收起回复
拾光Lv.8 发表于 昨天 15:44 | 查看全部
感谢老板
我要说一句 收起回复
拾光Lv.8 发表于 昨天 15:44 | 查看全部
火钳刘明
我要说一句 收起回复
TyCodingLv.8 发表于 昨天 15:45 | 查看全部
美文苑卖了现在又搞啥项目
我要说一句 收起回复

回复

 懒得打字嘛,点击右侧快捷回复【查看最新发布】   【应用商城享更多资源】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

创宇盾启航版免费网站防御网站加速服务
投诉/建议联系

discuzaddons@vip.qq.com

未经授权禁止转载,复制和建立镜像,
如有违反,按照公告处理!!!
  • 联系QQ客服
  • 添加微信客服

联系DZ插件网微信客服|最近更新|Archiver|手机版|小黑屋|DZ插件网! ( 鄂ICP备20010621号-1 )|网站地图 知道创宇云防御

您的IP:3.143.17.75,GMT+8, 2025-1-15 06:30 , Processed in 0.400101 second(s), 126 queries , Gzip On, Redis On.

Powered by Discuz! X5.0 Licensed

© 2001-2025 Discuz! Team.

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表