控制器
<?php
namespace App\Admin\Controllers;
use App\Exports\TmpPvwExport;
use App\Models\PubClient;
use App\Models\PubCountry;
use App\Models\PubSizeConvert;
use App\Models\PubSizeSection;
use App\Models\TmpPvw;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Layout\Content;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
class TestController extends AdminController
{
protected $title = '测试';
protected $description = [
'index' => '列表',
'pred_create' => '预下单',
'bulk_create' => '下大货',
'detail' =>'详情',
];
protected $bulk_info = []; //款式信息提取
protected $size_group_list = []; //尺码提取
protected $nationa_list = []; //国家名称提前
protected $total_list = []; //订单明细
protected $date_list = []; //出货日期和国家地区
protected $clearing_list = []; //结算类型 费用和国家
protected $parent_country = []; //出运国家地区
protected $carriage_list = []; //国家运输方式 Create By Pingtt 2020-03-20
protected $money_status = false; //货币状态 Create By Pingtt 2020-03-20
protected $country_type = []; //货币状态 Create By Pingtt 2020-03-20
const MONTH_STRING_TO_NUMBER = [
'Jan' => '01',
'Feb' => '02',
'Mar' => '03',
'Apr' => '04',
'May' => '05',
'Jun' => '06',
'Jul' => '07',
'Aug' => '08',
'Sep' => '09',
'Oct' => '10',
'Nov' => '11',
'Dec' => '12',
];
/**
* 大货下单测试部分 开始
*/
public function testbulk(Content $content){
$content->header($this->title)
->description($this->description['bulk_create'])
->breadcrumb(
['text' => $this->title, 'url' => '/test/testbulk'],
['text' => $this->description['bulk_create'], 'url' => '/exploit']
)
->row(view('tpl.test.bulk_create_load'));
return $content;
}
public function uploads_file(Request $request){
set_time_limit(0);
$t1 = microtime(true);
DB::beginTransaction();
try{
$purchase_file = UploadController::upload_path_file($request->PurchaseOrderFile,'tmp');
$country_file = UploadController::upload_path_file($request->TotalCountryBreakdownFile,'tmp');
$packing_file = UploadController::upload_path_file($request->PackingListFile,'tmp');
//提取订单信息 和 出货日期
$purchase_data = $this->init_excel('./'.$purchase_file,2);
$this->purchaseList($purchase_data);
//查询客户ID
$client_info = PubClient::where('name',$this->bulk_info['client_name'])->select('id')->first();
$this->bulk_info['client_id'] = $client_info->id;
//提取TotalCountryBreakdown表 提取尺码段
$country_data = $this->init_excel('./'.$country_file,2);
$this->totalCountry($country_data);
//提取订单 明细
$packing_data = $this->init_excel('./'.$packing_file,2);
$this->packingList($packing_data);
//验证表格是否一致
if($this->bulk_info['development_no'] != $this->size_group_list['bulk_info']['development_no'] || $this->size_group_list['bulk_info']['development_no'] != $this->total_list['bulk_info']['development_no']){
return response()->json(['status'=>400,'message'=>'上传文件款号不一致,请检查后重新上传']);
}
//重组出货日期
$tod_data = [];
foreach ($this->date_list as $k => $v){
foreach ($v as $key => $val){
$country_code = $this->initSubstr($val,'(');
$tod_data[$country_code] = trim($k);
}
}
//重组订单
$order_list = [];
$p_index = 0;
//尺码数量
$size_num = count($this->size_group_list['size_group_list']);
foreach ($this->total_list['total_list'] as $k => $v){
foreach ($v as $key => $val){
if(!isset($order_list[$val['acticle_no']])){
$order_list[$val['acticle_no']] = [
"acticle_no" => $val['acticle_no'],
"color_code" => $val['color_code'],
"color_name" => $val['color_name'],
"list" => [],
];
}
//尺码数量
$num_list = [];
$index = 0;
foreach ($this->size_group_list['size_group_list'] as $keys => $vals){
$num_list[$index]['size_name'] = $keys;
$num_list[$index]['size_id'] = $vals;
$num_list[$index]['size_num'] = isset($val['total_list'][$keys])?$val['total_list'][$keys]:0;
$index ++;
}
//查询国家名称
$country_info = PubCountry::where('ename',$k)->where('flag',$this->bulk_info['project_type'])->with('toParentCountry')->first();
//填充国家
if(isset($country_info->toParentCountry->id)){
$this->parent_country[$country_info->toParentCountry->id] = $country_info->toParentCountry->ename;
$cname = explode(' ',$country_info->cname);
$tod_times = $tod_data[trim($cname[0])];
$carriage_type = $this->carriage_list[trim($cname[0])];
$carriage_name = carrier_flag_type()[$this->carriage_list[trim($cname[0])]];
}else{
$tod_times = end($tod_data);
$carriage_type = '3';
$carriage_name = '默认陆运';
}
$order_list[$val['acticle_no']]['list'][$p_index] = [
'area_id' => $country_info->id,
'area_name' => $country_info->cname,
'country_id' => $country_info->parent_id,
'tod_date' => $tod_times,
'carriage_type' => $carriage_type,
'carriage_name' => $carriage_name,
'data' => $num_list,
];
}
$p_index++;
}
foreach ($order_list as $key => $value) {
$sort_arr = [];
foreach ($value['list'] as $k => $v) {
$sort_arr[] = $v['tod_date'];
}
array_multisort($sort_arr, SORT_ASC, $value['list']);
$order_list[$key] = $value;
}
$t2 = microtime(true);
/**
* 处理数据
*/
foreach ($order_list as $k => $v){
//生成预览表
$pvw_data = [
'client_name' => $this->bulk_info['client_name'], // 订单客户
'bulk_no' => $this->bulk_info['product_no'], // 大货款号
'order_no' => $this->bulk_info['order_no'], // 订单编号
'size_sec' => $this->bulk_info['size_group_id'], // 尺码段ID
'total' => 0, // 订单数量
'color_serial' => $v['acticle_no'], // 色组序号
'color_no' => $v['color_code'], // 订单色号
'color_name' => $v['color_name'], // 色组名称
'user_id' => getAdminID(), //操作人
'created_at' => getDateH(0),
'updated_at' => getDateH(0),
];
$start_tod = null;
$total = 0;
$pvw_id = DB::table('tmp_pvws')->insertGetId($pvw_data);
$order_list[$k]['pvws_id'] = $pvw_id;
foreach ($v['list'] as $kq => $vq){
if (empty($start_tod)){
$start_tod = $vq['tod_date'] ;
}
if($vq['tod_date'] < $start_tod){
$start_tod = $vq['tod_date'] ;
}
$nation_data = [
'pvws_id' => $pvw_id,
'country_id' => $vq['country_id'],
'country_store_id' => $vq['area_id'],
'tod' => $vq['tod_date'],
'transport' => $vq['carriage_type'],
'user_id' => getAdminID(),
'created_at' => getDateH(0),
'updated_at' => getDateH(0),
];
$nation_id = DB::table('tmp_nation')->insertGetId($nation_data);
$nation_total = 0;
$size_data = [];
foreach ($vq['data'] as $kn => $vn){
$nation_total += $vn['size_num'];
$size_data[] = [
'pvws_id' => $pvw_id,
'nation_id' => $nation_id,
'size_id' => $vn['size_id'],
'qty' => $vn['size_num'],
'country_id' => $vq['country_id'],
'country_store_id' => $vq['carriage_type'],
'user_id' => getAdminID(),
'created_at' => getDateH(0),
'updated_at' => getDateH(0),
];
}
DB::table('tmp_size')->insert($size_data);
DB::table('tmp_nation')->where(['id'=>$nation_id])->update(['total'=>$nation_total]);
$total += $nation_total;
}
DB::table('tmp_pvws')->where(['id'=>$pvw_id])->update(['total'=>$total,'fisrt_tod'=>$start_tod,'fisrt_iod'=>date( 'Y-m-d', strtotime($start_tod.' -6 day') )]);
}
DB::commit();
/**
* 返回
*/
$returnJson = [
'status' => 100,
'message' => trans('admin.collect_successful'),
'expend_info'=> '耗时'.round($t2-$t1,3).'秒,占用内存: ' . round(memory_get_usage()/1024/1024,1) .'M',
'bulk' => $this->bulk_info,
'order_list'=> $order_list,
'parent_country'=> $this->parent_country,
'size_group_list'=> $this->size_group_list['size_group_list'],
'purchase_file' => $purchase_file,
'country_file' => $country_file,
'packing_file' => $packing_file,
];
return response()->json($returnJson);
}catch (\Exception $e){
DB::rollBack();
return response()->json(['status'=>400,'message'=>$e->getLine(). $e->getMessage()]);
}
}
//截取
public function initSubstr($str,$string){
return trim(substr($str,0,strrpos($str,$string)));
}
//截取指定两个字符之间的字符串
public function cut($begin,$end,$str){
$b = mb_strpos($str,$begin) + mb_strlen($begin);
$e = mb_strpos($str,$end) - $b;
return mb_substr($str,$b,$e);
}
//提取Excel 重组数据
public function init_excel($file,$type=1){
$PHPReader = new \PHPExcel_Reader_Excel2007(); //建立reader对象,excel—2007以后格式
if (!$PHPReader->canRead($file)) {
$PHPReader = new \PHPExcel_Reader_Excel5();//建立reader对象,excel—2007以前格式
if (!$PHPReader->canRead($file)) {
return false;
}
}
$PHPExcel = $PHPReader->load($file); //加载excel对象
$sheet = $PHPExcel->getSheet(0);
$data = $sheet->toArray();
$selected = [];
if($type==2){
foreach ($data as $k => $v){
foreach ($v as $key => $val){
if($val || $val == '0'){
$selected[$k][] = $val;
}
}
}
}else{
$selected = $data;
}
return $selected;
}
//尺码段提取
public function totalCountry($fileData){
//循环处理
$size_group_list = [];
$country_list = [];
$bulk_info = [];
$country_status = 2;
$country_group = false;
$end_status = false;
$size_label = false;
foreach ($fileData as $k => $v){
if($end_status){
break;
}
for ($j = 0; $j < count($v); $j++) { //列数是以A列开始
$value = $v[$j];
//订单号
if (!isset($bulk_info['order_no'])) {
if ($value == 'Order No:') {
$j++;
$bulk_info['order_no'] = $v[$j];
//获取到需要的数据则 加入下一个循环
continue;
}
}
//款号
if (!isset($bulk_info['product_no'])) {
if ($value == 'Product No:') {
$j ++;
$bulk_info['product_no'] = $v[$j];
//获取到需要的数据则 加入下一个循环
break;
}
}
//款名
if (!isset($bulk_info['product_name'])) {
if ($value == 'Product Name:') {
$j ++;
$bulk_info['product_name'] = $v[$j];
//获取到需要的数据则 加入下一个循环
break;
}
}
//客户下单时间
if (!isset($bulk_info['order_date'])) {
if ($value == 'Date of Order:') {
$j ++;
$time = $this->getLocalUnixTime($v[$j]);
$bulk_info['order_date'] = date('Y-m-d',$time);
//获取到需要的数据则 加入下一个循环
break;
}
}
//编号
if (!isset($bulk_info['development_no'])) {
if ($value == 'Development No:') {
$j ++;
$bulk_info['development_no'] = $v[$j];
//获取到需要的数据则 加入下一个循环
break;
}
}
//国家获取
if ($value == 'Colour / Country Breakdown') {
$country_status = 1;
break;
}
if ($country_status == 1) {
if ($value == 'Country'){
$country_group = true;
break;
}
if(strpos($value,'Total:') !== false){
$country_group = false;
$country_status = 2;
break;
}
if($country_group){
$country_list[$value] = [];
break;
}
break;
}
//转换码获取
if($value == 'Size Label (Corresponding Sizes)'){
$size_label = true;
break;
}
if($size_label){
$map = explode('-',$value);
$country_name = strtolower($v[1]);
unset($v[0]);
unset($v[1]);
//查询 尺码段 基准
$size_get_list = PubSizeConvert::where('no',$map[0])->whereIn($country_name,$v)->orderBy('id','asc')->pluck('id','eur')->toArray();
$endKey = $size_get_list;
end($endKey);
$name = key($size_get_list).'-'.key($endKey);
//查询尺码段是否存在
$group = PubSizeSection::where(['no'=>trim($map[0]),'title'=>trim($map[1]),'allsizeid'=>implode(',',$size_get_list)])->first();
if($group){
$group_id = $group->id;
}else{
$insert_size_data = [
'client_id' => $this->bulk_info['client_id'],
'no' => trim($map[0]),
'title' => trim($map[1]),
'name' => $name,
'allsizeid' => implode(',',$size_get_list),
'created_at'=> date("Y-m-d H:i:s"),
'updated_at'=> date("Y-m-d H:i:s"),
];
$group_id = DB::table('pub_size_section')->insertGetId($insert_size_data);
$insert_size_all_data = [];
foreach ($size_get_list as $size_v){
$insert_size_all_data[] = [
'section_id' => $group_id,
'info_id' => $size_v,
];
}
DB::table('pub_sizesect_detail')->insert($insert_size_all_data);
}
//尺码段获取
$this->bulk_info['size_group_id'] = $group_id;
$this->bulk_info['size_group_name'] = trim($map[1]);
//尺码明细转数组
$size_group_list = [];
foreach ($v as $kq => $vq){
$size_group_list[$vq] = $size_get_list[$vq];
}
$size_label = false;
$end_status = true;
break;
}
}
}
$this->size_group_list = [
'bulk_info' => $bulk_info,
'size_group_list' => $size_group_list,
'nationa_list' => $country_list
];
}
//国别数量明细提取
public function packingList($fileData){
//循环处理
$bulk_info = [];
$total_list = [];
$total_status = 2;
$nationa = 2;
$nationa_name = '';
//色组区别开始
$acticle_status = false;
foreach ($fileData as $k => $v){
for ($j = 0; $j < count($v); $j++) { //列数是以A列开始
$value = $v[$j];
if (!isset($bulk_info['order_no'])) {
if ($value == 'Order No:') {
$j++;
$bulk_info['order_no'] = $v[$j];
//获取到需要的数据则 加入下一个循环
continue;
}
}
//大货款号
if (!isset($bulk_info['product_no'])) {
if ($value == 'Product No:') {
$j ++;
$bulk_info['product_no'] = $v[$j];
//获取到需要的数据则 加入下一个循环
break;
}
}
//款名
if (!isset($bulk_info['product_name'])) {
if ($value == 'Product Name:') {
$j ++;
$bulk_info['product_name'] = $v[$j];
//获取到需要的数据则 加入下一个循环
break;
}
}
//客户下单时间
if (!isset($bulk_info['order_date'])) {
if ($value == 'Date of Order:') {
$j ++;
$bulk_info['order_date'] = date("Y-m-d",strtotime($v[$j]));
//获取到需要的数据则 加入下一个循环
break;
}
}
//开发款号
if (!isset($bulk_info['development_no'])) {
if ($value == 'Development No:') {
$j ++;
$bulk_info['development_no'] = $v[$j];
//获取到需要的数据则 加入下一个循环
break;
}
}
//获取国家名称
if ($value == 'Size / Colour breakdown') {
$nationa = 1;
break;
}
if ($nationa == 1) {
$nationa_name = $value;
$total_list[$nationa_name] = [];
$nationa = 2;
continue;
}
//提取国家地区下的 色组编号
if(trim($value) == 'Article No:'){
$acticle_status = true;
continue;
}
//色组序号
if ($acticle_status){
for ($ji = 1; $ji < count($v); $ji++) { //列数是以A列开始
$val = $v[$ji];
if($val){
$total_list[$nationa_name][$ji-1]['acticle_no'] = $val;
}
continue;
}
$acticle_status = false;
break;
}
//色号
if($value == 'H&M Colour Code:'){
for ($ji = 1; $ji < count($v); $ji++) { //列数是以A列开始
$val = $v[$ji];
if($val){
$total_list[$nationa_name][$ji-1]['color_code'] = $val;
}
continue;
}
break;
}
//颜色名称
if($value == 'Colour Name:'){
for ($ji = 1; $ji < count($v); $ji++) { //列数是以A列开始
$val = $v[$ji];
if($val){
$total_list[$nationa_name][$ji-1]['color_name'] = $val;
}
continue;
}
break;
}
//如果值是 total 则改变状态 进入下一个循环;
if (trim($value) == 'Total') {
$total_status = 1;
break;
}
if ($total_status == 1) {
if ($value == 'Quantity:') {
$total_status = 2;
break;
}
$title = $this->cut('(', ')', $value);
for ($ji = 1; $ji < count($v); $ji++) { //列数是以A列开始
if(isset($v[$ji])){
$total_list[$nationa_name][$ji-1]['total_list'][$title] = isset($v[$ji])?intval($v[$ji]):0;
}else{
$total_list[$nationa_name][$ji-1]['total_list'][$title] = 0;
}
continue;
}
break;
}
}
}
$this->total_list = [
'bulk_info' => $bulk_info,
'total_list' => $total_list,
];
}
//订单基础信息 出货日期 结算方式 提取
public function purchaseList($fileData){
//循环处理
$date_list = [];
$date_status = 2;
$date_end = true;
$clearing_end = true;
$carrier_start = false;
//订单基础信息
$bulk_info = [];
foreach ($fileData as $k => $v){
//获取订单类型
if($k == 0){
$oneRow = explode(' ',strstr($v[0],'Order'));
$project_type = 1;
foreach ($oneRow as $q){
if(trim($q) == 'Online'){
$project_type = 2;
}
}
$bulk_info['project_type'] = $project_type; //订单类型 2-邮购单 1-线下
$bulk_info['client_name'] = $oneRow[count($oneRow)-1]; //订单类型 0-邮购单 1-线下
continue;
}
if(!$clearing_end){
break;
}
for ($j = 0; $j < count($v); $j++) { //列数是以A列开始
$value = $v[$j];
//订单号
if (!isset($bulk_info['order_no'])) {
if ($value == 'Order No:') {
$j++;
$bulk_info['order_no'] = $v[$j];
//获取到需要的数据则 加入下一个循环
continue;
}
}
//款号
if (!isset($bulk_info['product_no'])) {
if ($value == 'Product No:') {
$j ++;
$bulk_info['product_no'] = $v[$j];
//获取到需要的数据则 加入下一个循环
break;
}
}
//款名
if (!isset($bulk_info['product_name'])) {
if ($value == 'Product Name:') {
$j ++;
$bulk_info['product_name'] = $v[$j];
//获取到需要的数据则 加入下一个循环
break;
}
}
//客户下单时间
if (!isset($bulk_info['order_date'])) {
if ($value == 'Date of Order:') {
$j ++;
$bulk_info['order_date'] = date("Y-m-d", strtotime("-1 year",strtotime($v[$j])));
//获取到需要的数据则 加入下一个循环
break;
}
}
//季节
if (!isset($bulk_info['season'])) {
if ($value == 'Season:') {
$j ++;
$bulk_info['season'] = $v[$j];
//获取到需要的数据则 加入下一个循环
break;
}
}
//编号
if (!isset($bulk_info['development_no'])) {
if ($value == 'Development') {
$j ++;
$bulk_info['development_no'] = $v[$j];
//获取到需要的数据则 加入下一个循环
break;
}
}
// 货运方式 提取开始
if ($value == 'Terms of Delivery') {
$carrier_start = true;
break;
}
//获取国家地区 出货日期
if ($value == 'Time of Delivery') {
$carrier_start = false;
$date_status = 1;
break;
}
//处理 运输方式
if($carrier_start){
$str = str_replace("\n","",$fileData[$k][0]);
// dd($str);
// $k++;
$ex_str = explode('Transport by',$str);
if(isset($ex_str[1])){
$flag = $this->carrier_flag_get($ex_str[1]);
if($flag || $flag == '0'){
foreach (explode(',',$ex_str[0]) as $kq => $vq){
$coun = trim(str_replace("\n","",$vq));
$this->carriage_list[$coun] = $flag;
}
}
}
break;
}
//获取国家地区 出货日期
if($date_end){
if ($date_status == 1) {
if($value == 'Total:'){
$date_end = false;
$date_status = 2;
}else{
$time = $this->getLocalUnixTime($value);
$dateTime = date('Y-m-d',$time);
$country_arr = [];
foreach (explode(',',$v[$j+1]) as $kq => $vq){
$coun = str_replace("\n","",$vq);
$country_arr[] = trim($coun);
}
$date_list[$dateTime] = $country_arr;
break;
}
}
}
}
}
$this->bulk_info = $bulk_info;
$this->date_list = $date_list;
}
public function getCellValue($obj,$cellKey){
$val = $obj[$cellKey];
if($val){
return $val;
}else{
$this->getCellValue($obj,$cellKey++);
}
}
/**
* 货运方式提取
*/
public function carrier_flag_get($str){
foreach (carrier_flag_name() as $k => $v){
if(strpos($str,$k)){
return $v;
};
}
}
/*
* HTML 数据提取方法
*/
public function extractHTML($file_path)
{
set_time_limit(0);
$dom = HtmlDomParser::file_get_html($file_path);
$elements = $dom->findMulti('table');
$data = [];
$index = 0;
foreach ($elements as $k => $v) {
$tr_ele = $v->findMulti('tr');
foreach ($tr_ele as $key => $val) {
$td_ele = $val->findMulti('td');
foreach ($td_ele as $kq => $vq) {
$value = $vq->find('p', 0);
if($value->text()){
$data[$index][] = htmlspecialchars_decode($value->text());
}
}
$index++;
}
}
$elements->clear();
return $data;
}
/**
* 提取PackList HTML
* @param $file_path
*/
public function extractPackList($file_path){
set_time_limit(0);
$dom = HtmlDomParser::file_get_html($file_path);
$elements = $dom->find('table , body > p');
$data = [];
$index = 0;
foreach ($elements as $k => $v){
if ($v->tagName == 'table'){
$tr_ele = $v->findMulti('tr');
foreach ($tr_ele as $key => $val){
$td_ele = $val->findMulti('td');
foreach ($td_ele as $kq => $vq){
$value = $vq->find('p',0);
$data[$index][] = htmlspecialchars_decode($value->text());
}
$index++;
}
}else{
if($v->text()){
$data[$index][] = htmlspecialchars_decode($v->text());
$index++;
}
continue;
}
}
return $data;
}
/**
* 测试大货预览表导出
* @param Request $request
* @return mixed
*/
public function pvw_export_load(Request $request){
ob_end_clean();
ob_start();
$data = TmpPvw::where('id',$request->pvws_id)->first();
$filename = $data->bulk_no.'预览表';
return Excel::download(new TmpPvwExport($request->pvws_id), $filename.'.xlsx');
}
/**
* 时间戳转换
* @param $LastModified
* @return false|float|int
*/
public function getLocalUnixTime($LastModified) {
$cos_time_array = explode(' ', $LastModified);
$cos_time_array[1] = trim($cos_time_array[1],',');
//得到正常可以转换时间戳的时间 '2019-05-10 07:48:10'
$date_time = $cos_time_array[2] . '-' . self::MONTH_STRING_TO_NUMBER[$cos_time_array[1]] .
'-' . $cos_time_array[0] ;
//转换时间戳 再加上时差 8小时
$time_unix = strtotime($date_time) + 8 * 3600;
return $time_unix;
}
/**
* 大货下单测试部分 结束
*/
}
**视图:bulk_create_load.blade.php**
```php
<link rel="stylesheet" href="{{ \Illuminate\Support\Facades\URL::asset('common/common.css') }}">
<link rel="stylesheet" href="{{ \Illuminate\Support\Facades\URL::asset('vendor/Loading/load.css') }}" media="all">
{{--<link rel="stylesheet" href="{{ \Illuminate\Support\Facades\URL::asset('vendor/Loading/load-min.js') }}">--}}
<script src="{{ \Illuminate\Support\Facades\URL::asset('vendor/Loading/load-min.js') }}"></script>
<style>
.exploit .form-group{
margin-bottom: 0px;
}
.width081{
width: 10.207% !important;
}
.width919{
width: 89.7% !important;
}
.bulk .form-control{
font-size: 16px;
color: #111;
height: 30px;
padding: 2px 12px;
}
.bulk .control-label {
/*font-size: 14px;*/
padding-top: 3px;
}
.panel-body {
padding: 10px 15px 0px 15px;
}
.form-group {
margin-bottom: 5px;
}
.style-img-box{
max-height: 150px;
}
.thumbnail{
margin-bottom: 0px;
}
.btn.btn-file>input[type='file'] {
position: absolute;
top: 0;
right: 0;
max-width: 100%;
opacity: 0;
filter: alpha(opacity=0);
outline: none;
background: white;
cursor: inherit;
display: block;
}
</style>
<div class="content">
<div class="row">
<div class="col-md-12">
<div class="box box-info">
<!-- 创建工厂表单 -->
<!-- form start -->
<form action="#" method="post" accept-charset="UTF-8" class="form-horizontal" pjax-container>
<div class="hiddenCheck">
</div>
<div class="box-body">
<div class="fields-group">
<div class="col-md-10">
{{-- PDF上传 --}}
<div class="panel panel-default bulk_file" style="margin-bottom: 10px">
<div class="panel-heading">
<h3 class="panel-title">客户订单上传</h3>
</div>
<div class="panel-body">
<div class="form-group">
{{-- 选择PurchaseOrder --}}
<div class="col-md-3">
<label for="PurchaseOrder" class="asterisk control-label btn btn-sm btn-default col-sm-5" title="选择PurchaseOrder">
PurchaseOrder
<input type="file" class="PurchaseOrder" id="PurchaseOrderFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" onchange="insertInputText(this,'PurchaseOrderText','PurchaseOrder')" style="position: absolute;right: 0;top: 0;opacity: 0;width: 100%;">
</label>
<div class="col-sm-7">
<input type="text" class="form-control PurchaseOrderText" readonly/>
</div>
</div>
{{-- 选择TotalCountryBreakdown --}}
<div class="col-md-3">
<label for="TotalCountryBreakdown" class="asterisk control-label btn btn-sm btn-default col-sm-5" title="选择TotalCountryBreakdown">
TotalCountry
<input type="file" class="TotalCountryBreakdown" onchange="insertInputText(this,'TotalCountryBreakdownText','TotalCountryBreakdown')" id="TotalCountryBreakdownFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" style="position: absolute;right: 0;top: 0;opacity: 0;width: 100%;">
</label>
<div class="col-sm-7">
<input type="text" class="form-control TotalCountryBreakdownText" readonly/>
</div>
</div>
{{-- 选择PackingList --}}
<div class="col-md-3">
<label for="PackingList" class="asterisk control-label btn btn-sm btn-default col-sm-5" title="选择PackingList">
PackingList
<input type="file" class="PackingList" onchange="insertInputText(this,'PackingListText','PackingList')" id="PackingListFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" style="position: absolute;right: 0;top: 0;opacity: 0;width: 100%;">
</label>
<div class="col-sm-7">
<input type="text" class="form-control PackingListText" readonly/>
</div>
</div>
<div class="col-md-3">
<label for="PackingList" class="control-label col-sm-5" title=""></label>
<div class="col-sm-7">
<a href="javascript:;" class="btn btn-success uploadBulkFile" >提取订单信息</a>
</div>
</div>
</div>
<div class="form-group">
{{-- purchase_file --}}
<div class="col-md-3">
<input type="hidden" class="form-control purchase_file" name="purchase_file" id="purchase_file" value="{{ old('purchase_file') }}" required="1"/>
</div>
{{-- country_file --}}
<div class="col-md-3">
<input type="hidden" class="form-control country_file" name="country_file" id="country_file" value="{{ old('country_file')}}" required="1"/>
</div>
{{-- packing_file --}}
<div class="col-md-3">
<input type="hidden" class="form-control packing_file" name="packing_file" id="packing_file" value="{{ old('packing_file') }}" required="1"/>
</div>
</div>
</div>
</div>
{{-- 订单色组存放盒子 --}}
<div id="order_color_box">
</div>
<template class="extra-tpl">
<div class="panel panel-default bulk init_row_mkey" style="margin-bottom: 10px">
<div class="panel-heading">
<h3 class="panel-title">订单色组 </h3>
</div>
<div class="panel-body">
<div class="form-group">
{{-- 色号 --}}
<div class="col-md-3">
<label for="color_no_mkey" class="asterisk control-label col-sm-5" title="色号">色 号:</label>
<div class="col-sm-7">
<input type="text" class="form-control str_color_no_mkey" readonly>
<input type="hidden" class="form-control acticle_no_mkey" name="extra[new___LA_KEY__][acticle_no]" required="1"/>
<input type="hidden" class="form-control color_no_mkey" name="extra[new___LA_KEY__][color_no]" required="1"/>
</div>
</div>
{{-- 色组名称 --}}
<div class="col-md-3">
<label for="color_name_mkey" class="asterisk control-label col-sm-5" title="色组名称">色组名称:</label>
<div class="col-sm-7">
<input type="text" class="form-control color_name_mkey" name="extra[new___LA_KEY__][color_name]" readonly/>
</div>
</div>
{{-- 订单数量 --}}
<div class="col-md-3">
<label for="color_num_mkey" class="asterisk control-label col-sm-5" title="订单数量">订单数量:</label>
<div class="col-sm-7">
<input type="text" class="form-control color_num_mkey" name="extra[new___LA_KEY__][color_num]" readonly/>
</div>
</div>
{{-- 导出 --}}
<div class="col-md-3">
<div class="col-sm-7">
<input type="hidden" class="form-control pvws_id_mkey" name="extra[new___LA_KEY__][pvws_id]" required="1"/>
<a class="btn btn-sm btn-default" onclick="goToExports('pvws_id_mkey')" style="margin-right: 5px" >导出预览表</a>
</div>
</div>
</div>
<table class="table table-hover table-responsive" style="min-width: 1240px;overflow-x: auto">
<thead>
<tr>
<th class="column_tod_date_mkey" style="text-align: center;width: 100px">出货日期</th>
<th class="column_country_name_mkey" style="text-align: center;width: 150px">国家地区</th>
<th class="column_total_mkey" style="text-align: center;width: 100px">小计</th>
<th class="column_transport_mkey" style="text-align: center;width: 100px">运输方式</th>
</tr>
</thead>
<tbody class="trHtml_mkey">
</tbody>
</table>
</div>
</div>
</template>
<!-- /.box-body -->
<div class="box-footer">
<div class="col-md-2">
</div>
{{--<div class="col-md-8">--}}
{{--<div class="btn-group pull-left" style="margin-right: 10px">--}}
{{--<button type="submit" class="btn btn-primary submit" value="2" >提交</button>--}}
{{--</div>--}}
{{--</div>--}}
</div>
</div>
</div>
</div>
<!-- /.box-footer -->
</form>
</div>
</div>
</div>
<template class="num_detail">
<tr>
<td class="detail_tod_date_mkey" style="text-align: center;min-width: 110px"></td>
<td class="detail_country_mkey" style="text-align: center;width: 150px"></td>
<td class="detail_total_mkey" style="text-align: center;width: 100px"></td>
<td class="detail_transport_mkey" style="text-align: center;width: 100px"></td>
</tr>
</template>
{{--<script src="/js/upimg/jquery.2.1.1.min.js"></script>--}}
<script src="/js/upimg/upload_img.js"></script>
<script>
/**
* 实例化控件
**/
$(function () {
$('.grid-popup-link').magnificPopup({"type":"image"});
$(".fabric_type").select2({"allowClear":true,"placeholder":{"id":"","text":"面料类型"}});
$(".quarter_id").select2({"allowClear":true,"placeholder":{"id":"","text":"订单季节"}});
$(".cate_id").select2({"allowClear":true,"placeholder":{"id":"","text":"款式品类"}});
$(".bulk_sales").select2({"allowClear":true,"placeholder":{"id":"","text":"大货业务"}});
$(".bulk_aid").select2({"allowClear":true,"placeholder":{"id":"","text":"大货助理"}});
$(".bulk_buyer").select2({"allowClear":true,"placeholder":{"id":"","text":"大货采购"}});
$(".place_id").select2({"allowClear":true,"placeholder":{"id":"","text":"订单品名"}});
$(".size_range").select2({"allowClear":true,"placeholder":{"id":"","text":"尺码段"}});
$(".size_offer").select2({"allowClear":true,"placeholder":{"id":"","text":"报价码"}});
$(".size_datum").select2({"allowClear":true,"placeholder":{"id":"","text":"基础码"}});
$(".order_type").select2({"allowClear":true,"placeholder":{"id":"","text":"订单性质"}});
$(".ricamo_type").select2({"allowClear":true,"placeholder":{"id":"","text":"绣花方式"}});
$(".stampa_type").select2({"allowClear":true,"placeholder":{"id":"","text":"印花方式"}});
$(".wash_type").select2({"allowClear":true,"placeholder":{"id":"","text":"水洗方式"}});
$(".ricamo_factory").select2({"allowClear":true,"placeholder":{"id":"","text":"绣花工厂"}});
$(".stampa_factory").select2({"allowClear":true,"placeholder":{"id":"","text":"印花工厂"}});
$(".wash_factory").select2({"allowClear":true,"placeholder":{"id":"","text":"水洗工厂"}});
$(".is_seal").select2({"allowClear":true,"placeholder":{"id":"","text":"是否封样"}});
$(".is_entrust").select2({"allowClear":true,"placeholder":{"id":"","text":"是否委外"}});
$('.first_tod').parent().datetimepicker({"format":"YYYY-MM-DD","locale":"zh-CN","allowInputToggle":true,'minDate': new Date()});
$('.opd_date').parent().datetimepicker({"format":"YYYY-MM-DD","locale":"zh-CN","allowInputToggle":true,'minDate': new Date()});
$('.tod_date').parent().datetimepicker({"format":"YYYY-MM-DD","locale":"zh-CN","allowInputToggle":true,'minDate': new Date()});
$('.isw_date').parent().datetimepicker({"format":"YYYY-MM-DD","locale":"zh-CN","allowInputToggle":true,'minDate': new Date()});
$('.client_order_time').parent().datetimepicker({"format":"YYYY-MM-DD","locale":"zh-CN","allowInputToggle":true});
// 处理粘贴事件
$("#txtContentz").on('paste', function(eventObj) {
// 处理粘贴事件
initUploads(eventObj,'pic_front','pic_front_input')
// //阻止默认行为即不让剪贴板内容在div中显示出来
event.preventDefault();
});
// 处理粘贴事件
$("#txtContentf").on('paste', function(eventObj) {
// 处理粘贴事件
initUploads(eventObj,'pic_verso','pic_verso_input')
// //阻止默认行为即不让剪贴板内容在div中显示出来
event.preventDefault();
});
function initUploads(eventObj,$img,$imginput){
var event = eventObj.originalEvent;
var imageRe = new RegExp(/image\/.*/);
var fileList = $.map(event.clipboardData.items, function (o) {
if(!imageRe.test(o.type)){ return }
var blob = o.getAsFile();
return blob;
});
if(fileList[0]){
upload(fileList[0],LA.token,$img,$imginput);
}else {
sweetAlert('请截图后再粘帖');
}
// //阻止默认行为即不让剪贴板内容在div中显示出来
event.preventDefault();
}
$("#uploadImgZ").on('change', function () {
var file = $("#uploadImgZFile")[0].files[0];
upload(file,LA.token,'pic_front','pic_front_input')
event.preventDefault();
})
$("#uploadImgF").on('change', function () {
var file = $("#uploadImgFFile")[0].files[0];
upload(file,LA.token,'pic_verso','pic_verso_input')
event.preventDefault();
})
})
//上传文件改变触发事件, 显示上传文件名称
function insertInputText(e,j,fileName){
var File = $(e)[0].files[0];
var i = File.name.indexOf(fileName);
if(i == '-1'){
swal('请上传'+fileName+'文件','', 'error');
$(e).empty();
$('.'+j).empty();
return false;
}
$('.'+j).val(File.name)
event.preventDefault();
}
//提交上传文件
$(".uploadBulkFile").on('click', function () {
var PurchaseOrderFile = $("#PurchaseOrderFile")[0].files[0];
var TotalCountryBreakdownFile = $("#TotalCountryBreakdownFile")[0].files[0];
var PackingListFile = $("#PackingListFile")[0].files[0];
if(PurchaseOrderFile && TotalCountryBreakdownFile && PackingListFile){
bulk_upload(PurchaseOrderFile,TotalCountryBreakdownFile,PackingListFile);
}else{
swal('请上传文件后再提交','', 'error');
}
event.preventDefault();
})
//异步提交数据
function bulk_upload(PurchaseOrderFile,TotalCountryBreakdownFile,PackingListFile) {
var fd = new FormData();
var exploit_id =$('#exploit_id').val()
fd.append('PurchaseOrderFile', PurchaseOrderFile);
fd.append('TotalCountryBreakdownFile', TotalCountryBreakdownFile);
fd.append('PackingListFile', PackingListFile);
fd.append('exploit_id', exploit_id);
fd.append('_token', LA.token);
$.ajax({
url:"/admin/test/uploads_file",
type: 'POST',
dataType: 'json',
data: fd,
processData: false,
contentType: false,
xhrFields: { withCredentials: true },
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': 'true'
},
beforeSend:function(XMLHttpRequest){
$.mask_fullscreen();
},
success:function(data,textStatus){
if(data.status == 100){
index = 0;
swal(data.message,'','success');
$('#purchase_file').val(data.purchase_file);
$('#country_file').val(data.country_file);
$('#packing_file').val(data.packing_file);
initBulkInfo(data.bulk);
var arr = Object.keys(data.order_list);
$('#order_color_box').empty();
for (var i=0; i<arr.length; i++){
addHtml(data.order_list[arr[i]],data.size_group_list);
}
// createCountryCheckBox(data.parent_country)
}else{
swal(data.message,'','error');
}
},
complete:function(XMLHttpRequest,textStatus){
$.mask_close_all();
},
error:function(XMLHttpRequest,textStatus,errorThrown){
swal('error...状态文本值:'+textStatus+" 异常信息:"+errorThrown,'','error');
}
});
}
function initBulkInfo($data){
$('#bulk_no').val($data.product_no);
$('#bulk_name').val($data.product_name);
$('#order_no').val($data.order_no);
$('#season').val($data.sesson_id).select2();
$('#size_range').val($data.size_group_id).select2();
$('#order_date').val($data.order_date);
$('#client_order_time').val($data.order_date);
$('#order_flag').val($data.project_type).select2();
}
var index = 0;
var tpl = $('template.extra-tpl');
var detail_tpl = $('template.num_detail');
function addHtml(data,size_group){
//初始化订单色组数量;
var initTotal = 0;
//基础模板
var template = tpl.html().replace(/__LA_KEY__/g, index).replace(/_mkey/g, '_'+index);
$(".place_id_"+index).select2({"allowClear":true,"placeholder":{"id":"","text":"选择订单品名"}});
$('#order_color_box').append(template)
var arr = Object.keys(size_group);
var sizeHtml = '';
for (var i=0; i < arr.length ; i ++){
sizeHtml += "<td class='column_size_name_"+index+"_"+arr[i]+"' style='text-align: center;width: 150px'>"+arr[i]+"</td>"
}
$('.column_country_name_'+index).after(sizeHtml)
if(data){
$('.str_color_no_'+index).val(data.acticle_no+'#'+data.color_code);
$('.color_no_'+index).val(data.color_code);
$('.acticle_no_'+index).val(data.acticle_no);
$('.pvws_id_'+index).val(data.pvws_id);
$('.color_name_'+index).val(data.color_name);
}
// 尺码数量明细模板
var tod_date = 0;
var tod_date_bg = '#FFF';
for (key in data.list){
var detailtmp = detail_tpl.html().replace(/_mkey/g, '_'+index+'_'+key);
var detailSizeHtml = '';
var data_list = data.list[key];
var details = data_list.data;
var size_total = 0;
for (j in details) {
size_total += details[j].size_num;
detailSizeHtml += "<td class='detail_country_"+index+"_"+details[j].size_name+"' style='text-align: center;max-width: 120px'>" +
"<input type='hidden' name='extra[new_"+index+"][list][row"+key+"][size][]' value='"+details[j].size_name+"'>" +
"<input type='text' name='extra[new_"+index+"][list][row"+key+"][num][]' class='form-control' value='"+details[j].size_num+"'>" +
"</td>"
}
initTotal += size_total;
$('.trHtml_'+index).append(detailtmp)
//日期归类 填充背景色
if(tod_date != data_list.tod_date){
tod_date = data_list.tod_date
tod_date_bg = getRandomColorUndertint();
}
var tod_html = data_list.tod_date+"<input type='hidden' name='extra[new_"+index+"][list][row"+key+"][tod_date]' class='form-control' value='"+data_list.tod_date+"'>";
$('.detail_tod_date_'+index+'_'+key).html(tod_html).parent('tr').css('background',tod_date_bg)
//添加国别仓库ID 和 归属国别地区的ID
var area_html = data_list.area_name+"<input type='hidden' name='extra[new_"+index+"][list][row"+key+"][area_id]' value='"+data_list.area_id+"'>";
area_html += "<input type='hidden' name='extra[new_"+index+"][list][row"+key+"][country_id]' value='"+data_list.country_id+"'>";
area_html += "<input type='hidden' name='extra[new_"+index+"][list][row"+key+"][account_type]' value='"+data_list.account_type+"'>";
area_html += "<input type='hidden' name='extra[new_"+index+"][list][row"+key+"][amount]' value='"+data_list.amount+"'>";
area_html += "<input type='hidden' name='extra[new_"+index+"][list][row"+key+"][transport]' value='"+data_list.carriage_type+"'>";
$('.detail_country_'+index+'_'+key).html(area_html).after(detailSizeHtml);
$('.detail_total_'+index+'_'+key).html(size_total);
$('.detail_transport_'+index+'_'+key).html(data_list.carriage_name);
}
$('.color_num_'+index).val(initTotal);
index++;
}
//浅色
function getRandomColorUndertint() {
return '#' +
(function(color) {
return(color += '5678956789defdef' [Math.floor(Math.random() * 16)]) &&
(color.length == 6) ? color : arguments.callee(color);
})('');
}
/**
* 导出预览表
*/
function goToExports(key) {
var pvw_id = $('.'+key).val()
window.open("/admin/test/export_load?pvws_id="+pvw_id);
}
</script>
</div>
excel附件:
[PackingList.xlsx](https://download.csdn.net/download/xcbzsy/14121664)
[PurchaseOrder.xlsx](https://download.csdn.net/download/xcbzsy/14121667)
[TotalCountryBreakdown.xlsx](https://download.csdn.net/download/xcbzsy/14121670)