commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
/** |
|
3 |
* 扫码获取商品相关数据 |
|
4 |
*/ |
|
5 |
|
|
6 |
define('IN_ECS', true); |
|
7 |
|
|
8 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
9 |
require(dirname(__FILE__) . '/includes/lib_order.php'); |
|
10 |
|
|
11 |
$act = (isset($_REQUEST['act']) && !empty($_REQUEST['act'])) ? trim($_REQUEST['act']) : ''; |
|
12 |
assign_template(); |
|
13 |
if($act == 'view'){ |
|
14 |
$info = array(); |
|
15 |
foreach($_POST['data'] as $key=>$val){ |
|
16 |
$info[$key] = explode("\n",$val); |
|
17 |
$info[$key] = array_filter($info[$key],'back_filter'); |
|
18 |
} |
|
19 |
$info = array_filter($info); |
|
20 |
$find = ',';//条形码和数量之间的分隔号 |
|
21 |
$num = 1;//商品默认的数量 |
|
22 |
$data = array(); |
|
23 |
foreach($info as $key=>$val){ |
|
24 |
foreach($val as $k=>$v){ |
|
25 |
$pos = strpos($v,$find);//扫描过来的条形码是否带有数量属性 |
|
26 |
if($pos === false){ |
|
27 |
$v = trim($v); |
|
28 |
$data[$v] += $num; |
|
29 |
}else{ |
|
30 |
$vinfo = explode(',',$v); |
|
31 |
$gnum = ($vinfo[1]>0) ? $vinfo[1] : $num; |
|
32 |
$data[$vinfo[0]] += $gnum; |
|
33 |
} |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 |
if(empty($data)){ |
|
38 |
show_message("请先扫码!"); |
|
39 |
} |
|
40 |
//判断条形码中是否有字母 |
|
41 |
foreach($data as $key=>$val) |
|
42 |
{ |
|
43 |
if(!is_numeric($key)) |
|
44 |
{ |
|
45 |
show_message("您输入的条形码不正确!"); |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
$ginfo = get_goods_by_txm(array_keys($data)); |
|
51 |
$sao_data = array(); |
|
52 |
foreach($ginfo as $key=>&$val){ |
|
53 |
$val['market_price'] = price_format($val['market_price']); |
|
54 |
$val['goods_price'] = price_format($val['goods_price']); |
|
55 |
$val['goods_attr_price'] = price_format($val['goods_attr_price']); |
|
56 |
$val['goods_thumb'] = get_image_path($val['goods_id'], $val['goods_thumb'], true); |
|
57 |
$val['goods_img'] = get_image_path($val['goods_id'], $val['goods_img']); |
|
58 |
$val['url'] = build_uri('goods', array('gid'=>$val['goods_id']), $val['goods_name']); |
|
59 |
$val['buy_number'] = $data[$key]; |
|
60 |
$sao_data[$key]=$key.','.$data[$key]; |
|
61 |
} |
|
62 |
$_SESSION['saodata'] = $sao_data; |
|
63 |
$smarty->assign('page_title', '智能扫货商品展示'); // 页面标题 |
|
64 |
$smarty->assign('goodsinfo',$ginfo); |
|
65 |
$smarty->display('scan_list.dwt'); |
|
66 |
} |
|
67 |
elseif($act == 'del'){ |
|
68 |
$result = array('error'=>0,'info'=>''); |
|
69 |
$txm = (isset($_POST['txm']) && !empty($_POST['txm'])) ? trim($_POST['txm']) : ''; |
|
70 |
if($txm == ''){ |
|
71 |
$result['error'] = 1; |
|
72 |
$result['info'] = '非法操作'; |
|
73 |
die(json_encode($result)); |
|
74 |
} |
|
75 |
if(isset($_SESSION['saodata']) && !empty($_SESSION['saodata'])){ |
|
76 |
unset($_SESSION['saodata'][$txm]); |
|
77 |
die(json_encode($result)); |
|
78 |
}else{ |
|
79 |
$result['error'] = 1; |
|
80 |
$result['info'] = '请返回扫描页面,重新扫描'; |
|
81 |
die(json_encode($result)); |
|
82 |
} |
|
83 |
} |
|
84 |
elseif($act == 'addcart'){ |
|
85 |
include_once('includes/cls_json.php'); |
|
86 |
$result = array('error'=>0,'content'=>''); |
|
87 |
$json = new JSON; |
|
88 |
$info = array(1=>'商品不存在',2=>'商品缺货',3=>'商品已下架',4=>'商品不能单独销售',5=>'商品没有基本件',6=>'商品需要用户选择属性'); |
|
89 |
if(isset($_SESSION['saodata']) && !empty($_SESSION['saodata'])){ |
|
90 |
$ginfo = get_goods_by_txm(array_keys($_SESSION['saodata'])); |
|
91 |
$ok = $fail = array(); |
|
92 |
foreach($ginfo as $key=>$val){ |
|
93 |
$txminfo = explode(',',$_SESSION['saodata'][$key]); |
|
94 |
$buynumber = $txminfo[1]; |
|
95 |
$goods_id = $val['goods_id']; |
|
96 |
$spec = explode(',',$val['goods_attr_id']); |
|
97 |
if (addto_cart($goods_id, $buynumber, $spec)){ |
|
98 |
unset($_SESSION['saodata'][$key]); |
|
99 |
$ok[] = array('txm'=>$key); |
|
100 |
}else{ |
|
101 |
$fail[] = array('error'=>$err->error_no,'message'=>$info[$err->error_no],'txm'=>$key); |
|
102 |
} |
|
103 |
} |
|
104 |
$result = array('error'=>count($fail),'content'=>'提交商品中有部分商品存在异常,无法进入结算!以下为失败原因:','fail'=>$fail,'ok'=>$ok); |
|
105 |
die($json->encode($result)); |
|
106 |
|
|
107 |
}else{ |
|
108 |
$result = array('error'=>-1,'content'=>'提交购物车超时,请返回重新扫描!'); |
|
109 |
die($json->encode($result)); |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
113 |
//回调方法 |
|
114 |
function back_filter($data){ |
|
115 |
$data = str_replace("\r","",$data); |
|
116 |
if(!empty($data)){ |
|
117 |
return $data; |
|
118 |
} |
|
119 |
} |
|
120 |
?> |