Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

孙龙 / note-library

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • note-library
  • app
  • Http
  • Controllers
  • AjaxController.php
AjaxController.php 16.6 KB
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
1 2 3 4
<?php
namespace App\Http\Controllers;

use App\Exceptions\IcException;
孙龙's avatar
up
cf2e8c96
 
孙龙 committed 5 years ago
5
use App\Model\OfflinePrintModel;
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
6 7 8
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
9
use Log;
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
10 11 12
use App\Model\TemplateListModel;
use App\Model\SaleOrderListsModel;
use App\Model\TmplRelationsModel;
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
13
use App\Model\TemplateExtendModel;
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
14 15 16

Class AjaxController extends Controller
{
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
17
    public $erp;
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
18 19 20 21 22 23
    // 统一入口
    public function entrance(Request $request, $id)
    {
       return $this->$id($request);
    }

孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
24 25
    // 模板列表
    public function labelList($request)
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
26
    {
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
27 28 29 30 31 32 33
        $page = $request->input("page",1);
        $limit = $request->input("limit",10);
        $template_name = $request->input("template_name",'');
        $create_username = $request->input("create_username",'');
        $status = $request->input("status",'all');
        $begin_time = $request->input("begin_time",'');
        $end_time = $request->input("end_time",'');
孙龙's avatar
up
a88a7a4d
 
孙龙 committed 5 years ago
34
        $userType = $request->input("userType",0);//1只显示系统模板
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
35 36 37 38
        $admin_id = $request->user->userId;
        $perm = new PermController;
        // 用户角色
        $role = $perm->getUserRole($request);
孙龙's avatar
up
a88a7a4d
 
孙龙 committed 5 years ago
39
        $query = TemplateListModel::select('*')->CreateUserId($admin_id,$role,$create_username,$userType)->TemplateName($template_name)
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
40 41
            ->Status($status)
            ->SearchTime($begin_time,$end_time)
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
42
            ->OrderBy("status","desc")
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
43 44 45 46
            ->OrderBy("id","desc");
        $query = $query->paginate($limit,[],'page',$page);
        $list = $query->toArray();
        return ['code'=>0, 'count'=>$list['total'],'data'=>$list["data"]];
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
47 48
    }

孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
49 50
    // 标签使用记录
    public function record($request)
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
51
    {
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
52 53 54 55 56 57 58
        $page = $request->input("page",1);
        $limit = $request->input("limit",10);
        $sale_order_sn = $request->input("sale_order_sn",'');
        $goods_type = $request->input("goods_type",'');
        $status = $request->input("status",'all');
        $begin_time = $request->input("begin_time",'');
        $end_time = $request->input("end_time",'');
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
59 60


孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
        $perm = new PermController;
        // 用户角色
        $role = $perm->getUserRole($request);
        $admin_id = $request->user->userId;
        $query = TmplRelationsModel::select('*')->with("saleOrder")->CreateUserId($admin_id,$role)
            ->SaleOrderSn($sale_order_sn,$goods_type)->SearchTime($begin_time,$end_time)
            ->OrderBy("id","desc");
//        dump($query->toSql());
        $list = $query->paginate($limit,[],'page',$page);
//        dump($list);
        $arr = [];
        foreach($list as $k=>$item){
            $arr[$k]["id"] = $item->id;
            $arr[$k]["template_name"] = $item->template ? $item->template->template_name : '';
            $arr[$k]["sale_order_sn"] = $item->saleOrder ? $item->saleOrder->sale_order_sn : '';
            $arr[$k]["goods_type"] =  $item->saleOrder ? $item->saleOrder->goods_type : '';
孙龙's avatar
up
74754b18
 
孙龙 committed 5 years ago
77
            $arr[$k]["createUser"] =  $item->saleOrder ? $item->saleOrder->createUser : '';
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
78 79 80 81 82
            $arr[$k]["print_nums"] = $item->print_nums;
            $arr[$k]["create_time"] = date("Y-m-d h:i:s",$item->create_time);
            $arr[$k]["print_time"] = date("Y-m-d h:i:s",$item->print_time);
        }
        return ['code'=>0, 'count'=>collect($list)->get("total"),'data'=>$arr];
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
83 84
    }

孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
85 86 87 88 89 90 91 92 93 94

    /*
     * 模板列表修改状态
     */
    public function template_status($request){
        $id = $request->input("id",0);
        $status = $request->input("status",0);
        $perm = new PermController;
        // 用户角色
        $role = $perm->getUserRole($request);
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
95
        $tmpl = TemplateListModel::where("create_userid",$request->user->userId)->find(intval($id));
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
96 97 98
        if($tmpl){
            $tmpl->status = ($tmpl->status == -1) ? 1 :-1;
            $tmpl->save();
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
99
            //此处推送到erp
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
100
            $this->pushTemplateErp(intval($id));
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
101 102 103 104
            return $this->ajaxReturn(0,"修改成功");
        }else{
            return $this->ajaxReturn(-1,"没找到与自己对应的模板");
        }
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
105 106
    }

孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
107
    /*
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
108
     * 模板列表修改名称
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
109 110 111 112 113 114 115 116 117
     */
    public function edit_template_info($request){
        $id = $request->input("id",0);
        $template_name = $request->input("template_name",'');
        if(!$template_name){
            return $this->ajaxReturn(-1,"模板名称必填");
        }
        $tmpl = TemplateListModel::where("create_userid",$request->user->userId)->find(intval($id));
        if(!$tmpl){
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
118
            return $this->ajaxReturn(-1,"您只能修改自己创建的模板哦!");
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
119
        }
孙龙's avatar
up
6780167d
 
孙龙 committed 5 years ago
120 121 122

        $count = TemplateListModel::where(["create_userid"=>$request->user->userId,"template_name"=>$template_name])->count();
        if($count > 0){
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
123
            return $this->ajaxReturn(-1,"已经存在该名称的模板了!");
孙龙's avatar
up
6780167d
 
孙龙 committed 5 years ago
124 125
        }

孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
126
        $tmpl->template_name = $template_name;
孙龙's avatar
up
6780167d
 
孙龙 committed 5 years ago
127 128 129 130
        $bk = $tmpl->save();
        if($bk === false){
            return $this->ajaxReturn(-1,"修改模板失败!");
        }
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
131 132

        //此处推送到erp
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
133
        $this->pushTemplateErp(intval($id));
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
134 135 136 137 138 139


        return $this->ajaxReturn(0,"修改成功");
    }


孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
140 141 142 143 144 145 146

    protected function ajaxReturn($code,$msg="",$data=[]){
        return [
            "err_code"=>$code,
            "err_msg"=>$msg,
            "data"=>$data,
        ];
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
147 148
    }

孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
149

孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
150 151 152 153
    /*
     * 推送模板消息到erp
     */
    protected function pushTemplateErp($t_id=0){
孙龙's avatar
up
f1bc9ba7
 
孙龙 committed 5 years ago
154
//        return true;
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
155
        try{
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
156
            $template = TemplateListModel::find($t_id);
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
157
            //登录
孙龙's avatar
up
fdf03ae1
 
孙龙 committed 5 years ago
158
            $soap = new \SoapClient(env("ERP_DOMAIN").'/ormrpc/services/EASLogin?wsdl');
孙龙's avatar
up
69b35c0a
 
孙龙 committed 5 years ago
159
            $res = $soap->login( 'TC', 'unicom', 'eas', env('ERP_DB_NAME'),  'L2', 1, 'BaseDB');
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
160
            //接口
孙龙's avatar
up
fdf03ae1
 
孙龙 committed 5 years ago
161
            $this->erp = new \SoapClient(ENV("ERP_DOMAIN").'/ormrpc/services/WSIchuntjKFacade?wsdl');
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
162 163 164 165 166
            $res = $this->erp->createIssueLabel(json_encode([
                "templateId"=>$template->id,
                "templateNmae"=>$template->template_name,
                "createUser"=>$template->create_username,
                "status"=>intval($template->status),
孙龙's avatar
up
fdf03ae1
 
孙龙 committed 5 years ago
167
            ]));
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
168 169
            $template->is_push = 0;
            $arr = [];
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
170 171
            if($res){
                $res = \GuzzleHttp\json_decode($res,true);
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
172
                Log::info(print_r($res,true));
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
173
                if(isset($res["0000"])){
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
174 175 176 177
                    $template->is_push = 1;
                    $arr =  ['err_code'=>0,'err_msg'=>"模板推送成功"];
                }elseif(isset($res["4444"])){
                    $arr =  ['err_code'=>-1,'err_msg'=>sprintf("模板推送erp失败 %s",$res["4444"])];
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
178
                }
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
179 180
            }else{
                $arr =  ['err_code'=>-1,'err_msg'=>sprintf("模板信息推送到erp失败")];
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
181
            }
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
182 183 184
            $template->save();
            return $arr;

孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
185
        }catch(\Exception $e){
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
186 187 188 189
            $template->is_push = 0;//0未推送至erp   1已推送
            $template->save();
            Log::info(sprintf("模板:%s 信息推送到erp失败:%s",$t_id,$e->getMessage()));
            return ['err_code'=>-1,'err_msg'=>sprintf("模板信息推送到erp异常,原因:%s",$e->getMessage())];
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
190 191 192
        }
    }

孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
193 194 195 196 197 198

    /*
     * 添加模板
     */
    public function add_template($request){
        $template_name = $request->input("designName",'');
孙龙's avatar
up
30e1e1d6
 
孙龙 committed 5 years ago
199
        $html = $request->input("htmlp",'');
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
        $lableBg = $request->input("lableBg",'');
        $lableBorder = $request->input("lableBorder",'');
        $lableSize = $request->input("lableSize",'');
        if(!$template_name){
            return $this->ajaxReturn(-1,"请填写模板名称!");
        }

        if(!$html){
            return $this->ajaxReturn(-1,"模板标签是空!");
        }

        $attribute["lableBg"] = $lableBg;
        $attribute["lableBorder"] = $lableBorder;
        $attribute["lableSize"] = $lableSize;

        $data['template_name'] = $template_name;
        $data['html'] = $html;
        $data['attribute'] = $attribute;


孙龙's avatar
up
3d487875
 
孙龙 committed 5 years ago
220 221 222 223 224 225 226 227 228
        $id  = $request->input("t_id",0);
        if(intval($id) > 0){
//----------------------------修改模板------------------------------------------------------------------
            $count = TemplateListModel::where("id",intval($id))->where("create_userid",$request->user->userId)->count("id");
            if($count <= 0){
                return $this->ajaxReturn(-1,"没找到属于您的模板信息");
            }
            $templateInfo = TemplateListModel::where("id",intval($id))->select("id","template_name","status")->first();
            if($templateInfo->status <= 0){
孙龙's avatar
up
77292988
 
孙龙 committed 5 years ago
229
                return $this->ajaxReturn(-1,"该模板已经被主人禁用了");
孙龙's avatar
up
3d487875
 
孙龙 committed 5 years ago
230 231
            }

孙龙's avatar
up
a68710bd
 
孙龙 committed 5 years ago
232 233 234 235 236 237 238
            if($template_name != $templateInfo->template_name){
                $count = TemplateListModel::where("create_userid",$request->user->userId)->where("template_name",$template_name)->count("id");
                if($count > 0){
                    return $this->ajaxReturn(-1,"模板名称已经存在,请修改模板名称再提交!");
                }
            }

孙龙's avatar
up
3d487875
 
孙龙 committed 5 years ago
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
            $data['t_id'] = intval($id);
            try{
                DB::Connection("label")->transaction(function () use($data,$request) {
                    //创建模板
                    $templateList = TemplateListModel::where(["id"=>$data['t_id']])->update([
                        "template_name"=>trim($data['template_name']),
                        "update_time"=>time(),
                    ]);
                    if($templateList === false){
                        throw new \Exception("修改模板名称失败",-1);
                    }
                    //创建模板扩展信息 属性
                    $templateExtend = TemplateExtendModel::where(["template_id"=>$data['t_id']])->update([
                        "html"=>$data['html'],
                        "attribute"=>json_encode($data['attribute']),
                    ]);
孙龙's avatar
up
77292988
 
孙龙 committed 5 years ago
255
                    if($templateExtend === false){
孙龙's avatar
up
3d487875
 
孙龙 committed 5 years ago
256 257
                        throw new \Exception("修改模板属性失败",-1);
                    }
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
258 259

                    //此处推送到erp
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
260
                    $this->pushTemplateErp($data['t_id']);
孙龙's avatar
up
3d487875
 
孙龙 committed 5 years ago
261 262 263 264 265 266 267 268 269 270 271
                });
                return $this->ajaxReturn(0,"修改模板成功");
            }catch(\Exception $e){
                return $this->ajaxReturn(-1,$e->getMessage());
            }
            exit;
        }

// --------------------------新增模板------------------------------------------------------------

        //新增模板
孙龙's avatar
up
086e8785
 
孙龙 committed 5 years ago
272 273 274 275 276 277 278
        $count = TemplateListModel::where("template_name",trim($data['template_name']))
            ->where(function($q) use($request){
                $q->where(["create_userid"=>$request->user->userId])->orWhere(["create_userid"=>1000]);
            })->count("id");
        if($count){
            return $this->ajaxReturn(-1,"模板名称已经存在,请修改模板名称再提交!");
        }
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
279 280 281 282
        try{
            DB::Connection("label")->transaction(function () use($data,$request) {
                //创建模板
                $templateList = TemplateListModel::create([
孙龙's avatar
up
086e8785
 
孙龙 committed 5 years ago
283
                    "template_name"=>trim($data['template_name']),
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
                    "create_userid"=>$request->user->userId,
                    "create_username"=>$request->user->name,
                    "create_time"=>time(),
                    "update_time"=>time(),
                ]);
                if(!$templateList){
                    throw new \Exception("添加模板失败",-1);
                }
                //创建模板扩展信息 属性
                $templateExtend = TemplateExtendModel::create([
                    "template_id"=>$templateList->id,
                    "html"=>$data['html'],
                    "attribute"=>json_encode($data['attribute']),
                ]);
                if(!$templateExtend){
                    throw new \Exception("添加模板失败",-1);
孙龙's avatar
up
c3a7675c
 
孙龙 committed 5 years ago
300 301
                }
                //此处推送到erp
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
302
                $this->pushTemplateErp($templateList->id);
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
303
            });
孙龙's avatar
up
809dcce0
 
孙龙 committed 5 years ago
304
            return $this->ajaxReturn(0,"添加模板成功");
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
305
        }catch(\Exception $e){
孙龙's avatar
up
086e8785
 
孙龙 committed 5 years ago
306
            return $this->ajaxReturn(-1,$e->getMessage());
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
307 308 309
        }


孙龙's avatar
up
30e1e1d6
 
孙龙 committed 5 years ago
310 311
    }

孙龙's avatar
up
f1bc9ba7
 
孙龙 committed 5 years ago
312 313 314 315 316 317 318 319 320 321
    /*
     * 推送模板信息到erp
     */
    public function push_template_erp($request){
        $id  = $request->input("t_id",0);
        $template = TemplateListModel::where(["create_userid"=>$request->user->userId])->find($id);
        if(!$template){
            return $this->ajaxReturn(-1,"没找到属于您的模板相关信息");
        }
        //此处推送到erp
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
322 323 324 325 326 327 328
        $res = $this->pushTemplateErp($template->id);
        if(!empty($res) && $res['err_code'] < 0){
            return $this->ajaxReturn(-1,$res['err_msg']);
        }
        $template->is_push = 1;
        if($template->save() === false){
            return $this->ajaxReturn(-1,推送失败);
孙龙's avatar
up
f1bc9ba7
 
孙龙 committed 5 years ago
329 330 331 332
        }
        return $this->ajaxReturn(0,"推送模板成功");
    }

孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
333

孙龙's avatar
up
6780167d
 
孙龙 committed 5 years ago
334 335 336 337 338 339 340 341 342 343 344 345
    /*
     * 复制模板
     */
    public function copy_template($request){
        $id  = $request->input("t_id",0);
        $copyTemplate = TemplateListModel::find($id);
        if(!$copyTemplate){
            return $this->ajaxReturn(-1,"没找到该模板相关信息");
        }
        try{
           DB::Connection("label")->transaction(function () use($copyTemplate,$request) {
               $templateList = TemplateListModel::create([
孙龙's avatar
up
4f6cd31d
 
孙龙 committed 5 years ago
346
                    "template_name"=>$copyTemplate->template_name."_copy"."_".date("Ymdhis"),
孙龙's avatar
up
6780167d
 
孙龙 committed 5 years ago
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
                    "create_userid"=>$request->user->userId,
                    "create_username"=>$request->user->name,
                    "create_time"=>time(),
                    "update_time"=>time(),
                ]);
               if(!$templateList){
                   throw new \Exception("复制模板失败",-1);
               }

               //创建模板扩展信息 属性
               $templateExtend = TemplateExtendModel::create([
                   "template_id"=>$templateList->id,
                   "html"=>$copyTemplate->template_extend->html,
                   "attribute"=>$copyTemplate->template_extend->attribute,
               ]);
               if(!$templateExtend){
                   throw new \Exception("复制模板失败",-1);
               }
               //此处推送到erp
孙龙's avatar
up
466e8323
 
孙龙 committed 5 years ago
366
               $this->pushTemplateErp($templateList->id);
孙龙's avatar
up
6780167d
 
孙龙 committed 5 years ago
367 368 369 370 371 372 373 374 375 376 377 378 379 380

            });
            $data = [];
            if($copyTemplate->create_userid == "1000"){
                $data = ["redictUrl"=>"/web/labelList"];
            }
            return $this->ajaxReturn(0,"复制模板成功",$data);
        }catch(\Exception $e){
            return $this->ajaxReturn(-1,$e->getMessage());
        }

    }


孙龙's avatar
up
30e1e1d6
 
孙龙 committed 5 years ago
381 382 383
    /**
     * 编辑模板 获取模板详情
     */
孙龙's avatar
up
42c88eac
 
孙龙 committed 5 years ago
384 385 386 387 388 389
    public function getTemplateDetail($request){
        $id  = $request->input("t_id",0);
        $count = TemplateListModel::where("id",intval($id))->where("create_userid",$request->user->userId)->count("id");
        if($count <= 0){
            return $this->ajaxReturn(-1,"没找到属于您的模板信息");
        }
孙龙's avatar
up
af0b14b7
 
孙龙 committed 5 years ago
390
        $templateInfo = TemplateListModel::where("id",intval($id))->select("id","template_name","status")->first();
孙龙's avatar
up
cc27fb0a
 
孙龙 committed 5 years ago
391
        if($templateInfo->status <= 0){
孙龙's avatar
up
77292988
 
孙龙 committed 5 years ago
392
            return $this->ajaxReturn(-1,"该模板已经被主人禁用了");
孙龙's avatar
up
cc27fb0a
 
孙龙 committed 5 years ago
393
        }
孙龙's avatar
up
3d487875
 
孙龙 committed 5 years ago
394
        $templateInfo->template_extend = isset($templateInfo->template_extend) ? $templateInfo->template_extend : null;
孙龙's avatar
up
42c88eac
 
孙龙 committed 5 years ago
395
        return $this->ajaxReturn(0,"ok",$templateInfo);
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
396 397 398
    }


孙龙's avatar
up
cf2e8c96
 
孙龙 committed 5 years ago
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
    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");
    }


孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
434
}