您现在的位置是:首页 > cms教程 > Ecshop商城教程Ecshop商城教程

ecshop红包功能添加方法

南莲2025-02-06Ecshop商城教程已有人查阅

导读1.领取红包:也就是传递一个红包ID,和user_id然后update更新过来2.获取未领取过的红包列表:然后随机函数array_rand($arr,1),随机返回一个数组,从而获得红包列表的红包ID以上两步基本满足,领取红包功能。

思路:
1.领取红包:也就是传递一个红包ID,和user_id然后update更新过来
2.获取未领取过的红包列表:然后随机函数array_rand($arr,1),随机返回一个数组,从而获得红包列表的红包ID以上两步基本满足,领取红包功能。
3.判断该用户是否已经领取过红包
基本代码
html代码1:
<input type="button" value="领取红包" onClick="bouns(30)">
<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js" ></script>
<script>
function bouns($type_id){
$.ajax({
,
success: function(html){
if(html == 'ok'){
alert('成功领取红包');
}if(html == 'no_bouns'){
alert('已经没有红包了哦');
}if(html == 'no_start_date'){
alert('领取红包的时间还没到哦');
}if(html == 'no_end_date'){
alert('你来晚了哦,红包已经结束了哦');
}if(html == 'pull_bonus'){
alert('你咋又来了呢,每个ID只能领取一次哦');
}
}
});
}
</script>
完整版html代码:
<script>
$(document).ready(function(){
$type_id = '30';
check_user_bonus();
//alert($f);
});
$('#DivBg').click(function(){
$(this).css('display','none');
});
// 领取红包
function bouns(){
$.ajax({
,
success: function(html){
if(html == 'ok'){ // 可以根据返回的值,多做几种选择
alert('成功领取红包');
}else{
alert(html);
}
}
});
}
//检测用户是否领取过红包;领取过,则不显示;未领取就显示红包
function check_user_bonus(){
$.ajax({
,
success: function (html){
if(html !=0){ // 0,显示红包;否则就隐藏红包
$("#DivBg").css('display','none');
}else{
$("#DivBg").css('display','block');
}
}
});
}
</script>
BonusController.php
public function bonus_ajax(){
$type_id = $_GET['type_id'];
$m = model('Bonus')->get_bonus($type_id);
echo $m;
}
BonusModel.class.php
<?php
defined('IN_ECTOUCH') or die('Deny Access');
class BonusModel extends BaseModel {
/**
* 红包
*
* @access private
* @param integer $brand_id
* @return array
*/
// 获取ecs_bouns_type 红包类型
function get_bonus_type($type_id=''){
if(!empty($type_id)){ // 有值获取单个;无值则获取全部
$where = ' where type_id = '.$type_id;
}else{
$where = ' ';
}
$sql = 'select * from '. $this->pre . 'bonus_type '.$where;
$res = $this->query($sql);
return $res;
}
// 获取ecs_user_bouns 红包列表(未被领取的红包)
function get_user_bonus($bouns_type_id=''){
if(!empty($bouns_type_id)){ // 有值获取单个;无值则获取全部
$where = ' where user_id =0 and bonus_type_id = '.$bouns_type_id; //必须是“线下发放红包”
}else{
$where = ' ';
}
$sql = 'select bonus_id from '. $this->pre . 'user_bonus '.$where;
$res = $this->query($sql);
return $res;
}
// 合并红包类型 与红包列表
function bouns_info($bouns_type_id){
$bouns_type = $this->get_bonus_type($bouns_type_id);
$bouns_type[0]['user_bouns'] = $this->get_user_bonus($bouns_type_id);
return $bouns_type;
}
//检测是否重复领取; 已经领取( >1 )
function check_user_bonus($bonus_type_id){
$sql = 'select * from '. $this->pre .'user_bonus where bonus_type_id = '.$bonus_type_id.' and user_id='.$_SESSION['user_id'];
$result = $this->query($sql);
return count($result);
}
// 领取红包
function get_bonus($type_id){
$user_id = $_SESSION['user_id'];
$time = gmtime();
//红包类型
$bonus_type = $this->get_bonus_type($type_id);
// 红包列表
$bouns_list = $this->get_user_bonus($type_id);
// 是否领取过红包
$check_bonus = $this->check_user_bonus($type_id);
// 判断条件
if(empty($user_id)){
$str = 'no_user'; // 1.未登录
}elseif(count($bouns_list) < 1){
$str = 'no_bouns'; // 3.没有红包(红包领取完了)
}elseif($bonus_type[0]['send_type'] !=3){ //2.红包类型不对 ,必须"线下发放红包"
$str = 'send_type_err'; //
}elseif($time < $bonus_type[0]['use_start_date']){ //4.领取红包时间还未到
$str = 'no_start_date';
}elseif($time > $bonus_type[0]['use_end_date']){ //5.领取红包时间还已经结束
$str = 'no_end_date';
}elseif($check_bonus > 0){ // 6.已经领取过红包
$str = 'pull_bonus';
}else{
$rand_key = array_rand($bouns_list,1);
$rand_id = $bouns_list[$rand_key]['bonus_id'];
$sql = "UPDATE ". $this->pre ."user_bonus SET user_id = ".$user_id.",used_time = ".$time." where bonus_id=".$rand_id;
if($this->query($sql)){
$str = 'ok';
}else{
$str = 'err';
}
}
echo $str;
}
}

本文标签:

很赞哦! ()

相关源码

  • (自适应)代理记账财务会计咨询服务个人公司网站模板该响应式网站模板为代理记账、财政咨询及财务会计类企业设计,基于PbootCMS内核开发。通过自适应手机端的HTML5技术,帮助企业高效构建专业财税服务平台查看源码
  • 自适应建材瓷砖卫浴大理石类pbootcms网站模板源码下载为建材瓷砖、卫浴瓷砖企业打造的高端响应式门户模板,基于PbootCMS内核深度开发。采用前沿HTML5自适应架构,无缝兼容手机端触控交互与PC端展示场景。查看源码
  • (自适应)餐饮小吃火锅加盟pbootcms模板源码下载本模板基于PbootCMS系统开发,为火锅餐饮、小吃加盟等餐饮企业打造。采用响应式设计,适配各类移动设备,帮助餐饮企业展示特色菜品、加盟政策和服务优势。查看源码
  • 自适应车行汽车租赁二手车行业企业网站模板为汽车租赁与二手车交易场景深度优化,采用PbootCMS内核开发,聚焦车辆展示、租赁流程与服务介绍三大核心模块。响应式布局确保PC与移动端数据实时同步,后台一键管理车辆信息查看源码
  • (自适应响应式)家电维修清晰服务网站pbootcms模板免费下载本模板基于PbootCMS内核开发,为维修服务类企业打造,特别适合家电维修、设备维护等行业使用。通过简洁直观的界面设计,帮助企业快速搭建专业级服务平台,实现线上业务高效管理。查看源码
  • (自适应手机端)英文外贸电子产品通用pbootcms模板源码下载为电子产品外贸企业设计的响应式网站模板,采用PbootCMS开发内核,支持多语言展示。模板默认集成产品展示系统、询价表单模块和企业资质展示区,满足跨境贸易基础需求。整站采用模块化设计,便于扩展业务场景。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