load->database(); $this->table = 'specialstock'; $this->load_table('specialstock'); } public function get_features($features) { return $this->find("features = '$features'"); } public function get_supplier($supplier) { return $this->find("supplier = '$supplier'"); } public function get_sku($sku) { return $this->find("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,$whlabel,$oldwhlabel='',$number)//库存验证 提交订单时验证 { /** if($oldwhlabel == $whlabel && $state == $oldstate)//如果没有改变仓库和产品和状态直接返回通过 { return array('t'=>0);exit; } **/ if(stripos($whlabel,'z|') === false && stripos($oldwhlabel,'z|') === false)//如果新老产品都不含特殊库存 { return array('t'=>0);exit; } if(!$whlabel || $whlabel == '|') { return array('t'=>0);exit; } //先预先判断开始,否则清除数据后造成库存错误 if(stripos($whlabel,'z|') !== false && ($state == '207' || $state == '209'))//待发货状态 { $pp = explode('|',trim($whlabel,'|')); $x = 0;$save = array(); foreach ($pp as $va) { $x++; $num = explode('-',$va); if(stripos($num[2],'z') !== false)//如果是特殊库存 { $wh = $this->specialstock->find_count("state = '0' and number = '$num[0]' and (zd = '$number' or zd = '')");//通用 if($wh < $num[1]) { $save[] = $x-1;continue;//提前先加X不然出错,所以要减1 } } } if(isset($save[0]))//非预设仓库提醒 { return array('t'=>1,'m'=>json_encode(array('t'=>2,'msg'=>"红色商品名库存匹配错误或库存不够扣减",'error'=>$save,'success'=>false)));exit; } } $this->db->trans_begin(); //预先判断结束 //if($oldwhlabel != $whlabel || $state != $oldstate) //{ $wl = $this->specialstock->find_all("zd = '$number'");//查找是否有占用库存情况features if($wl)//如果有那么清除所有占用 { $i = 0; foreach ($wl as $v) { $this->specialstock->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(stripos($whlabel,'z|') !== false && isset($pp[0]) && ($state == '207' || $state == '209')) { foreach ($pp as $va) { $num = explode('-',$va); if(stripos($num[2],'z') !== false)//如果是特殊库存 { $whlabel = $this->specialstock->find_all("state = '0' and number = '$num[0]' and zd = ''");//通用 $xzkc = $this->specialstock->read(rtrim($num[2],'z'));//选择的这个库存 if($xzkc['zd'] != '') { return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'所选库存已被占单!请重新打开选择页面','oldwarehouse'=>$oldwarehouse-1,'success'=>false)));exit; } $this->specialstock->save(array('zd'=>$number,'zdlist'=>date('Y-m-d H:i:s',time())),rtrim($num[2],'z'));//通用 for($i=0;$i<$num[1]-1;$i++) { $this->specialstock->save(array('zd'=>$number,'zdlist'=>date('Y-m-d H:i:s',time())),$whlabel[$i]['id']);//通用 } } } } if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); return array('t'=>0);exit; } else { $this->db->trans_rollback(); return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'库存操作错误,请重试!','oldwarehouse'=>$oldwarehouse-1,'success'=>false)));exit; } } } //end class