load->library('session'); $this->load->_model('Model_stock','stock'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_warehouse','warehouse'); $this->load->_model('Model_product','product'); $this->load->_model('Model_whlabel','whlabel'); } //定义方法的调用规则 获取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 == 'list') { $this->_list(); } 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); $category = $this->input->post('category',true); $grade = $this->input->post('grade',true); $size = $this->input->post('size',true); $lowe = $this->input->post('lowe',true); $color = $this->input->post('color',true); $where = "1=1 "; if($sku) { $where .= " and sku = '$sku'"; } if($category) { $where .= " and category = '$category'"; } if($grade) { $where .= " and grade = '$grade'"; } if($size) { $where .= " and size = '$size'"; } if($lowe) { $where .= " and lowe = '$lowe'"; } if($color) { $where .= " and color = '$color'"; } //数据排序 $order_str = "id asc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->stock->find_all($where,'id,warehouse,sku,title,znum,ynum',$order_str,$start,$perpage); foreach ($info_list as $key=>$value) { $warehouse = $this->warehouse->read($value['warehouse']); $info_list[$key]['warehouse'] = $warehouse['title']; } $total = $this->stock->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('stock',$this->data); } //添加 public function _add() { $post = $this->input->post(NULL, TRUE); if(isset($post['category'])) { $category = $this->input->post('category',true); $warehouse = $this->input->post('warehouse',true); $znum = $this->input->post('znum',true); $ynum = $this->input->post('ynum',true); $hairtype = explode(',',rtrim($this->input->post('hairtype',true),',')); $grade = explode(',',rtrim($this->input->post('grade',true),',')); $size = explode(',',rtrim($this->input->post('size',true),',')); $color = explode(',',rtrim($this->input->post('color',true),',')); $lowe = explode(',',rtrim($this->input->post('lowe',true),',')); $title = ""; $ps = array('warehouse'=>$warehouse,'znum'=>$znum,'ynum'=>$ynum); $rows = array(array($category),$hairtype,$grade,$size,$color,$lowe); $key = array('category','hairtype','grade','size','color','lowe'); if($category == 126 || $category == 131|| $category == 132) { $number = $this->cp($ps,$rows,$key); } else if($category == 127) { $type = $this->input->post('type',true); $headroad = explode(',',rtrim($this->input->post('headroad',true),',')); $density = explode(',',rtrim($this->input->post('density',true),',')); $lacesize = explode(',',rtrim($this->input->post('lacesize',true),',')); if($type == 195 || $type == 197 || $type == 199) { array_push($rows,array($type),$headroad,$density,$lacesize); array_push($key,'type','headroad','density','lacesize'); $number = $this->cp($ps,$rows,$key); } else { array_push($rows,array($type),$headroad,$density); array_push($key,'type','headroad','density'); $number = $this->cp($ps,$rows,$key); } } else if($category == 128) { $lacetype = $this->input->post('lacetype',true); $haircap = explode(',',rtrim($this->input->post('haircap',true),',')); $density = explode(',',rtrim($this->input->post('density',true),',')); array_push($rows,array($lacetype),$haircap,$density); array_push($key,'lacetype','haircap','density'); $number = $this->cp($ps,$rows,$key); } else if($category == 129) { $wide = explode(',',rtrim($this->input->post('wide',true),',')); array_push($rows,$wide); array_push($key,'wide'); $number = $this->cp($ps,$rows,$key); } else if($category == 130) { $weight = explode(',',rtrim($this->input->post('weight',true),',')); array_push($rows,$weight); array_push($key,'weight'); $number = $this->cp($ps,$rows,$key); } else if($category == 133) { $package = explode(',',rtrim($this->input->post('package',true),',')); $unitweight = explode(',',rtrim($this->input->post('unitweight',true),',')); array_push($rows,$package,$unitweight); array_push($key,'package','unitweight'); $number = $this->cp($ps,$rows,$key); } else if($category == 134) { $pieceweight = explode(',',rtrim($this->input->post('pieceweight',true),',')); array_push($rows,$pieceweight); array_push($key,'pieceweight'); $number = $this->cp($ps,$rows,$key); } if(isset($number)) { echo json_encode(array('msg'=>'成功!重复:'.$number['0'].' 条,无配置:'.$number['1'].'条','success'=>true));exit; } else { echo json_encode(array('msg'=>'提交失败,请重试','success'=>true));exit; } } $this->_Template('stock_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->stock->read($id); foreach($data as $k=>$v) { $post[$k] = 0; } $post['id'] = $id; $post['sku'] = $this->input->post('sku',true); $post['warehouse'] = $this->input->post('warehouse',true); $post['znum'] = $this->input->post('znum',true); $post['ynum'] = $this->input->post('ynum',true); $category = $this->input->post('category',true); $list['category'] = $category; $list['hairtype'] = $this->input->post('hairtype',true); $list['grade'] = $this->input->post('grade',true); $list['size'] = $this->input->post('size',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); } } else if($category == 128) { $list['lacetype'] = $this->input->post('lacetype',true); $list['haircap'] = $this->input->post('haircap',true); $list['density'] = $this->input->post('density',true); } else if($category == 129) { $list['wide'] = $this->input->post('wide',true); } else if($category == 130) { $list['weight'] = $this->input->post('weight',true); } else if($category == 133) { $list['package'] = $this->input->post('package',true); $list['unitweight'] = $this->input->post('unitweight',true); } else if($category == 134) { $list['pieceweight'] = $this->input->post('pieceweight',true); } foreach($list as $k=>$v) { if($v != 0) { $num .=$v; $post[$k] = $v; $typeclass = $this->typeclass->read($v); $title = $title.$typeclass['title']." "; } } $post['title'] = rtrim($title,' '); $post['number'] = $num; $rows = $this->stock->get_number($num); if(!$rows || $rows['id'] == $id) { $this->stock->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]; $stock = $this->stock->read($arg_array); $this->data['stock'] = $stock; $this->_Template('stock_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->stock->remove($v); } echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true)); } } //笛卡儿积 function cp($ps,$sets,$list) { $result = array();$j=0;$l=""; 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;$itypeclass->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->stock->get_number($num);//查询stock是否存在此拼接的数据ID if($info_list) { $j++; } else { $csku = $this->product->get_number($num); if($csku) { $post['sku'] = $csku['sku']; $post['title'] = rtrim($title,' '); $this->stock->insert($post); } else { $l++; } } } if ($this->db->trans_status() === FALSE) { $this->db->trans_commit(); return NULL; } else { $this->db->trans_commit(); return array('0'=>$j,'1'=>$l); } } //管理 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); $sku = $this->input->post('sku',true); $category = $this->input->post('category',true); $grade = $this->input->post('grade',true); $size = $this->input->post('size',true); $lowe = $this->input->post('lowe',true); $color = $this->input->post('color',true); $where = "1=1 "; if($sku) { $where .= " and sku = '$sku'"; } if($category) { $where .= " and category = '$category'"; } if($grade) { $where .= " and grade = '$grade'"; } if($size) { $where .= " and size = '$size'"; } if($lowe) { $where .= " and lowe = '$lowe'"; } if($color) { $where .= " and color = '$color'"; } //数据排序 $order_str = "id asc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } //取得信息列表 $info_list = $this->stock->find_all($where,'id,warehouse,sku,title,pieceweight,znum,ynum,number',$order_str,$start,$perpage); foreach ($info_list as $key=>$value) { $warehouse = $this->warehouse->read($value['warehouse']); $info_list[$key]['warehouse'] = $warehouse['title']; $n = $this->whlabel->find_count('sku = "'.$value['sku'].'"'); $info_list[$key]['pieceweight'] = $n; if($value['znum'] > $n) { if($value['ynum'] > $n) { $info_list[$key]['number'] = "".($value['znum']-$n).""; } else { $info_list[$key]['number'] = $value['znum']-$n; } } } $total = $this->stock->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('stock_list',$this->data); } }