ecshop 按订单金额发放红包 发放存在多发的问题

http://bbs.ecshop.com/viewthread.php?tid=159368

原始问题如上,截屏如下

ecshop_bonus

 

解决问题是看  includes\lib_order.php 的函数 get_total_bonus

原来代码是如下的

/* 按订单发的红包 */
$sql = “SELECT FLOOR(‘$amount’ / min_amount) * type_money ” .
“FROM ” . $GLOBALS[‘ecs’]->table(‘bonus_type’) .
” WHERE send_type = ‘” . SEND_BY_ORDER . “‘ ” .
” AND send_start_date <= ‘$today’ ” .
“AND send_end_date >= ‘$today’ ” .
“AND min_amount > 0 “;

很显然,凡是比较最低订单金额大的订单,都会导致商的个数的红包,我们其实只要发的是最大的红包那个就可以了,所以我们修改如下

/* 按订单发的红包 */
$sql = “SELECT FLOOR(‘$amount’ / min_amount) * type_money ” .
“FROM ” . $GLOBALS[‘ecs’]->table(‘bonus_type’) .
” WHERE send_type = ‘” . SEND_BY_ORDER . “‘ ” .
” AND send_start_date <= ‘$today’ ” .
“AND send_end_date >= ‘$today’ ” .
“AND min_amount > 0 and min_amount <= ‘$amount’ order by min_amount desc limit 1 “; 注意上面这行的条件增加了
and min_amount <= ‘$amount’ order by min_amount desc limit 1
就是说最接近订单额度的红包发放条件,取一个即可

ecshop 注册送红包

在user.php 的注册成功信息显示前面,大概是  show_message(sprintf($_LANG['register_success'].............前面加入
注意下下面的 $bonus_type_id = 1; 需要先在后台加入对应的红包的id

//phpsir 1111
$bonus_type_id=1;
$bonus = $db->getRow('SELECT * FROM ' . $ecs->table("bonus_type") . " WHERE send_type = 0 And type_id =  $bonus_type_id", true); 
if($bonus){ if(time()<($bonus['send_end_date']+28800)){
 $sql = "INSERT INTO " . $ecs->table('user_bonus') . "(bonus_type_id, bonus_sn, user_id, used_time, order_id, emailed) " . "VALUES ('$bonus[type_id]', 0, '$_SESSION[user_id]', 0, 0, 0)";
 $db->query($sql); } } 
//phpsir 1111_end