ecshop红包序列号可多次多人使用插件

插件功能介绍:1、一个卡号多人使用。2、每个注册会员只能使用一次。
当我们商品搞促销的时候,需要经常用到这个功能,下面的插件是从网上搜集,本公司亲测修改之中的错误后,完全可以使用。ecshop添加可多次使用的红包步骤如下:
1) 、打开 admin/templates/bonus_type_info.htm 文件,搜索如下代码
      <input type="radio" name="send_type" value="3" {if $bonus_arr.send_type eq 3} checked="true" {/if} onClick="showunit(3)"  />{$lang.send_by[3]}
再其后面添加
<input type="radio" name="send_type" value="4" {if $bonus_arr.send_type eq 4} checked="true" {/if} onClick="showunit(4)"  />通用红包 多次使用
2)、打开 admin/bonus.php 文件,搜索如下代码
    elseif ($_REQUEST['send_by'] == SEND_BY_PRINT)
    {
        $smarty->assign('type_list',    get_bonus_type());
        $smarty->display('bonus_by_print.htm');
    }
再其后添加
    elseif ($_REQUEST['send_by'] == 4)
    {
        $smarty->assign('type_list',    get_bonus_type_edait());
        $smarty->display('bonus_by_print_edait.htm');
    }
再搜索如下代码
if ($_REQUEST['act'] == 'send_by_print')
{
    @set_time_limit(0);
    /* 红下红包的类型ID和生成的数量的处理 */
    $bonus_typeid = !empty($_POST['bonus_type_id']) ? $_POST['bonus_type_id'] : 0;
    $bonus_sum    = !empty($_POST['bonus_sum'])     ? $_POST['bonus_sum']     : 1;
    /* 生成红包序列号 */
    $num = $db->getOne("SELECT MAX(bonus_sn) FROM ". $ecs->table('user_bonus'));
    $num = $num ? floor($num / 10000) : 100000;
    for ($i = 0, $j = 0; $i < $bonus_sum; $i++)
    {
        $bonus_sn = ($num + $i) . str_pad(mt_rand(0, 9999), 4, '0', STR_PAD_LEFT);
        $db->query("INSERT INTO ".$ecs->table('user_bonus')." (bonus_type_id, bonus_sn) VALUES('$bonus_typeid', '$bonus_sn')");
        $j++;
    }
    /* 记录管理员操作 */
    admin_log($bonus_sn, 'add', 'userbonus');
    /* 清除缓存 */
    clear_cache_files();
    /* 提示信息 */
    $link[0]['text'] = $_LANG['back_bonus_list'];
    $link[0]['href'] = 'bonus.php?act=bonus_list&bonus_type=' . $bonus_typeid;
    sys_msg($_LANG['creat_bonus'] . $j . $_LANG['creat_bonus_num'], 0, $link);
}
再其后添加
if ($_REQUEST['act'] == 'send_by_print_edait')
{
    @set_time_limit(0);
    /* 红下红包的类型ID和生成的数量的处理 */
    $bonus_typeid = !empty($_POST['bonus_type_id']) ? $_POST['bonus_type_id'] : 0;
    $bonus_sum    = !empty($_POST['bonus_sum'])     ? $_POST['bonus_sum']     : 1;
    /* 生成红包序列号 */
    for ($i = 0, $j = 0; $i < $bonus_sum; $i++)
    {
        $bonus_sn = $_POST['bonus_txt'];
        $db->query("INSERT INTO ".$ecs->table('user_bonus')." (bonus_type_id, bonus_sn) VALUES('$bonus_typeid', '$bonus_sn')");
        $j++;
    }
    /* 记录管理员操作 */
    admin_log($bonus_sn, 'add', 'userbonus');
    /* 清除缓存 */
    clear_cache_files();
    /* 提示信息 */
    $link[0]['text'] = $_LANG['back_bonus_list'];
    $link[0]['href'] = 'bonus.php?act=bonus_list&bonus_type=' . $bonus_typeid;
    sys_msg($_LANG['creat_bonus'] . $j . $_LANG['creat_bonus_num'], 0, $link);
}
再搜索如下代码
if ($_REQUEST['act'] == 'bonus_list')
{
    $smarty->assign('full_page',    1);
    $smarty->assign('ur_here',      $_LANG['bonus_list']);
    $smarty->assign('action_link',   array('href' => 'bonus.php?act=list', 'text' => $_LANG['04_bonustype_list']));
    $list = get_bonus_list();
    /* 赋值是否显示红包序列号 */
    $bonus_type = bonus_type_info(intval($_REQUEST['bonus_type']));
    if ($bonus_type['send_type'] == SEND_BY_PRINT)
    {
        $smarty->assign('show_bonus_sn', 1);
    }
    /* 赋值是否显示发邮件操作和是否发过邮件 */
    elseif ($bonus_type['send_type'] == SEND_BY_USER)
    {
        $smarty->assign('show_mail', 1);
    }
    $smarty->assign('bonus_list',   $list['item']);
    $smarty->assign('filter',       $list['filter']);
    $smarty->assign('record_count', $list['record_count']);
    $smarty->assign('page_count',   $list['page_count']);
    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);
    assign_query_info();
    $smarty->display('bonus_list.htm');
}
将以上代码修改为如下
if ($_REQUEST['act'] == 'bonus_list')
{
    $smarty->assign('full_page',    1);
    $smarty->assign('ur_here',      $_LANG['bonus_list']);
    $smarty->assign('action_link',   array('href' => 'bonus.php?act=list', 'text' => $_LANG['04_bonustype_list']));
    $list = get_bonus_list();
    /* 赋值是否显示红包序列号 */
    $bonus_type = bonus_type_info(intval($_REQUEST['bonus_type']));
    if ($bonus_type['send_type'] == SEND_BY_PRINT)
    {
        $smarty->assign('show_bonus_sn', 1);
    }
    /* 赋值是否显示发邮件操作和是否发过邮件 */
    elseif ($bonus_type['send_type'] == SEND_BY_USER)
    {
        $smarty->assign('show_mail', 1);
    }
    if ($bonus_type['send_type'] == 4)
    {
        $smarty->assign('show_bonus_sn', 1);
    }
    $smarty->assign('bonus_list',   $list['item']);
    $smarty->assign('filter',       $list['filter']);
    $smarty->assign('record_count', $list['record_count']);
    $smarty->assign('page_count',   $list['page_count']);
    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);
    assign_query_info();
    $smarty->display('bonus_list.htm');
}
再搜索如下代码
if ($_REQUEST['act'] == 'query_bonus')
{
    $list = get_bonus_list();
    /* 赋值是否显示红包序列号 */
    $bonus_type = bonus_type_info(intval($_REQUEST['bonus_type']));
    if ($bonus_type['send_type'] == SEND_BY_PRINT)
    {
        $smarty->assign('show_bonus_sn', 1);
    }
    /* 赋值是否显示发邮件操作和是否发过邮件 */
    elseif ($bonus_type['send_type'] == SEND_BY_USER)
    {
        $smarty->assign('show_mail', 1);
    }
    $smarty->assign('bonus_list',   $list['item']);
    $smarty->assign('filter',       $list['filter']);
    $smarty->assign('record_count', $list['record_count']);
    $smarty->assign('page_count',   $list['page_count']);
    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);
    make_json_result($smarty->fetch('bonus_list.htm'), '',
        array('filter' => $list['filter'], 'page_count' => $list['page_count']));
}
将以上代码修改为如下
if ($_REQUEST['act'] == 'query_bonus')
{
    $list = get_bonus_list();
    /* 赋值是否显示红包序列号 */
    $bonus_type = bonus_type_info(intval($_REQUEST['bonus_type']));
    if ($bonus_type['send_type'] == SEND_BY_PRINT)
    {
        $smarty->assign('show_bonus_sn', 1);
    }
    /* 赋值是否显示发邮件操作和是否发过邮件 */
    elseif ($bonus_type['send_type'] == SEND_BY_USER)
    {
        $smarty->assign('show_mail', 1);
    }
    if ($bonus_type['send_type'] == 4)
    {
        $smarty->assign('show_bonus_sn', 1);
    }
    $smarty->assign('bonus_list',   $list['item']);
    $smarty->assign('filter',       $list['filter']);
    $smarty->assign('record_count', $list['record_count']);
    $smarty->assign('page_count',   $list['page_count']);
    $sort_flag  = sort_flag($list['filter']);
    $smarty->assign($sort_flag['tag'], $sort_flag['img']);
    make_json_result($smarty->fetch('bonus_list.htm'), '',
        array('filter' => $list['filter'], 'page_count' => $list['page_count']));
}
3)、打开admin/includes/lib_main.php文件,最后面 ?> 上一行加入以下代码
function get_bonus_type_edait()
{
    $bonus = array();
    $sql = 'SELECT type_id, type_name, type_money FROM ' . $GLOBALS['ecs']->table('bonus_type') .
           ' WHERE send_type = 4';
    $res = $GLOBALS['db']->query($sql);
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $bonus[$row['type_id']] = $row['type_name'].' [' .sprintf($GLOBALS['_CFG']['currency_format'], $row['type_money']).']';
    }
    return $bonus;
}
4)、打开includes/lib_order.php文件,搜索如下代码
function bonus_info($bonus_id, $bonus_sn = '')
{
    $sql = "SELECT t.*, b.* " .
            "FROM " . $GLOBALS['ecs']->table('bonus_type') . " AS t," .
                $GLOBALS['ecs']->table('user_bonus') . " AS b " .
            "WHERE t.type_id = b.bonus_type_id ";
    if ($bonus_id > 0)
    {
        $sql .= "AND b.bonus_id = '$bonus_id'";
    }
    else
    {
        $sql .= "AND b.bonus_sn = '$bonus_sn'";
    }
    return $GLOBALS['db']->getRow($sql);
}
将以上代码修改为如下
function bonus_info($bonus_id, $bonus_sn = '') // 此函数为前台订单提交页面,验证红包
{
    $sql = "SELECT t.*, b.* " .
            "FROM " . $GLOBALS['ecs']->table('bonus_type') . " AS t," .
                $GLOBALS['ecs']->table('user_bonus') . " AS b " .
            "WHERE t.type_id = b.bonus_type_id    ";
    if ($bonus_id > 0)
    {
        $sql .= " AND b.bonus_id = '$bonus_id'";
        $row = $GLOBALS['db']->getRow($sql);
        return $row;
    }
    else
    {
        $sql .= " AND b.bonus_sn = '$bonus_sn'";
        $row = $GLOBALS['db']->getRow($sql);
    }
    // 如果想每人只使用N次,请用下面的部分
    if ($row['send_type'] == 4) // 如果是第4类型红包,那么就找一个未使用的红包,这种红包可被多次使用,不限制每人使用次数
    {
        $sess_userid = $_SESSION["user_id"];
        $sql = "SELECT t.*, b.* " .
                "FROM " . $GLOBALS['ecs']->table('bonus_type') . " AS t," .
                    $GLOBALS['ecs']->table('user_bonus') . " AS b " .
                "WHERE t.type_id = b.bonus_type_id  and b.user_id = '$sess_userid'   and  b.bonus_sn = '$bonus_sn' ";
        $rows = $GLOBALS['db']->getAll($sql);
        $allow_used_bonus_num = 2; // 最大允许使用次数
        if (count($rows) >= $allow_used_bonus_num )
        {
            return false;
        }
        else
        {
            $sql = "SELECT t.*, b.* " .
                    "FROM " . $GLOBALS['ecs']->table('bonus_type') . " AS t," .
                        $GLOBALS['ecs']->table('user_bonus') . " AS b " .
                    "WHERE t.type_id = b.bonus_type_id  and b.user_id = 0 and  b.bonus_sn = '$bonus_sn' ";
            $row = $GLOBALS['db']->getRow($sql);
            return $row;
        }
       
    }
    return $row;
}
6)、打开include/lib_transaction.php文件,搜索如下代码
function add_bonus($user_id, $bouns_sn)
{
    if (empty($user_id))
    {
        $GLOBALS['err']->add($GLOBALS['_LANG']['not_login']);
        return false;
    }
    /* 查询红包序列号是否已经存在 */
    $sql = "SELECT bonus_id, bonus_sn, user_id, bonus_type_id FROM " .$GLOBALS['ecs']->table('user_bonus') .
           " WHERE bonus_sn = '$bouns_sn'";
    $row = $GLOBALS['db']->getRow($sql);
    if ($row)
    {
        if ($row['user_id'] == 0)
        {
            //红包没有被使用
            $sql = "SELECT send_end_date, use_end_date ".
                   " FROM " . $GLOBALS['ecs']->table('bonus_type') .
                   " WHERE type_id = '" . $row['bonus_type_id'] . "'";
            $bonus_time = $GLOBALS['db']->getRow($sql);
            $now = gmtime();
            if ($now > $bonus_time['use_end_date'])
            {
                $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_use_expire']);
                return false;
            }
            $sql = "UPDATE " .$GLOBALS['ecs']->table('user_bonus') . " SET user_id = '$user_id' ".
                   "WHERE bonus_id = '$row[bonus_id]'";
            $result = $GLOBALS['db'] ->query($sql);
            if ($result)
            {
                 return true;
            }
            else
            {
                return $GLOBALS['db']->errorMsg();
            }
        }
        else
        {
            if ($row['user_id']== $user_id)
            {
                //红包已经添加过了。
                $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_is_used']);
            }
            else
            {
                //红包被其他人使用过了。
                $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_is_used_by_other']);
            }
            return false;
        }
    }
    else
    {
        //红包不存在
        $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_not_exist']);
        return false;
    }
}
将以上代码修改为如下
function add_bonus($user_id, $bouns_sn) //此函数为用户中心添加(绑定)红包函数
{
    if (empty($user_id))
    {
        $GLOBALS['err']->add($GLOBALS['_LANG']['not_login']);
        return false;
    }
    /* 查询红包序列号是否已经存在 */
    $sql = "SELECT bonus_id, bonus_sn, user_id, bonus_type_id FROM " .$GLOBALS['ecs']->table('user_bonus') .
           " WHERE bonus_sn = '$bouns_sn'";
    $row = $GLOBALS['db']->getRow($sql);
    if ($row)
    {
        if ($row['user_id'] == 0)
        {
            //红包没有被使用
            $sql = "SELECT send_end_date, use_end_date ".
                   " FROM " . $GLOBALS['ecs']->table('bonus_type') .
                   " WHERE type_id = '" . $row['bonus_type_id'] . "'";
            $bonus_time = $GLOBALS['db']->getRow($sql);
            $now = gmtime();
            if ($now > $bonus_time['use_end_date'])
            {
                $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_use_expire']);
                return false;
            }
            $sql = "UPDATE " .$GLOBALS['ecs']->table('user_bonus') . " SET user_id = '$user_id' ".
                   "WHERE bonus_id = '$row[bonus_id]'";
            $result = $GLOBALS['db'] ->query($sql);
            if ($result)
            {
                 return true;
            }
            else
            {
                return $GLOBALS['db']->errorMsg();
            }
        }
        else
        {
            if ($row['user_id']== $user_id)
            {
                //红包已经添加过了。
                $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_is_used']);
            }
            else
            {
                //红包被其他人使用过了。
                $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_is_used_by_other']);
            }
            return false;
        }
    }
    else
    {
        //红包不存在
        $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_not_exist']);
        return false;
    }
}
7)、打开user.php文件,最后面 ?> 上一行加入以下代码
function add_bonus($user_id, $bouns_sn)
{
    if (empty($user_id))
    {
        $GLOBALS['err']->add($GLOBALS['_LANG']['not_login']);
        return false;
    }
    /* 查询红包序列号是否已经存在 */
    $sql = "SELECT bonus_id, bonus_sn, user_id, bonus_type_id FROM " .$GLOBALS['ecs']->table('user_bonus') .
         " WHERE bonus_sn = '$bouns_sn'";
    $row = $GLOBALS['db']->getRow($sql);
	//var_dump($row);
    if ($row)
    {
		 if($row['send_type'] == 4) // 如果是第4类型红包,那么就找一个未使用的红包,这种红包可被多次使用,不限制每人使用次数
		{
   		      $sql = "SELECT t.*, b.* " .
					"FROM " . $GLOBALS['ecs']->table('bonus_type') . " AS t," .
						$GLOBALS['ecs']->table('user_bonus') . " AS b " .
					"WHERE t.type_id = b.bonus_type_id     and user_id  = '$user_id' ";
			if ($bonus_id > 0)
			{
				$sql .= "AND b.bonus_id = '$bonus_id'";
			}
			else
			{
				$sql .= "AND b.bonus_sn = '$bouns_sn'";
			}
			//echo $sql; 
			$row = $GLOBALS['db']->getRow($sql);       
			//var_dump($row);
			  // 此处是限制某用户只能使用一次此红包 仅仅在用户没有使用过的情况下,进入下面的语句中,分发一个未用红包。
			if(!$row){
                           
				$sql = "SELECT t.*, b.* " .
				"FROM " . $GLOBALS['ecs']->table('bonus_type') . " AS t," .
				$GLOBALS['ecs']->table('user_bonus') . " AS b " .
				"WHERE t.type_id = b.bonus_type_id  and b.used_time = 0   and user_id  = 0   ";
				if ($bonus_id > 0)
				{
				$sql .= "AND b.bonus_id = '$bonus_id'";
				}
				else
				{
				$sql .= "AND b.bonus_sn = '$bouns_sn'";
				}
				//echo $sql; 
				$row = $GLOBALS['db']->getRow($sql);       
				//var_dump($row);
			}
		}
        if ($row['user_id'] == 0)
        {
            //红包没有被使用
            $sql = "SELECT send_end_date, use_end_date ".
                   " FROM " . $GLOBALS['ecs']->table('bonus_type') .
                   " WHERE type_id = '" . $row['bonus_type_id'] . "'";
            $bonus_time = $GLOBALS['db']->getRow($sql);
            $now = gmtime();
            if ($now > $bonus_time['use_end_date'])
            {
                $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_use_expire']);
                return false;
            }
            $sql = "UPDATE " .$GLOBALS['ecs']->table('user_bonus') . " SET user_id = '$user_id' ".
                   "WHERE bonus_id = '$row[bonus_id]'";
            $result = $GLOBALS['db'] ->query($sql);
            if ($result)
            {
                 return true;
            }
            else
            {
                return $GLOBALS['db']->errorMsg();
            }
        }
        else
        {
            if ($row['user_id']== $user_id)
            {
                //红包已经添加过了。
                $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_is_used']);
            }
            else
            {
                //红包被其他人使用过了。
                $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_is_used_by_other']);
            }
            return false;
        }
    }
    else
    {
        //红包不存在
        $GLOBALS['err']->add($GLOBALS['_LANG']['bonus_not_exist']);
        return false;
    }
}
8)、新增加 admin/templates/bonus_by_print_edait.htm 文件,代码如下
<!-- $Id: bonus_by_print.htm 14216 2008-03-10 02:27:21Z testyang $ -->
{include file="pageheader.htm"}
<div class="main-div">
<form action="bonus.php" method="post" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table width="100%">
  <tr>
    <td class="label">{$lang.bonus_type_id}</td>
    <td>
    <select name="bonus_type_id">
      {html_options options=$type_list selected=$smarty.get.id}
    </select>
    </td>
  </tr>
   <tr>
      <td class="label">{$lang.send_bonus_count}</td>
      <td>
      <input type="text" name="bonus_sum" size="30" maxlength="6" />
      </td>
    </tr>
   <tr>
      <td class="label">红包字符串</td>
      <td>
      <input type="text" name="bonus_txt" size="30" maxlength="10" />
      10位数 如:1000100001</td>
    </tr>
    <td class="label">&nbsp;</td>
    <td></td>
   </tr>
   <tr>
   <td class="label">&nbsp;</td>
   <td>
    <input type="submit" value="{$lang.button_submit}" class="button" />
    <input type="reset" value="{$lang.button_reset}" class="button" />
  </td>
 </tr>
</table>
<input type="hidden" name="act" value="send_by_print_edait" />
</form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="JavaScript"> 
<!--
document.forms['theForm'].elements['bonus_sum'].focus();
/**
 * 检查表单输入的数据
 */
function validate()
{
    validator = new Validator("theForm");
    validator.required("bonus_type_id",   bonus_type_empty);
    validator.required("bonus_sum",   bonus_sum_empty);
    validator.isNumber("bonus_sum",   bonus_sum_number, true);
    return validator.passed();
}
 
onload = function()
{
    // 开始检查订单
    startCheckOrder();
}
//-->
</script>
{/literal}
{include file="pagefooter.htm"}

本文原创地址:https://www.ecshop.cx/article-308.html
版权所有 © 转载时必须以链接形式注明出处!

觉得本文对您有用,想收藏下来!方法很简单:请点击-〉
我们一直坚持白天工作、晚上熬夜更新资源,付出了巨大的精力和时间,其中的辛酸难以言述。

实时购买动态 ×

匿名网友 在 2019-10-26 购买了 ecshop商品详情页一键购买,快速购买,直接购买功能,闪电下单

';