load->library('session'); $this->load->_model('Model_purchaseorder','purchaseorder'); $this->load->_model('Model_purchase','purchase'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_express','express'); $this->load->_model('Model_country','country'); $this->load->_model('Model_productdescribe','productdescribe'); $this->load->_model('Model_customs','customs'); $this->load->_model('Model_detailed','detailed'); $this->load->_model('Model_productdescription','productdescription'); $this->load->_model('Model_logistics','logistics'); $this->load->_model('Model_hl','hl'); $this->load->_model('Model_excel','excel'); $this->load->_model('Model_warehouse','warehouse'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'add')//添加 { $this->_add(); } else if($arg == 'edit')//修改 { $this->_edit($arg_array); } else if($arg == 'price')//获取供应商价格表 { $this->_price(); } else if($arg == 'del')//修改 { $this->_del(); } else if($arg == 'describe') { $this->_describe(); } else if($arg == 'list') { $this->_list(); } else if($arg == 'monitor') { $this->_monitor(); } else if($arg == 'lssue') { $this->_lssue(); } 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); $purchase = $this->input->post('purchase',true);//供应商 $orderinfo = $this->input->post('orderinfo',true);//订单号 $type = $this->input->post('type',true);//订单状态 $ktime = $this->input->post('ktime',true); $jtime = $this->input->post('jtime',true); $ktime = strtotime($ktime); $jtime = strtotime($jtime); $where = "1=1"; if($purchase) { $where .= " and purchase = '$purchase'"; } if($ktime && $jtime) { $where .= " and addtime > '$ktime' and addtime < '$jtime'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } if($type) { $where .= " and type = '$type'"; } //数据排序 $order_str = "id desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->purchaseorder->find_all($where,'id,purchase,orderinfo,type,time,addtime,monitor',$order_str,$start,$perpage); //格式化数据 foreach ($info_list as $key=>$value) { $purchase = $this->purchase->read($value['purchase']); $info_list[$key]['purchase'] = $purchase['title']; if($value['type'] == 1) { $info_list[$key]['type'] = "待发货"; } else if($value['type'] == 2) { $info_list[$key]['type'] = "已发货"; } else if($value['type'] == 3) { $info_list[$key]['type'] = "已验收"; } $info_list[$key]['time'] = date('Y-m-d',$value['time']); $info_list[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']); if($value['monitor'] == 0) { $info_list[$key]['monitor'] = ""; } else { $info_list[$key]['monitor'] = date('Y-m-d H:i:s',$value['monitor']); } } $total = $this->purchaseorder->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->data['purchase'] = $this->purchase->find_all(); $this->_Template('purchaseorder',$this->data); } //管理 public function _list() { $this->_Template('purchaseorder_list',$this->data); } //添加 public function _add() { $post = $this->input->post(NULL, TRUE); if(isset($post['purchase'])) { $post['purchase'] = $this->input->post('purchase',true); $post['price'] = $this->input->post('price',true); $post['warehouse'] = $this->input->post('warehouse',true); $time = $this->input->post('time',true); $post['time'] = strtotime($time); $post['money'] = $this->input->post('money',true); $post['content'] = $this->input->post('content',true); $post['client'] = $this->input->post('client'); $post['name'] = $this->input->post('name',true); $post['phone'] = $this->input->post('phone',true); $post['country'] = $this->input->post('country',true); $post['province'] = $this->input->post('province',true); $post['city'] = $this->input->post('city',true); $post['zipcode'] = $this->input->post('zipcode',true); $post['street'] = $this->input->post('street',true); $post['address'] = $this->input->post('address',true); $post['express'] = $this->input->post('express',true); $post['product'] = $this->input->post('fpdata',true); $post['orderinfo'] = date('Ymd',time()).rand(100,999); $post['addtime'] = time(); if($this->purchaseorder->insert($post)) { echo json_encode(array('msg'=>'修改成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit; } } $country = $this->country->find_all('1=1','id,name');//所有国家信息 $this->data['country'] = $country; $purchase = $this->purchase->find_all('1=1','id,title'); $this->data['purchase'] = $purchase; $this->_Template('purchaseorder_add',$this->data); //$price = explode('|',trim($purchase['price'],'|'));//数组化权限内容 //$pricetitle = explode('|',trim($purchase['pricetitle'],'|'));//数组化权限内容 } //修改 public function _edit($arg_array) { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); $post['purchase'] = $this->input->post('purchase',true); $post['price'] = $this->input->post('price',true); $post['warehouse'] = $this->input->post('warehouse',true); $time = $this->input->post('time',true); $post['time'] = strtotime($time); $post['money'] = $this->input->post('money',true); $post['content'] = $this->input->post('content',true); $post['client'] = $this->input->post('client'); $post['name'] = $this->input->post('name',true); $post['phone'] = $this->input->post('phone',true); $post['country'] = $this->input->post('country',true); $post['province'] = $this->input->post('province',true); $post['city'] = $this->input->post('city',true); $post['zipcode'] = $this->input->post('zipcode',true); $post['street'] = $this->input->post('street',true); $post['address'] = $this->input->post('address',true); $post['express'] = $this->input->post('express',true); $post['product'] = $this->input->post('fpdata',true); if($this->purchaseorder->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]; $purchaseorder = $this->purchaseorder->read($arg_array); $country = $this->country->find_all('1=1','id,name');//所有国家信息 $this->data['purchaseorder'] = $purchaseorder; //获取供应商价格表开始 $data = $this->purchase->read($purchaseorder['purchase']); $priceid = explode('|',rtrim($data['price'],'|'));//数组内容 $pricetitle = explode('|',rtrim($data['pricetitle'],'|'));//数组内容 $price = array(); for($i=0;$i$priceid[$i],'title'=>$pricetitle[$i]); } //获取供应商价格表结束 $purchase = $this->purchase->find_all('1=1','id,title'); $this->data['purchase'] = $purchase; $this->data['price'] = $price; $this->data['country'] = $country; $fpdata = explode('*',rtrim($purchaseorder['product'],'*')); foreach ($fpdata as $k=>$v) { $fpdata[$k] = explode('|',$v); } $this->data['fpdata'] = $fpdata; $this->_Template('purchaseorder_edit',$this->data); } //查找供应商价格表 public function _price() { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); $data = $this->purchase->read($id); $priceid = explode('|',rtrim($data['price'],'|'));//数组内容 $pricetitle = explode('|',rtrim($data['pricetitle'],'|'));//数组内容 $price = array(); for($i=0;$i$priceid[$i],'title'=>$pricetitle[$i]); } echo json_encode(array('msg'=>($price),'success'=>true));exit; } } //查找商品价格 public function _describe() { $post = $this->input->post(NULL, TRUE); if(isset($post['data'])) { $data = $this->input->post('data'); $priceid = $this->input->post('priceid'); $data = explode('-',$data); $number = '';$num = count($data); //循环删除记录 for($i=0;$i<$num-1;$i++) { if($data[$i] != 0) { $number=$number.$data[$i]; if($i == 2) { $number=$number.$data[$num-1]; } } } $list = $this->productdescribe->get_price($priceid,$number); if($list) { echo json_encode(array('msg'=>($list),'n'=>$data[$num-1],'success'=>true)); } else { echo json_encode(array('msg'=>'此信息没有配置价格!','n'=>$data[$num-1],'success'=>false));exit; } } } //删除 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->purchaseorder->remove($v); } echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true)); } } //管理 public function _lssue() { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); if($this->purchaseorder->save(array('type'=>2,'lssue'=>time()),$id)) { echo json_encode(array('msg'=>'操作成功','id'=>$id,'success'=>true));exit; } else { echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit; } } if(isset($post['page'])) { $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $purchase = $this->input->post('purchase',true);//供应商 $orderinfo = $this->input->post('orderinfo',true);//订单号 $type = $this->input->post('type',true);//订单状态 $ktime = $this->input->post('ktime',true); $jtime = $this->input->post('jtime',true); $ktime = strtotime($ktime); $jtime = strtotime($jtime); $where = "1=1 and type = 1"; if($purchase) { $where .= " and purchase = '$purchase'"; } if($ktime && $jtime) { $where .= " and addtime > '$ktime' and addtime < '$jtime'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } if($type) { $where .= " and type = '$type'"; } //数据排序 $order_str = "id desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->purchaseorder->find_all($where,'id,purchase,orderinfo,type,time,addtime,currency',$order_str,$start,$perpage); //格式化数据 foreach ($info_list as $key=>$value) { $purchase = $this->purchase->read($value['purchase']); $info_list[$key]['purchase'] = $purchase['title']; if($value['type'] == 1) { $info_list[$key]['type'] = "待发货"; } else if($value['type'] == 2) { $info_list[$key]['type'] = "已发货"; } else if($value['type'] == 3) { $info_list[$key]['type'] = "已验收"; } $info_list[$key]['time'] = date('Y-m-d',$value['time']); $info_list[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']); $info_list[$key]['currency'] = "

