load->library('session');
$this->load->_model('Model_commodity','commodity');
$this->load->_model('Model_commodityread','commodityread');
$this->load->_model('Model_shop','shop');
$this->load->_model('Model_apismt','apismt');
$this->load->_model('Model_typeclass','typeclass');
$this->load->_model('Model_commodityread_del','commodityreaddel');
}
//定义方法的调用规则 获取URI第二段值
public function _remap($arg,$arg_array)
{
if($arg == 'aeorder')//同步
{
$this->_aeorder();
}
else if($arg == 'edit')//修改
{
$this->_edit($arg_array);
}
else if($arg == 'batchedit')//批量修改
{
$this->_batchedit();
}
else if($arg == 'skuedit')//修改
{
$this->_skuedit($arg_array);
}
else
{
$this->_index();
}
}
//管理
public function _index()
{
$dt = 0;
if(isset($_SESSION['api']))
{
$user = $this->user->get_api($_SESSION['api']);
$usp = $user;
$fgshop = "";$sid = "";
$usersp = explode('|',trim($user['shop'],'|'));
foreach ($usersp as $value)
{
$fgshop .= " shop = ".$value." or";
$sid .= " id = ".$value." or";
}
}
$post = $this->input->post(NULL, TRUE);
if(isset($post['page']))
{
$page = $this->input->post('page',true);
$perpage = $this->input->post('perpage',true);
$shop = $this->input->post('shop',true);
$productid = $this->input->post('productid',true);
$title = $this->input->post('title',true);
$type = $this->input->post('type',true);
$code = $this->input->post('code',true);
$skuid = $this->input->post('skuid',true);
$category = $this->input->post('category',true);
$categorytypeclass = $this->typeclass->get_titleclassid($category,16);
$where = "1=1 and (".rtrim($fgshop,'or').")";
if($shop)
{
$where .= " and shop = '$shop'";
}
if($productid)
{
$where .= " and productid = '$productid'";
}
if($title)
{
$where .= " and title like '%$title%'";
}
if($type)
{
$where .= " and type = '$type'";
}
if($category)
{
$where .= " and category like '%".$categorytypeclass['id']."%'";
}
if($code)
{
$u = $this->commodityread->get_sku($code);
$u = $u['productid'];
$where .= " and productid = '$u'";
}
if($skuid)
{
$u = $this->commodityread->get_skuid($skuid);
$u = $u['productid'];
$where .= " and productid = '$u'";
}
//数据排序
$order_str = "time desc";
if(empty($page))
{
$start = 0;
$perpage = 1;
}
else
{
$start = ($page - 1)*$perpage;
}
//取得信息列表
$info_list = $this->commodity->find_all($where,'id,shop,productid,img,title,category,time',$order_str,$start,$perpage);
//格式化数据
foreach ($info_list as $key=>$v)
{
$shop = $this->shop->read($v['shop']);
$info_list[$key]['shop'] = $shop['shopname'];
$info_list[$key]['img'] = "";
$category = '';
if($v['category'])
{
$v['category'] = explode(',',trim($v['category'],','));
foreach ($v['category'] as $vv)
{
$typeclass = $this->typeclass->read($vv);
$category .= "
".$typeclass['title']."
"; } $info_list[$key]['category'] = $category; } else { $info_list[$key]['category'] = ''; } $info_list[$key]['time'] = ""; } $total = $this->commodity->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; } $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or')); $this->data['wlshop'] = $wlshop; $this->_Template('commodity',$this->data); } //修改 public function _edit($arg_array) { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); $category = $this->input->post('category',true); $data = $this->input->post('data'); if($data) { $data = explode('|',rtrim($data,'|')); foreach ($data as $v) { $d = explode('@',$v); $this->commodityread->save(array('sku'=>$d[1]),$d[0]); } } if($this->commodity->save(array('category'=>','.$category),$id)) { echo json_encode(array('msg'=>'操作成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit; } } $arg_array = $arg_array[0]; $commodity = $this->commodity->read($arg_array); $this->data['commodity'] = $commodity; $sku = $this->commodityread->find_all('productid = '.$commodity['productid']); $this->data['sku'] = $sku; $this->_Template('commodity_edit',$this->data); } public function _batchedit_b()//老系统形式,保留,不用 { $dictionaries = $this->typeclass->find_all('ae!= "" and (classid=13 or classid=22 or classid=8 or classid=15 or classid=27 or classid=25 or classid=26 or classid=18 or classid=14 or classid=9 or classid=12 or classid=10 or classid=6)'); //产品人发类型颜色 $dtc = array();$ctd = array(); foreach ($dictionaries as $v) { if(stripos($v['spare'],'|') !== false)//如果有多个值 { $v['spare'] = explode('|',$v['spare']); foreach ($v['spare'] as $vs) { $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'title'=>$v['title'],'id'=>$v['id']); } } else { $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'title'=>$v['title'],'id'=>$v['id']); } $ctd[$v['id']] = $v['title']; } $ctd[126] = 'Hair Weaving'; $ctd[127] = 'Closure'; $ctd[128] = 'Wigs'; $ctd[130] = 'Clip-in Full Head'; $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); $ndata = $this->input->post('data',true); $id = explode(',',rtrim($id,',')); $data = explode('-',rtrim($ndata,'-')); $rows = array(); foreach ($id as $val) { //a:颜色 b:密度 c:头路设计 $u = $this->commodityread->read($val); $u['codeid'] = strtolower($u['codeid']); $u['codeid'] = str_replace(array('stretched length','inches','& '),array('length','',''),$u['codeid']); $sku = explode(';',rtrim($u['codeid'],';')); $codeid = array();$whlabel = ''; $fpdata = ''; foreach ($sku as $v) { $va = explode(':',$v); $codeid[$va[0]] = $va[1]; } $num = '';$ti = '';$tit = '';$error = '';$i = 1; foreach ($data as $k=>$v) { if($v == 'a') { if(isset($codeid['color']) && isset($dtc[$codeid['color']])) { $num .= $dtc[$codeid['color']]['id'].'-'; $ti .= $dtc[$codeid['color']]['title'].' '; } else { $num .= '57-'; $ti .= 'Natural Black '; } } else if($v == 'b') { if(isset($codeid['density']) && isset($dtc[$codeid['density']])) { $num .= $dtc[$codeid['density']]['id'].'-'; $ti .= $dtc[$codeid['density']]['title'].' '; } else { $num .= '71-'; $ti .= '150% '; } } else if($v == 'c') { if(isset($codeid['part design']) && isset($dtc[$codeid['part design']])) { $num .= $dtc[$codeid['part design']]['id'].'-'; $ti .= $dtc[$codeid['part design']]['title'].' '; } else { $num .= '75-'; $ti .= 'Free Part '; } } else { if($i == 2) { $num .= $v.'-id-'; } else { $num .= $v.'-'; } $ti .= $ctd[$v].' '; } $i++; } if(stripos($codeid['length'],'closure') !== false && stripos($ndata,'127') !== false) { $v = preg_replace(array('/([\s\S]*)closure/','/([\s\S]*)closure\s/'),array('',''),$codeid['length']); $v = preg_replace('/([\s]*)/','',$v); $fpdata = $dtc[$v]['id'].',-'.str_replace('id-','',$num).'|'.$ti.$v.'inch |1|0.00|0.00|'.$v.'|0.00|0.00;'; $tit = ''.$ti.$v.'inch
'; $whlabel = '|'.str_replace(array('-','id'),array('',$dtc[$v]['id']),$num).'-1'; } else { $codeid['length'] = explode(' ',$codeid['length']); foreach ($codeid['length'] as $v) { if(is_numeric($v)) { $fpdata .= $dtc[$v]['id'].',-'.str_replace('id-','',$num).'|'.$ti.$v.'inch |1|0.00|0.00|'.$v.'|0.00|0.00;'; $tit .= ''.$ti.$v.'inch
'; $whlabel .= '|'.str_replace(array('-','id'),array('',$dtc[$v]['id']),$num).'-1'; } else { break; } } } $fa = '';$wl = ''; $u['fpdata'] = explode(';',rtrim($u['fpdata'],';')); $u['whlabel'] = explode('|',trim($u['whlabel'],'|')); for($i=0;$i