load->_model('Model_whlabel', 'whlabel');
$this->load->_model('Model_warehouse', 'warehouse');
$this->load->_model('Model_specialstock', 'specialstock');
$this->load->_model('Model_logic_u9tools','logic_u9tools');
$this->load->_model('Model_classid','classid');
$this->load->_model('Model_typeclass','typeclass');
$this->load->_model('Model_purchase', 'purchase');
$this->load->_model("Model_shop", "shop");
$this->load->_model("Model_whlabellabel","whlabellabel");
$this->load->_model("Model_logic_zhlp",'logic_zhlp');
$this->load->_model("Model_whlabellabelprint","whlabellabelprint");
}
//定义方法的调用规则 获取URI第二段值
public function _remap($arg, $arg_array)
{
if ($arg == 'bqckexcel') //
{
//获取标签出库的按条件导出的excel
$this->_bqck_excel();
}
elseif ($arg == 'bqrkexcel') //
{
//获取标签出库的按条件导出的excel
$this->_bqrk_excel();
}
elseif ($arg == 'whlabel_cprk_excel') //
{
$this->_whlabel_cprk_excel();
}
elseif($arg == 'bqplindex'){
$this->_bqplindex();
}elseif($arg == 'bqplprint'){
$this->_bqplprint();
}elseif($arg == 'bqpladd'){
$this->_bqpladd();
}
else {
$this->_index();
}
}
private function _index(){
die('No direct script access allowed');
}
private function _bqck_excel(){
if (isset($_GET['excel'])) {
//统计时间
$timetk = $this->input->get('timetk', true);
$timetj = $this->input->get('timetj', true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$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);//sku
$warehouse = $this->input->get('warehouse',true);//仓库
$purchase = $this->input->get('purchase',true);//供应商
$where = "state=1 ";
if ($timetk && $timetj) {
$where .= " and outk > '$timetk' and outk < '$timetj'";
}
if ($sku) {
$where .= " and sku = '$sku'";
}
if ($warehouse) {
$where .= " and warehouse = '$warehouse'";
}
if ($purchase) {
$where .= " and purchase = '$purchase'";
}
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-%'";
}
$ck = ($warehouse == '12') ? 'specialstock' : 'whlabel';
$order_str = "outk desc";
//取得信息列表
$info_list = $this->$ck->find_all($where, 'id,warehouse,purchase,sku,title,features,state,outk,details', $order_str);
$classid = $this->classid->sku();
$tcall = $this->typeclass->find_all();
$typeclass = array();
foreach ($tcall 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']);
}
$prc = array();
$purchase = $this->purchase->find_all();
foreach ($purchase as $k => $v) {
$prc[$v['id']] = $v['title'];
}
foreach ($info_list as $key => $value) {
$warehouse = $this->warehouse->read($value['warehouse']);
$info_list[$key]['warehouse'] = ($ck == 'specialstock') ? '特殊仓' : $warehouse['title'];
$info_list[$key]['purchase'] = (isset($prc[$value['purchase']])) ? $prc[$value['purchase']] : '未知';
$u9_info = $this->logic_u9tools->getOneU9bm($value['features'],$classid,$typeclass);
$info_list[$key]['features'] = empty($u9_info['jm'])?"?**?":$u9_info['jm'];
if ($value['state'] == 0) {
$info_list[$key]['state'] = "在库";
} else if ($value['state'] == 1) {
$info_list[$key]['state'] = "出库";
} else if ($value['state'] == 2) {
$info_list[$key]['state'] = "退库";
} else if ($value['state'] == 3) {
$info_list[$key]['state'] = "调拨中";
} else if ($value['state'] == 4) {
$info_list[$key]['state'] = "再加工";
} else if ($value['state'] == 5) {
$info_list[$key]['state'] = "维修中";
} else if ($value['state'] == 6) {
$info_list[$key]['state'] = "盘亏";
} else if ($value['state'] == 7) {
$info_list[$key]['state'] = "更换标签";
} else if ($value['state'] == 8) {
$info_list[$key]['state'] = "其它";
} else if ($value['state'] == 9) {
$info_list[$key]['state'] = "预设";
} else if ($value['state'] == 10) {
$info_list[$key]['state'] = "美店零售";
}
$info_list[$key]['outk'] = date('Y-m-d H:i:s', $value['outk']);
}
//生成excel
$filename = date("Y-m-d")."标签出库导出.xls";
$str = "
";
$str .= "";
$str .= "| 仓库 | 供应商 | SKU | 名称 | 料号 | 状态 | 出库时间 | 所在位置 |
";
foreach ($info_list as $key=>$value)
{
$str .= "";
$str .= "| ". $value['warehouse']. " | ";
$str .= "". $value['purchase']. " | ";
$str .= "". $value['sku']. " | ";
$str .= "". $value['title']. " | ";
$str .= "". $value['features']. " | ";
$str .= "". $value['state']. " | ";
$str .= "". $value['outk']. " | ";
$str .= "". $value['details']. " | ";
$str .= "
";
}
$str .= "
";
header( "Content-Type: application/vnd.ms-excel; name='excel'" );
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=".$filename );
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header( "Pragma: no-cache" );
header( "Expires: 0" );
exit($str);
}else{
}
}
public function _bqrk_excel(){
if (isset($_GET['excel'])) {
$sku = $this->input->get('sku', true);
$bs = $this->input->get('bs', true);
$number = $this->input->get('number', true);
$warehouse = $this->input->get('warehouse', true);
$purchase = $this->input->get('purchase', true);
$orderinfo = $this->input->get('orderinfo', true);
$waybill = $this->input->get('waybill', 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);
$state = $this->input->get('state', true);
$label = $this->input->get('label', true);
$timetk = $this->input->get('ktime', true);
$timetj = $this->input->get('jtime', true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$where = "1=1 ";
if ($timetk && $timetj) {
$where .= " and enter > '$timetk' and enter < '$timetj'";
}
if ($sku) {
$where .= " and sku = '$sku'";
}
if ($bs != '') {
$where .= " and bs = '$bs'";
}
if ($number) {
$where .= " and number = '$number'";
}
if ($warehouse) {
$where .= " and warehouse = '$warehouse'";
}
if ($purchase) {
$where .= " and purchase = '$purchase'";
}
if ($orderinfo) {
$where .= " and orderinfo = '$orderinfo'";
}
if ($waybill) {
$where .= " and waybill = '$waybill'";
}
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 ($label) {
$where .= " and label = '$label'";
}
if ($state || $state == 0) {
$where .= " and state = '$state'";
}
$ck = ($warehouse == '12') ? 'specialstock' : 'whlabel';
//数据排序
$order_str = "enter desc";
//取得信息列表
$info_list = $this->$ck->find_all($where, 'id,warehouse,purchase,sku,title,features,state,enter,details', $order_str);
$prc = array();
$purchase = $this->purchase->find_all();
foreach ($purchase as $k => $v) {
$prc[$v['id']] = $v['title'];
}
$classid = $this->classid->sku();
$tcall = $this->typeclass->find_all();
foreach ($tcall 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']);
}
foreach ($info_list as $key => $value) {
$warehouse = $this->warehouse->read($value['warehouse']);
$info_list[$key]['warehouse'] = ($ck == 'specialstock') ? '特殊仓' : $warehouse['title'];
$info_list[$key]['purchase'] = (isset($prc[$value['purchase']])) ? $prc[$value['purchase']] : '未知';
$u9_info = $this->logic_u9tools->getOneU9bm($value['features'],$classid,$typeclass);
$info_list[$key]['features'] = empty($u9_info['jm'])?"?**?":$u9_info['jm'];
if ($value['state'] == 0) {
$info_list[$key]['state'] = "在库";
} else if ($value['state'] == 1) {
$info_list[$key]['state'] = "出库";
} else if ($value['state'] == 2) {
$info_list[$key]['state'] = "退库";
} else if ($value['state'] == 3) {
$info_list[$key]['state'] = "调拨中";
} else if ($value['state'] == 4) {
$info_list[$key]['state'] = "再加工";
} else if ($value['state'] == 5) {
$info_list[$key]['state'] = "维修中";
} else if ($value['state'] == 6) {
$info_list[$key]['state'] = "盘亏";
} else if ($value['state'] == 7) {
$info_list[$key]['state'] = "更换标签";
} else if ($value['state'] == 8) {
$info_list[$key]['state'] = "其它";
} else if ($value['state'] == 9) {
$info_list[$key]['state'] = "预设";
} else if ($value['state'] == 10) {
$info_list[$key]['state'] = "美店零售";
}
$info_list[$key]['enter'] = date('Y-m-d H:i:s', $value['enter']);
}
//生成excel
$filename = date("Y-m-d")."标签入库导出.xls";
$str = "
";
$str .= "";
$str .= "| 仓库 | 供应商 | SKU | 名称 | 料号 | 状态 | 入库时间 | 所在位置 |
";
foreach ($info_list as $key=>$value)
{
$str .= "";
$str .= "| ". $value['warehouse']. " | ";
$str .= "". $value['purchase']. " | ";
$str .= "". $value['sku']. " | ";
$str .= "". $value['title']. " | ";
$str .= "". $value['features']. " | ";
$str .= "". $value['state']. " | ";
$str .= "". $value['enter']. " | ";
$str .= "". $value['details']. " | ";
$str .= "
";
}
$str .= "
";
header( "Content-Type: application/vnd.ms-excel; name='excel'" );
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=".$filename );
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header( "Pragma: no-cache" );
header( "Expires: 0" );
exit($str);
}
}
public function _whlabel_cprk_excel(){
if (empty($_SESSION['api'])) {
exit('No direct script access allowed');
}
// $user = $this->user->get_api($_SESSION['api']);
// $warehouses = $user['warehouse'];
// if(empty($warehouses)){
// exit('没有仓库权限!!!');
// }
// $warehouses = explode('|',trim($warehouses,'|'));
// $ware_list = [];
// foreach ($warehouses as $v) {
// if(!empty($v)){
// $ware_list[] = $v;
// }
// }
$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);
$purchase = $this->input->get('purchase', true);
$ktime = $this->input->get('ktime', true);
$jtime = $this->input->get('jtime', true);
$ktime = strtotime($ktime);
$jtime = strtotime($jtime);
$where = " ";
// if ($warehouse) {
// if(in_array($warehouse,$ware_list)){
// $where .= " warehouse = '$warehouse' ";
// }else{
// $where .= " warehouse = 0 ";
// }
// }else{
// $where .= " warehouse in (".implode(',',$ware_list).")";
// }
if($warehouse){
$where .= " warehouse = '$warehouse' ";
}else{
$where .=" 1 = 1 ";
}
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 ($purchase) {
$where .= " and purchase = '$purchase'";
}
if ($sku) {
$where .= " and sku like '%$sku%'";
}
if ($ktime && $jtime) {
$where .= " and enter > '$ktime' and enter < '$jtime'";
}
//取得信息列表
$info_list = $this->whlabel->find_pc($where, 'enter,warehouse,sku', 'id,warehouse,shop,sku,title,enter,features');
if(!empty($info_list)){
$wh = array();
$w = $this->warehouse->find_all('1=1', 'id,title');
foreach ($w as $v) {
$wh[$v['id']] = $v['title'];
}
$classid = $this->classid->sku();
$tcall = $this->typeclass->find_all();
foreach ($tcall 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']);
}
foreach ($info_list as $k => $v) {
$info_list[$k]['warehouse'] = $wh[$v['warehouse']];
$info_list[$k]['enter'] = date('Y-m-d H:i:s', $v['enter']);
$g = $this->whlabel->find_count($where . ' and enter = "' . $v['enter'] . '" and sku = "' . $v['sku'] . '" and warehouse = "' . $v['warehouse'] . '"');
$info_list[$k]['g'] = $g;
if(!empty($v['features'])){
$u9_info = $this->logic_u9tools->getOneU9bm($v['features'],$classid,$typeclass);
$info_list[$k]['features'] = empty($u9_info['jm'])?"?**?":$u9_info['jm'];
}
}
}
//生成excel
$filename = date("Y-m-d")."产品入库导出.xls";
$str = "
";
$str .= "";
$str .= "| 仓库 | SKU | 产品名称 | 入库时间 | 数量 | 料号 |
";
foreach ($info_list as $key=>$value)
{
$str .= "";
$str .= "| ". $value['warehouse']. " | ";
$str .= "". $value['sku']. " | ";
$str .= "". $value['title']. " | ";
$str .= "". $value['enter']. " | ";
$str .= "". $value['g']. " | ";
$str .= "". $value['features']. " | ";
$str .= "
";
}
$str .= "
";
header( "Content-Type: application/vnd.ms-excel; name='excel'" );
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=".$filename );
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header( "Pragma: no-cache" );
header( "Expires: 0" );
exit($str);
}
private function _bqplindex(){
if($this->input->method() == 'post'){
$rows = array('total'=>0,'over'=>1,'pagenum'=>1,'rows'=>([]));
echo json_encode($rows);exit;
}
$this->_Template('whlabelfz_bqpl', $this->data);
}
private function _getShop($str){
$str = trim($str);
if($str == '无'){
return '';
}else{
$str = strtolower($str);
if($str =='alipearl'){
return 1;
}elseif($str == 'supernova'){
return 2;
}elseif($str == 'asteriahair'){
return 3;
}elseif($str == 'westkiss'){
return 4;
}elseif($str == 'yolissahair'){
return 5;
}elseif($str == 'wiggins'){
return 6;
}
}
}
private function _bqpladd(){
$params = $this->input->post('data',true);
$params = json_decode($params,true);
$list = [];
$error_list= [];
$warehouse_list = $this->warehouse->find_all("1 = 1","id,title");
$warehouse_list = array_column($warehouse_list,'id','title');
$purchase_list = $this->purchase->find_all("1 = 1","id,title");
$purchase_list = array_column($purchase_list,'id','title');
$classid = $this->classid->sku();
foreach($params as $k => $v){
$r = $this->_transferForm($v['0'],$v,$warehouse_list,$purchase_list,$classid,$k);
if($r['code'] != 1){
$error_list[] = [
'sku'=>$v['0'],
'msg'=>$r['msg']
];
}else{
$tmp_data = $r['data'];
$tmp_data['details'] = $v['4'];
$this->whlabellabelprint->insert($tmp_data);
$list[] = $tmp_data['data'];
}
}
if(empty($error_list)){
echo json_encode(['code'=>1,'msg'=>'操作成功','data'=>[],'error'=>[]]);exit;
}else{
echo json_encode(['code'=>-1,'msg'=>'导入数据异常','data'=>[],'error'=>$error_list]);exit;
}
}
/**
* 将数据转化为 批量打印标签需要data格式
*/
private function _transferForm($tmsku,$info,$warehouse_list,$purchase_list,$classid,$i){
if (is_numeric($tmsku)) {
$yyh = $this->whlabellabel->get_label($tmsku);
} else {
$yyh = $this->whlabellabel->get_sku($tmsku);
}
if(!empty($yyh)){
return ['code'=>1,'msg'=>"获取标签",'data'=>[
'sku_shop_id' => 0,
'sku_master_id' => 0,
'status' => 0,
'shop' =>0,
'purchase' => $yyh['purchase'],
'warehouse' => $yyh['warehouse'],
'cpbz' => $yyh['cpbz'],
'title' => $yyh['title'],
'number' => $yyh['number'],
'features' => $yyh['features'],
'featurespp' => $yyh['featurespp'],
'time' => time(),
'dynum' => $info['1'],
'sku' => $info['sku'],
'label' => time() . rand(0, 9).$i
]];
}
$r = $this->logic_u9tools->getErpSkuByU9Lp($tmsku);
if($r['code'] == -1 ){
return ['code'=>-1,'msg'=>"未找到对应的料品"];
}
$str = $r['data'];
$arr = explode("-",trim($str,"-"));
$data = $this->logic_zhlp->transferSku($arr);
$res = $this->logic_zhlp->sortByColume($data);
if($res['code'] == -1){
return $res;
}
$insert_arr = [];
$insert_arr['sku_master_id']= $insert_arr['sku_shop_id'] =0;
$insert_arr['status'] = 0;
$insert_arr['shop'] = '';
$purchase = isset($purchase_list[$info['2']])?$purchase_list[$info['2']]:1;
$insert_arr['purchase'] = $purchase;
$warehouse = isset($warehouse_list[$info['3']])?$warehouse_list[$info['3']]:1;
$insert_arr['warehouse'] = $warehouse;
$insert_arr['cpbz'] = '';
$post = $res['data'];
$list = [];
$category = $post['category'];
$list['category'] = $category;
$list['hairtype'] = empty($post['hairtype'])?'':$post['hairtype'];
$list['grade'] = empty($post['grade'])?'':$post['grade'];
$list['size'] = empty($post['size'])?'':$post['size'];
$list['hairnumber'] = empty($post['hairnumber'])?'':$post['hairnumber'];
$list['extension'] = empty($post['extension'])?'':$post['extension'];
if ($category == 1297) {
$list['sywignumber'] = empty($post['sywignumber'])?'':$post['sywignumber'];
}
if ($category == 1702) {
$list['syhairnumber'] = empty($post['syhairnumber'])?'':$post['syhairnumber'];
$list['syother'] = empty($post['syother'])?'':$post['syother'];
}
if ($category == 133) {
$list['fittype'] = empty($post['fittype'])?'':$post['fittype'];
$list['acother'] = empty($post['acother'])?'':$post['acother'];
}
$list['color'] = empty($post['color'])?'':$post['color'];
$list['lowe'] = empty($post['lowe'])?'':$post['lowe'];
if ($category == 127) {
$list['type'] = empty($post['type'])?'':$post['type'];
$list['headroad'] = empty($post['headroad'])?'':$post['headroad'];
$list['density'] =empty($post['density'])?'':$post['density'];
if ($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199) {
$list['lacesize'] = empty($post['lacesize'])?'':$post['lacesize'];
}
$list['lacecolor'] = empty($post['lacecolor'])?'':$post['lacecolor'];
$list['lacetypes'] = empty($post['lacetypes'])?'':$post['lacetypes'];
}
if ($category == 128) {
$list['lacetype'] =empty($post['lacetype'])?'':$post['lacetype'];
$list['haircap'] = empty($post['haircap'])?'':$post['haircap'];
$list['density'] = empty($post['density'])?'':$post['density'];
$list['lacecolor'] = empty($post['lacecolor'])?'':$post['lacecolor'];
$list['lacetypes'] = empty($post['lacetypes'])?'':$post['lacetypes'];
$list['wigother'] = empty($post['wigother'])?'':$post['wigother'];
$list['wigother1'] = empty($post['wigother1'])?'':$post['wigother1'];
$list['wigother2'] = empty($post['wigother2'])?'':$post['wigother2'];
}
if ($category == 129) {
$list['wide'] = empty($post['wide'])?'':$post['wide'];
}
if ($category == 131) {
$list['gifttype'] = empty($post['gifttype'])?'':$post['gifttype'];
$list['giftother'] = empty($post['giftother'])?'':$post['giftother'];
}
if ($category == 134) {
$list['pieceweight'] = empty($post['pieceweight'])?'':$post['pieceweight'];
}
if ($category == 1297) {
$list['synthetictype'] = empty($post['synthetictype'])?'':$post['synthetictype'];
$list['sywigother'] = empty($post['sywigother'])?'':$post['sywigother'];
}
if ($category == 130 || $category == 133 || $category == 1702) {
$list['items'] = empty($post['items'])?'':$post['items'];
$list['weight'] = empty($post['weight'])?'':$post['weight'];
}
if ($category == 1702) {
$list['syhairther'] = empty($post['syhairther'])?'':$post['syhairther'];
}
$pm = $scsku = $classid;
$number = $features = $title = "";
foreach ($list as $k => $v) {
if ($v != 0) {
$number .= $v;
$features .= $v . '-';
$typeclass = $this->typeclass->read($v);
if (isset($pm[$typeclass['classid']])) {
if (stripos($typeclass['zh'], '|') !== false) {
$exzh = explode('|', $typeclass['zh']);
$pm[$typeclass['classid']] = $exzh[0];
} else {
$pm[$typeclass['classid']] = $typeclass['zh'];
}
}
$scsku[$typeclass['classid']] = $typeclass['bqsku'];
if ($k != 'size') {
$title .= $typeclass['title'] . " ";
}
}
}
$typeclass = $this->typeclass->read($list['size']);
$title .= $typeclass['title'];
$time = time();
$insert_arr['title'] = rtrim($title, ' ');
$insert_arr['number'] = $number;
$insert_arr['features'] = "-".trim($features, '-')."-";
$featurespp = str_replace(array('-163-', '-164-', '-165-', '-166-'), '-', $features);
$featurespp = explode('-', trim($featurespp, '-'));
if (isset($featurespp[5])) {
$insert_arr['featurespp'] = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4] . '-' . $featurespp[5];
} else {
$insert_arr['featurespp'] = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4];
}
$insert_arr['time'] = $time;
$insert_arr['dynum'] = $info['1'];
$scsku = implode("-", $scsku);
$zh = implode(" ", $pm);
$scsku = str_replace('- ', '-', trim($scsku, '-'));
$scsku = str_replace(array('--------', '-------', '------', '-----', '----', '---', '--'), '-', $scsku);
$bqsku = $scsku;;
$insert_arr['sku'] = $bqsku;
$label = time() . rand(0, 9).$i;
$insert_arr['label'] = $label;
return [
'code'=>1,
'msg'=>"success",
'data'=>$insert_arr
];
}
private function _bqplprint(){
}
}