标记为已发货

"; } $total = $this->purchaseorder->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->data['purchase'] = $this->purchase->find_all(); $this->_Template('purchaseorder_lssue',$this->data); } //管理 public function _monitor() { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); if($this->purchaseorder->save(array('type'=>3,'monitor'=>time()),$id)) { echo json_encode(array('msg'=>'操作成功','id'=>$id,'success'=>true));exit; } else { echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit; } } if(isset($post['page'])) { $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $purchase = $this->input->post('purchase',true);//供应商 $orderinfo = $this->input->post('orderinfo',true);//订单号 $type = $this->input->post('type',true);//订单状态 $ktime = $this->input->post('ktime',true); $jtime = $this->input->post('jtime',true); $ktime = strtotime($ktime); $jtime = strtotime($jtime); $where = "1=1 and type = 2"; if($purchase) { $where .= " and purchase = '$purchase'"; } if($ktime && $jtime) { $where .= " and addtime > '$ktime' and addtime < '$jtime'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } if($type) { $where .= " and type = '$type'"; } //数据排序 $order_str = "id desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->purchaseorder->find_all($where,'id,purchase,orderinfo,type,time,addtime,lssue,currency',$order_str,$start,$perpage); //格式化数据 foreach ($info_list as $key=>$value) { $purchase = $this->purchase->read($value['purchase']); $info_list[$key]['purchase'] = $purchase['title']; if($value['type'] == 1) { $info_list[$key]['type'] = "待发货"; } else if($value['type'] == 2) { $info_list[$key]['type'] = "已发货"; } else if($value['type'] == 3) { $info_list[$key]['type'] = "已验收"; } $info_list[$key]['time'] = date('Y-m-d',$value['time']); $info_list[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']); $info_list[$key]['lssue'] = date('Y-m-d H:i:s',$value['lssue']); $info_list[$key]['currency'] = "

标记为已验收

"; } $total = $this->purchaseorder->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->data['purchase'] = $this->purchase->find_all(); $this->_Template('purchaseorder_monitor',$this->data); } }