load->database(); $this->table = 'whlabel'; $this->load_table('whlabel'); } public function get_supplier($supplier) { return $this->find("supplier = '$supplier'"); } public function get_sku($sku) { return $this->find("sku = '$sku'"); } public function get_cpid($cpid) { return $this->find("cpid = '$cpid'"); } public function get_features($features) { return $this->find("features = '$features'"); } public function get_warehousesku($warehouse,$sku) { return $this->find("warehouse = '$warehouse' and sku = '$sku'"); } public function get_enter($enter) { return $this->find("enter = '$enter'"); } public function get_number($number) { return $this->find("number = '$number'"); } public function get_cxzd($number,$zd) { return $this->find("number = '$number' and zd = '$zd'"); } public function get_numberout($number,$warehouse) { return $this->find("state = '0' and number = '$number' and warehouse = '$warehouse'"); } public function get_labelnumberout($shop,$number,$warehouse) { return $this->find("state = '0' and shop = '$shop' and number = '$number' and warehouse = '$warehouse' and zd = ''"); } public function get_labelnumberout_purchase($shop,$number,$warehouse,$purchase) { return $this->find("state = '0' and shop = '$shop' and number = '$number' and warehouse = '$warehouse' and purchase = '$purchase' and zd = ''"); } public function get_labelnumberout_purchase_nopur($shop,$number,$warehouse) { return $this->find("state = '0' and shop = '$shop' and number = '$number' and warehouse = '$warehouse' and zd = ''"); } public function get_numberret($number,$warehouse,$orderinfo,$waybill) { return $this->find("state = 1 and number = '$number' and warehouse = '$warehouse' and orderinfo = '$orderinfo' and waybill = '$waybill'"); } public function get_label($label) { return $this->find("label = '$label'"); } public function get_title($title) { return $this->find("title like '%$title%'"); } public function get_kcyz($number,$warehouse)//库存验证 检查库存是否充足----//这个判断和出库不一样! { $save = array();$x=0; $pp = explode('|',trim($number,'|')); foreach ($pp as $va) { $ckcg = 0; $num = explode('-',$va); for($i=0;$i<$num[1];$i++) { $whlabel = $this->get_numberout($num[0],$warehouse); if(!$whlabel) { $ckcg++; } } if($ckcg > 0) { $save[] = $x; } $x++; } if(count($save) > 0) { return $save; } else { return 1; } } public function get_kc($oldstate,$state,$zd,$ys,$warehouse,$whlabel,$features,$fpdatatitle,$number,$shop,$oldwarehouse=0,$oldwhlabel='')//库存验证 提交订单时验证 { //smt:edit-bcbz-readonly-customersmt_medit,dlz:edit-readonly-customer_medit //$aa = $this->whlabel->find_all("zd = '$number'");//过一天删除这个条件,过度用,下面aa也删除 //if($oldwarehouse == $warehouse && $oldwhlabel == $whlabel && $state == $oldstate)//如果没有改变仓库和产品和状态直接返回通过 //{ //return array('t'=>0);exit; //} if(!$whlabel || $whlabel == '|') { return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'请先添加产品信息!','oldwarehouse'=>$oldwarehouse-1,'success'=>false)));exit; } //先预先判断开始,否则清除数据后造成库存错误 if($zd == '1' && ($state == '207' || $state == '209'))//待发货状态 { $pp = explode('|',trim($whlabel,'|')); $features = explode('|',rtrim($features,'|')); $x = 0;$save = array(); //合并重复项开始 /** //已在SKU编辑中去重了 待观察这个可以去掉 $hbdata = array(); foreach ($pp as $va) { $num = explode('-',$va); if(!isset($hbdata[$num[0]])) { $hbdata[$num[0]] = array($num[0],$num[1]); } else { $hbdata[$num[0]][1] += $num[1]; } } $pp = array(); foreach ($hbdata as $va) { $pp[] = $va[0].'-'.$va[1]; } **/ //合并重复项结束 foreach ($pp as $va) { $num = explode('-',$va); $wh = $this->whlabel->find_count("state = '0' and number = '$num[0]' and warehouse = '$warehouse' and (zd = '$number' or zd = '') and (shop IS NULL or shop = '')");//通用 $shopwh = $this->whlabel->find_count("state = '0' and number = '$num[0]' and warehouse = '$warehouse' and (zd = '$number' or zd = '') and shop like '%,".$shop.",%'");//专属 $x++; if($wh+$shopwh < $num[1]) { $save[] = $x-1;continue;//提前先加X不然出错,所以要减1 } } if(isset($save[0]) && $ys == '0')//非预设仓库提醒 { return array('t'=>1,'m'=>json_encode(array('t'=>2,'msg'=>"红色商品名库存匹配错误或库存不够扣减",'oldwarehouse'=>$oldwarehouse-1,'error'=>$save,'success'=>false)));exit; } } if($zd == '1' && $state != '207' && $state != '209')//待发货状态 { return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'此状订单状态无法占用库存','success'=>false)));exit; } $this->db->trans_begin(); //预先判断结束 //if($oldwarehouse != $warehouse || $oldwhlabel != $whlabel || $state != $oldstate) //{ $wl = $this->whlabel->find_all("zd = '$number'");//查找是否有占用库存情况 if($wl)//如果有那么清除所有占用 { $i = 0; foreach ($wl as $v) { if($v['sku'] == 'Preset' && $v['state'] == '9') { $this->whlabel->remove($v['id']);//删除预设 $i++; } else { $this->whlabel->save(array('zd'=>''),$v['id']);//专属 $i++; } } if($i != count($wl)) { return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>"库存操作失败,请重试",'oldwarehouse'=>$oldwarehouse-1,'success'=>false)));exit; } } if(isset($save[0]) && $ys == '1' && ($state == '207' || $state == '209'))//预设库存增加库存 { foreach ($save as $v) { $time = time(); $pp[$v] = explode('-',$pp[$v]); for($i=0;$i<$pp[$v][1];$i++) { $this->whlabel->insert(array('purchase'=>1,'shop'=>'','sku'=>'Preset','state'=>9,'number'=>$pp[$v][0],'features'=>$features[$v],'title'=>$fpdatatitle[$v],'label'=>$time.rand(1000,9999),'enter'=>$time,'time'=>$time,'retreatwarehouse'=>$warehouse,'warehouse'=>$warehouse,'zd'=>$number)); } unset($pp[$v]); } } //} if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); } else { $this->db->trans_rollback(); return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'库存操作错误,请重试!','oldwarehouse'=>$oldwarehouse-1,'success'=>false)));exit; } $this->db->trans_begin(); if($zd == '1' && isset($pp[0]) && ($state == '207' || $state == '209')) { //$pp = explode('|',trim($whlabel,'|'));//预先判断已有这一步 foreach ($pp as $va) { $num = explode('-',$va); $whlabel = $this->whlabel->find_all("state = '0' and number = '$num[0]' and warehouse = '$warehouse' and zd = '' and (shop IS NULL or shop = '')");//通用 $shopwhlabel = $this->whlabel->find_all("state = '0' and number = '$num[0]' and warehouse = '$warehouse' and zd = '' and shop like '%,".$shop.",%'");//专属 if(count($shopwhlabel) > 0)//如果有专属库存 { if(count($shopwhlabel) >= $num[1]) { for($i=0;$i<$num[1];$i++) { $this->whlabel->save(array('zd'=>$number),$shopwhlabel[$i]['id']);//专属 } } else { for($i=0;$iwhlabel->save(array('zd'=>$number),$shopwhlabel[$i]['id']);//扣减专属 } for($i=0;$i<$num[1]-count($shopwhlabel);$i++) { $this->whlabel->save(array('zd'=>$number),$whlabel[$i]['id']);//扣减通用 } } } else { for($i=0;$i<$num[1];$i++) { $this->whlabel->save(array('zd'=>$number),$whlabel[$i]['id']);//通用 } } } } if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); return array('t'=>0); } else { $this->db->trans_rollback(); return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'库存操作错误,请重试!','oldwarehouse'=>$oldwarehouse-1,'success'=>false))); } } } //end class