Example #1
0
 foreach ($delivery_stock_result as $value) {
     $goods_attr_id = get_goods_attr_id($value['goods_id'], $value['goods_attr']);
     $store_row = get_storeid_youhuo($order['province'], $order['city'], $order['district'], $order['xiangcun'], $value['goods_id'], $goods_attr_id, $order['supplier_id'], $order_id);
     if (!$store_row['store_id'] or $store_row['store_number'] < $value['sums']) {
         $store_error = '有个别货物对应仓库库存不够,无法完成此次发货操作!请稍候重新发货!';
         break;
     }
 }
 if ($store_error) {
     sys_msg($store_error);
 } else {
     $add_time = gmtime();
     $add_date = local_date('Ymd');
     foreach ($delivery_stock_result as $value) {
         $goods_attr_id = get_goods_attr_id($value['goods_id'], $value['goods_attr']);
         $store_row = get_storeid_youhuo($order['province'], $order['city'], $order['district'], $order['xiangcun'], $value['goods_id'], $goods_attr_id, $order['supplier_id'], $order_id);
         $sql = "select max(today_sn) from " . $ecs->table('store_inout_list') . " where inout_mode=1 and  add_date='{$add_date}' ";
         $inout_count = $db->getOne($sql);
         $inout_sn = $inout_count ? intval($inout_count + 1) : 1;
         $today_sn = $inout_sn;
         $inout_sn = str_pad($inout_sn, 4, "0", STR_PAD_LEFT);
         $inout_sn = 'ck' . $add_date . $inout_sn;
         $stock_type_id = 0;
         //默认为自营仓库
         if ($order['supplier_id'] > 0) {
             $stock_type_id = $db->getOne('select type from ' . $ecs->table('store_type') . " where supplier_id=" . $order['supplier_id']);
         }
         $sql = "insert into " . $ecs->table('store_inout_list') . "(inout_sn, inout_status, store_id, adminer_id, inout_type, inout_mode, order_sn, " . "takegoods_man, today_sn, add_date, add_time, supplier_id, store_type_id)  " . "values('{$inout_sn}', '3', '{$store_row['store_id']}', '{$_SESSION['admin_id']}', '1', '1', '{$order['order_sn']}', " . "'{$_SESSION['admin_name']}', '{$today_sn}' , '{$add_date}', '{$add_time}','{$order['supplier_id']}','{$stock_type_id}' ) ";
         $db->query($sql);
         $inout_rec_id = $db->insert_id();
         $sql = "insert into " . $ecs->table('store_inout_goods') . "(inout_rec_id, goods_id, goods_sn, attr_value, inout_mode, number_yingshou, number_shishou, supplier_id, store_type_id)  " . "values('{$inout_rec_id}', '{$value['goods_id']}', '{$value['goods_sn']}', '{$goods_attr_id}', '1', '{$value['sums']}', '{$value['sums']}','{$order['supplier_id']}','{$stock_type_id}') ";
Example #2
0
/**
 * 改变商品库存减
 */
function change_morestorck_morecity_stock_jian($order_id)
{
    global $ecs, $db;
    $sql = "select o.order_id, o.order_sn, o.country, o.province, o.city, o.district, o.xiangcun, o.supplier_id, og.rec_id, og.goods_id, og.goods_name, og.goods_sn, og.goods_number, og.goods_attr_id from  " . $ecs->table('order_goods') . " AS og " . " left join " . $ecs->table('order_info') . " AS o on og.order_id=o.order_id where og.order_id='{$order_id}' ";
    $ret = $db->query($sql);
    if ($ret) {
        $userName = $_SESSION['user_name'] . '(' . $_SESSION['user_id'] . ')';
        while ($order_row = $db->fetchRow($ret)) {
            $rec_id = $order_row['rec_id'];
            $send_store_number = $order_row['goods_number'];
            $goods_attr = str_replace(",", "|", $order_row['goods_attr_id']);
            $store_row = get_storeid_youhuo($order_row['province'], $order_row['city'], $order_row['district'], $order_row['xiangcun'], $order_row['goods_id'], $goods_attr, $order_row['supplier_id']);
            if (!$store_row['store_id'] or $store_row['store_number'] < $send_store_number) {
                return '对不起!商品[' . $order_row['goods_name'] . ']没有对应仓库或者对应仓库库存不够!';
            } else {
                $stock_type_id = 0;
                //默认为自营仓库
                if ($order_row['supplier_id'] > 0) {
                    $stock_type_id = $db->getOne('select type from ' . $ecs->table('store_type') . " where supplier_id=" . $order_row[supplier_id]);
                }
                $admin_id = $db->getOne("select admin_id from " . $ecs->table('store_adminer') . " where store_id=" . $store_row['store_id'] . " limit 1");
                $add_time = gmtime();
                $add_date = local_date('Ymd');
                $sql = "select max(today_sn) from " . $ecs->table('store_inout_list') . " where inout_mode=1 and  add_date='{$add_date}' ";
                $inout_count = $db->getOne($sql);
                $inout_sn = $inout_count ? intval($inout_count + 1) : 1;
                $today_sn = $inout_sn;
                $inout_sn = str_pad($inout_sn, 4, "0", STR_PAD_LEFT);
                $inout_sn = 'ck' . $add_date . $inout_sn;
                $sql = "insert into " . $ecs->table('store_inout_list') . "(inout_sn, inout_status, store_id, adminer_id, inout_type, inout_mode, order_sn, " . "takegoods_man, today_sn, add_date, add_time, supplier_id, store_type_id)  " . "values('{$inout_sn}', '3', '{$store_row['store_id']}', '{$admin_id}', '2', '1', '{$order_row['order_sn']}', " . "'{$userName}', '{$today_sn}' , '{$add_date}', '{$add_time}', '{$order_row['supplier_id']}', '{$stock_type_id}' ) ";
                $db->query($sql);
                $inout_rec_id = $db->insert_id();
                $sql = "insert into " . $ecs->table('store_inout_goods') . "(inout_rec_id, goods_id, goods_sn, attr_value, inout_mode, number_yingshou, number_shishou, supplier_id, store_type_id)  " . "values('{$inout_rec_id}', '{$order_row['goods_id']}', '{$order_row['goods_sn']}', '{$goods_attr}', '1', '{$send_store_number}', '{$send_store_number}', '{$order_row['supplier_id']}', '{$stock_type_id}') ";
                $db->query($sql);
                $upre = order_update_stock_out($inout_rec_id, $store_row['store_id']);
                //更新库存表
                if ($upre['error']) {
                    //sys_msg($upre['error_item']);
                }
                $sql = "update " . $ecs->table('order_goods') . " set send_store_number='{$send_store_number}', send_store_id='{$store_row['store_id']}' where rec_id='{$rec_id}' ";
                $db->query($sql);
                //$links[] = array('text' => $_LANG['order_info'], 'href' => 'order.php?act=info&order_id=' . $order_row['order_id']);
                //sys_msg('恭喜 成功出库', 1, $links);
            }
        }
        return true;
    } else {
        return '异常错误,请返回,重新提交!';
    }
}
Example #3
0
function cancel_delivery($order_id, $delivery_id)
{
    global $db, $ecs, $_CFG;
    /* 取得参数 */
    $delivery = '';
    /* 根据发货单id查询发货单信息 */
    if (!empty($delivery_id)) {
        $delivery_order = delivery_order_info($delivery_id);
    } else {
        sys_msg('订单号不能为空!', 1);
    }
    /* 查询订单信息 */
    $order = order_info($order_id);
    /* 取消当前发货单物流单号 */
    $_delivery['invoice_no'] = '';
    $_delivery['status'] = 2;
    $query = $db->autoExecute($ecs->table('delivery_order'), $_delivery, 'UPDATE', "delivery_id = {$delivery_id}", 'SILENT');
    if (!$query) {
        /* 操作失败 */
        $links[] = array('text' => $GLOBALS['_LANG']['delivery_sn'] . $GLOBALS['_LANG']['detail'], 'href' => 'order.php?act=delivery_info&delivery_id=' . $delivery_id);
        sys_msg($GLOBALS['_LANG']['act_false'], 1, $links);
        exit;
    }
    /* 修改定单发货单号 */
    $invoice_no_order = explode('<br>', $order['invoice_no']);
    $invoice_no_delivery = explode('<br>', $delivery_order['invoice_no']);
    foreach ($invoice_no_order as $key => $value) {
        $delivery_key = array_search($value, $invoice_no_delivery);
        if ($delivery_key !== false) {
            unset($invoice_no_order[$key], $invoice_no_delivery[$delivery_key]);
            if (count($invoice_no_delivery) == 0) {
                break;
            }
        }
    }
    $_order['invoice_no'] = implode('<br>', $invoice_no_order);
    /* 更新配送状态 */
    $order_finish = get_all_delivery_finish($order_id);
    $shipping_status = $order_finish == -1 ? SS_SHIPPED_PART : SS_SHIPPED_ING;
    $arr['shipping_status'] = $shipping_status;
    if ($shipping_status == SS_SHIPPED_ING) {
        $arr['shipping_time'] = '';
        // 发货时间
    }
    $arr['invoice_no'] = $_order['invoice_no'];
    update_order($order_id, $arr);
    /* 发货单取消发货记录log */
    order_action($order['order_sn'], $order['order_status'], $shipping_status, $order['pay_status'], $action_note, null, 1);
    /* 如果使用库存,则增加库存 */
    /* 代码增加_start   By  morestock_morecity  */
    if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_SHIP) {
        $delivery_stock_sql = "SELECT * FROM " . $GLOBALS['ecs']->table('delivery_goods') . " WHERE delivery_id = '{$delivery_id}' ";
        $delivery_stock_result = $GLOBALS['db']->getAll($delivery_stock_sql);
        $store_error = '';
        //$goods_attr_id = get_goods_attr_id($value['goods_id'], $value['goods_attr']);
        $store_id_zhyh = get_storeid_by_ssq($order['province'], $order['city'], $order['district'], $order['xiangcun'], $order['supplier_id']);
        if (!$store_id_zhyh) {
            $store_error = '该发货单没有对应仓库!';
        }
        if ($store_error) {
            sys_msg($store_error);
        } else {
            foreach ($delivery_stock_result as $key => $value) {
                $goods_attr_id = get_goods_attr_id($value['goods_id'], $value['goods_attr']);
                $store_row = get_storeid_youhuo($order['province'], $order['city'], $order['district'], $order['xiangcun'], $value['goods_id'], $goods_attr_id, $order['supplier_id'], $order_id);
                $add_time = gmtime();
                $add_date = local_date('Ymd');
                $sql = "select max(today_sn) from " . $ecs->table('store_inout_list') . " where inout_mode=2 and  add_date='{$add_date}' ";
                $inout_count = $db->getOne($sql);
                $inout_sn = $inout_count ? intval($inout_count + 1) : 1;
                $today_sn = $inout_sn;
                $inout_sn = str_pad($inout_sn, 4, "0", STR_PAD_LEFT);
                $inout_sn = 'rk' . $add_date . $inout_sn;
                $stock_type_id = 0;
                if ($order['supplier_id'] > 0) {
                    $stock_type_id = $db->getOne('select type from ' . $ecs->table('store_type') . " where supplier_id=" . $order['supplier_id']);
                }
                $sql = "insert into " . $ecs->table('store_inout_list') . "(inout_sn, inout_status, store_id, adminer_id, inout_type, inout_mode, order_sn, " . "takegoods_man, today_sn, add_date, add_time, supplier_id, store_type_id)  " . "values('{$inout_sn}', '3', '{$store_row['store_id']}', '{$_SESSION['supplier_user_id']}', '5', '2', '{$order['order_sn']}', " . "'{$_SESSION['supplier_name']}', '{$today_sn}' , '{$add_date}', '{$add_time}','{$order['supplier_id']}', '{$stock_type_id}' ) ";
                $db->query($sql);
                $inout_rec_id = $db->insert_id();
                $sql = "insert into " . $ecs->table('store_inout_goods') . "(inout_rec_id, goods_id, goods_sn, attr_value, inout_mode, number_yingshou, number_shishou, supplier_id, store_type_id)  " . "values('{$inout_rec_id}', '{$value['goods_id']}', '{$value['goods_sn']}', '{$goods_attr_id}', '2', '{$value['send_number']}', '{$value['send_number']}','{$order['supplier_id']}', '{$stock_type_id}') ";
                $db->query($sql);
                $upre = update_stock_in($inout_rec_id, $store_row['store_id']);
                //更新库存表
            }
        }
    }
    /* 代码增加_end   By  morestock_morecity  */
    /* 发货单全退回时,退回其它 */
    if ($order['order_status'] == SS_SHIPPED_ING) {
        /* 如果订单用户不为空,计算积分,并退回 */
        if ($order['user_id'] > 0) {
            /* 取得用户信息 */
            $user = user_info($order['user_id']);
            /* 计算并退回积分 */
            $integral = integral_to_give($order);
            log_account_change($order['user_id'], 0, 0, -1 * intval($integral['rank_points']), -1 * intval($integral['custom_points']), sprintf($GLOBALS['_LANG']['return_order_gift_integral'], $order['order_sn']));
            /* todo 计算并退回红包 */
            return_order_bonus($order_id);
        }
    }
    /* 清除缓存 */
    clear_cache_files();
    /* 操作成功 */
    $links[] = array('text' => $GLOBALS['_LANG']['delivery_sn'] . $GLOBALS['_LANG']['detail'], 'href' => 'order.php?act=delivery_info&delivery_id=' . $delivery_id);
    sys_msg($GLOBALS['_LANG']['act_ok'], 0, $links);
}