excle导入
public function import_upload(){
set_time_limit(900);
if(!empty($_FILES ['xls_path']['name'])){
$tmp_file = $_FILES ['xls_path']['tmp_name'];
$file_types = explode ( ".",$_FILES ['xls_path']['name']);
$file_type = $file_types[count($file_types) - 1];
$operator = $_SESSION[C('USER_AUTH_KEY')];
$import_id = time(); /*判别是不是.xls文件,判别是不是excel文件*/
if(!in_array(strtolower($file_type),array('xls','xlsx'))){
$this->error('不是Excel文件,重新上传');
}
if($_FILES['size']>2097152){
$this->error('上传文件大小不能超过2M');
}
/*设置上传路径*/
$savePath = substr($_SERVER['DOCUMENT_ROOT'],0,-8) . "upload_dir/update_goods/"; /*以时间来命名上传的文件*/
$str = date('Ymdhis');
$file_name = $str . "." . $file_type; /*是否上传成功*/
if(!copy( $tmp_file, $savePath . $file_name)){
$this->error('上传失败');
} $excel_row = $this->Execlimport($savePath.$file_name,strtolower($file_type));
if($excel_row['data'][0]['Rows']>1001){
$this->error('单次上传数据不能超过1000条');
}
if($excel_row['error']==1){
// echo $excel_row['data'][0]['Cols'];
// var_dump($excel_row['data'][0]);
// if($excel_row['data'][0]['Cols']!=22){
// exit();
// //$this->error('数据列与模板不符,上传模板格式的数据表');
// }
$col_title = array(
0=>array('title'=>'序号'),
1=>array('title'=>'商品编号','name'=>'goods_bzno','required'=>1),
2=>array('title'=>'OMS编码','name'=>'goods_no','required'=>1),
3=>array('title'=>'一级分类','name'=>'cate','required'=>1,'type'=>'int'),
4=>array('title'=>'二级分类','name'=>'second_cate'),
5=>array('title'=>'三级分类','name'=>'three_cate'),
6=>array('title'=>'分类标签','name'=>'cate_tag'),
7=>array('title'=>'适合性别','name'=>'gender'),
8=>array('title'=>'商品名称','name'=>'goods_name','required'=>1),
9=>array('title'=>'尺寸','name'=>'size','required'=>0),
10=>array('title'=>'颜色','name'=>'color','required'=>0),
11=>array('title'=>'疯狂价','name'=>'crazy_price','required'=>1,'type'=>'double'),
12=>array('title'=>'柜台价','name'=>'shop_price','required'=>1,'type'=>'double'),
13=>array('title'=>'进货价','name'=>'buy_price','required'=>1,'type'=>'double'),
14=>array('title'=>'上下架','name'=>'is_putaway','required'=>1),
15=>array('title'=>'残次品','name'=>'is_defective'),
16=>array('title'=>'买手','name'=>'buyer','required'=>1),
17=>array('title'=>'供应商','name'=>'supplier_id','required'=>1),
18=>array('title'=>'批次','name'=>'bathch','required'=>0),
19=>array('title'=>'商品参数1','name'=>'param1','required'=>0),
20=>array('title'=>'商品参数2','name'=>'param2','required'=>0),
21=>array('title'=>'商品参数3','name'=>'param3','required'=>0),
22=>array('title'=>'商品参数4','name'=>'param4','required'=>0),
23=>array('title'=>'商品参数5','name'=>'param5','required'=>0),
24=>array('title'=>'商品参数6','name'=>'param6','required'=>0),
25=>array('title'=>'商品参数7','name'=>'param7','required'=>0),
26=>array('title'=>'商品参数8','name'=>'param8','required'=>0),
27=>array('title'=>'商品参数9','name'=>'param9','required'=>0),
28=>array('title'=>'商品参数10','name'=>'param10','required'=>0),
29=>array('title'=>'商品参数11','name'=>'param11','required'=>0),
30=>array('title'=>'商品参数12','name'=>'param12','required'=>0),
31=>array('title'=>'商品参数13','name'=>'param13','required'=>0),
32=>array('title'=>'商品参数14','name'=>'param14','required'=>0),
33=>array('title'=>'商品参数15','name'=>'param15','required'=>0),
34=>array('title'=>'商品参数16','name'=>'param16','required'=>0),
35=>array('title'=>'商品参数17','name'=>'param17','required'=>0),
36=>array('title'=>'商品参数18','name'=>'param18','required'=>0),
37=>array('title'=>'商品参数19','name'=>'param19','required'=>0),
38=>array('title'=>'商品参数20','name'=>'param20','required'=>0),
39=>array('title'=>'商品参数21','name'=>'param21','required'=>0),
40=>array('title'=>'商品参数22','name'=>'param22','required'=>0),
41=>array('title'=>'商品参数23','name'=>'param23','required'=>0),
42=>array('title'=>'商品参数24','name'=>'param24','required'=>0),
43=>array('title'=>'商品参数25','name'=>'param25','required'=>0),
44=>array('title'=>'商品参数26','name'=>'param26','required'=>0),
45=>array('title'=>'商品参数27','name'=>'param27','required'=>0),
46=>array('title'=>'商品参数28','name'=>'param28','required'=>0),
47=>array('title'=>'商品参数29','name'=>'param29','required'=>0),
48=>array('title'=>'商品参数30','name'=>'param30','required'=>0),
49=>array('title'=>'商品状态','name'=>'state','required'=>1)
);
//供应商
$supplier_arr = $this->supper_name_id();
//买手
$user_arr = $this->user_name_id();
//分类
$cate_arr = $this->cate_title_id();
//获取一、二、三级分类
$other_cate = $this->getOtherCate();
//获取所有分类标签
$cate_tags = $this->getCateTag();
//封装性别数组
$gender = array(
'男' => 1,
'女' => 2,
'中性' => 3,
'童'=> 4
);
//上下架
$putaway_arr = array('上架'=>1,'下架'=>0);
//是否残次
$defective_arr = array('是'=>1,'否'=>0);
//商品状态
// $state_arr = array('首页上架'=>1,'列表页上架'=>2,'隐身上架'=>3,'下架'=>4);
$state_arr = array_flip($this->state_ary);
$excel_arr = array();
$goods_arr = array();
foreach($excel_row['data'][0]['Content'] as $key=>$value){
if($key==1){
foreach($value as $k=>$val){
if($col_title[$k]['title']!=$val){
$this->error('数据列与模板不符,上传失败');
}
}
}else{
// if(empty($value[1]) || empty($value[2])){
// continue;
// }
$row_arr = array();
$row_arr['goods_bzno'] = trim($value[1]);
$row_arr['goods_no'] = trim($value[2]);
if(empty($row_arr['goods_no'])){
$this->error('OMS编码不能为空!');
}
$row_arr['goods_name'] = trim($value[8]);
$row_arr['size'] = trim($value[9]);
$row_arr['color'] = trim($value[10]);
$row_arr['crazy_price'] = trim($value[11]);
$row_arr['shop_price'] = trim($value[12]);
$row_arr['buy_price'] = trim($value[13]);
$row_arr['bathch'] = trim($value[18]);
$i = 15;
$param_arr = array();
for($i=19;$i<49;$i++){
$row_arr['param'.($i-18)] = trim($value[$i]);
if(!empty($value[$i])){
$param_arr[] = trim($value[$i]);
}
}
// $row_arr['param1'] = $value[15];
// $row_arr['param2'] = $value[16];
// $row_arr['param3'] = $value[17];
// $row_arr['param4'] = $value[18];
// $row_arr['param5'] = $value[19];
// $row_arr['param6'] = $value[20];
// $param_arr = array();
// if(!empty($value[15])){
// $param_arr[] = $value[15];
// }
// if(!empty($value[16])){
// $param_arr[] = $value[16];
// }
// if(!empty($value[17])){
// $param_arr[] = $value[17];
// }
// if(!empty($value[18])){
// $param_arr[] = $value[18];
// }
// if(!empty($value[19])){
// $param_arr[] = $value[19];
// }
// if(!empty($value[20])){
// $param_arr[] = $value[20];
// }
$row_arr['goods_param'] = $param_arr; $row_arr['cate_text'] = trim($value[3]);
$row_arr['is_putaway_text'] = trim($value[14]);
$row_arr['is_defective_text'] = trim($value[15]);
$row_arr['buyer_text'] = trim($value[16]);
$row_arr['supplier_id_text'] = trim($value[17]);
$row_arr['state_text'] = trim($value[49]);
$row_arr['cate'] = trim($other_cate[$value[3]]['id']);
$row_arr['second_cate'] = trim($other_cate[$value[3]]['item'][$value[4]]['id']);
$row_arr['three_cate'] = trim($other_cate[$value[3]]['item'][$value[4]]['item'][$value[5]]['id']);
if(empty($row_arr['cate']) || empty($row_arr['second_cate'])){
$this->error('请确认商品编号:'.$row_arr['goods_bzno'].'的一、二级分类是否存在!');
}
$row_arr['cate_tag'] = $cate_tags[$value[6]];
$row_arr['gender'] = !is_null($gender[$value[7]])?$gender[$value[7]]:0;
$row_arr['is_putaway'] = trim($putaway_arr[$value[14]]);
$row_arr['is_defective'] = trim($defective_arr[$value[15]]);
$row_arr['buyer'] = trim($user_arr[$value[16]]);
$row_arr['supplier_id'] = trim($supplier_arr[$value[17]]);
$row_arr['state'] = trim($state_arr[$value[49]]);
$goods_arr[] = trim($value[2]); $excel_arr[$row_arr['goods_no']] = $row_arr; }
}
}
//判断商品的适合性别是否合法
$gender_err = rtrim($gender_err,',');
if(!empty($gender_err)){
$this->error('OMS编码:'.$gender_err.' 商品适合性别不合法!');
}
/*
* 增加‘导入表与既存商品价格不一致时,给出提示并整张表不可导’功能
*/
foreach ($excel_arr as $key => $value) {
$tmp_excel_str[] = $key;
}
$m_spec = M('Spec');
$spec_field = 'goods_no,crazy_price,goods_id';
$spec_map['goods_no'] = array('IN',$tmp_excel_str);
$s_spec_arr = $m_spec->field($spec_field)->where($spec_map)->group('goods_no')->select();
foreach ($s_spec_arr as $key => $value) {
$data_price[$value['goods_id']][$value['goods_no']] = $value['crazy_price'];
$check_goods_id[] = $value['goods_id'];
$check_goods_no[] = $value['goods_no'];
}
$error_goods_no = array_diff($tmp_excel_str, $check_goods_no);
if(!empty($error_goods_no)){
foreach ($error_goods_no as $key => $value) {
$err_goods_no .= $value.',';
}
$final_err = rtrim($err_goods_no,',');
$this->error('商品编码:'.$final_err.'不存在!');
}
//校验商品是否属于正式运营专题
$checkRs = $this->check_special_goods(array_unique($check_goods_id));
$this->assign('checkRs',$checkRs);
$e_goods = $excel_arr;
$m_goods = M('goods g');
$w_goods['s.goods_no'] = array('in',$goods_arr);
$j_goods = " inner join ".C('DB_PREFIX')."spec s on g.goods_id=s.goods_id ";
$j_goods .= " inner join ".C('DB_PREFIX')."goodscollect gc on g.goods_id=gc.goods_id and gc.type=0 ";
$f_goods = "g.goods_id,s.spec_id,g.goods_bzno,s.goods_no,g.goods_name,s.attr,s.skusize,s.color,s.crazy_price,s.shop_price,s.buy_price,g.bathch,g.goods_param,g.cate,g.second_cate,g.three_cate,g.cate_tag,g.gender,s.is_putaway,s.is_defective,g.buyer,g.supplier_id,gc.state,gc.status";
$l_goods = $m_goods->field($f_goods)->join($j_goods)->where($w_goods)->select();
$goods_excel = $msg_arr = $neq_msg_arr = $neq_price_arr = array();
$goods_price = array();
$status_arr = array(3,5);
foreach($l_goods as $key=>$value){
unset($e_goods[$value['goods_no']]);
//赋值
$neq_m_arr = $m_arr = $g_arr = array();
$g_arr['spec_id'] = $value['spec_id'];
$g_arr['goods_id'] = $value['goods_id'];
$g_arr['goods_bzno'] = $value['goods_bzno'];
$g_arr['goods_no'] = $value['goods_no'];
$g_arr['cate'] = $value['cate'];
$g_arr['second_cate'] = $value['second_cate'];
$g_arr['three_cate'] = $value['three_cate'];
$g_arr['cate_tag'] = $value['cate_tag'];
$g_arr['gender'] = $value['gender'];
$g_arr['goods_name'] = $value['goods_name'];
$g_arr['color'] = $value['color'];
$g_arr['skusize'] = $value['skusize'];
$g_arr['attr'] = $value['attr'];
$g_arr['crazy_price'] = $value['crazy_price'];
$g_arr['shop_price'] = $value['shop_price'];
$g_arr['buy_price'] = $value['buy_price'];
$g_arr['is_putaway'] = $value['is_putaway'];
$g_arr['is_defective'] = $value['is_defective'];
$g_arr['buyer'] = $value['buyer'];
$g_arr['supplier_id'] = $value['supplier_id'];
$g_arr['bathch'] = $value['bathch'];
$g_arr['goods_param'] = $value['goods_param'];
$g_arr['state'] = $value['state'];
$g_arr['status'] = $value['status'];
$g_arr['im_cate'] = $excel_arr[$value['goods_no']]['cate'];
$g_arr['im_second_cate'] = !empty($excel_arr[$value['goods_no']]['second_cate'])?$excel_arr[$value['goods_no']]['second_cate']:0;
$g_arr['im_three_cate'] = !empty($excel_arr[$value['goods_no']]['three_cate'])?$excel_arr[$value['goods_no']]['three_cate']:0;
$g_arr['im_cate_tag'] = !empty($excel_arr[$value['goods_no']]['cate_tag'])?$excel_arr[$value['goods_no']]['cate_tag']:0;
$g_arr['im_gender'] = $excel_arr[$value['goods_no']]['gender'];
$g_arr['im_goods_name'] = $excel_arr[$value['goods_no']]['goods_name'];
$g_arr['im_color'] = $excel_arr[$value['goods_no']]['color'];
$g_arr['im_skusize'] = $excel_arr[$value['goods_no']]['size'];
$attr2 = array();
if(empty($excel_arr[$value['goods_no']]['color'])){
if(!empty($excel_arr[$value['goods_no']]['size'])){
$attr2['skuSize'] = $excel_arr[$value['goods_no']]['size'];
}
}else{
$attr2['color'] = $excel_arr[$value['goods_no']]['color'];
if(!empty($excel_arr[$value['goods_no']]['size'])){
$attr2['skuSize'] = $excel_arr[$value['goods_no']]['size'];
}
}
if(!isset($goods_price[$value['goods_id']])){
$goods_price[$value['goods_id']] = $excel_arr[$value['goods_no']]['crazy_price'];
} $g_arr['im_attr'] = serialize($attr2);
$g_arr['im_crazy_price'] = $excel_arr[$value['goods_no']]['crazy_price'];
$g_arr['im_shop_price'] = $excel_arr[$value['goods_no']]['shop_price'];
$g_arr['im_buy_price'] = $excel_arr[$value['goods_no']]['buy_price'];
$g_arr['im_is_putaway'] = $excel_arr[$value['goods_no']]['is_putaway'];
$g_arr['im_is_defective'] = $excel_arr[$value['goods_no']]['is_defective'];
$g_arr['im_buyer'] = $excel_arr[$value['goods_no']]['buyer'];
$g_arr['im_supplier_id'] = $excel_arr[$value['goods_no']]['supplier_id'];
$g_arr['im_bathch'] = $excel_arr[$value['goods_no']]['bathch'];
$g_arr['im_goods_param'] = serialize($excel_arr[$value['goods_no']]['goods_param']);
$g_arr['im_state'] = $excel_arr[$value['goods_no']]['state'];
if(in_array($value['status'],$status_arr)){
$g_arr['im_status'] = 2;
$g_arr['im_post_checktime'] = time();
}else{
$g_arr['im_status'] = $value['status'];
$g_arr['im_post_checktime'] = 0;
}
$g_arr['operator'] = $operator;
$g_arr['import_id'] = $import_id;
//验证是否必填,验证是否已经有值
if(!empty($excel_arr[$value['goods_no']]['cate']) && !empty($excel_arr[$value['goods_no']]['cate_text'])){ //所属分类
if(!empty($value['cate'])){
$m_arr['cate']['ct'] = 1;
}
}else{
if(empty($value['cate'])){
$neq_m_arr['cate']['neq'] = 1;
}else{
$g_arr['im_cate'] = $value['cate'];
}
}
if(!empty($excel_arr[$value['goods_no']]['goods_name'])){ //商品名称
if(!empty($value['goods_name'])){
$m_arr['goods_name']['ct'] = 1;
}
}else{
if(empty($value['goods_name'])){
$neq_m_arr['goods_name']['neq'] = 1;
}else{
$g_arr['im_goods_name'] = $value['goods_name'];
}
}
$attr = unserialize($value['attr']);
if(!empty($excel_arr[$value['goods_no']]['size'])){ //尺寸
if(!empty($attr['skuSize'])){
$m_arr['size']['ct'] = 1;
}
}
if(!empty($excel_arr[$value['goods_no']]['color'])){ //颜色
if(!empty($attr['color'])){
$m_arr['color']['ct'] = 1;
}
}
if((empty($excel_arr[$value['goods_no']]['size']) && empty($excel_arr[$value['goods_no']]['color'])) && (!empty($attr['skuSize']) || !empty($attr['color']))){
$attr1 = array();
// var_dump($attr);
if(empty($attr['color'])){
if(!empty($attr['skuSize'])){
$attr1['skuSize'] = $attr['skuSize'];
}
}else{
$attr1['color'] = $attr['color'];
if(!empty($attr['skuSize'])){
$attr1['skuSize'] = $attr['skuSize'];
}
}
$g_arr['im_attr'] = serialize($attr1);
}
if(!empty($excel_arr[$value['goods_no']]['crazy_price'])){ //疯狂价
if(!empty($value['crazy_price'])){
$m_arr['crazy_price']['ct'] = 1;
}
if(!is_numeric($excel_arr[$value['goods_no']]['crazy_price'])){
$neq_m_arr['crazy_price']['n_int'] = 1;
}
if(!isset($neq_price_arr[$value['goods_bzno']])){
if($goods_price[$value['goods_id']]!=$excel_arr[$value['goods_no']]['crazy_price']){
$neq_price_arr[$value['goods_bzno']] = 1;
}
}
//if($goods_excel[$value['spec_id']]['im_crazy_price'])
}else{
if(empty($value['crazy_price'])){
$neq_m_arr['crazy_price']['neq'] = 1;
}else{
$g_arr['im_crazy_price'] = $value['crazy_price'];
}
}
if(!empty($excel_arr[$value['goods_no']]['shop_price'])){ //柜台价
if(!empty($value['shop_price'])){
$m_arr['shop_price']['ct'] = 1;
}
if(!is_numeric($excel_arr[$value['goods_no']]['shop_price'])){
$neq_m_arr['shop_price']['n_int'] = 1;
}
}else{
if(empty($value['shop_price'])){
$neq_m_arr['shop_price']['neq'] = 1;
}else{
$g_arr['im_shop_price'] = $value['shop_price'];
}
}
if(!empty($excel_arr[$value['goods_no']]['buy_price'])){ //进货价
if(!empty($value['buy_price'])){
$m_arr['buy_price']['ct'] = 1;
}
if(!is_numeric($excel_arr[$value['goods_no']]['buy_price'])){
$neq_m_arr['buy_price']['n_int'] = 1;
}
}else{
if(empty($value['buy_price'])){
$neq_m_arr['buy_price']['neq'] = 1;
}else{
$g_arr['im_buy_price'] = $value['buy_price'];
}
}
if((!empty($excel_arr[$value['goods_no']]['is_putaway']) || $excel_arr[$value['goods_no']]['is_putaway'] == 0) && !empty($excel_arr[$value['goods_no']]['is_putaway_text'])){ //上下架
if(!empty($value['is_putaway']) || $value['is_putaway'] ==0){
$m_arr['is_putaway']['ct'] = 1;
}
}else{
if(empty($value['is_putaway']) && $value['is_putaway'] != 0){
$neq_m_arr['is_putaway']['neq'] = 1;
}else{
$g_arr['im_is_putaway'] = $value['is_putaway'];
}
}
if((!empty($excel_arr[$value['goods_no']]['is_defective']) || $excel_arr[$value['goods_no']]['is_defective'] == 0) && !empty($excel_arr[$value['goods_no']]['is_defective_text'])){ //是否残次
if(!empty($value['is_defective']) || $value['is_defective'] ==0){
$m_arr['is_defective']['ct'] = 1;
}
}else{
$g_arr['im_is_defective'] = $value['is_defective'];
}
if(!empty($excel_arr[$value['goods_no']]['buyer']) && !empty($excel_arr[$value['goods_no']]['buyer_text'])){ //买手
if(!empty($value['buyer'])){
$m_arr['buyer']['ct'] = 1;
}
}else{
if(empty($value['buyer'])){
$neq_m_arr['buyer']['neq'] = 1;
}else{
$g_arr['im_buyer'] = $value['buyer'];
}
}
if(!empty($excel_arr[$value['goods_no']]['supplier_id']) && !empty($excel_arr[$value['goods_no']]['supplier_id_text'])){ //供应商
if(!empty($value['supplier_id'])){
$m_arr['supplier_id']['ct'] = 1;
}
}else{
if(empty($value['supplier_id'])){
$neq_m_arr['supplier_id']['neq'] = 1;
}else{
$g_arr['im_supplier_id'] = $value['supplier_id'];
}
}
if(!empty($excel_arr[$value['goods_no']]['bathch'])){ //批次
if(!empty($value['bathch'])){
$m_arr['bathch']['ct'] = 1;
}
}else{
if(!empty($value['bathch'])){
$g_arr['im_bathch'] = $value['bathch'];
}
}
if(!empty($excel_arr[$value['goods_no']]['goods_param'])){ //参数
$goods_param = unserialize($value['goods_param']);
if(!empty($value['goods_param'])){
$m_arr['goods_param']['ct'] = 1;
}
}else{
if(!empty($value['goods_param'])){
$g_arr['im_goods_param'] = $value['goods_param'];
}
}
if(!empty($excel_arr[$value['goods_no']]['state']) && !empty($excel_arr[$value['goods_no']]['state_text'])){ //商品状态
if(!empty($value['state'])){
$m_arr['state']['ct'] = 1;
}
}else{
if(empty($value['state'])){
$neq_m_arr['state']['neq'] = 1;
}else{
$g_arr['im_state'] = $excel_arr[$value['goods_no']]['state'];
}
} if(!empty($m_arr)){
$msg_arr[$value['goods_no']] = $m_arr;
}
if(!empty($neq_m_arr)){
$neq_msg_arr[$value['goods_no']] = $neq_m_arr;
}
$goods_excel[$value['spec_id']] = $g_arr;
$data_excel_goods[$value['goods_id']][$value['goods_no']] = $excel_arr[$value['goods_no']]['crazy_price'];
}
if(!empty($msg_arr)){
$m_edit_goods = M('edit_goods');
$w_edit_goods['operator'] = $operator;
if($m_edit_goods->where($w_edit_goods)->delete()!==false){
$data = $goods_excel;
sort($data);
//导入表与既存商品价格不一致时,给出提示并整张表不可导。
foreach ($data_excel_goods as $key => $value) {
if(isset($data_price[$key])){
$price_diff[$key] = $data_excel_goods[$key]+$data_price[$key];
}
}
foreach ($price_diff as $k => $v) {
if(count(array_unique($price_diff[$k])) > 1){
$this->error('商品ID'.$k.'所属SKU价格不一致');
}
}
if($m_edit_goods->addAll($data)===false){
$this->error('上传失败,创建备份失败!');
}
}else{
$this->error('上传失败,清除历史备份失败!');
}
}
$yz_arr = array(
'ct'=>array(
'cate'=>'分类',
'goods_name'=>'商品名称',
'size'=>'尺寸',
'color'=>'颜色',
'crazy_price'=>'疯狂价',
'shop_price'=>'柜台价',
'buy_price'=>'进货价',
'is_putaway'=>'上下架',
'is_defective'=>'残次品',
'buyer'=>'买手',
'supplier_id'=>'供应商',
'bathch'=>'批次',
'goods_param'=>'商品参数',
'state'=>'商品状态'
),
'neq'=>array(
'cate'=>'分类',
'goods_name'=>'商品名称',
'crazy_price'=>'疯狂价',
'shop_price'=>'柜台价',
'buy_price'=>'进货价',
'is_putaway'=>'上下架',
'buyer'=>'买手',
'supplier_id'=>'供应商',
'state'=>'商品状态'
),
'n_int'=>array(
'crazy_price'=>'疯狂价',
'shop_price'=>'柜台价',
'buy_price'=>'进货价'
)
);
$this->assign('yz_arr',$yz_arr);
$this->assign('msg_arr',$msg_arr);
$this->assign('neq_msg_arr',$neq_msg_arr);
$this->assign('neq_price_arr',$neq_price_arr);
$this->assign('goods_excel',$goods_excel);
$this->assign('e_goods',$e_goods);
$this->assign('import_id',$import_id);
$this->display();
}
}
public function Execlimport($file, $excel_type = 'xls')
{
// $file='E:\work\cbd\cbdroot\upload_dir\supplier_goods\20140604\538e8fee0ae11.xls';
// echo $file;
if (!file_exists($file))
{
return [
"error" => 0,
'message' => 'file not found!'
];
} Vendor("PHPExcel.PHPExcel");
Vendor("PHPExcel.PHPExcel.IOFactory");
Vendor("PHPExcel.PHPExcel.Reader.Excel5");
Vendor("PHPExcel.PHPExcel.Reader.Excel2007");
if ($excel_type == 'xls')
{
$objReader = PHPExcel_IOFactory::createReader('Excel5');
}
else
{
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
}
try
{
$PHPReader = $objReader->load($file);
}
catch (Exception $e)
{
}
if (!isset($PHPReader))
{
return [
"error" => 0,
'message' => 'read error!'
];
}
$allWorksheets = $PHPReader->getAllSheets();
$i = 0;
foreach ($allWorksheets as $objWorksheet)
{
$sheetname = $objWorksheet->getTitle();
$allRow = $objWorksheet->getHighestRow();//how many rows
$highestColumn = $objWorksheet->getHighestColumn();//how many columns
$allColumn = PHPExcel_Cell::columnIndexFromString($highestColumn);
$array[$i]["Title"] = $sheetname;
$array[$i]["Cols"] = $allColumn;
$array[$i]["Rows"] = $allRow;
$arr = [];
$isMergeCell = [];
foreach ($objWorksheet->getMergeCells() as $cells)
{//merge cells
foreach (PHPExcel_Cell::extractAllCellReferencesInRange($cells) as $cellReference)
{
$isMergeCell[$cellReference] = true;
}
}
for ($currentRow = 1; $currentRow <= $allRow; $currentRow++)
{
$row = [];
for ($currentColumn = 0; $currentColumn < $allColumn; $currentColumn++)
{
;
$cell = $objWorksheet->getCellByColumnAndRow($currentColumn, $currentRow);
$afCol = PHPExcel_Cell::stringFromColumnIndex($currentColumn + 1);
$bfCol = PHPExcel_Cell::stringFromColumnIndex($currentColumn - 1);
$col = PHPExcel_Cell::stringFromColumnIndex($currentColumn);
$address = $col . $currentRow;
$value = $objWorksheet->getCell($address)->getValue();
if (substr($value, 0, 1) == '=')
{
return [
"error" => 0,
'message' => 'can not use the formula!'
];
exit;
}
if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_NUMERIC)
{
$cellstyleformat = $cell->getStyle($cell->getCoordinate())->getNumberFormat();
// $cellstyleformat=$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat();
// var_dump($cell->getCoordinate());
// exit();
$formatcode = $cellstyleformat->getFormatCode();
if (preg_match('/^([$[A-Z]*-[0-9A-F]*])*[hmsdy]/i', $formatcode))
{
$value = gmdate("Y-m-d", PHPExcel_Shared_Date::ExcelToPHP($value));
}
else
{
$value = PHPExcel_Style_NumberFormat::toFormattedString($value, $formatcode);
}
}
if ($isMergeCell[$col . $currentRow] && $isMergeCell[$afCol . $currentRow] && !empty($value))
{
$temp = $value;
}
elseif ($isMergeCell[$col . $currentRow] && $isMergeCell[$col . ($currentRow - 1)] && empty($value))
{
$value = $arr[$currentRow - 1][$currentColumn];
}
elseif ($isMergeCell[$col . $currentRow] && $isMergeCell[$bfCol . $currentRow] && empty($value))
{
$value = $temp;
}
$row[$currentColumn] = $value;
}
$arr[$currentRow] = $row;
}
$array[$i]["Content"] = $arr;
$i++;
}
spl_autoload_register([
'Think',
'autoload'
]);//must, resolve ThinkPHP and PHPExcel conflicts
unset($objWorksheet);
unset($PHPReader);
unset($PHPExcel);
unlink($file);
return [
"error" => 1,
"data" => $array
];
}
public function import_upload(){
set_time_limit(900);
if(!empty($_FILES ['xls_path']['name'])){
$tmp_file = $_FILES ['xls_path']['tmp_name'];
$file_types = explode ( ".",$_FILES ['xls_path']['name']);
$file_type = $file_types[count($file_types) - 1];
$operator = $_SESSION[C('USER_AUTH_KEY')];
$import_id = time(); /*判别是不是.xls文件,判别是不是excel文件*/
if(!in_array(strtolower($file_type),array('xls','xlsx'))){
$this->error('不是Excel文件,重新上传');
}
if($_FILES['size']>2097152){
$this->error('上传文件大小不能超过2M');
}
/*设置上传路径*/
$savePath = substr($_SERVER['DOCUMENT_ROOT'],0,-8) . "upload_dir/update_goods/"; /*以时间来命名上传的文件*/
$str = date('Ymdhis');
$file_name = $str . "." . $file_type; /*是否上传成功*/
if(!copy( $tmp_file, $savePath . $file_name)){
$this->error('上传失败');
} $excel_row = $this->Execlimport($savePath.$file_name,strtolower($file_type));
if($excel_row['data'][0]['Rows']>1001){
$this->error('单次上传数据不能超过1000条');
}
if($excel_row['error']==1){
// echo $excel_row['data'][0]['Cols'];
// var_dump($excel_row['data'][0]);
// if($excel_row['data'][0]['Cols']!=22){
// exit();
// //$this->error('数据列与模板不符,上传模板格式的数据表');
// }
$col_title = array(
0=>array('title'=>'序号'),
1=>array('title'=>'商品编号','name'=>'goods_bzno','required'=>1),
2=>array('title'=>'OMS编码','name'=>'goods_no','required'=>1),
3=>array('title'=>'一级分类','name'=>'cate','required'=>1,'type'=>'int'),
4=>array('title'=>'二级分类','name'=>'second_cate'),
5=>array('title'=>'三级分类','name'=>'three_cate'),
6=>array('title'=>'分类标签','name'=>'cate_tag'),
7=>array('title'=>'适合性别','name'=>'gender'),
8=>array('title'=>'商品名称','name'=>'goods_name','required'=>1),
9=>array('title'=>'尺寸','name'=>'size','required'=>0),
10=>array('title'=>'颜色','name'=>'color','required'=>0),
11=>array('title'=>'疯狂价','name'=>'crazy_price','required'=>1,'type'=>'double'),
12=>array('title'=>'柜台价','name'=>'shop_price','required'=>1,'type'=>'double'),
13=>array('title'=>'进货价','name'=>'buy_price','required'=>1,'type'=>'double'),
14=>array('title'=>'上下架','name'=>'is_putaway','required'=>1),
15=>array('title'=>'残次品','name'=>'is_defective'),
16=>array('title'=>'买手','name'=>'buyer','required'=>1),
17=>array('title'=>'供应商','name'=>'supplier_id','required'=>1),
18=>array('title'=>'批次','name'=>'bathch','required'=>0),
19=>array('title'=>'商品参数1','name'=>'param1','required'=>0),
20=>array('title'=>'商品参数2','name'=>'param2','required'=>0),
21=>array('title'=>'商品参数3','name'=>'param3','required'=>0),
22=>array('title'=>'商品参数4','name'=>'param4','required'=>0),
23=>array('title'=>'商品参数5','name'=>'param5','required'=>0),
24=>array('title'=>'商品参数6','name'=>'param6','required'=>0),
25=>array('title'=>'商品参数7','name'=>'param7','required'=>0),
26=>array('title'=>'商品参数8','name'=>'param8','required'=>0),
27=>array('title'=>'商品参数9','name'=>'param9','required'=>0),
28=>array('title'=>'商品参数10','name'=>'param10','required'=>0),
29=>array('title'=>'商品参数11','name'=>'param11','required'=>0),
30=>array('title'=>'商品参数12','name'=>'param12','required'=>0),
31=>array('title'=>'商品参数13','name'=>'param13','required'=>0),
32=>array('title'=>'商品参数14','name'=>'param14','required'=>0),
33=>array('title'=>'商品参数15','name'=>'param15','required'=>0),
34=>array('title'=>'商品参数16','name'=>'param16','required'=>0),
35=>array('title'=>'商品参数17','name'=>'param17','required'=>0),
36=>array('title'=>'商品参数18','name'=>'param18','required'=>0),
37=>array('title'=>'商品参数19','name'=>'param19','required'=>0),
38=>array('title'=>'商品参数20','name'=>'param20','required'=>0),
39=>array('title'=>'商品参数21','name'=>'param21','required'=>0),
40=>array('title'=>'商品参数22','name'=>'param22','required'=>0),
41=>array('title'=>'商品参数23','name'=>'param23','required'=>0),
42=>array('title'=>'商品参数24','name'=>'param24','required'=>0),
43=>array('title'=>'商品参数25','name'=>'param25','required'=>0),
44=>array('title'=>'商品参数26','name'=>'param26','required'=>0),
45=>array('title'=>'商品参数27','name'=>'param27','required'=>0),
46=>array('title'=>'商品参数28','name'=>'param28','required'=>0),
47=>array('title'=>'商品参数29','name'=>'param29','required'=>0),
48=>array('title'=>'商品参数30','name'=>'param30','required'=>0),
49=>array('title'=>'商品状态','name'=>'state','required'=>1)
);
//供应商
$supplier_arr = $this->supper_name_id();
//买手
$user_arr = $this->user_name_id();
//分类
$cate_arr = $this->cate_title_id();
//获取一、二、三级分类
$other_cate = $this->getOtherCate();
//获取所有分类标签
$cate_tags = $this->getCateTag();
//封装性别数组
$gender = array(
'男' => 1,
'女' => 2,
'中性' => 3,
'童'=> 4
);
//上下架
$putaway_arr = array('上架'=>1,'下架'=>0);
//是否残次
$defective_arr = array('是'=>1,'否'=>0);
//商品状态
// $state_arr = array('首页上架'=>1,'列表页上架'=>2,'隐身上架'=>3,'下架'=>4);
$state_arr = array_flip($this->state_ary);
$excel_arr = array();
$goods_arr = array();
foreach($excel_row['data'][0]['Content'] as $key=>$value){
if($key==1){
foreach($value as $k=>$val){
if($col_title[$k]['title']!=$val){
$this->error('数据列与模板不符,上传失败');
}
}
}else{
// if(empty($value[1]) || empty($value[2])){
// continue;
// }
$row_arr = array();
$row_arr['goods_bzno'] = trim($value[1]);
$row_arr['goods_no'] = trim($value[2]);
if(empty($row_arr['goods_no'])){
$this->error('OMS编码不能为空!');
}
$row_arr['goods_name'] = trim($value[8]);
$row_arr['size'] = trim($value[9]);
$row_arr['color'] = trim($value[10]);
$row_arr['crazy_price'] = trim($value[11]);
$row_arr['shop_price'] = trim($value[12]);
$row_arr['buy_price'] = trim($value[13]);
$row_arr['bathch'] = trim($value[18]);
$i = 15;
$param_arr = array();
for($i=19;$i<49;$i++){
$row_arr['param'.($i-18)] = trim($value[$i]);
if(!empty($value[$i])){
$param_arr[] = trim($value[$i]);
}
}
// $row_arr['param1'] = $value[15];
// $row_arr['param2'] = $value[16];
// $row_arr['param3'] = $value[17];
// $row_arr['param4'] = $value[18];
// $row_arr['param5'] = $value[19];
// $row_arr['param6'] = $value[20];
// $param_arr = array();
// if(!empty($value[15])){
// $param_arr[] = $value[15];
// }
// if(!empty($value[16])){
// $param_arr[] = $value[16];
// }
// if(!empty($value[17])){
// $param_arr[] = $value[17];
// }
// if(!empty($value[18])){
// $param_arr[] = $value[18];
// }
// if(!empty($value[19])){
// $param_arr[] = $value[19];
// }
// if(!empty($value[20])){
// $param_arr[] = $value[20];
// }
$row_arr['goods_param'] = $param_arr; $row_arr['cate_text'] = trim($value[3]);
$row_arr['is_putaway_text'] = trim($value[14]);
$row_arr['is_defective_text'] = trim($value[15]);
$row_arr['buyer_text'] = trim($value[16]);
$row_arr['supplier_id_text'] = trim($value[17]);
$row_arr['state_text'] = trim($value[49]);
$row_arr['cate'] = trim($other_cate[$value[3]]['id']);
$row_arr['second_cate'] = trim($other_cate[$value[3]]['item'][$value[4]]['id']);
$row_arr['three_cate'] = trim($other_cate[$value[3]]['item'][$value[4]]['item'][$value[5]]['id']);
if(empty($row_arr['cate']) || empty($row_arr['second_cate'])){
$this->error('请确认商品编号:'.$row_arr['goods_bzno'].'的一、二级分类是否存在!');
}
$row_arr['cate_tag'] = $cate_tags[$value[6]];
$row_arr['gender'] = !is_null($gender[$value[7]])?$gender[$value[7]]:0;
$row_arr['is_putaway'] = trim($putaway_arr[$value[14]]);
$row_arr['is_defective'] = trim($defective_arr[$value[15]]);
$row_arr['buyer'] = trim($user_arr[$value[16]]);
$row_arr['supplier_id'] = trim($supplier_arr[$value[17]]);
$row_arr['state'] = trim($state_arr[$value[49]]);
$goods_arr[] = trim($value[2]); $excel_arr[$row_arr['goods_no']] = $row_arr; }
}
}
//判断商品的适合性别是否合法
$gender_err = rtrim($gender_err,',');
if(!empty($gender_err)){
$this->error('OMS编码:'.$gender_err.' 商品适合性别不合法!');
}
/*
* 增加‘导入表与既存商品价格不一致时,给出提示并整张表不可导’功能
*/
foreach ($excel_arr as $key => $value) {
$tmp_excel_str[] = $key;
}
$m_spec = M('Spec');
$spec_field = 'goods_no,crazy_price,goods_id';
$spec_map['goods_no'] = array('IN',$tmp_excel_str);
$s_spec_arr = $m_spec->field($spec_field)->where($spec_map)->group('goods_no')->select();
foreach ($s_spec_arr as $key => $value) {
$data_price[$value['goods_id']][$value['goods_no']] = $value['crazy_price'];
$check_goods_id[] = $value['goods_id'];
$check_goods_no[] = $value['goods_no'];
}
$error_goods_no = array_diff($tmp_excel_str, $check_goods_no);
if(!empty($error_goods_no)){
foreach ($error_goods_no as $key => $value) {
$err_goods_no .= $value.',';
}
$final_err = rtrim($err_goods_no,',');
$this->error('商品编码:'.$final_err.'不存在!');
}
//校验商品是否属于正式运营专题
$checkRs = $this->check_special_goods(array_unique($check_goods_id));
$this->assign('checkRs',$checkRs);
$e_goods = $excel_arr;
$m_goods = M('goods g');
$w_goods['s.goods_no'] = array('in',$goods_arr);
$j_goods = " inner join ".C('DB_PREFIX')."spec s on g.goods_id=s.goods_id ";
$j_goods .= " inner join ".C('DB_PREFIX')."goodscollect gc on g.goods_id=gc.goods_id and gc.type=0 ";
$f_goods = "g.goods_id,s.spec_id,g.goods_bzno,s.goods_no,g.goods_name,s.attr,s.skusize,s.color,s.crazy_price,s.shop_price,s.buy_price,g.bathch,g.goods_param,g.cate,g.second_cate,g.three_cate,g.cate_tag,g.gender,s.is_putaway,s.is_defective,g.buyer,g.supplier_id,gc.state,gc.status";
$l_goods = $m_goods->field($f_goods)->join($j_goods)->where($w_goods)->select();
$goods_excel = $msg_arr = $neq_msg_arr = $neq_price_arr = array();
$goods_price = array();
$status_arr = array(3,5);
foreach($l_goods as $key=>$value){
unset($e_goods[$value['goods_no']]);
//赋值
$neq_m_arr = $m_arr = $g_arr = array();
$g_arr['spec_id'] = $value['spec_id'];
$g_arr['goods_id'] = $value['goods_id'];
$g_arr['goods_bzno'] = $value['goods_bzno'];
$g_arr['goods_no'] = $value['goods_no'];
$g_arr['cate'] = $value['cate'];
$g_arr['second_cate'] = $value['second_cate'];
$g_arr['three_cate'] = $value['three_cate'];
$g_arr['cate_tag'] = $value['cate_tag'];
$g_arr['gender'] = $value['gender'];
$g_arr['goods_name'] = $value['goods_name'];
$g_arr['color'] = $value['color'];
$g_arr['skusize'] = $value['skusize'];
$g_arr['attr'] = $value['attr'];
$g_arr['crazy_price'] = $value['crazy_price'];
$g_arr['shop_price'] = $value['shop_price'];
$g_arr['buy_price'] = $value['buy_price'];
$g_arr['is_putaway'] = $value['is_putaway'];
$g_arr['is_defective'] = $value['is_defective'];
$g_arr['buyer'] = $value['buyer'];
$g_arr['supplier_id'] = $value['supplier_id'];
$g_arr['bathch'] = $value['bathch'];
$g_arr['goods_param'] = $value['goods_param'];
$g_arr['state'] = $value['state'];
$g_arr['status'] = $value['status'];
$g_arr['im_cate'] = $excel_arr[$value['goods_no']]['cate'];
$g_arr['im_second_cate'] = !empty($excel_arr[$value['goods_no']]['second_cate'])?$excel_arr[$value['goods_no']]['second_cate']:0;
$g_arr['im_three_cate'] = !empty($excel_arr[$value['goods_no']]['three_cate'])?$excel_arr[$value['goods_no']]['three_cate']:0;
$g_arr['im_cate_tag'] = !empty($excel_arr[$value['goods_no']]['cate_tag'])?$excel_arr[$value['goods_no']]['cate_tag']:0;
$g_arr['im_gender'] = $excel_arr[$value['goods_no']]['gender'];
$g_arr['im_goods_name'] = $excel_arr[$value['goods_no']]['goods_name'];
$g_arr['im_color'] = $excel_arr[$value['goods_no']]['color'];
$g_arr['im_skusize'] = $excel_arr[$value['goods_no']]['size'];
$attr2 = array();
if(empty($excel_arr[$value['goods_no']]['color'])){
if(!empty($excel_arr[$value['goods_no']]['size'])){
$attr2['skuSize'] = $excel_arr[$value['goods_no']]['size'];
}
}else{
$attr2['color'] = $excel_arr[$value['goods_no']]['color'];
if(!empty($excel_arr[$value['goods_no']]['size'])){
$attr2['skuSize'] = $excel_arr[$value['goods_no']]['size'];
}
}
if(!isset($goods_price[$value['goods_id']])){
$goods_price[$value['goods_id']] = $excel_arr[$value['goods_no']]['crazy_price'];
} $g_arr['im_attr'] = serialize($attr2);
$g_arr['im_crazy_price'] = $excel_arr[$value['goods_no']]['crazy_price'];
$g_arr['im_shop_price'] = $excel_arr[$value['goods_no']]['shop_price'];
$g_arr['im_buy_price'] = $excel_arr[$value['goods_no']]['buy_price'];
$g_arr['im_is_putaway'] = $excel_arr[$value['goods_no']]['is_putaway'];
$g_arr['im_is_defective'] = $excel_arr[$value['goods_no']]['is_defective'];
$g_arr['im_buyer'] = $excel_arr[$value['goods_no']]['buyer'];
$g_arr['im_supplier_id'] = $excel_arr[$value['goods_no']]['supplier_id'];
$g_arr['im_bathch'] = $excel_arr[$value['goods_no']]['bathch'];
$g_arr['im_goods_param'] = serialize($excel_arr[$value['goods_no']]['goods_param']);
$g_arr['im_state'] = $excel_arr[$value['goods_no']]['state'];
if(in_array($value['status'],$status_arr)){
$g_arr['im_status'] = 2;
$g_arr['im_post_checktime'] = time();
}else{
$g_arr['im_status'] = $value['status'];
$g_arr['im_post_checktime'] = 0;
}
$g_arr['operator'] = $operator;
$g_arr['import_id'] = $import_id;
//验证是否必填,验证是否已经有值
if(!empty($excel_arr[$value['goods_no']]['cate']) && !empty($excel_arr[$value['goods_no']]['cate_text'])){ //所属分类
if(!empty($value['cate'])){
$m_arr['cate']['ct'] = 1;
}
}else{
if(empty($value['cate'])){
$neq_m_arr['cate']['neq'] = 1;
}else{
$g_arr['im_cate'] = $value['cate'];
}
}
if(!empty($excel_arr[$value['goods_no']]['goods_name'])){ //商品名称
if(!empty($value['goods_name'])){
$m_arr['goods_name']['ct'] = 1;
}
}else{
if(empty($value['goods_name'])){
$neq_m_arr['goods_name']['neq'] = 1;
}else{
$g_arr['im_goods_name'] = $value['goods_name'];
}
}
$attr = unserialize($value['attr']);
if(!empty($excel_arr[$value['goods_no']]['size'])){ //尺寸
if(!empty($attr['skuSize'])){
$m_arr['size']['ct'] = 1;
}
}
if(!empty($excel_arr[$value['goods_no']]['color'])){ //颜色
if(!empty($attr['color'])){
$m_arr['color']['ct'] = 1;
}
}
if((empty($excel_arr[$value['goods_no']]['size']) && empty($excel_arr[$value['goods_no']]['color'])) && (!empty($attr['skuSize']) || !empty($attr['color']))){
$attr1 = array();
// var_dump($attr);
if(empty($attr['color'])){
if(!empty($attr['skuSize'])){
$attr1['skuSize'] = $attr['skuSize'];
}
}else{
$attr1['color'] = $attr['color'];
if(!empty($attr['skuSize'])){
$attr1['skuSize'] = $attr['skuSize'];
}
}
$g_arr['im_attr'] = serialize($attr1);
}
if(!empty($excel_arr[$value['goods_no']]['crazy_price'])){ //疯狂价
if(!empty($value['crazy_price'])){
$m_arr['crazy_price']['ct'] = 1;
}
if(!is_numeric($excel_arr[$value['goods_no']]['crazy_price'])){
$neq_m_arr['crazy_price']['n_int'] = 1;
}
if(!isset($neq_price_arr[$value['goods_bzno']])){
if($goods_price[$value['goods_id']]!=$excel_arr[$value['goods_no']]['crazy_price']){
$neq_price_arr[$value['goods_bzno']] = 1;
}
}
//if($goods_excel[$value['spec_id']]['im_crazy_price'])
}else{
if(empty($value['crazy_price'])){
$neq_m_arr['crazy_price']['neq'] = 1;
}else{
$g_arr['im_crazy_price'] = $value['crazy_price'];
}
}
if(!empty($excel_arr[$value['goods_no']]['shop_price'])){ //柜台价
if(!empty($value['shop_price'])){
$m_arr['shop_price']['ct'] = 1;
}
if(!is_numeric($excel_arr[$value['goods_no']]['shop_price'])){
$neq_m_arr['shop_price']['n_int'] = 1;
}
}else{
if(empty($value['shop_price'])){
$neq_m_arr['shop_price']['neq'] = 1;
}else{
$g_arr['im_shop_price'] = $value['shop_price'];
}
}
if(!empty($excel_arr[$value['goods_no']]['buy_price'])){ //进货价
if(!empty($value['buy_price'])){
$m_arr['buy_price']['ct'] = 1;
}
if(!is_numeric($excel_arr[$value['goods_no']]['buy_price'])){
$neq_m_arr['buy_price']['n_int'] = 1;
}
}else{
if(empty($value['buy_price'])){
$neq_m_arr['buy_price']['neq'] = 1;
}else{
$g_arr['im_buy_price'] = $value['buy_price'];
}
}
if((!empty($excel_arr[$value['goods_no']]['is_putaway']) || $excel_arr[$value['goods_no']]['is_putaway'] == 0) && !empty($excel_arr[$value['goods_no']]['is_putaway_text'])){ //上下架
if(!empty($value['is_putaway']) || $value['is_putaway'] ==0){
$m_arr['is_putaway']['ct'] = 1;
}
}else{
if(empty($value['is_putaway']) && $value['is_putaway'] != 0){
$neq_m_arr['is_putaway']['neq'] = 1;
}else{
$g_arr['im_is_putaway'] = $value['is_putaway'];
}
}
if((!empty($excel_arr[$value['goods_no']]['is_defective']) || $excel_arr[$value['goods_no']]['is_defective'] == 0) && !empty($excel_arr[$value['goods_no']]['is_defective_text'])){ //是否残次
if(!empty($value['is_defective']) || $value['is_defective'] ==0){
$m_arr['is_defective']['ct'] = 1;
}
}else{
$g_arr['im_is_defective'] = $value['is_defective'];
}
if(!empty($excel_arr[$value['goods_no']]['buyer']) && !empty($excel_arr[$value['goods_no']]['buyer_text'])){ //买手
if(!empty($value['buyer'])){
$m_arr['buyer']['ct'] = 1;
}
}else{
if(empty($value['buyer'])){
$neq_m_arr['buyer']['neq'] = 1;
}else{
$g_arr['im_buyer'] = $value['buyer'];
}
}
if(!empty($excel_arr[$value['goods_no']]['supplier_id']) && !empty($excel_arr[$value['goods_no']]['supplier_id_text'])){ //供应商
if(!empty($value['supplier_id'])){
$m_arr['supplier_id']['ct'] = 1;
}
}else{
if(empty($value['supplier_id'])){
$neq_m_arr['supplier_id']['neq'] = 1;
}else{
$g_arr['im_supplier_id'] = $value['supplier_id'];
}
}
if(!empty($excel_arr[$value['goods_no']]['bathch'])){ //批次
if(!empty($value['bathch'])){
$m_arr['bathch']['ct'] = 1;
}
}else{
if(!empty($value['bathch'])){
$g_arr['im_bathch'] = $value['bathch'];
}
}
if(!empty($excel_arr[$value['goods_no']]['goods_param'])){ //参数
$goods_param = unserialize($value['goods_param']);
if(!empty($value['goods_param'])){
$m_arr['goods_param']['ct'] = 1;
}
}else{
if(!empty($value['goods_param'])){
$g_arr['im_goods_param'] = $value['goods_param'];
}
}
if(!empty($excel_arr[$value['goods_no']]['state']) && !empty($excel_arr[$value['goods_no']]['state_text'])){ //商品状态
if(!empty($value['state'])){
$m_arr['state']['ct'] = 1;
}
}else{
if(empty($value['state'])){
$neq_m_arr['state']['neq'] = 1;
}else{
$g_arr['im_state'] = $excel_arr[$value['goods_no']]['state'];
}
} if(!empty($m_arr)){
$msg_arr[$value['goods_no']] = $m_arr;
}
if(!empty($neq_m_arr)){
$neq_msg_arr[$value['goods_no']] = $neq_m_arr;
}
$goods_excel[$value['spec_id']] = $g_arr;
$data_excel_goods[$value['goods_id']][$value['goods_no']] = $excel_arr[$value['goods_no']]['crazy_price'];
}
if(!empty($msg_arr)){
$m_edit_goods = M('edit_goods');
$w_edit_goods['operator'] = $operator;
if($m_edit_goods->where($w_edit_goods)->delete()!==false){
$data = $goods_excel;
sort($data);
//导入表与既存商品价格不一致时,给出提示并整张表不可导。
foreach ($data_excel_goods as $key => $value) {
if(isset($data_price[$key])){
$price_diff[$key] = $data_excel_goods[$key]+$data_price[$key];
}
}
foreach ($price_diff as $k => $v) {
if(count(array_unique($price_diff[$k])) > 1){
$this->error('商品ID'.$k.'所属SKU价格不一致');
}
}
if($m_edit_goods->addAll($data)===false){
$this->error('上传失败,创建备份失败!');
}
}else{
$this->error('上传失败,清除历史备份失败!');
}
}
$yz_arr = array(
'ct'=>array(
'cate'=>'分类',
'goods_name'=>'商品名称',
'size'=>'尺寸',
'color'=>'颜色',
'crazy_price'=>'疯狂价',
'shop_price'=>'柜台价',
'buy_price'=>'进货价',
'is_putaway'=>'上下架',
'is_defective'=>'残次品',
'buyer'=>'买手',
'supplier_id'=>'供应商',
'bathch'=>'批次',
'goods_param'=>'商品参数',
'state'=>'商品状态'
),
'neq'=>array(
'cate'=>'分类',
'goods_name'=>'商品名称',
'crazy_price'=>'疯狂价',
'shop_price'=>'柜台价',
'buy_price'=>'进货价',
'is_putaway'=>'上下架',
'buyer'=>'买手',
'supplier_id'=>'供应商',
'state'=>'商品状态'
),
'n_int'=>array(
'crazy_price'=>'疯狂价',
'shop_price'=>'柜台价',
'buy_price'=>'进货价'
)
);
$this->assign('yz_arr',$yz_arr);
$this->assign('msg_arr',$msg_arr);
$this->assign('neq_msg_arr',$neq_msg_arr);
$this->assign('neq_price_arr',$neq_price_arr);
$this->assign('goods_excel',$goods_excel);
$this->assign('e_goods',$e_goods);
$this->assign('import_id',$import_id);
$this->display();
}
}
excle导入的更多相关文章
- Springboot Excle导入导出
Springboot Excle导入导出 导入操作:Excle批量导入 导出操作:下载模版 开发笔记 pom.xml <!-- Excle相关jar --> <dependency& ...
- POI实现大数据EXCLE导入导出,解决内存溢出问题
使用POI能够导出大数据保证内存不溢出的一个重要原因是SXSSFWorkbook生成的EXCEL为2007版本,修改EXCEL2007文件后缀为ZIP打开可以看到,每一个Sheet都是一个xml文件, ...
- EXCLE 导入 或 导出
首先要引用 NPOI.dll (可在网上下载!)//导入public void OnSubmit() { string path = Server.MapPat ...
- ssm中实现excle导入导出
1 pom.xml <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-oox ...
- .net core ajax使用EPPlus上传excle导入总结
前端 <form class="layui-form" id="div_imp" style="display:none;"> ...
- Excle 导入DataSet
using System.Data.OleDb;using System.Data; public void ReadExcelFiless() { //strin ...
- org.apache.poi3.1.7 Excle并发批量导入导出
org.apache.poi3.1.7 升级,需要修改设置方式: 1.org.apache.poi3.1.4 的设置单元格: XSSFCellStyle cellStyle = wb.createCe ...
- 项目积累——JAVA知识积累
调用天气: <iframe src="http://www.thinkpage.cn/weather/weather.aspx?uid=&c=CHXX0008&l=zh ...
- POI使用 (4.0) 常用改动
POI 升级到高版本后,原有的EXCLE导入导出工具类部分代码已不适用,目前只是对我自己写的工具类的过期代码进行更新,以后继续更新 若有问题请指出,再修改 1.数据类型 Cell.CELL_TYPE_ ...
随机推荐
- UI控件之ListView
一,一个简单的TextView列表 public class FirstActivity extends Activity { private String[] data = {"Apple ...
- 对Java Serializable(序列化)的理解和总结
我对Java Serializable(序列化)的理解和总结 博客分类: Java技术 JavaOSSocketCC++ 1.序列化是干什么的? 简单说就是为了保存在内存中的各种对象的状 ...
- CO-类的本质、description方法
类的本质 1. 类也是个对象 其实类也是一个对象,是Class类型的对象,简称“类对象” Class类型的定义 typedef struct objc_class *Class; 类名就代表着类对象 ...
- python mysql
mysql Linux 安装mysql: apt-get install mysql-server 安装python-mysql模块:apt-get install python-mysqldb Wi ...
- CSS3导航效果
来自codepen http://codepen.io/mouradhamoud/pen/RRvVZp <!DOCTYPE html> <html> <head> ...
- SQL having 子句
1.为什么存在? 在 SQL 中增加 HAVING 子句原因是,WHERE 关键字无法与合计函数一起使用. 2.举例子: SELECT Customer,SUM(OrderPrice) FROM Or ...
- strtr函数的用法
http://php.net/manual/en/function.strtr.php <?php $trans = array("h" => "-" ...
- thinkphp伪静态(url重写)
1. 服务器开启url_rewrite功能,linux空间的php虚拟主机只需要开启apache的mod_rewriet,如果是iis6.0就要安装ISAPI Rewrite模块,apache只要开启 ...
- Linux鲜为人知的安全漏洞:不要将输出内容管道给你的shell
将wget或curl输出的内容管道给bash或者sh是一件非常愚蠢的事,例如像下面这样: wget -O - http://example.com/install.sh | sudo sh 命令解释: ...
- 字符编码-UNICODE,GBK,UTF-8区别【转转】
字符编码介绍及不同编码区别 今天看到这篇关于字符编码的文章,抑制不住喜悦(总结的好详细)所以转到这里来.转自:祥龙之子http://www.cnblogs.com/cy163/archive/2007 ...