Commit 57dfabaa by 孙龙

up

parent 6c28bc50
<?php
namespace App\Http\Controllers;
use App\Exceptions\IcException;
use App\Model\TmplRelationsModel;
use Illuminate\Http\Request;
use App\Http\Requests;
......@@ -93,70 +93,44 @@ class WebController extends Controller
public function showPage($request,$info){
$info['title'] = '预览';
$id = $request->input("tmpl_relation_id",0);
// dump($id);
$tmpRelation = TmplRelationsModel::where("id",intval($id))->first();
$tmpRelation->template = $tmpRelation->template;
$tmpRelation->tmpRelation = $tmpRelation->template->template_extend;
$tmpRelation->saleOrder = $tmpRelation->saleOrder;
$info['templateInfo'] = $tmpRelation;
$info["ichunt2020"]["sale_order_sn"] = $tmpRelation->saleOrder->sale_order_sn;
$info["ichunt2020"]["goods_type"] = $tmpRelation->saleOrder->goods_type;
$info["ichunt2020"]["goods_brand"] = $tmpRelation->saleOrder->goods_brand;
$info["ichunt2020"]["goods_number"] = $tmpRelation->saleOrder->goods_number;
$info["ichunt2020"]["sku_code"] = $tmpRelation->saleOrder->customer_code;
$info["ichunt2020"]["customer_code"] = $tmpRelation->saleOrder->customer_code;
$info["ichunt2020"]["customer_com"] = $tmpRelation->saleOrder->customer_com;
try{
$matches = [];
$a = preg_match_all('/<<<(.*?)>>>/i',$tmpRelation->tmpRelation->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,$tmpRelation->tmpRelation->html);
}else{
$html = $tmpRelation->tmpRelation->html;
$html = (new \App\Services\LabelService)->getLabelHtml(5);
$info["html"] = $html;
return view('web', $info);
}
$dom = HtmlDomParser::str_get_html( $html );
$textareas = $dom->find('textarea');
foreach($textareas as $k=>$textarea){
$textarea->innertext = $textarea->datatypes;
public function prints($request,$info){
$tmpl_relationids = $request->input("tmpl_relationids",'');
$tmpl_relationid_arr = explode(",",$tmpl_relationids);
if(empty($tmpl_relationids)){
die("没有要打印的数据");
}
$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;
if(!empty($tmpl_relationid_arr)){
$tmpl_relationid_arr = array_unique($tmpl_relationid_arr);
$tmpl_relationid_arr = array_map("intval",$tmpl_relationid_arr);
$tmpl_relationid_arr = array_filter($tmpl_relationid_arr,function($val){
if ($val > 0) {
return true;
} else {
return false;
}
$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;
});
}
// dump($tmpl_relationid_arr);
$info['title'] = '打印';
$templateRelation = TmplRelationsModel::where("create_userid",$request->user->userId)->whereIn("id",$tmpl_relationid_arr)
->get();
$html = [];
foreach($templateRelation as $item){
$createHtml = (new \App\Services\LabelService)->getLabelHtml($item->id);
if($createHtml){
array_push($html,$createHtml);
}
}catch(\Exception $e){
dump($e->getMessage());
}
// \View::make('admin.messages', $info["ichunt2020"]);
// dump($html);exit;
$info["html"] = $dom;
return view('web', $info);
$info["html"] = $html;
return view('web.prints', $info);
}
......
<?php
namespace App\Services;
use App\Http\Requests;
use DB;
use Sunra\PhpSimple\HtmlDomParser;
use Log;
use App\Http\Controllers\Controller;
use App\Model\TemplateListModel;
use App\Model\NodesModel;
use App\Model\TmplRelationsModel;
class LabelService {
public function getLabelHtml($id){
// dump($id);
$tmpRelation = TmplRelationsModel::where("id",intval($id))->first();
$tmpRelation->template = $tmpRelation->template;
$tmpRelation->tmpRelation = $tmpRelation->template->template_extend;
$tmpRelation->saleOrder = $tmpRelation->saleOrder;
$info['templateInfo'] = $tmpRelation;
$info["ichunt2020"]["sale_order_sn"] = $tmpRelation->saleOrder->sale_order_sn;
$info["ichunt2020"]["goods_type"] = $tmpRelation->saleOrder->goods_type;
$info["ichunt2020"]["goods_brand"] = $tmpRelation->saleOrder->goods_brand;
$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_com"] = $tmpRelation->saleOrder->customer_com;
try{
$matches = [];
$a = preg_match_all('/<<<(.*?)>>>/i',$tmpRelation->tmpRelation->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,$tmpRelation->tmpRelation->html);
}else{
$html = $tmpRelation->tmpRelation->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
......@@ -121,7 +121,15 @@ layui.use(['form', 'table', 'laydate'], function(){
layer.msg("至少得选中一个打印标签", { time:2000}); // 阻止重复提交
return;
}
//layer.alert(JSON.stringify(data));
var tmp = [];
console.log(data);
for(var k=0;k<data.length;k++){
tmp.push(data[k].id)
}
var href ="/web/prints?tmpl_relationids="+tmp.join(",")
window.open(href)
break;
case 'getCheckLength':
var data = checkStatus.data;
......
<div class="dybox">
@foreach($html as $item)
{!! $item !!}
@endforeach
</div>
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