123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704 |
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class Weight extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->load->library('session');
- $this->load->_model('Model_weight','weight');
- $this->load->_model('Model_typeclass','typeclass');
- $this->load->_model('Model_excel','excel');
- }
- //定义方法的调用规则 获取URI第二段值
- public function _remap($arg,$arg_array)
- {
- if($arg == 'add')//添加
- {
- $this->_add();
- }
- else if($arg == 'edit')//修改
- {
- $this->_edit($arg_array);
- }
- else if($arg == 'del')//修改
- {
- $this->_del();
- }
- else if($arg == 'cx')
- {
- $this->_cx();
- }
- else if($arg == 'weight')
- {
- $this->_weight();
- }
- else if($arg == 'excel')//修改
- {
- $this->_excel();
- }
- else if($arg == 'drexcel')//修改
- {
- $this->_drexcel($arg_array);
- }
- else if($arg == 'mb')//修改
- {
- $this->_mb();
- }
- else
- {
- $this->_index();
- }
- }
- //管理
- public function _index()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['page']))
- {
- $page = $this->input->post('page',true);
- $perpage = $this->input->post('perpage',true);
- $sku = $this->input->post('sku',true);
- $title = $this->input->post('title',true);
- $features = $this->input->post('category',true);
- $where = "1=1 ";
- if($features)
- {
- $where .= " and features like '%$features-%'";
- }
- if($sku)
- {
- $where .= " and sku like '%$sku%'";
- }
- if($title)
- {
- $where .= " and title like '%$title%'";
- }
- //数据排序
- $order_str = "id asc";
- if(empty($page))
- {
- $start = 0;
- $perpage = 1;
- }
- else
- {
- $start = ($page - 1)*$perpage;
- }
- //取得信息列表
- $info_list = $this->weight->find_all($where,'id,title,sku,weight',$order_str,$start,$perpage);
- foreach ($info_list as $key=>$value)
- {
- $info_list[$key]['weight'] = $value['weight'].'克';
- }
- $total = $this->weight->find_count($where);
- $pagenum = ceil($total/$perpage);
- $over = $total-($start+$perpage);
- $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
- echo json_encode($rows);exit;
- }
- $this->_Template('weight',$this->data);
- }
- //添加
- public function _add()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['weight']))
- {
- $list = array();$num = "";$title = "";
- $post['weight'] = $this->input->post('weight',true);
- $category = $this->input->post('category',true);
- $list['category'] = $category;
- $list['hairtype'] = $this->input->post('hairtype',true);
- $list['grade'] = $this->input->post('grade',true);
- $size = $this->input->post('size',true);
- $list['size'] = rtrim($size,',');
- $list['hairnumber'] = $this->input->post('hairnumber',true);
- $list['extension'] = $this->input->post('extension',true);
- if($category == 1297)
- {
- $list['sywignumber'] = $this->input->post('sywignumber',true);
- }
- if($category == 1702)
- {
- $list['syhairnumber'] = $this->input->post('syhairnumber',true);
- $list['syother'] = $this->input->post('syother',true);
- }
- if($category == 133)
- {
- $list['fittype'] = $this->input->post('fittype',true);
- $list['acother'] = $this->input->post('acother',true);
- }
- $list['color'] = $this->input->post('color',true);
- $list['lowe'] = $this->input->post('lowe',true);
-
- if($category == 127)
- {
- $list['type'] = $this->input->post('type',true);
- $list['headroad'] = $this->input->post('headroad',true);
- $list['density'] = $this->input->post('density',true);
- if($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199)
- {
- $list['lacesize'] = $this->input->post('lacesize',true);
- }
- $list['lacecolor'] = $this->input->post('lacecolor',true);
- $list['lacetypes'] = $this->input->post('lacetypes',true);
- }
- if($category == 128)
- {
- $list['lacetype'] = $this->input->post('lacetype',true);
- $list['haircap'] = $this->input->post('haircap',true);
- $list['density'] = $this->input->post('density',true);
- $list['lacecolor'] = $this->input->post('lacecolor',true);
- $list['lacetypes'] = $this->input->post('lacetypes',true);
- $list['wigother'] = $this->input->post('wigother',true);
- }
- if($category == 129)
- {
- $list['wide'] = $this->input->post('wide',true);
- }
-
- if($category == 131)
- {
- $list['gifttype'] = $this->input->post('gifttype',true);
- $list['giftother'] = $this->input->post('giftother',true);
- }
-
- if($category == 134)
- {
- $list['pieceweight'] = $this->input->post('pieceweight',true);
- }
- if($category == 1297)
- {
- $list['synthetictype'] = $this->input->post('synthetictype',true);
- $list['sywigother'] = $this->input->post('sywigother',true);
- }
- if($category == 130 || $category == 133 || $category == 1702)
- {
- $list['items'] = $this->input->post('items',true);
- }
- if($category == 1702)
- {
- $list['syhairther'] = $this->input->post('syhairther',true);
- }
- foreach($list as $k=>$v)
- {
- if($v != 0)
- {
- $num .=$v.'-';
- $post[$k] = $v;
- $typeclass = $this->typeclass->read($v);
- $title = $title.$typeclass['title']." ";
- }
- }
- $post['sku'] = rtrim($num,'-');
- $post['title'] = rtrim($title,' ');
- $rows = $this->weight->get_title($title);
- if(!$rows)
- {
- $this->weight->insert($post);
- echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'添加失败,有重复数据','success'=>false));exit;
- }
- }
- $this->_Template('weight_add',$this->data);
- }
- //修改
- public function _edit($arg_array)
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['id']))
- {
- $list = array();$num = "";$title = "";
- $id = $this->input->post('id',true);
- $data = $this->weight->read($id);
- foreach($data as $k=>$v)
- {
- $post[$k] = 0;
- }
- $post['id'] = $id;
- $post['sku'] = $this->input->post('sku',true);
- $post['weight'] = $this->input->post('weight',true);
- $category = $this->input->post('category',true);
- $list['category'] = $category;
- $list['hairtype'] = $this->input->post('hairtype',true);
- $list['grade'] = $this->input->post('grade',true);
- $size = $this->input->post('size',true);
- $list['size'] = rtrim($size,',');
- $list['hairnumber'] = $this->input->post('hairnumber',true);
- $list['extension'] = $this->input->post('extension',true);
- if($category == 1297)
- {
- $list['sywignumber'] = $this->input->post('sywignumber',true);
- }
- if($category == 1702)
- {
- $list['syhairnumber'] = $this->input->post('syhairnumber',true);
- $list['syother'] = $this->input->post('syother',true);
- }
- if($category == 133)
- {
- $list['fittype'] = $this->input->post('fittype',true);
- $list['acother'] = $this->input->post('acother',true);
- }
- $list['color'] = $this->input->post('color',true);
- $list['lowe'] = $this->input->post('lowe',true);
-
- if($category == 127)
- {
- $list['type'] = $this->input->post('type',true);
- $list['headroad'] = $this->input->post('headroad',true);
- $list['density'] = $this->input->post('density',true);
- if($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199)
- {
- $list['lacesize'] = $this->input->post('lacesize',true);
- }
- $list['lacecolor'] = $this->input->post('lacecolor',true);
- $list['lacetypes'] = $this->input->post('lacetypes',true);
- }
- if($category == 128)
- {
- $list['lacetype'] = $this->input->post('lacetype',true);
- $list['haircap'] = $this->input->post('haircap',true);
- $list['density'] = $this->input->post('density',true);
- $list['lacecolor'] = $this->input->post('lacecolor',true);
- $list['lacetypes'] = $this->input->post('lacetypes',true);
- $list['wigother'] = $this->input->post('wigother',true);
- }
- if($category == 129)
- {
- $list['wide'] = $this->input->post('wide',true);
- }
-
- if($category == 131)
- {
- $list['gifttype'] = $this->input->post('gifttype',true);
- $list['giftother'] = $this->input->post('giftother',true);
- }
-
- if($category == 134)
- {
- $list['pieceweight'] = $this->input->post('pieceweight',true);
- }
- if($category == 1297)
- {
- $list['synthetictype'] = $this->input->post('synthetictype',true);
- $list['sywigother'] = $this->input->post('sywigother',true);
- }
- if($category == 130 || $category == 133 || $category == 1702)
- {
- $list['items'] = $this->input->post('items',true);
- }
- if($category == 1702)
- {
- $list['syhairther'] = $this->input->post('syhairther',true);
- }
- foreach($list as $k=>$v)
- {
- if($v != 0)
- {
- $num .=$v.'-';
- $post[$k] = $v;
- $typeclass = $this->typeclass->read($v);
- $title = $title.$typeclass['title']." ";
- }
- }
- $post['sku'] = rtrim($num,'-');
- $post['title'] = rtrim($title,' ');
- $rows = $this->weight->get_title($title);
- if(!$rows || $rows['id'] == $id)
- {
- $this->weight->save($post,$id);
- echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'修改失败,有重复数据','success'=>false));exit;
- }
- }
- $arg_array = $arg_array[0];
- $weight = $this->weight->read($arg_array);
- $this->data['weight'] = $weight;
- $this->_Template('weight_edit',$this->data);
- }
- //删除
- public function _del()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['s']))
- {
- $id_arr = $this->input->post('s');
- $id_arr = explode(',',$id_arr);
- if(!$id_arr)
- {
- echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
- }
- //循环删除记录
- foreach ($id_arr as $v)
- {
- $this->weight->remove($v);
- }
- echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
- }
- }
- //笛卡儿积
- function cp($ps,$sets,$list)
- {
- $result = array();$j=0;
- for($i=0,$count=count($sets); $i<$count-1; $i++)
- {
- if($i==0)
- {
- $result = $sets[$i];
- }
- $tmp = array();
- foreach($result as $res)
- {
- foreach($sets[$i+1] as $set)
- {
- $tmp[] = $res.','.$set;
- }
- }
- $result = $tmp;
- }
- $this->db->trans_begin();
- foreach ($result as $v)
- {
- $post = array();$title = "";$num="";
- $data = explode(',',$v);
- for($i=0;$i<count($list); $i++)
- {
- $post[$list[$i]] = $data[$i];
- $typeclass = $this->typeclass->read($data[$i]);
- $title = $title.$typeclass['title']." ";
- if($data[$i] != 0)
- {
- $num .=$data[$i];//所有数据ID拼接
- }
- }
- foreach ($ps as $kp=>$vp)
- {
- $post[$kp] = $vp;
- }
- $post['number'] = $num;
- $info_list = $this->weight->get_number($num);//查询weight是否存在此拼接的数据ID
- if($info_list)
- {
- $j++;
- }
- else
- {
- $skunum = $this->weight->find_count();
- $post['sku'] = 'LY'.substr(strval($skunum+1+10000000),1,7);
- $post['title'] = rtrim($title,' ');
- $this->weight->insert($post);
- }
-
- }
- if ($this->db->trans_status() === FALSE)
- {
- $this->db->trans_commit();
- return NULL;
- }
- else
- {
- $this->db->trans_commit();
- return $j;
- }
- }
-
- public function _weight()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['data']))
- {
- $data = $this->input->post('data');
- $list = explode('-',rtrim($data,'-'));
- $weight = '';$lssku = '';$sku = array();
- $weightdata = $this->weight->find_all();
- foreach ($weightdata as $w)
- {
- $sku[$w['sku']] = $w['weight'];
- }
- if(stripos($data,'126') !== false && isset($sku['126']))
- {
- $weight = $sku['126'];
- }
- else if(stripos($data,'127') !== false)
- {
- if(isset($list[8]))
- {
- $sku127a = $list[0].'-'.$list[2].'-'.$list[4].'-'.$list[5].'-'.$list[8];
- $sku127b = $list[0].'-'.$list[4].'-'.$list[5].'-'.$list[8];
- if(isset($sku[$sku127a]))
- {
- $weight = $sku[$sku127a];
- }
- else if(isset($sku[$sku127b]))
- {
- $weight = $sku[$sku127b];
- }
- else
- {
- $weight = 0;
- }
- }
- }
- else if(stripos($data,'128') !== false)
- {
- $sku128 = $list[0].'-'.$list[4].'-'.$list[5].'-'.$list[7];
- if(isset($sku[$sku128]))
- {
- $weight = $sku[$sku128];
- }
- else
- {
- $weight = 0;
- }
- }
- else if(stripos($data,'130') !== false || stripos($data,'133') !== false)
- {
- $sku130 = $list[0].'-'.$list[5].'-'.$list[4];
- if(isset($sku[$sku130]))
- {
- $weight = $sku[$sku130];
- }
- else
- {
- $weight = 0;
- }
- }
- else
- {
- $weight = 0;
- }
- echo json_encode(array('weight'=>$weight,'success'=>true));
- }
- }
-
- public function _cx()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['data']))
- {
- $weight = 0;
- $list = $this->input->post('data');
- $list = '-'.$list;
- $listarray = explode('-',trim($list,'-'));
- $tc = array();
- $typeclass = $this->typeclass->find_all();
- foreach ($typeclass as $v)
- {
- $tc[$v['id']] = $v;
- }
- $listarray = array_filter($listarray);
- $ttpx = array('128'=>'','18'=>'','14'=>'','10'=>'');
- $features = '';
- if(stripos($list,'-126-') !== false)
- {
- $features = $listarray[0];
- }
- else if(stripos($list,'-127-') !== false)
- {
- $features = $listarray[0].'-'.$listarray[8].'-'.$listarray[4];
- }
- else if(stripos($list,'-128-') !== false)
- {
- foreach ($listarray as $v)
- {
- if(isset($tc[$v]) && isset($ttpx[$tc[$v]['classid']]))
- {
- $ttpx[$tc[$v]['classid']] = $v;
- }
- }
- $features = '128'.implode("-",$ttpx);
- }
- else if(stripos($list,'-130-') !== false || stripos($list,'-133-') !== false)
- {
- $features = $listarray[0].'-'.$listarray[5].'-'.(isset($listarray[4])?$listarray[4]:'');
- }
- $data = $this->weight->get_features($features);
- if($data)
- {
- $weight = $data['weight'];
- }
- echo json_encode(array('weight'=>$weight,'success'=>true));
- }
- }
-
- public function _excel()
- {
- if(isset($_GET['excel']))
- {
- $where = "1=1";
- $features = $this->input->get('category',true);
- $sku = $this->input->get('sku',true);
- $title = $this->input->get('title',true);
- if($sku)
- {
- $where .= " and sku like '%$sku%'";
- }
- if($title)
- {
- $where .= " and title like '%$title%'";
- }
- if($features)
- {
- $where .= " and features like '%$features%'";
- }
- $order_str = "id asc";
- $list = array();
- $rows = $this->weight->find_all($where,'title,sku,weight');
- $title = "产品重量";
- $titlename = "<table border=1>
- <tr align='center'>
- <td>产品名称</td>
- <td>sku</td>
- <td>重量</td>
- </tr>
- </table>";
- $filename = $title.".xls";
- $tail = "";
- $this->excel->get_fz2($rows,$titlename,$filename,$tail);
- }
- }
-
- public function _mb()
- {
- $list = array();
- $rows = array();
- $title = "导入模板";
- $titlename = "<table border=1>
- <tr align='center'>
- <td>标签sku</td>
- <td>重量</td>
- </tr>
- </table>";
- $filename = $title.".xls";
- $tail = "";
- $this->excel->get_fz2($rows,$titlename,$filename,$tail);
-
- }
-
- public function _drexcel($arg_array)
- {
- $dir = '/data/excel/'.date('Ymd',time()).'/';
- $config['upload_path'] = '.'.$dir ;
- $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
- $config['allowed_types'] = 'xls|xlsx|csv';
- $config['max_size'] = 10240;
- $this->load->library('upload', $config);
- $this->upload->initialize($config);
- if ($this->upload->do_upload('userfile'))
- {
- $full_path = $dir.$this->upload->data('file_name');
- $fileName = '.' . $full_path;
- if (!file_exists($fileName))
- {
- echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
- }
- else
- {
- libxml_use_internal_errors(true);
- require_once "./data/excel/PHPExcel/IOFactory.php";
- $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
- $phpExcel->setActiveSheetIndex(0);// 设置为默认表
- $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
- $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
- $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
- ++$column;//如果列数大于26行
- $list = array();
- for ($i = 2; $i <= $row; $i++) // 行数循环
- {
- $data = array();
- for ($c = 'A'; $c != $column; $c++) // 列数循环
- {
- $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
- }
- $list[] = $data;
- }
- }
- $i = 0;$j = 0;$ed = array();
- foreach ($list as $key=>$value)
- {
- $tc = 0;
- $i = $key+1;
- $time = time();
- $post['sku'] = $value['0'];//SKU
- $post['weight'] = $value['1'];//重量
- $post['features'] = $arg_array[0].'-';
- $post['title'] = $arg_array[1].' ';
- $post['title'] = str_replace('%20',' ',$post['title']);
- $s = $this->weight->get_sku($post['sku']);
- if($s)
- {
- $ed[] = array($i.'行 - '.$value['0'].' - 此信息已存在!');
- $j++;
- continue;
- }
- $features = explode('-',trim($post['sku'],'-'));
- foreach ($features as $k=>$v)
- {
- /**
- if($k > 0 && is_numeric($v))
- {
- $v = $v.'inch';
- }
- **/
- $title = $this->typeclass->get_bq_sku($v);
- if(isset($title['id']))
- {
- $post['features'] .= $title['id'].'-';
- $post['title'] .= $v.' ';
- }
- else
- {
- $ed[] = array($i.'行 - '.$value['0'].' - 字典库中不存在此名称!');
- $j++;
- $tc = 1;
- break(1);
- }
- }
- if($tc == 1)
- {
- continue;
- }
- $post['title'] = trim($post['title'],' ');
- $post['title'] = str_replace('Hair Weaving-','',$post['title']);
- $post['features'] = trim($post['features'],'-');
- $f = $this->weight->get_features($post['features']);
- if($f)
- {
- $ed[] = array($i.'行 - '.$value['0'].' - 此信息已存在!');
- $j++;
- continue;
- }
- $this->weight->insert($post);
- }
- if($j > 0)
- {
- $tt = date('Ymd',time());
- $title = '导入错误信息-'.$tt;
- $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
- $tail = "\n";
- $filename = $title.".xls";
- $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
- $dir = '/data/excel/'.$time.'/';
- $file_name = 'error_'.$time.rand(1000,9999);
- if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
- $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
- fwrite($myfile,$ecl);
- fclose($myfile);
- $error = $dir.$file_name.'.xls';
- echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
- }
- }
- }
- }
|