代码拉取完成,页面将自动刷新
<?php
/**
* 扫码获取商品相关数据
* author yangsong
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require(dirname(__FILE__) . '/includes/lib_order.php');
$act = (isset($_REQUEST['act']) && !empty($_REQUEST['act'])) ? trim($_REQUEST['act']) : '';
assign_template();
if($act == 'view'){
$info = array();
foreach($_POST['data'] as $key=>$val){
$info[$key] = explode("\n",$val);
$info[$key] = array_filter($info[$key],'back_filter');
}
$info = array_filter($info);
$find = ',';//条形码和数量之间的分隔号
$num = 1;//商品默认的数量
$data = array();
foreach($info as $key=>$val){
foreach($val as $k=>$v){
$pos = strpos($v,$find);//扫描过来的条形码是否带有数量属性
if($pos === false){
$v = trim($v);
$data[$v] += $num;
}else{
$vinfo = explode(',',$v);
$gnum = ($vinfo[1]>0) ? $vinfo[1] : $num;
$data[$vinfo[0]] += $gnum;
}
}
}
if(empty($data)){
show_message("请先扫码!");
}
//判断条形码中是否有字母
foreach($data as $key=>$val)
{
if(!is_numeric($key))
{
show_message("您输入的条形码不正确!");
}
}
$ginfo = get_goods_by_txm(array_keys($data));
$sao_data = array();
foreach($ginfo as $key=>&$val){
$val['market_price'] = price_format($val['market_price']);
$val['goods_price'] = price_format($val['goods_price']);
$val['goods_attr_price'] = price_format($val['goods_attr_price']);
$val['goods_thumb'] = get_image_path($val['goods_id'], $val['goods_thumb'], true);
$val['goods_img'] = get_image_path($val['goods_id'], $val['goods_img']);
$val['url'] = build_uri('goods', array('gid'=>$val['goods_id']), $val['goods_name']);
$val['buy_number'] = $data[$key];
$sao_data[$key]=$key.','.$data[$key];
}
$_SESSION['saodata'] = $sao_data;
$smarty->assign('page_title', '智能扫货商品展示'); // 页面标题
$smarty->assign('goodsinfo',$ginfo);
$smarty->display('scan_list.dwt');
}
elseif($act == 'del'){
$result = array('error'=>0,'info'=>'');
$txm = (isset($_POST['txm']) && !empty($_POST['txm'])) ? trim($_POST['txm']) : '';
if($txm == ''){
$result['error'] = 1;
$result['info'] = '非法操作';
die(json_encode($result));
}
if(isset($_SESSION['saodata']) && !empty($_SESSION['saodata'])){
unset($_SESSION['saodata'][$txm]);
die(json_encode($result));
}else{
$result['error'] = 1;
$result['info'] = '请返回扫描页面,重新扫描';
die(json_encode($result));
}
}
elseif($act == 'addcart'){
include_once('includes/cls_json.php');
$result = array('error'=>0,'content'=>'');
$json = new JSON;
$info = array(1=>'商品不存在',2=>'商品缺货',3=>'商品已下架',4=>'商品不能单独销售',5=>'商品没有基本件',6=>'商品需要用户选择属性');
if(isset($_SESSION['saodata']) && !empty($_SESSION['saodata'])){
$ginfo = get_goods_by_txm(array_keys($_SESSION['saodata']));
$ok = $fail = array();
foreach($ginfo as $key=>$val){
$txminfo = explode(',',$_SESSION['saodata'][$key]);
$buynumber = $txminfo[1];
$goods_id = $val['goods_id'];
$spec = explode(',',$val['goods_attr_id']);
if (addto_cart($goods_id, $buynumber, $spec)){
unset($_SESSION['saodata'][$key]);
$ok[] = array('txm'=>$key);
}else{
$fail[] = array('error'=>$err->error_no,'message'=>$info[$err->error_no],'txm'=>$key);
}
}
$result = array('error'=>count($fail),'content'=>'提交商品中有部分商品存在异常,无法进入结算!以下为失败原因:','fail'=>$fail,'ok'=>$ok);
die($json->encode($result));
}else{
$result = array('error'=>-1,'content'=>'提交购物车超时,请返回重新扫描!');
die($json->encode($result));
}
}
//回调方法
function back_filter($data){
$data = str_replace("\r","",$data);
if(!empty($data)){
return $data;
}
}
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。