| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Bh extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');		$this->load->_model('Model_whlabel','whlabel');		$this->load->_model('Model_warehouse','warehouse');		$this->load->_model('Model_purchase','purchase');		$this->load->_model('Model_excel','excel');		$this->load->_model('Model_fullorder','fullorder');		$this->load->_model('Model_fullordertt','fullordertt');		$this->load->_model('Model_fullorder_smt','fullorder_smt');		$this->load->_model('Model_fullordersmt','fullordersmt');		$this->load->_model('Model_express','express');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_typeclass','typeclass');		$this->load->_model('Model_country','country');		$this->load->_model('Model_warehouse','warehouse');		$this->load->_model('Model_kdniao','kdniao');		$this->load->_model('Model_notice','notice');		$this->load->_model('Model_dhl','dhl');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_fullorderexcel','fullorderexcel');		$this->load->_model('Model_ljg','ljg');		$this->load->_model('Model_usps','usps');		$this->load->_model('Model_specialstock','specialstock');		$this->load->_model('Model_whlabellabel','whlabellabel');		$this->load->_model('Model_whlabelwz','whlabelwz');		$this->load->_model('Model_whlabelbarcode','whlabelbarcode');		$this->load->_model('Model_bh','bh');	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'xr')//在库标签        {             $this->_xr();        }		else if($arg == 'exceljs')        {             $this->_exceljs();        }		else if($arg == 'uck')        {             $this->_uck();        }		else		{			 $this->_index();		}    }	//进销存浏览	public function _index()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',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);			$sku = $this->input->post('sku',true);			$warehouse = $this->input->post('warehouse',true);			$usa = $this->input->post('usa',true);			$purchase = $this->input->post('purchase',true);			$lacetype = $this->input->post('lacetype',true);			$state = $this->input->post('state',true);			$px = $this->input->post('px',true);			$ktime = $this->input->post('ktime',true);			$jtime = $this->input->post('jtime',true);			//$ktime = strtotime($ktime);			//$jtime = strtotime($jtime);			$where = "1=1";$gj = "";$ck = "";			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($usa)            {				if(!$warehouse)				{                    $where  .= " and (warehouse = '5' or warehouse = '8')";				}            }			if($warehouse)            {                $where  .= " and warehouse = '$warehouse'";            }			if($purchase)            {                $where  .= " and purchase = '$purchase'";            }			if($state)            {                $where  .= " and state = '$state'";            }						if($ktime && $jtime)            {                $gj  = " and enter > '$ktime' and enter < '$jtime'";				$ck  = " and outk > '$ktime' and outk < '$jtime'";            }            //数据排序            if($px == 'ksts')			{				$order_str = "ksts asc,jybh desc";				$where .= " and jybh > 0";			}			else			{				$order_str = $px." desc";			}            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }			if($sku)            {                $where  .= " and sku like '%$sku%'";				$info_list = $this->bh->find_all($where,'id,sku,title,t1,t3,t7,t14,t30,t60,t90,jybh,ksts',$order_str,$start,$perpage);            }			else			{				$info_list = $this->bh->find_all($where,'id,sku,title,t1,t3,t7,t14,t30,t60,t90,jybh,ksts',$order_str,$start,$perpage);			}            foreach ($info_list as $key=>$value) 		    {				if($value['jybh'] == '0')				{					$info_list[$key]['jybh'] = '无';				}			}			$rows = array();$list = array();		    $total = count($this->bh->find_all($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('bh',$this->data);	}		//进销存浏览	public function _xr()//数据写入	{	    $this->db->query("delete from crowd_bh");		$post = $this->input->post(NULL, TRUE);		if(isset($_GET['xr']))  		{			$info_list = $this->whlabel->find_pc("warehouse = '5'",'sku','warehouse,sku,title,number');			$this->db->trans_begin();			foreach ($info_list as $key=>$value) 		    {				$c = $this->whlabel->find_count('warehouse = "5" and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and number = "'.$value['number'].'"');				$info_list[$key]['t1'] = 0;				$info_list[$key]['t3'] = 0;				$info_list[$key]['t7'] = 0;				$info_list[$key]['t14'] = 0;				$info_list[$key]['t30'] = 0;				$info_list[$key]['t60'] = 0;				$info_list[$key]['t90'] = 0;				$fullorder = $this->fullorder->find_all("whlabel like '%".$value['number']."%' and librarytime > '".(strtotime(date("Y-m-d",time()))-90*24*3600)."'",'whlabel,librarytime');				$fullordersmt = $this->fullordersmt->find_all("whlabel like '%".$value['number']."%' and librarytime > '".(strtotime(date("Y-m-d",time()))-90*24*3600)."'",'whlabel,librarytime');				$data = array_merge($fullorder,$fullordersmt);				foreach ($data as $val) 		        {					$dt = explode('|',trim($val['whlabel'],'|'));					foreach ($dt as $v) 		            {						$v = explode('-',$v);						if($v[0] == $value['number'])						{							if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-24*3600))							{								$info_list[$key]['t1'] += $v[1];							}							if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-3*24*3600))							{								$info_list[$key]['t3'] += $v[1];							}							if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-7*24*3600))							{								$info_list[$key]['t7'] += $v[1];							}							if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-14*24*3600))							{								$info_list[$key]['t14'] += $v[1];							}							if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-30*24*3600))							{								$info_list[$key]['t30'] += $v[1];							}							if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-60*24*3600))							{								$info_list[$key]['t60'] += $v[1];							}							if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-90*24*3600))							{								$info_list[$key]['t90'] += $v[1];							}						}					}									}				if($info_list[$key]['t30'] > 0)				{				    $mt = $info_list[$key]['t30']/30;				    $info_list[$key]['ksts'] = intval($c/$mt);				    $info_list[$key]['jybh'] = ($info_list[$key]['ksts'] < 30)?($info_list[$key]['t30'] - $c):0;				}				else				{					$info_list[$key]['ksts'] = 0;				    $info_list[$key]['jybh'] = 0;				}				$this->bh->insert($info_list[$key]);		    }			if ($this->db->trans_status() === TRUE)            {			    $this->db->trans_commit();			    echo 'OK';		    }		    else		    {			    $this->db->trans_rollback();			    echo 'orver';		    }		}	}		public function _exceljs()	{		if(isset($_GET['excel']))  		{			$page = $this->input->get('page',true);		    $perpage = $this->input->get('perpage',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);			$sku = $this->input->get('sku',true);			$warehouse = $this->input->get('warehouse',true);			$usa = $this->input->get('usa',true);			$purchase = $this->input->get('purchase',true);			$lacetype = $this->input->get('lacetype',true);			$state = $this->input->get('state',true);			$px = $this->input->get('px',true);			$ktime = $this->input->get('ktime',true);			$jtime = $this->input->get('jtime',true);			//$ktime = strtotime($ktime);			//$jtime = strtotime($jtime);			$where = "1=1";$gj = "";$ck = "";			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($usa)            {				if(!$warehouse)				{                    $where  .= " and (warehouse = '5' or warehouse = '8')";				}            }			if($warehouse)            {                $where  .= " and warehouse = '$warehouse'";            }			if($purchase)            {                $where  .= " and purchase = '$purchase'";            }			if($state)            {                $where  .= " and state = '$state'";            }						if($ktime && $jtime)            {                $gj  = " and enter > '$ktime' and enter < '$jtime'";				$ck  = " and outk > '$ktime' and outk < '$jtime'";            }            //数据排序			if($px == 'ksts')			{				$order_str = "ksts asc,jybh desc";				$where .= " and jybh > 0";			}			else			{				$order_str = $px." desc";			}            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }			if($sku)            {                $where  .= " and sku like '%$sku%'";				$info_list = $this->bh->find_all($where,'sku,title,t1,t3,t7,t14,t30,t60,t90,jybh,ksts',$order_str);            }			else			{				$info_list = $this->bh->find_all($where,'sku,title,t1,t3,t7,t14,t30,t60,t90,jybh,ksts',$order_str);			}			/**			foreach ($info_list as $key=>$value) 		    {				$warehouse = $this->warehouse->read($value['warehouse']);				$info_list[$key]['warehouse'] = $warehouse['title'];			}			**/			foreach ($info_list as $key=>$value) 		    {				if($value['jybh'] == '0')				{					$info_list[$key]['jybh'] = '无';				}			}            $title = "备货详情 ".date("Y-m-d",time());             $titlename = "<table border=1>            <tr align='center'>			<td>SKU</td>			<td>产品名称</td>			<td>昨天销量</td>			<td>3天销量</td>			<td>7天销量</td>			<td>14天销量</td>			<td>30天销量</td>			<td>60天销量</td>			<td>90天销量</td>			<td>建议备货</td>			<td>可售天数</td>            </tr>            </table>";             $filename = $title.".xls";			$tail = "";            $this->excel->get_fz2($info_list,$titlename,$filename,$tail);	    }	}		public function _uck()	{		if(isset($_GET['excel']))		{			$tc = array();			$typeclass = $this->typeclass->find_all();			foreach ($typeclass as $v) 		    {				$tc[$v['id']] = $v['zh'];			}			$data = array();$t = array();$rq = '';			$ts = strtotime(date("Y-m-d",time()))-strtotime(date("Y-m",time()));			$ts = $ts/(24*3600);			for($i=0;$i<$ts;$i++)			{				$t[] = date("Y-m-d",strtotime('-'.($ts-$i).' day'));				$rq .=  "<td>".date("Y-m-d",strtotime('-'.($ts-$i).' day'))."</td>";			}			$info_list = $this->whlabel->find_pc("warehouse = '5'",'sku','warehouse,sku,features');			foreach ($info_list as $k=>$v) 		    {				$features = explode('-',trim($v['features'],'-'));				if(!isset($features[3]) || !isset($features[4]))				{					continue;				}				$data[$k][0] = $tc[$features[0]];//类型				$data[$k][1] = ($features[3] != 57)?$tc[$features[3]]:'';//颜色,自然色不显示				$data[$k][2] = $tc[$features[4]];//曲度				$data[$k][3] = '';				if(isset($data[$k][1]))				{					$data[$k][3] .= $data[$k][1];				}				if(isset($data[$k][2]))				{					$data[$k][3] .= $data[$k][2];				}				if(isset($features[5]))				{					$data[$k][3] .= $tc[$features[5]];				}				if(isset($features[2]))				{					$data[$k][3] .= $tc[$features[2]];				}				//$data[$k][3] 颜色,曲度,头套种类,尺寸				$data[$k][4] = $v['sku'];				$data[$k][5] = $this->whlabel->find_count('sku = "'.$v['sku'].'" and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'" and (state = 0 or (state = 1 and outk > '.strtotime(date("Y-m",time())).'))');//月初库存				$data[$k][] = $this->whlabel->find_count('warehouse = "5" and sku = "'.$v['sku'].'" and state = 0 and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'"');//剩余库存				$data[$k][] = '';				$data[$k][] = '';				$byck = 0;				foreach ($t as $vv) 		        {					$sl = $this->whlabel->find_count('sku = "'.$v['sku'].'" and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'" and state = 1 and outk > '.strtotime($vv).' and outk < '.(strtotime($vv)+24*3600));					$data[$k][] = ($sl > 0)?'<b>'.$sl.'</b>':'';					$byck += $sl;				}				$data[$k][] = ($byck > 0)?$byck:'';			}			            $title = "详情 ".date("Y-m-d",time());            $titlename = "<table border=1>            <tr align='center'>			<td>类别</td>			<td>颜色</td>			<td>曲度</td>			<td>名称</td>			<td>SKU</td>			<td>月初库存</td>			<td>剩余库存</td>			<td>在途数量</td>			<td>预达日期</td>".			$rq			."<td>本月出库</td></tr>            </table>";             $filename = $title.".xls";			$tail = "";            $this->excel->get_fz2($data,$titlename,$filename,$tail);	    }	}}
 |