定型管 電子鈑金
返回列表 回復 發帖

帖子標題:[分享] ecshop 添加可多次使用的紅包步驟

1) 添加一種新的紅包類型4 ,
文件 admin/templates/bonus_type_info.htm 找到
  <input type="radio" name="send_type" value="0" {if $bonus_arr.send_type eq 0} checked="true" {/if} onClick="showunit(0)"  />{$lang.send_by[0]}
      <input type="radio" name="send_type" value="1" {if $bonus_arr.send_type eq 1} checked="true" {/if} onClick="showunit(1)"  />{$lang.send_by[1]}
      <input type="radio" name="send_type" value="2" {if $bonus_arr.send_type eq 2} checked="true" {/if} onClick="showunit(2)"  />{$lang.send_by[2]}
      <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/templates/bonus_by_print_phpsir.htm
修改文件 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_phpsir());
$smarty->display('bonus_by_print_phpsir.htm');
    }
3) 增加 get_bonus_type_phpsir 函數
文件 admin/includes/lib_main.php
function get_bonus_type_phpsir()
{
    $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) 在 bonus.php 裏面找到
if ($_REQUEST['act'] == 'send_by_print')
{
...........................
}
在其後面添加,處理增加這類紅包時候生成方法
if ($_REQUEST['act'] == 'send_by_print_phpsir')
{
    @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);
}
5) 修改 bonus.php 讓後臺顯示紅包內容
if ($_REQUEST['act'] == 'bonus_list')
{
...........................
}

if ($_REQUEST['act'] == 'query_bonus')
{
...........................
}
在裏面增加
if ($bonus_type['send_type'] == 4)
    {
        $smarty->assign('show_bonus_sn', 1);
}
至此 後臺部分完成。
前臺部分 修改
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'";
        $row = $GLOBALS['db']->getRow($sql);
        return $row;
    }
    else
    {
        $sql .= " AND b.bonus_sn = '$bonus_sn'";
        $row = $GLOBALS['db']->getRow($sql);
    }
if($row['send_type'] == 4) // phpsir 如果是第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.used_time = 0  ";
        if ($bonus_id > 0)
        {
            $sql .= "AND b.bonus_id = '$bonus_id'";
        }
        else
        {
            $sql .= "AND b.bonus_sn = '$bonus_sn'";
        }
//print $sql;
$row = $GLOBALS['db']->getRow($sql);
        //var_dump($row);
        return $row;
}

// 如果想每人只使用N次,請用下面的部分
/*
if($row['send_type'] == 4) // phpsir 如果是第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.used_time = 0   and  b.bonus_sn = '$bonus_sn' ";
            $row = $GLOBALS['db']->getRow($sql);
            return $row;
        }
}
*/
return $row;
}
註意:修改PHP文件時候不要用記事本打開,否則文件編碼會出問題導致網站報錯,建議用專業的dreamweaver來修改。


ecshop模板
网站模板
提醒您: 您在"ECSHOP 交流討論區"交流請遵守台灣法律規範,"最模板" 發表的文章《ecshop 添加可多次使用的紅包步驟》版權歸屬作者所有,如是轉貼版權歸屬原作者所有.本論壇不對其真實性做任何考證.
我正在找一個指定序號,但是多人可領用的紅包,每人使用一次。
用這個方法來試試看。

感謝樓主分享
提醒您: 您在"ECSHOP 交流討論區"交流請遵守台灣法律規範,"nelsonisso" 發表的文章《》版權歸屬作者所有,如是轉貼版權歸屬原作者所有.本論壇不對其真實性做任何考證.
返回列表