Commit cf2e8c96 by 孙龙

up

parent 897f5560
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Exceptions\IcException;
use App\Model\OfflinePrintModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
......@@ -395,4 +396,39 @@ Class AjaxController extends Controller
}
public function offline_upload($request){
$uploadService = new \App\Services\UploadService();
$offlineLabelService = new \App\Services\OfflineLabelService();
$resData = $uploadService->upload($request);
if($resData === false || empty($resData->data)){
return $this->ajaxReturn(-1,"文件上传失败,请检查文件格式或者联系管理员");
}
$data = $offlineLabelService->getOfflineUploadData($resData->data);
return $this->ajaxReturn(0,"ok",$data);
}
/*
* 离线导入打印标签
*/
public function offlinePrint($request){
$html = $request->input("html",'');
$datas = $request->input("datas",'');
$returnHtml = [];
foreach($datas as $k=>$item){
$createHtml = (new \App\Services\LabelService)->getLabelOfflineHtml($html,$item);
if($createHtml){
array_push($returnHtml,$createHtml->outertext);
}
}
$str = \GuzzleHttp\json_encode($returnHtml);
$path = storage_path(sprintf('offline_print/%s.txt',$request->user->userId));
$bk = file_put_contents($path,$str);
if($bk === false){
return $this->ajaxReturn(-1,"打印失败");
}
return $this->ajaxReturn(0,"ok");
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Model\OfflinePrintModel;
use App\Model\TmplRelationsModel;
use Illuminate\Http\Request;
use App\Http\Requests;
......@@ -184,5 +185,15 @@ class WebController extends Controller
}
public function offlinePrint($request,$info){
$path = storage_path(sprintf('offline_print/%s.txt',$request->user->userId));
$content = file_get_contents($path);
$info["html"] = json_decode($content,true);
// dump($info);
return view('web.prints', $info);
}
}
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class OfflinePrintModel extends Model{
protected $connection = 'label'; //库名
protected $table = 'offline_print';
protected $primaryKey = 'id'; //设置id
protected $guarded = ['id']; //设置字段黑名单
public $timestamps = false;
}
\ No newline at end of file
......@@ -28,6 +28,7 @@ class LabelService {
$info["ichunt2020"]["goods_number"] = $tmpRelation->saleOrder->goods_number;
$info["ichunt2020"]["sku_code"] = $tmpRelation->saleOrder->sku_code;
$info["ichunt2020"]["customer_code"] = $tmpRelation->saleOrder->customer_code;
$info["ichunt2020"]["customer_type"] = $tmpRelation->saleOrder->customer_type;
$info["ichunt2020"]["customer_com"] = $tmpRelation->saleOrder->customer_com;
try{
$matches = [];
......@@ -86,4 +87,77 @@ class LabelService {
}
}
public function getLabelOfflineHtml($_html,$item){
$info["ichunt2020"]["sale_order_sn"] = isset($item["sale_order_sn"]) ? $item["sale_order_sn"] : "";
$info["ichunt2020"]["goods_type"] = isset($item["goods_type"]) ? $item["goods_type"] : '';
$info["ichunt2020"]["goods_brand"] = isset($item["goods_brand"]) ? $item["goods_brand"] : "";
$info["ichunt2020"]["goods_number"] = isset($item["goods_number"]) ? $item["goods_number"] : "";
$info["ichunt2020"]["sku_code"] = isset($item["sku_code"]) ? $item["sku_code"] : "";
$info["ichunt2020"]["customer_code"] = isset($item["customer_code"]) ? $item["customer_code"] : "";
$info["ichunt2020"]["customer_type"] = isset($item["customer_type"]) ? $item["customer_type"] : "";
$info["ichunt2020"]["customer_com"] = isset($item["customer_com"]) ? $item["customer_com"] : "";
return $this->getHtml($_html,$info);
}
protected function getHtml($_html,$info){
try{
$matches = [];
$a = preg_match_all('/<<<(.*?)>>>/i',$_html,$matches);
foreach($matches[1] as $k=>$field){
$arr[$k] = isset($info["ichunt2020"][$field])?$info["ichunt2020"][$field] : '';
}
if(!empty($matches)){
$html = str_replace($matches[0],$arr,$_html);
}else{
$html = $_html;
}
$dom = HtmlDomParser::str_get_html( $html );
//处理文本
$textareas = $dom->find('textarea');
foreach($textareas as $k=>$textarea){
// dump($textarea->datatypes);
if($textarea->datatypes){
$textarea->innertext = $textarea->datatypes;
}
if($textarea->datatypes !== false && $textarea->datatypes == ""){
$textarea->innertext = "";
$textarea->placeholder = "";
}
}
//处理一维码
$yiweimaits = $dom->find("div[name='yiweimait']");
foreach($yiweimaits as $k=>$yiweimait){
$a = $yiweimait->style;
$b = 'data:image/png;base64,' . DNS1D::getBarcodePNG($yiweimait->datatypes, "C128");
$c = preg_replace('/background: url\((.*?)\) 0% 0% \/ 100% 100%/'," background: url({$b}) 0% 0% / 100% 100% ",$a);
$yiweimait->style = $c;
}
//处理二维码
$erweimas = $dom->find("div[name='erweimait']");
foreach($erweimas as $k=>$erweima){
$a =$erweima->style;
$b = 'data:image/png;base64,' . DNS2D::getBarcodePNG($erweima->datatypes, "QRCODE");
$c = preg_replace('/background: url\((.*?)\) 0% 0% \/ 100% 100%/'," background: url({$b}) 0% 0% / 100% 100% ",$a);
$erweima->style = $c;
}
return $dom;
}catch(\Exception $e){
Log::info(sprintf("解析便签模板失败:%s",$e->getMessage()));
return false;
}
}
}
\ No newline at end of file
<?php
namespace App\Services;
class OfflineLabelService{
public $excelTitle=[
"customer_com",
"sale_order_sn",
"goods_type",
"goods_brand",
"goods_number",
"sku_code",
"customer_code",
"customer_type",
];
public function getOfflineUploadData($data){
$arr = [];
if(isset($data[0])) unset($data[0]);
foreach($data as $key=>$item){
$item = array_map("trim",$item);
foreach($item as $k=>$vv){
if(in_array($k,[0,1,2,3])){
if($vv == "" || $vv == null){
unset($item);
}
}
}
if(isset($item) && !empty($item)){
$arr[] = $item;
}
}
$tmp = [];
foreach($arr as $k=>$v){
foreach($v as $kk=>$vv){
if(isset($this->excelTitle[$kk])){
$tmp[$k][$this->excelTitle[$kk]] = $vv;
}
}
}
return $tmp;
}
}
\ No newline at end of file
<?php
namespace App\Services;
use Excel;
use Log;
use Illuminate\Support\Facades\Input;
class UploadService {
public $data = [];
/**
* 上传客户资料
* @param $req
* @return bool
*/
public function upload($req){
try{
$file = Input::file('file');
if($file){
$excel_file_path = $file->getRealPath();
Excel::load($excel_file_path, function($reader){
for($i=0;$i<($reader->getSheetCount());$i++){
$res = null;
$res = $reader->getSheet($i);
$sheet_title = trim($res->getTitle());
//判断sheet是否为空 名称是否正确
$res = $res->toArray();
call_user_func_array([$this,"setData"],[$res]);
//预存储数据
}
},'GBK');
}
return $this;
}catch(\Exception $e){
Log::info(sprintf("上传文件失败 %s",$e->getMessage()));
return false;
}
}
protected function setData($result=[]){
$this->data = $result;
}
}
\ No newline at end of file
/**
* Created by ICHUNT on 2020/5/18.
*/
layui.use(['form', 'table', 'laydate','upload'], function() {
var form = layui.form;
var table = layui.table;
var laydate = layui.laydate;
var $ = layui.jquery
var upload = layui.upload;
var data_123456 = [];
upload.render({
elem: '#offline_upload'
,url: '/ajax/offline_upload'
,accept: 'file' //普通文件
,done: function(res){
if(res.err_code == 0){
data_123456 = res.data
//执行重载
elem_data(data_123456);
layer.msg("上传成功", {icon: 16, time: 2000}); // 阻止重复提交
}else{
layer.msg("上传失败", {icon: 16, time: 2000}); // 阻止重复提交
}
}
});
//工具栏事件
table.on('toolbar(demo)', function(obj){
var checkStatus = table.checkStatus(obj.config.id);
switch(obj.event){
case 'getCheckData':
var data = checkStatus.data;
if(data.length <= 0){
layer.msg("至少得选中一个打印标签", { time:2000}); // 阻止重复提交
return;
}
var tmp = [];
console.log($(".editgo").html())
console.log(data);
$.post("/ajax/offlinePrint",{html:$(".editgo").html(),datas:data},function(result){
if(result.err_code == 0){
var href ="/web/offlinePrint";
window.open(href)
}else{
layer.msg("打印失败", { time:2000}); // 阻止重复提交
}
});
break;
default:
return
};
});
function elem_data(data_123456){
table.render({
elem: '#demo'
//,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,limit: 10
,toolbar: '#toolbarDemo'
,defaultToolbar:[]
,cols: [[ //表头
{field:"id", type: 'checkbox',fixed: 'left'},
{title: '序号',field:"",fixed: 'left',type:"numbers"}
,{field: 'customer_com', title: "公司"}
,{field: 'sale_order_sn', title: '销售单号'}
,{field: 'goods_type', title: '型号'}
,{field: 'goods_brand', title: '品牌'}
,{field: 'goods_number', title: '数量',width:80}
,{field: 'customer_type', title: '客户编码'}
,{field: 'customer_type', title: '客户型号'}
]]
,data:data_123456
})
}
})
\ No newline at end of file
@include('web.offline_design')
\ No newline at end of file
@include('web.offline_design')
<div class=" site-demo-button" style="margin-top: 30px;">
<legend>离线使用</legend>
<form class="layui-form" action="">
<div>
<button type="button" class="layui-btn" id="offline_upload"><i class="layui-icon"></i>上传文件</button>
<button type="button" class="layui-btn layui-btn-normal">下载模板</button>
</div>
</form>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="getCheckData">去打印</button>
</div>
</script>
</div>
<table id="demo" lay-filter="demo"></table>
This diff could not be displayed because it is too large.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment