load->_model('Model_shop','shop'); $this->load->_model('Model_fullorder','fullorder'); $this->load->_model('Model_fullordertt','fullordertt'); $this->load->_model('Model_fullordersmt','fullordersmt'); $this->load->_model('Model_fullorderout','fullorderout'); $this->load->_model('Model_country','country'); $this->load->_model('Model_express','express'); $this->load->_model('Model_whlabel','whlabel'); $this->load->_model('Model_specialstock','specialstock'); $this->load->_model('Model_fullorderoutlist','fullorderoutlist'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'edit') { $this->_edit($arg_array); } else if($arg == 'cz') { $this->_cz($arg_array); } else if($arg == 'list') { $this->_list($arg_array); } else { $this->_index(); } } public function _index() { if(isset($_SESSION['api'])) { $user = $this->user->get_api($_SESSION['api']); $usp = $user; $fgshop = "";$sid = ""; $user = explode('|',trim($user['shop'],'|')); foreach ($user 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); $name = $this->input->post('name',true); $shop = $this->input->post('shop',true); $number = $this->input->post('number',true); $orderinfo = $this->input->post('orderinfo',true); $waybill = $this->input->post('waybill',true); $timetk = $this->input->post('timetkk',true); $timetj = $this->input->post('timetjj',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = "1 = 1"; if($timetk && $timetj) { $where .= " and stime > '$timetk' and stime < '$timetj'"; } if($name) { $where .= " and name = '$name'"; } if($shop) { $where .= " and shop = '$shop'"; } if($number) { $where .= " and number = '$number'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } if($waybill) { $where .= " and waybill = '$waybill'"; } //数据排序 $order_str = "stime desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->fullorderout->find_all($where,'id,shop,name,number,orderinfo,express,waybill,stime',$order_str,$start,$perpage); foreach ($info_list as $key=>$value) { $shop = $this->shop->read($value['shop']); $info_list[$key]['shop'] = $shop['shopname']; $express = $this->express->read($value['express']); $info_list[$key]['express'] = $express['servicename']; $info_list[$key]['stime'] = date('Y-d-m H:i:s',$value['stime']); } $total = $this->fullorderout->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; } if(isset($post['hq'])) { $label = $this->input->post('hq',true); $warehouse = $this->input->post('warehouse',true); if(!$label) { echo json_encode(array('msg'=>'输入信息不能为空!','success'=>false));exit; } $fullorder_name = 'fullorder';$outtype = 1; $y = $this->fullorder->get_waybill($label); if(!$y) { $y = $this->fullorder->get_number($label); if(!$y) { $fullorder_name = 'fullordersmt';$outtype = 1; $y = $this->fullordersmt->get_waybill($label); if(!$y) { $y = $this->fullordersmt->get_number($label); if(!$y) { echo json_encode(array('msg'=>'无此数据','success'=>false));exit; } } } } $y['stime'] = time(); unset($y['id']); $fpdata = explode(';',rtrim($y['fpdata'],';')); $y['fpdata'] = ''; foreach ($fpdata as $k=>$v) { $d = explode('|',$v); $c = $d[2]; for($i=0;$i<$c;$i++) { $d['2'] = 0; $d['3'] = ''; $y['fpdata'] .= implode("|",$d).';'; } } $whlabellist = '|'; $whlabel = explode('|',trim($y['whlabel'],'|')); foreach ($whlabel as $k=>$v) { $d = explode('-',$v); $c = $d[1]; for($i=0;$i<$c;$i++) { $d['1'] = 1; $whlabellist .= implode("-",$d).'|'; } } $y['whlabel'] = $whlabellist; $y['content'] = ''; if($this->fullorderout->insert($y)) { echo json_encode(array('msg'=>'添加成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit; } } $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or')); $this->data['wlshop'] = $wlshop; $this->_Template('fullorderout',$this->data); } public function _edit($arg_array) { if(isset($_SESSION['api'])) { $user = $this->user->get_api($_SESSION['api']); if($user['vip'] == 1) { $vip = 1; } else { $vip = 0; } } else { $vip = 0; } $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); $data = $this->fullorderout->read($id); $content = $this->input->post('content',true); $fpdata = $this->input->post('fpdata',true); $torderinfo = $this->input->post('torderinfo',true); $thexpress = $this->input->post('thexpress',true); $fpdata = preg_replace(array('/(\_+)/'),array(' '),$fpdata); $fpdata =str_replace(array(' |','| '),array('|','|'),$fpdata); $number = $this->input->post('number',true); $whlabel = $data['whlabel']; $whlabellist = explode('|',trim($whlabel,'|')); $fpdatalist = explode(';',rtrim($fpdata,';')); $asd = array(); $this->db->trans_begin(); foreach ($whlabellist as $k=>$v) { $list = $this->fullorderoutlist->get_u($number,$v,$k); if($list) { $read = explode('|',trim($fpdatalist[$k],'|')); $this->fullorderoutlist->save(array('content'=>$content,'fpdata'=>$fpdatalist[$k],'torderinfo'=>$torderinfo,'thexpress'=>$thexpress,'fd'=>$read[3]),$list['id']); } } $this->fullorderout->save(array('content'=>$content,'fpdata'=>$fpdata,'torderinfo'=>$torderinfo,'thexpress'=>$thexpress),$id); if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); echo json_encode(array('msg'=>'提交成功','id'=>$id,'asd'=>$whlabellist,'success'=>true));exit; } else { $this->db->trans_rollback(); echo json_encode(array('msg'=>'提交失败,请重试','success'=>false));exit; } } $arg_array = $arg_array[0];$fpdata = array(); $fullorder = $this->fullorderout->read($arg_array); $this->data['fullorder'] = $fullorder; $shop = $this->shop->read($fullorder['shop']); $this->data['shop'] = $shop['shopname']; $express = $this->express->read($fullorder['express']); $this->data['express'] = $express['servicename']; $country = $this->country->read($fullorder['country']); $this->data['country'] = $country['ename'];$f = array(); $whlabel = explode('|',trim($fullorder['whlabel'],'|')); $fpdata = explode(';',rtrim($fullorder['fpdata'],';')); foreach ($fpdata as $k=>$v) { $d = explode('|',$v); $d['w'] = $whlabel[$k]; $f[] = $d; } $this->data['fpdata'] = $f; $this->_Template('fullorderout_edit',$this->data); } public function _cz() { $post = $this->input->post(NULL, TRUE); if(isset($post['czid'])) { $time = time(); $czid = $this->input->post('czid',true); $whlabel = $this->input->post('whlabel',true); $number = $this->input->post('number',true); $x = $this->input->post('x',true); $data = $this->fullorderout->get_number($number); $fpdata = explode(';',rtrim($data['fpdata'],';')); $title = array(1=>'加入库存',2=>'退回国内',3=>'美仓销售',4=>'货物错误',5=>'待入库存'); $d = explode('|',$fpdata[$x]); $d[2] = $czid; $fpdata[$x] = implode("|",$d); $this->db->trans_begin(); $k = 0; if($czid == 1) { $k = explode('-',$whlabel); if($k[2] == 'z')//特殊库存 { $t = $this->specialstock->get_cxzd($k[0],$number); if($t) { $this->specialstock->save(array('state'=>0,'retreat'=>$time,'time'=>$time),$t['id']); $this->fullorderout->save(array('fpdata'=>implode(";",$fpdata).';'),$data['id']); } else { $d[2] = 5; $fpdata[$x] = implode("|",$d); $this->fullorderout->save(array('fpdata'=>implode(";",$fpdata).';'),$data['id']); } } else { $t = $this->whlabel->get_cxzd($k[0],$number); if($t) { $this->whlabel->save(array('state'=>0,'retreat'=>$time,'time'=>$time),$t['id']); $this->fullorderout->save(array('fpdata'=>implode(";",$fpdata).';'),$data['id']); } else { $d[2] = 5; $fpdata[$x] = implode("|",$d); $this->fullorderout->save(array('fpdata'=>implode(";",$fpdata).';'),$data['id']); } } $post = $data; $post['pzt'] = $d[2]; $post['fpdata'] = $fpdata[$x]; $post['whlabel'] = $whlabel; $post['time'] = time(); $post['num'] = $x; unset($post['id']); $this->fullorderoutlist->insert($post); if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); echo json_encode(array('msg'=>'操作成功!','id'=>$d[2],'title'=>$title[$d[2]],'x'=>$x,'success'=>true));exit; } else { $this->db->trans_rollback(); echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit; } } else { $post = $data; $post['pzt'] = $czid; $post['fpdata'] = $fpdata[$x]; $post['whlabel'] = $whlabel; $post['time'] = time(); $post['num'] = $x; unset($post['id']); $this->fullorderoutlist->insert($post); $this->fullorderout->save(array('fpdata'=>implode(";",$fpdata).';'),$data['id']); if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); echo json_encode(array('msg'=>'操作成功!','id'=>$czid,'title'=>$title[$czid],'x'=>$x,'success'=>true));exit; } else { $this->db->trans_rollback(); echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit; } } } } public function _list() { if(isset($_SESSION['api'])) { $user = $this->user->get_api($_SESSION['api']); $usp = $user; $fgshop = "";$sid = ""; $user = explode('|',trim($user['shop'],'|')); foreach ($user 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); $name = $this->input->post('name',true); $shop = $this->input->post('shop',true); $number = $this->input->post('number',true); $orderinfo = $this->input->post('orderinfo',true); $waybill = $this->input->post('waybill',true); $pzt = $this->input->post('pzt',true); $timetk = $this->input->post('timetkk',true); $timetj = $this->input->post('timetjj',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = "1 = 1"; if($timetk && $timetj) { $where .= " and stime > '$timetk' and stime < '$timetj'"; } if($name) { $where .= " and name = '$name'"; } if($shop) { $where .= " and shop = '$shop'"; } if($number) { $where .= " and number = '$number'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } if($waybill) { $where .= " and waybill = '$waybill'"; } if($pzt) { $where .= " and pzt = '$pzt'"; } //数据排序 $order_str = "stime desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->fullorderoutlist->find_all($where,'id,shop,pzt,number,fpdata,fd,stime',$order_str,$start,$perpage); foreach ($info_list as $key=>$value) { if($value['pzt'] == 1) { $info_list[$key]['pzt'] = '加入库存'; } else if($value['pzt'] == 2) { $info_list[$key]['pzt'] = '退回国内'; } else if($value['pzt'] == 3) { $info_list[$key]['pzt'] = '美仓销售'; } else if($value['pzt'] == 4) { $info_list[$key]['pzt'] = '货物错误'; } else if($value['pzt'] == 5) { $info_list[$key]['pzt'] = '待入库存'; } $shop = $this->shop->read($value['shop']); $info_list[$key]['shop'] = $shop['shopname']; $title = explode('|',trim($value['fpdata'],'|')); $info_list[$key]['fpdata'] = $title[1]; $info_list[$key]['stime'] = date('Y-d-m H:i:s',$value['stime']); } $total = $this->fullorderoutlist->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('fullorderoutlist',$this->data); } }