load->library('session'); $this->load->_model('Model_allocation','allocation'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_warehouse','warehouse'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'list') { $this->_list(); } else if($arg == 'add')//添加 { $this->_add(); } else if($arg == 'edit')//修改 { $this->_edit($arg_array); } else if($arg == 'del')//修改 { $this->_del(); } 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); $ktime = $this->input->post('ktime',true); $jtime = $this->input->post('jtime',true); $cwarehouse = $this->input->post('cwarehouse',true); $type = $this->input->post('type',true); $order = $this->input->post('order',true); $ktime = strtotime($ktime); $jtime = strtotime($jtime)+24*3600; $where = "1=1 "; if($cwarehouse) { $where .= " and cwarehouse = '$cwarehouse'"; } if($type) { $where .= " and type = '$type'"; } if($order) { $where .= " and order = '$order'"; } if($ktime && $jtime) { $where .= " and addtime > '$ktime' and addtime < '$jtime'"; } //数据排序 $order_str = "id asc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->allocation->find_all($where,'id, order,title,cwarehouse,rwarehouse,addtime,name,type',$order_str,$start,$perpage); foreach ($info_list as $key=>$value) { 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'] = "已调入"; } else if($value['type'] == 4) { $info_list[$key]['type'] = "已结束"; } $cwarehouse = $this->warehouse->read($value['cwarehouse']); $info_list[$key]['cwarehouse'] = $cwarehouse['title']; $rwarehouse = $this->warehouse->read($value['rwarehouse']); $info_list[$key]['rwarehouse'] = $rwarehouse['title']; $info_list[$key]['addtime'] = date('Y-m-d',$value['addtime']); } $total = $this->allocation->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('allocation',$this->data); } //管理 public function _list() { $post = $this->input->post(NULL, TRUE); if(isset($post['page'])) { $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $ktime = $this->input->post('ktime',true); $jtime = $this->input->post('jtime',true); $cwarehouse = $this->input->post('cwarehouse',true); $type = $this->input->post('type',true); $order = $this->input->post('order',true); $ktime = strtotime($ktime); $jtime = strtotime($jtime)+24*3600; $where = "1=1 "; if($cwarehouse) { $where .= " and cwarehouse = '$cwarehouse'"; } if($type) { $where .= " and type = '$type'"; } if($order) { $where .= " and order = '$order'"; } if($ktime && $jtime) { $where .= " and addtime > '$ktime' and addtime < '$jtime'"; } //数据排序 $order_str = "id asc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->allocation->find_all($where,'id, order,title,cwarehouse,rwarehouse,addtime,name,type,time',$order_str,$start,$perpage); foreach ($info_list as $key=>$value) { if($value['type'] == 1) { $info_list[$key]['type'] = "未调出"; $info_list[$key]['time'] = "

订单已调出

"; } else if($value['type'] == 2) { $info_list[$key]['type'] = "已调出"; $info_list[$key]['time'] = "

订单已调入

"; } else if($value['type'] == 3) { $info_list[$key]['type'] = "已调入"; $info_list[$key]['time'] = "

订单已验收

"; } else if($value['type'] == 4) { $info_list[$key]['type'] = "已结束"; $info_list[$key]['time'] = "

"; } $cwarehouse = $this->warehouse->read($value['cwarehouse']); $info_list[$key]['cwarehouse'] = $cwarehouse['title']; $rwarehouse = $this->warehouse->read($value['rwarehouse']); $info_list[$key]['rwarehouse'] = $rwarehouse['title']; $info_list[$key]['addtime'] = date('Y-m-d',$value['addtime']); } $total = $this->allocation->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('allocation_list',$this->data); } //添加 public function _add() { $post = $this->input->post(NULL, TRUE); if(isset($post['title'])) { $post['title'] = $this->input->post('title',true); $post['name'] = $this->input->post('name',true); $time = $this->input->post('time',true); $post['time'] = strtotime($time); $post['cwarehouse'] = $this->input->post('cwarehouse',true); $post['rwarehouse'] = $this->input->post('rwarehouse',true); $post['order'] = date('Ymd',time()).rand(100,999); $user = $this->user->get_api($_SESSION['api']); $post['name'] = $user['name']; $post['type'] = 1; $post['addtime'] = time(); if($post['cwarehouse'] == $post['rwarehouse']) { echo json_encode(array('msg'=>'调入仓库和调出仓库不能相同!','success'=>false));exit; } if($this->allocation->insert($post)) { echo json_encode(array('msg'=>'添加成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit; } } $class = $this->typeclass->find_all('classid = 200'); $this->data['class'] = $class; $this->_Template('allocation_add',$this->data); } //修改 public function _edit($arg_array) { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); $a = $this->allocation->read($id); if($a['type'] == 1) { $type = 2; $z = "已调出"; $c = "订单已调入"; } else if($a['type'] == 2) { $type = 3; $z = "已调入"; $c = "订单已验收"; } else if($a['type'] == 3) { $type = 4; $z = "已结束"; $c = ""; } if($this->allocation->save(array('type'=>$type),$id)) { echo json_encode(array('msg'=>'修改成功','z'=>$z,'c'=>$c,'id'=>$id,'success'=>true));exit; } else { echo json_encode(array('msg'=>'修改失败,请重试','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->allocation->remove($v); } echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true)); } } }