bhq@iemsoft.cn
2018-11-27 e2b48dac099e43f4b3243cdf19a7522e4b5eccbe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH . 'includes/lib_order.php');
require_once(ROOT_PATH . 'includes/lib_supplier_common_wap.php');
$act = empty($_REQUEST['act'])?'list':trim($_REQUEST['act']);
//库存查询
if($act == 'list')
{
    $data = goods_stock();
    $goods = $data['goods'];
    $filter = $data['filter'];
    $smarty->assign('goods',$goods);
    $smarty->assign('filter',$filter);
    _wap_assign_header_info('库存列表');
    _wap_assign_footer_order_info();
    _wap_display_page('goods_stock_list.htm');
}
 
//获取商品库存列表
function goods_stock()
{
    global $ecs,$db;
    $result = get_filter($param_str);
    if($result === false)
    {
        $filter['goods_name'] = empty($_REQUEST['goods_name'])?'':trim($_REQUEST['goods_name']);
        $filter['goods_sn'] = empty($_REQUEST['goods_sn'])?'':trim($_REQUEST['goods_sn']);
        $where = ' WHERE supplier_id='.$_SESSION['supplier_id'];
        if(!empty($filter['goods_name']))
        {
            $where .= ' AND goods_name LIKE "%'.$filter['goods_name'].'%" ';
        }
        if(!empty($filter['goods_sn']))
        {
            $where .= ' AND goods_sn LIKE "%'.$filter['goods_sn'].'%" ';
        }
        $sql = 'SELECT COUNT(*) FROM '.$ecs->table('goods').$where;
        $filter['record_count'] = $db->getOne($sql);
 
        $filter['page'] = empty($_REQUEST['page']) || (intval($_REQUEST['page']) <= 0) ? 1 : intval($_REQUEST['page']);
 
        if (isset($_REQUEST['page_size']) && intval($_REQUEST['page_size']) > 0)
        {
            $filter['page_size'] = intval($_REQUEST['page_size']);
        }
        elseif (isset($_COOKIE['ECSCP']['page_size']) && intval($_COOKIE['ECSCP']['page_size']) > 0)
        {
            $filter['page_size'] = intval($_COOKIE['ECSCP']['page_size']);
        }
        else
        {
            $filter['page_size'] = 15;
        }
        $filter = page_and_size($filter);
        $limit = ' LIMIT '. $filter['start'] .',' . $filter['page_size'];
        $sql = 'SELECT goods_id,goods_sn,goods_name,goods_number FROM '.$ecs->table('goods').$where.$limit;
        set_filter($filter, $sql);
    }
    else
    {
        $sql    = $result['sql'];
        $filter = $result['filter'];
    }
 
    $goods = $db->getAll($sql);
 
    foreach($goods as $goods_key => $goods_val)
    {
        $sql = 'SELECT goods_attr AS goods_attr_id,product_number FROM '.$ecs->table('products').' WHERE goods_id='.$goods_val['goods_id'];
        $attr = $db->getAll($sql);
        foreach($attr as $attr_key => $attr_val)
        {
            $goods_attr_arr = explode('|',$attr_val['goods_attr_id']);
            $attr_sql = implode(' OR goods_attr_id= ',$goods_attr_arr);
            $sql = 'SELECT attr_value FROM '.$ecs->table('goods_attr').' WHERE goods_attr_id='.$attr_sql;
            $attr_name_arr = $db->getAll($sql);
            $attr_name = '';
            foreach( $attr_name_arr as $name_key=>$name_val)
            {
                $attr_name .= implode(' ',$name_val);
            }
            $attr_val['goods_attr_name'] = $attr_name;
            $attr[$attr_key] = $attr_val;
        }
        $goods_val['goods_attr'] = $attr;
        $goods[$goods_key] = $goods_val;
    }
    $arr = array('goods' => $goods, 'filter' => $filter);
    return $arr;
}