实现ecshop支付时减库存个功能

2016-09-07 22:02 来源:www.chinab4c.com 作者:ecshop专家

ecshop后台减少库存的时机默认只有下订单时和发货时,不能满足各种客户需求啊,要增加一个商家付款后就能减少库存,先解决方法如下

1. includes/inc_constant.php 文件 大约207行 加上

    
define('SDT_PAY',                   2); // 支付时减少库

languages/zh-cn/admin/shop_config.php 文件 大约338行加上

    
$_LANG['cfg_range']['stock_dec_time']['2'] = '商家付款后';

给 数据表 ship_config 中 id 为 423 的行 store_range 增加 2
2. includes/lib_order.php 文件 大约2207行 增加如下代码

    
case 2 :
            $sql = "SELECT goods_id, SUM(goods_number) AS num, MAX(extension_code) AS extension_code, product_id FROM " . $GLOBALS['ecs']->table('order_goods') .
                    " WHERE order_id = '$order_id' AND is_real = 1 GROUP BY goods_id, product_id";
        break;

includes/lib_payment.php 文件

    
/* 修改订单状态为已付款 */
                $sql = 'UPDATE ' . $GLOBALS['ecs']->table('order_info') .
                            " SET order_status = '" . OS_CONFIRMED . "', " .
                                " confirm_time = '" . gmtime() . "', " .
                                " pay_status = '$pay_status', " .
                                " pay_time = '".gmtime()."', " .
                                " money_paid = order_amount," .
                                " order_amount = 0 ".
                       "WHERE order_id = '$order_id'";
                $GLOBALS['db']->query($sql);
//在这段之后增加
include_once(ROOT_PATH . 'includes/lib_order.php');
/* 如果使用库存,且付款时减库存,则减少库存 by sid*/
if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PAY){
      change_order_goods_storage($order['order_id'], true, SDT_PAY);
}

3. admin/order.php 文件

    
/* 如果使用库存,且下订单时减库存,则增加库存 */
                if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE)
                {
                    change_order_goods_storage($order_id, false, SDT_PLACE);
                }
//在这段之后增加
//无效与取消时加库存
if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PAY){
    change_order_goods_storage($order_id, false, SDT_PAY);
}

4. flow.php 文件

 

    
/* 如果订单金额为0 处理虚拟卡 */
    if ($order['order_amount'] <= 0)
    {
//在这段之后加上
//扣库存
if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PAY){
      change_order_goods_storage($order['order_id'], true, SDT_PAY);
}

admin/order.php 文件

    
$payment = payment_info($order['pay_id']);
        if ($payment['is_cod'])
        {
            $arr['shipping_status'] = SS_RECEIVED;
            $order['shipping_status'] = SS_RECEIVED;
        }
        update_order($order_id, $arr);
//在这段之后增加
//扣库存
if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PAY){
      change_order_goods_storage($order['order_id'], true, SDT_PAY);
}

    
/* 如果使用库存,且下订单时减库存,则增加库存 */
        if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE)
        {
            change_order_goods_storage($order_id, false, SDT_PLACE);
        }
//在这段之后增加
if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PAY)
        {
             change_order_goods_storage($order_id, false, SDT_PAY);
        }

继续往下

    
/* 如果使用库存,且下订单时减库存,则增加库存 */
        if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE)
        {
            change_order_goods_storage($order_id, false, SDT_PLACE);
        }
//在这段之后增加
if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PAY)
        {
             change_order_goods_storage($order_id, false, SDT_PAY);
        }

如此,一个完整的ecshop商家付款后减少库存的功能就实现了!!

bug:这个教程是有bug的,当你下订单后先不要支付,然后返回用户中心切换支付方式或者使用余额支付,库存不减

(责任编辑:chinab4c)