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'] = '
'.$value['sku'].'
'; 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'] .= ''.date('Y-m-d',$v['time']).' 备货数量:'.$v['bhnum'].' 未入库
'; } 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'] = '下单
'; } $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'] = ''.$value['sku'].'
'; foreach ($bh as $v) { $info_list[$key]['sku'] .= ''.date('Y-m-d',$v['time']).' 备货数量:'.$v['bhnum'].'
'; } 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 = "SKU | 用友料号 | 美仓库存 | 在途 | 美仓库存+在途 | 许昌库存 | 等级 | 前周出库 | 近7天出库 | 近30天出库 | 预计可用天数 | 本月缺货 | 占单数量 | 补货预警 | 备货提醒 | 出库异常 | 需要备货 |