| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Model_ck extends Lin_Model {	function __construct(){	parent::__construct();	$this->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;$i<count($shopwhlabel);$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'];						}						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
 |