load_table('setting'); $this->load->_model("Model_logic_ding","logic_ding"); } public function get_kcyz($state,$warehouse,$shop,$number,$whlabel,$fpdata)//库存验证 { $save = array();$x=0; $pp = explode('|',trim($number,'|')); if($warehouse['zd'] == 1 && $warehouse['bdck'] != '') { $n = 'get_'.$warehouse['bdck']; $y = $this->$n($state,$warehouse,$shop,$number,$whlabel,$fpdata,$yz=1); return $y; } } public function get_kc($state,$warehouse,$shop,$number,$whlabel,$fpdata)//库存操作开始 { if(!preg_match('/[0-9]/',$whlabel)) { return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'请先添加产品信息!','success'=>false)));exit; } $wl = $this->specialstock->find_all("zd = '$number'"); if($wl) { foreach ($wl as $v) { $this->specialstock->save(array('zd'=>''),$v['id']);//专属 } } //非待发货和客户待收货状态以及仓库不占单 if(($state != '207' && $state != '209') || $warehouse['zd'] == 0)//待发货状态 { $wlw = $this->whlabel->find_all("zd = '$number'"); if($wlw) { foreach ($wlw as $v) { $this->whlabel->save(array('zd'=>''),$v['id']);//专属 } } } $fhw = '|';$j = 0; $fd = explode(';',trim($fpdata,';')); $wcfpd = ''; $pp = explode('|',trim($whlabel,'|')); if($warehouse['bdck'] == 'specialstock' && ($state == '207' || $state == '209'))//特殊仓含特殊产品的不处理whlabel和fpdata 但需要状态符合 { foreach ($pp as $v) { if(stripos($v,$warehouse['hz']) === false) { $num = explode('-',$v); $fhw .= $num[0].'-'.$num[1].'-0|'; $cffpt = explode('|',trim($fd[$j],'|')); $cffpt[9] = 0; $wcfpd .= implode("|",$cffpt).';'; } else { $fhw .= $v.'|'; $wcfpd .= $fd[$j].';'; } $j++; } } else { foreach ($pp as $v) { $num = explode('-',$v); if(isset($num[2]) && $num[2] == 'DNOTO')//选择不占单的 { $fhw .= $v.'|'; $wcfpd .= $fd[$j].';'; } else { $fhw .= $num[0].'-'.$num[1].'-0|'; $cffpt = explode('|',trim($fd[$j],'|')); $cffpt[9] = 0; $wcfpd .= implode("|",$cffpt).';'; } $j++; } } $whlabel = $fhw; $fpdata = $wcfpd; if($warehouse['zd'] == 1 && $warehouse['bdck'] != '') { $n = 'get_'.$warehouse['bdck']; $z = $this->$n($state,$warehouse,$shop,$number,$whlabel,$fpdata); return $z;exit; } else { return array('t'=>0,'whlabel'=>$whlabel,'fpdata'=>$fpdata);exit; } } public function get_whlabel($state,$warehouse,$shop,$number,$whlabel,$fpdata,$yz=0) { //smt:edit-bcbz-readonly-customersmt_medit,dlz:edit-readonly-customer_medit if(!$whlabel || $whlabel == '|') { return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'请先添加产品信息!','success'=>false)));exit; } //先预先判断开始,否则清除数据后造成库存错误 if($state == '207' || $state == '209')//待发货状态 { $pp = explode('|',trim($whlabel,'|')); $cxsl = array();//产品数组化提供下面查询 foreach ($pp as $key=>$va) { $w = explode('-',$va); if(!isset($w[2])) { $w[2] = 0; } $cxsl[$key] = $w; } $x = 0;$save = array(); foreach ($pp as $key=>$va) { $num = explode('-',$va); if(!isset($num[2]) || isset($num[2]) && $num[2] != "DNOTO") { foreach ($cxsl as $k=>$v) { if($v[0] == $num[0] && $num[2] != "DNOTO" && $key != $k) { $num[1] += $v[1];//如果有相同产品并且未禁止占单,那么合并占单数量 } } } $wh = $this->whlabel->find_count("state = '0' and number = '$num[0]' and warehouse = '".$warehouse['id']."' 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['id']."' and (zd = '$number' or zd = '') and shop like '%,".$shop.",%'");//专属 $x++; if($wh+$shopwh < $num[1] || (isset($num[2]) && $num[2] == "DNOTO" && $warehouse['zdms'] == 2)) { //$this->logic_ding->sendToDing("库存验证数据【".$number."】".json_encode($num)."库存数量:".($wh+$shopwh)."仓库的占单模式".$warehouse['zdms']); $save[] = $x-1;continue;//提前先加X不然出错,所以要减1 } } //$this->logic_ding->sendToDing("库存验证数据2【".$number."】".json_encode($num)."库存数量:".($wh+$shopwh)."仓库的占单模式".$warehouse['zdms']."$".json_encode($save)); if(isset($save[0]) && $warehouse['zdms'] == 2) { return array('t'=>1,'m'=>json_encode(array('t'=>2,'msg'=>"红色商品名库存不够扣减或不允许占单",'error'=>$save,'hq'=>"state = '0' and number = '$num[0]' and warehouse = '".$warehouse['id']."' and (zd = '$number' or zd = '') and (shop IS NULL or shop = '')",'success'=>false)));exit; } if($yz == 0) { $z = $this->get_whlabel_zd($state,$warehouse,$shop,$number,$whlabel,$fpdata); return $z; } } else//订单状态不符合 { return array('t'=>0,'whlabel'=>$whlabel,'fpdata'=>$fpdata);exit; } } public function get_whlabel_zd($state,$warehouse,$shop,$number,$whlabel,$fpdata) { $fhw = '|'; $fpdata = explode(';',trim($fpdata,';')); $wcfpd = ''; $wlw = $this->whlabel->find_all("zd = '".$number."'"); if($state == '207' || $state == '209') { $x = 0; $pp = explode('|',trim($whlabel,'|')); $wzdid = '';$szdid = '';$wfcid = array(); foreach ($pp as $va) { $fhid = '';$DNOTO = 0; $num = explode('-',$va); if(isset($num[2]) && $num[2] == "DNOTO") { $DNOTO = 1; } $whlabel = $this->whlabel->find_all("state = '0' and number = '$num[0]' and warehouse = '".$warehouse['id']."' and (zd = '".$number."' or zd = '') and (shop IS NULL or shop = '')");//通用 $shopwhlabel = $this->whlabel->find_all("state = '0' and number = '$num[0]' and warehouse = '".$warehouse['id']."' and (zd = '".$number."' or zd = '') and shop like '%,".$shop.",%'");//专属 if(count($shopwhlabel) > 0 && $DNOTO < 1)//如果有专属库存 { if(count($shopwhlabel) >= $num[1]) { for($i=0;$i<$num[1];$i++) { $fhid .= $shopwhlabel[$i]['id'].$warehouse['hz'].'~'; //$this->whlabel->save(array('zd'=>$number),$shopwhlabel[$i]['id']);//专属 ~符号这里改验货也需要改 $wzdid .= 'id != '.$shopwhlabel[$i]['id'].' and '; $wfcid[] = $shopwhlabel[$i]['id']; } } else { for($i=0;$iwhlabel->save(array('zd'=>$number),$shopwhlabel[$i]['id']);//扣减专属 $wzdid .= 'id != '.$shopwhlabel[$i]['id'].' and '; $wfcid[] = $shopwhlabel[$i]['id']; } for($i=0;$i<$num[1]-count($shopwhlabel);$i++) { if(isset($whlabel[$i])) { $fhid .= $whlabel[$i]['id'].$warehouse['hz'].'~'; //$this->whlabel->save(array('zd'=>$number),$whlabel[$i]['id']);//扣减通用 $wzdid .= 'id != '.$whlabel[$i]['id'].' and '; $wfcid[] = $whlabel[$i]['id']; } } } $fhw .= $num[0].'-'.$num[1].'-'.rtrim($fhid,'~')."|"; $cffpt = explode('|',trim($fpdata[$x],'|')); $cffpt[9] = rtrim($fhid,'~'); $wcfpd .= implode("|",$cffpt).';'; } else if(count($whlabel) >= $num[1] && $DNOTO < 1) { for($i=0;$i<$num[1];$i++) { $fhid .= $whlabel[$i]['id'].$warehouse['hz'].'~'; //$this->whlabel->save(array('zd'=>$number),$whlabel[$i]['id']);//通用 $wzdid .= 'id != '.$whlabel[$i]['id'].' and '; $wfcid[] = $whlabel[$i]['id']; } $fhw .= $num[0].'-'.$num[1].'-'.rtrim($fhid,'~')."|"; $cffpt = explode('|',trim($fpdata[$x],'|')); $cffpt[9] = rtrim($fhid,'~'); $wcfpd .= implode("|",$cffpt).';'; } else { $fhw .= $va."|"; $wcfpd .= $fpdata[$x].';'; } $x++; } } $this->db->trans_begin(); if(isset($wlw[0])) { foreach ($wlw as $v) { $this->whlabel->save(array('zd'=>''),$v['id']);//专属 } } if($wzdid != '') { foreach ($wfcid as $v) { $this->whlabel->save(array('zd'=>$number),$v); } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'库存操作错误,请重试!','success'=>false))); } else { $this->db->trans_commit(); return array('t'=>0,'whlabel'=>$fhw,'fpdata'=>$wcfpd); } } public function get_specialstock($state,$warehouse,$shop,$number,$whlabel,$fpdata,$yz=0) { if(!$whlabel || $whlabel == '|' || stripos($whlabel,$warehouse['hz']) === false) { return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'请先添加特殊产品信息!','success'=>false)));exit; } //先预先判断开始,否则清除数据后造成库存错误 if($state == '207' || $state == '209')//待发货状态 { $pp = explode('|',trim($whlabel,'|')); $x = 0;$save = array(); foreach ($pp as $va) { $x++; $num = explode('-',$va); if(stripos($va,$warehouse['hz']) !== 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; } if($yz == 0) { $z = $this->get_specialstock_zd($state,$warehouse,$shop,$number,$whlabel,$fpdata); return $z; } } else//订单状态不符合 { return array('t'=>0,'whlabel'=>$whlabel,'fpdata'=>$fpdata);exit; } } public function get_specialstock_zd($state,$warehouse,$shop,$number,$whlabel,$fpdata) { $fpdata = explode(';',trim($fpdata,';')); $wcfpd = ''; $this->db->trans_begin(); $wl = $this->whlabel->find_all("zd = '".$number."'"); if($wl) { foreach ($wl as $v) { $this->whlabel->save(array('zd'=>''),$v['id']);//专属 } } if($state == '207' || $state == '209') { $fhw = array();$x = 0;$wzdid = ''; $pp = explode('|',trim($whlabel,'|')); foreach ($pp as $va) { $num = explode('-',$va); if(stripos($va,$warehouse['hz']) !== false) { $fhid = ''; $num = explode('-',$va); $whlabel = $this->specialstock->find_all("state = '0' and number = '$num[0]' and zd = ''");//通用 $fgzid = explode('~',trim($num[2],'~')); foreach ($fgzid as $vid) { $xzkc = $this->specialstock->read(rtrim($vid,$warehouse['hz']));//选择的这个库存 if($xzkc['zd'] != '') { return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'所选库存已被占单!请重新打开选择页面','success'=>false)));exit; } } for($i=0;$i<$num[1];$i++) { $fhid .= $whlabel[$i]['id'].$warehouse['hz'].'~'; $this->specialstock->save(array('zd'=>$number,'zdlist'=>date('Y-m-d H:i:s',time())),$whlabel[$i]['id']);//通用 $wzdid .= 'id != '.$whlabel[$i]['id'].' and '; } $fhw[] = $num[0].'-'.$num[1].'-'.rtrim($fhid,'~'); $cffpt = explode('|',trim($fpdata[$x],'|')); $cffpt[9] = rtrim($fhid,'~'); $wcfpd .= implode("|",$cffpt).';'; } else { $fhw[] = $va; $wcfpd .= $fpdata[$x].';'; } $x++; } $fhw = '|'.implode("|",$fhw).'|'; } if ($this->db->trans_status() === TRUE) { $this->db->trans_commit(); return array('t'=>0,'whlabel'=>$fhw,'fpdata'=>$wcfpd);exit; } else { $this->db->trans_rollback(); return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'库存操作错误,请重试!','success'=>false)));exit; } } //预先判断仓开始 public function get_yx_whlabel($state,$warehouse,$shop,$number,$whlabel,$fpdata)//通用仓 { $z = $this->get_whlabel($state,$warehouse,$shop,$number,$whlabel,$fpdata); return $z; } public function get_yx_specialstock($state,$warehouse,$shop,$number,$whlabel,$fpdata)//特殊仓 { $pp = explode('|',trim($whlabel,'|')); $fpdata = explode(';',trim($fpdata,';')); $wcfpd = '';$fhw = array(); $x = 0;$save = array(); $kytskc = array(); foreach ($pp as $k=>$va) { $num = explode('-',$va); $wh = $this->specialstock->find_count("state = '0' and number = '$num[0]' and zd = ''"); if(!isset($num[1])) { $num[1] = 1; } if($wh >= $num[1]) { $kytskc[] = $num[0].'-'.$num[1].'-z';//有可占用的 } else { $kytskc[] = $num[0].'-'.$num[1].'-0'; } } $y = 0; $this->db->trans_begin(); foreach ($kytskc as $va) { $num = explode('-',$va); if(stripos($va,$warehouse['hz']) !== false) { $whlabel = $this->specialstock->find_all("state = '0' and number = '$num[0]' and zd = ''");//通用 $fhid = ''; for($i=0;$i<$num[1];$i++) { $fhid .= $whlabel[$i]['id'].$warehouse['hz'].'~'; $this->specialstock->save(array('zd'=>$number,'zdlist'=>date('Y-m-d H:i:s',time())),$whlabel[$i]['id']);//通用 } $fhw[] = $num[0].'-'.$num[1].'-'.rtrim($fhid,'~'); $cffpt = explode('|',trim($fpdata[$x],'|')); $cffpt[9] = rtrim($fhid,'~'); $wcfpd .= implode("|",$cffpt).';'; $y++; } else { $fhw[] = $num[0].'-'.$num[1].'-0'; $wcfpd .= $fpdata[$x].';'; } $x++; } if($this->db->trans_status() === TRUE) { $this->db->trans_commit(); return array('t'=>0,'whlabel'=>"|".implode("|",$fhw)."|",'fpdata'=>$wcfpd);exit; } else { $this->db->trans_rollback(); return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'库存操作错误,请重试!','success'=>false)));exit; } } //预先判断仓结束 public function get_fl($hz,$whlabel,$fpdata)//特殊仓 { $sfxh = 0; if($hz != '') { $num = explode('|',trim($whlabel,'|')); $bh = substr_count($whlabel,$hz); if($bh == count($num)) { $sfxh = 1;//有现货 } } $f = explode(';',trim($fpdata,';')); //$fl = substr_count($fpdata,'Bob');//暂时不用这个,防止产品出现大小写不一致 $i = 0; foreach ($f as $v) { if(stripos($fpdata,'bob') !== false && (stripos($v,'bob') !== false || stripos($v,'wig') === false)) { $i++; } } if(count($f) == $i) { $type = $this->typeclass->get_type('37','BOBTYPE'); } else if(stripos($fpdata,'wig') !== false) { $type = $this->typeclass->get_type('37','WIGTYPE'); } else { $type = $this->typeclass->get_type('37','OTHERTYPE'); } $ckfl = $type['id']; return array('sfxh'=>$sfxh,'ckfl'=>$ckfl); } } //end class