| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class whlabelstockup extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');		$this->load->_model('Model_whlabel_stockup','whlabel_stockup');		$this->load->_model('Model_whlabel','whlabel');		$this->load->_model('Model_whlabeltransport','whlabeltransport');		$this->load->_model('Model_classid','classid');		$this->load->_model('Model_whlabel_qh','whlabel_qh');		$this->load->_model('Model_typeclass','typeclass');		$this->load->_model('Model_whlabel_type','whlabel_type');		$this->load->_model('Model_whlabel_bh','whlabel_bh');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_purchase','purchase');		$this->load->_model('Model_apiyy','apiyy');		$this->load->_model('Model_excel','excel');		$this->load->_model('Model_whlabel_bh_transfer','whlabel_bh_transfer');	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'count')        {             $this->_count();        }		else if($arg == 'xd')        {             $this->_xd($arg_array);        }		else if($arg == 'excel')        {             $this->_excel();        }		else		{			 $this->_index();		}    }	//管理	public function _index()	{		$wt = array();		$whlabel_type = $this->whlabel_type->find_all();		foreach ($whlabel_type as $v) 		{			$wt[$v['id']] = $v['title'];		}		$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);			$jm = $this->input->post('jm',true);			$text = $this->input->post('text',true);			$type = $this->input->post('type',true);			$repair = $this->input->post('repair',true);			$stockup = $this->input->post('stockup',true);			$outbound = $this->input->post('outbound',true);			$lacecolor = $this->input->post('lacecolor',true);			$category = $this->input->post('category',true);			$size = $this->input->post('size',true);			$grade = $this->input->post('grade',true);			$color = $this->input->post('color',true);			$lowe = $this->input->post('lowe',true);			$lacetype = $this->input->post('lacetype',true);			$haircap = $this->input->post('haircap',true);			$density = $this->input->post('density',true);			$where = "1=1";			if($lacecolor)            {                $where  .= " and features like '%-$lacecolor-%'";            }			if($lacetype)            {                $where  .= " and features like '%-$lacetype-%'";            }			if($category)            {                $where  .= " and features like '%-$category-%'";            }			if($size)            {                $where  .= " and features like '%-$size-%'";            }			if($grade)            {                $where  .= " and features like '%-$grade-%'";            }			if($color)            {                $where  .= " and features like '%-$color-%'";            }			if($lowe)            {                $where  .= " and features like '%-$lowe-%'";            }			if($haircap)            {                $where  .= " and features like '%-$haircap-%'";            }			if($density)            {                $where  .= " and features like '%-$density-%'";            }			if($sku)            {                $where  .= " and sku like '%$sku%'";            }			if($jm)            {                $where  .= " and jm = '$jm'";            }			if($text)            {                $where  .= " and text = '$text'";            }			if($type)            {                $where  .= " and type = '$type'";            }			if($repair != '')            {                $where  .= " and repair = '$repair'";            }			if($stockup != '')            {                $where  .= " and stockup = '$stockup'";            }			if($outbound != '')            {                $where  .= " and outbound = '$outbound'";            }            //数据排序            $order_str = "repair desc";//备货预警从大到小            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->whlabel_stockup->find_all($where,'id,sku,jm,us,uszt,cs,xc,type,st,seven,thirty,availableday,lackday,zd,repair,stockup,outbound,bhnum',$order_str,$start,$perpage);			foreach ($info_list as $key=>$value) 		    {				$data = $this->whlabel_stockup->read($value['id']);				 $bh = $this->whlabel_bh->find_all("sku = '".$data['bhsku']."' and features = '".$data['features']."' and time > '".(time()-7*24*3600)."'");				$info_list[$key]['sku'] = '<p>'.$value['sku'].'</p>';				foreach ($bh as $v) 		        {					$printnum = $this->whlabel_bh_transfer->get_number($v['number']);					if(isset($printnum['ctime11']) && $printnum['ctime11'] > 0)					{						continue;					}					$info_list[$key]['sku'] .= '<p style="color: #2084db;">'.date('Y-m-d',$v['time']).' 备货数量:'.$v['bhnum'].' 未入库</p>';									}				if($value['repair'] == 0)				{					$info_list[$key]['repair'] = '/';				}				else				{					$info_list[$key]['repair'] = '补货';				}				if($value['stockup'] == 0)				{					$info_list[$key]['stockup'] = '/';				}				else				{					$info_list[$key]['stockup'] = '备货';				}				if($value['outbound'] == 0)				{					$info_list[$key]['outbound'] = '正常';				}				else				{					$info_list[$key]['outbound'] = '异常';				}				if(isset($wt[$value['type']]))				{					$info_list[$key]['type'] = $wt[$value['type']];				}				else				{					$info_list[$key]['type'] = '未设置';				}				$info_list[$key]['cs'] = $value['us']+$value['uszt'];				$info_list[$key]['bhnum'] = '<p><input value="'.$value['bhnum'].'" name="xd" type="text" style="width:80%;margin:0 10%;padding:5px 0;border: 1px #ccc solid;font-size: 13px;text-align: center;color: #333;border-radius: 5px;"></p><p><b id="xf'.$key.'" class="xd">下单</b></p>';		    }		    $total = $this->whlabel_stockup->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('whlabelstockup',$this->data);	}	public function _count()	{		$c = array();		$time = time();		$typeclass = array();		$tc = $this->typeclass->find_all();		foreach ($tc as $v)		{			$typeclass[$v['id']] = $v;		}		$classid = $this->classid->sku();		$info_list = $this->whlabel->find_pc('warehouse=5','sku,purchase,features','*','id asc');		$this->db->truncate('whlabel_stockup');		$this->db->trans_begin();		$asd = 0;		foreach ($info_list as $key=>$value) 		{			$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$value['features']);			$features = explode('-',trim($features,'-'));			$pm = $classid;			$jm = $classid;			$bhsku = array();			$bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');			foreach($features as $k=>$v)			{				if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))				{					if($typeclass[$v]['bm'] != '')					{						$bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];					}				}				if($v != 0)				{					if($k != 'size')					{			            $title .= $typeclass[$v]['title']." ";					}					$bhsku[$typeclass[$v]['classid']] = $typeclass[$v]['bqsku'];					if(!isset($typeclass[$v]))					{						continue;					}					if(isset($pm[$typeclass[$v]['classid']]))					{						if(stripos($typeclass[$v]['zh'],'|') !== false)						{							$tz = explode('|',$typeclass[$v]['zh']);							$pm[$typeclass[$v]['classid']] = $tz[0];						}						else						{							$pm[$typeclass[$v]['classid']] = $typeclass[$v]['zh'];						}					}					if(isset($jm[$typeclass[$v]['classid']]))					{						$jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];												}			    }			}			$jm = array_filter($jm);			$zh = implode(" ",$pm);			$zh = str_replace('自然色 ','',trim($zh,' '));			$zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);			$zh = preg_replace("/\r\n|\r|\n/",'',$zh);//中文			$bhsku = array_filter($bhsku);//去除空值			$post['bhsku'] = implode("-",$bhsku);			$post['bm'] = '03'.implode("",$bmpx);						$post['features'] = $value['features'];			$post['title'] = $value['title'];			$post['sku'] = $value['sku'];			$post['jm'] = implode("-",$jm);//简码			$post['zh'] = $zh;			$post['us'] = $this->whlabel->find_count('state = 0 and warehouse = 5 and sku = "'.$value['sku'].'" and features = "'.$value['features'].'"');//美仓库存			$post['xc'] = $this->whlabel->find_count('state = 0 and warehouse = 13 and features = "'.$value['features'].'"');//许昌库存			$qh = $this->whlabel_qh->get_data($value['features'],date('Ym',$time));			if(isset($qh['num']))			{				if($post['us']+$post['xc'] < 1 && $qh['gxtime'] < date('Ymd',$time))				{					$this->whlabel_qh->save(array("num"=>$qh['num']+1,"gxtime"=>date('Ymd',$time)),$qh['id']);					$qh['num'] += 1;				}			}			else			{				$this->whlabel_qh->insert(array("sku"=>$value['sku'],"features"=>$value['features'],"num"=>0,"gtime"=>date('Ym',$time),"gxtime"=>date('Ymd',$time)));				$qh['num'] = 0;			}			$zt = $this->whlabeltransport->find_all('sku = "'.$value['sku'].'" and warehouse = 5 and features = "'.$value['features'].'" and cz = "0"');			$post['uszt'] = array_sum(array_column($zt,'num'));//在途库存			$post['type'] = $value['type'];//等级类型			//$post['text'] = $value['text'];//备注			$post['seven'] = $this->whlabel->find_count('sku = "'.$value['sku'].'" and features = "'.$value['features'].'" and outk > "'.($time-7*24*3600).'" and outk < "'.$time.'"');//7天出库			$post['st'] = $this->whlabel->find_count('sku = "'.$value['sku'].'" and features = "'.$value['features'].'" and outk > "'.($time-14*24*3600).'" and outk < "'.($time-7*24*3600).'"');//前7天出库			$post['thirty'] = $this->whlabel->find_count('sku = "'.$value['sku'].'" and features = "'.$value['features'].'" and outk > "'.($time-30*24*3600).'" and outk < "'.$time.'"');//30天出库			$post['zd'] = $this->whlabel->find_count('sku = "'.$value['sku'].'" and state = 0 and zd != "" and features = "'.$value['features'].'"');//占单数量			if($post['thirty'] > 0 && 30-$qh['num'] > 0)			{				$post['availableday'] = sprintf("%01.1f",($post['uszt']+$post['us']-$post['zd'])/($post['thirty']/(30-$qh['num'])));//预计可用天数			}			else			{				$post['availableday'] = sprintf("%01.1f",($post['uszt']-$post['zd']));			}			$post['lackday'] = $qh['num'];//本月缺货天数			$post['repair'] = '0';//是否需要补货			if($value['type'] > 0 && $value['type'] < 5 && $post['availableday'] < 40)			{				$post['repair'] = '1';//补货			}			$post['stockup'] = '0';			if(($post['uszt']+$post['xc']) < $post['thirty'])			{				$post['stockup'] = '1';//备货			}			$post['outbound'] = '0';//正常			if($post['seven'] > 0)			{				if($post['seven'] >= $post['seven']*2)				{					$post['outbound'] = '1';//异常				}			}			$bhnum = $post['thirty']/30*40-($post['uszt']+$post['us']-$post['zd']);//  30天出库/30天*40天-(在途+美仓-占单)			if($bhnum > 0)			{				$post['bhnum'] = $bhnum;			}			else			{			    $post['bhnum'] = 0;			}			$asd++;			$this->whlabel_stockup->insert($post);		}		if ($this->db->trans_status() === FALSE)		{    		$this->db->trans_rollback();		}		else		{    		$this->db->trans_commit();		}		echo $asd;	}		public function _xd($arg_array)	{		$tc = $this->typeclass->find_all();		$typeclass = array();		foreach ($tc as $v)		{			$tcjm[$v['id']] = array($v['jm'],$v['classid']);			$typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm'],'bqsku'=>$v['bqsku']);		}		$post = $this->input->post(NULL, TRUE);		if(isset($post['bhid']))		{			$id = $this->input->post('bhid',true);			$data = $this->whlabel_stockup->read($id);			$jm = $data['jm'];			$sku = $data['bhsku'];			$pm = $data['zh'];			$title = $data['title'];			$post['bm'] =  $data['bm'];			$post['features'] = $data['features'];						$post['num'] = $this->input->post('num',true);			$ztime = $this->input->post('ztime',true);			$post['ztime'] = strtotime($ztime);			$post['jm'] = $jm;			$post['sku'] = $sku;			$post['pm'] = $pm;			$post['title'] = $title;			if($ztime)			{			    $post['ztime'] = strtotime($ztime);			}			$time = time();			$post['time'] = $time;//操作时间			$post['printnum'] = $time;			$post['type'] = 0;			$post['number'] = date('YmdHis',time()).rand(100,999);			//传输料号开始			$lc = 0;			$lh = $this->apiyy->get_cjlp(array('jm'=>$post['jm'],'title'=>$post['title'],'zh'=>$post['pm'],'bm'=>$post['bm']));			if(isset($lh['Data'][0]))			{				if($lh['Data'][0]['m_isSucess'] != 1)				{					if($lh['Data'][0]['m_errorMsg'] != '料号 已存在,请重新输入!')					{						echo json_encode(array('msg'=>$lh['Data'][0]['m_errorMsg'],'bm'=>$post['bm'],'jm'=>$post['jm'],'success'=>false));exit;					}				}			}			else			{				echo json_encode(array('msg'=>'料号错误','cs'=>json_encode($lh),'success'=>false));exit;							}			if($this->whlabel_bh->insert($post))			{			    echo json_encode(array('msg'=>'添加成功','success'=>true));exit;			}			else			{				echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;			}		}		$w = $this->shop->find_all("yyid != ''");		$this->data['yyck'] = $w;		$whlabelstockup = $this->whlabel_stockup->read($arg_array[0]);		$this->data['whlabelstockup'] = $whlabelstockup ;		$this->data['num'] = $arg_array[1];		$purchase = $this->purchase->find_all("yyid != ''");		$this->data['purchase'] = $purchase;		$this->_Template('whlabelstockup_xd',$this->data);	}				public function _excel()    {		$user = $this->user->get_api($_SESSION['api']);		if($user)		{		    $fgshop = "";$sid = "";		    $user = explode('|',trim($user['shop'],'|'));			foreach ($user as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}		}		$post = $this->input->get(NULL, TRUE);		if(isset($post['a']))  		{			$sku = $this->input->get('sku',true);			$jm = $this->input->get('jm',true);			$text = $this->input->get('text',true);			$type = $this->input->get('type',true);			$repair = $this->input->get('repair',true);			$stockup = $this->input->get('stockup',true);			$outbound = $this->input->get('outbound',true);			$lacecolor = $this->input->get('lacecolor',true);			$category = $this->input->get('category',true);			$size = $this->input->get('size',true);			$grade = $this->input->get('grade',true);			$color = $this->input->get('color',true);			$lowe = $this->input->get('lowe',true);			$lacetype = $this->input->get('lacetype',true);			$haircap = $this->input->get('haircap',true);			$density = $this->input->get('density',true);			$where = "1=1";			if($lacecolor)            {                $where  .= " and features like '%-$lacecolor-%'";            }			if($lacetype)            {                $where  .= " and features like '%-$lacetype-%'";            }			if($category)            {                $where  .= " and features like '%-$category-%'";            }			if($size)            {                $where  .= " and features like '%-$size-%'";            }			if($grade)            {                $where  .= " and features like '%-$grade-%'";            }			if($color)            {                $where  .= " and features like '%-$color-%'";            }			if($lowe)            {                $where  .= " and features like '%-$lowe-%'";            }			if($haircap)            {                $where  .= " and features like '%-$haircap-%'";            }			if($density)            {                $where  .= " and features like '%-$density-%'";            }			if($sku)            {                $where  .= " and sku = '$sku'";            }			if($jm)            {                $where  .= " and jm = '$jm'";            }			if($text)            {                $where  .= " and text = '$text'";            }			if($type)            {                $where  .= " and type = '$type'";            }			if($repair != '')            {                $where  .= " and repair = '$repair'";            }			if($stockup != '')            {                $where  .= " and stockup = '$stockup'";            }			if($outbound != '')            {                $where  .= " and outbound = '$outbound'";            }            //数据排序            $order_str = "repair desc";//备货预警从大到小						$dowid = $this->input->get('a');			$wid = "";			if($dowid != "")			{				$id_arr =  explode(',',rtrim($dowid,','));				$wid  .= " id = 0 or";				foreach ($id_arr as $v) 		        {                    $wid  .= " id = '$v' or";                }				$wid = " and (".rtrim($wid,'or').")";			}						 $info_list = $this->whlabel_stockup->find_all($where.$wid,'id,sku,jm,us,uszt,cs,xc,type,st,seven,thirty,availableday,lackday,zd,repair,stockup,outbound,bhnum',$order_str);			foreach ($info_list as $key=>$value) 		    {				$data = $this->whlabel_stockup->read($value['id']);				 $bh = $this->whlabel_bh->find_all("sku = '".$data['bhsku']."' and features = '".$data['features']."' and time > '".(time()-7*24*3600)."'");				$info_list[$key]['sku'] = '<p>'.$value['sku'].'</p>';				foreach ($bh as $v) 		        {					$info_list[$key]['sku'] .= '<p style="color: #2084db;">'.date('Y-m-d',$v['time']).' 备货数量:'.$v['bhnum'].'</p>';				}				if($value['repair'] == 0)				{					$info_list[$key]['repair'] = '/';				}				else				{					$info_list[$key]['repair'] = '补货';				}				if($value['stockup'] == 0)				{					$info_list[$key]['stockup'] = '/';				}				else				{					$info_list[$key]['stockup'] = '备货';				}				if($value['outbound'] == 0)				{					$info_list[$key]['outbound'] = '正常';				}				else				{					$info_list[$key]['outbound'] = '异常';				}				if(isset($wt[$value['type']]))				{					$info_list[$key]['type'] = $wt[$value['type']];				}				else				{					$info_list[$key]['type'] = '未设置';				}				$info_list[$key]['cs'] = $value['us']+$value['uszt'];				unset($info_list[$key]['id']);		    }		}			$title = '预警及备货'.date('Y-m-d H:i',time());             $titlename = "<table border=1>            <tr>         <td>SKU</td><td>用友料号</td><td>美仓库存</td><td>在途</td><td>美仓库存+在途</td><td>许昌库存</td><td>等级</td><td>前周出库</td><td>近7天出库</td><td>近30天出库</td><td>预计可用天数</td><td>本月缺货</td><td>占单数量</td><td>补货预警</td><td>备货提醒</td><td>出库异常</td><td>需要备货</td>  </tr>            </table>";             $filename = $title.".xls"; 			$tail = "\n";            $this->excel->get_fz2($info_list,$titlename,$filename,$tail);	}}
 |