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
  • WebController.php
WebController.php 5.46 KB
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
1 2 3
<?php
namespace App\Http\Controllers;

孙龙's avatar
up
57dfabaa
 
孙龙 committed 5 years ago
4

孙龙's avatar
up
cf2e8c96
 
孙龙 committed 5 years ago
5
use App\Model\OfflinePrintModel;
孙龙's avatar
up
5cfb199b
 
孙龙 committed 5 years ago
6
use App\Model\TmplRelationsModel;
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
7 8 9 10
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
11
use App\Model\TemplateListModel;
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
12
use App\Model\NodesModel;
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
13 14
use DNS1D;
use DNS2D;
孙龙's avatar
up
8c305c70
 
孙龙 committed 5 years ago
15
use Sunra\PhpSimple\HtmlDomParser;
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
16 17 18 19 20 21 22 23 24 25 26 27

class WebController extends Controller
{
    // 获取页面信息
    public function getPageInfo($request)
    {
        $uri = '/' . $request->path();

        $username = $request->user->email;
        $useremail= $request->user->email;

        // 菜单
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
28
        $menuconfig = DB::table('config')->where('config_title', '标签管理系统')->first();
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
        $menus = [];
        if ($menuconfig && !($menus = json_decode($menuconfig->config_data)))
            $menus = [];

        $perm = new PermController;

        // 用户角色
        $role = $perm->getUserRole($request);

        // 获取权限菜单
        if ($role != 1) {
            $menus = $perm->getPermMenu($menus, $request->user->userId);
        }

        $userPerms = $perm->getUserAllPerms($request->user->userId, $role); // 用户权限

        $data = [
            'header'    => $request->user->header,
            'uri'       => $uri,
            'username'  => $username,
            'useremail' => $useremail,
            'menus'     => $menus,
            'userPerms' => $userPerms,
        ];

        return $data;
    }

    // 首页
    public function index(Request $request)
    {
孙龙's avatar
up
be847d8f
 
孙龙 committed 5 years ago
60
//        $JobsModel = new JobsModel();
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
61 62 63 64 65 66 67 68 69 70 71 72 73

        $info = $this->getPageInfo($request);

        return view('index', $info);
    }

    public function entrance(Request $request, $id='')
    {
        $info = $this->getPageInfo($request);
        $info['id'] = $id;
        return $this->$id($request, $info);
    }

孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
74 75
    // 模板列表
    public function labelList($request, $info)
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
76
    {
孙龙's avatar
up
a88a7a4d
 
孙龙 committed 5 years ago
77
        $info['title'] = '我的标签模板列表';
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
78 79 80
        return view('web', $info);
    }

孙龙's avatar
up
a88a7a4d
 
孙龙 committed 5 years ago
81 82 83 84 85 86 87 88 89 90 91
    // 模板列表
    public function systemlabelList($request, $info)
    {
        $info['title'] = '系统内置标签模板列表';
        $info['id']= "labelList";
        $info["labelListSystem"] = 1;
        return view('web', $info);
    }



孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
92 93
    // 标签使用记录
    public function record($request, $info)
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
94
    {
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
95
        $info['title'] = '标签使用记录';
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
96 97 98
        return view('web', $info);
    }

孙龙's avatar
up
ffec89cd
 
孙龙 committed 5 years ago
99 100 101
    /*
     * 设计
     */
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
102 103 104 105
    public function design($request,$info){
        $info['title'] = '标签设计';
        return view('web', $info);
    }
孙龙's avatar
离线使用功能
2b66c205
 
孙龙 committed 5 years ago
106 107 108 109 110 111 112 113 114

    /*
     * 离线使用
     */
    public function offline($request,$info){
        $info['title'] = '离线使用';
        return view('web', $info);
    }

孙龙's avatar
up
ffec89cd
 
孙龙 committed 5 years ago
115 116 117
    /*
     * 标签预览
     */
孙龙's avatar
up
5cfb199b
 
孙龙 committed 5 years ago
118 119 120
    public function showPage($request,$info){
        $info['title'] = '预览';
        $id = $request->input("tmpl_relation_id",0);
孙龙's avatar
up
69b35c0a
 
孙龙 committed 5 years ago
121
        $html = (new \App\Services\LabelService)->getLabelHtml($id);
孙龙's avatar
up
57dfabaa
 
孙龙 committed 5 years ago
122 123 124
        $info["html"] = $html;
        return view('web', $info);
    }
孙龙's avatar
up
8c305c70
 
孙龙 committed 5 years ago
125

孙龙's avatar
up
ffec89cd
 
孙龙 committed 5 years ago
126
    /*
孙龙's avatar
up
1e853cf6
 
孙龙 committed 5 years ago
127 128 129 130 131
     * 标签预览
     */
    public function showTemplate($request,$info){
        $info['title'] = '预览';
        $id = $request->input("t_id",0);
孙龙's avatar
up
a88a7a4d
 
孙龙 committed 5 years ago
132 133 134 135
//        $count = TemplateListModel::where("id",intval($id))->where("create_userid",$request->user->userId)->count("id");
//        if($count <= 0){
//            return back()->with('showTemplateerror', '没找到属于您的模板信息');
//        }
孙龙's avatar
up
1e853cf6
 
孙龙 committed 5 years ago
136
        $templateInfo = TemplateListModel::where("id",intval($id))->select("id","template_name","status")->first();
孙龙's avatar
up
a88a7a4d
 
孙龙 committed 5 years ago
137 138 139
//        if($templateInfo->status <= 0){
//            return back()->with('showTemplateerror', '该模板已经被主人禁用了');
//        }
孙龙's avatar
up
1e853cf6
 
孙龙 committed 5 years ago
140 141 142 143 144 145 146 147
//        dump($templateInfo->template_extend);

        $html = $templateInfo->template_extend;
        $info["html"] = $html->html;
        return view('web', $info);
    }

    /*
孙龙's avatar
up
ffec89cd
 
孙龙 committed 5 years ago
148 149
     * 打印标签
     */
孙龙's avatar
up
57dfabaa
 
孙龙 committed 5 years ago
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    public function prints($request,$info){
        $tmpl_relationids = $request->input("tmpl_relationids",'');
        $tmpl_relationid_arr = explode(",",$tmpl_relationids);
        if(empty($tmpl_relationids)){
            die("没有要打印的数据");
        }
        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;
                }
            });
        }
//        dump($tmpl_relationid_arr);
        $info['title'] = '打印';

        $templateRelation = TmplRelationsModel::where("create_userid",$request->user->userId)->whereIn("id",$tmpl_relationid_arr)
            ->get();
孙龙's avatar
up
1e853cf6
 
孙龙 committed 5 years ago
172 173 174
        if(!$templateRelation){
            die("没有要打印的数据");
        }
孙龙's avatar
up
57dfabaa
 
孙龙 committed 5 years ago
175 176 177 178 179
        $html = [];
        foreach($templateRelation as $item){
            $createHtml = (new \App\Services\LabelService)->getLabelHtml($item->id);
            if($createHtml){
                array_push($html,$createHtml);
孙龙's avatar
up
1705a0e7
 
孙龙 committed 5 years ago
180
            }
孙龙's avatar
up
8c305c70
 
孙龙 committed 5 years ago
181
        }
孙龙's avatar
up
f088f2e0
 
孙龙 committed 5 years ago
182

孙龙's avatar
up
57dfabaa
 
孙龙 committed 5 years ago
183 184
        $info["html"] = $html;
        return view('web.prints', $info);
孙龙's avatar
up
5cfb199b
 
孙龙 committed 5 years ago
185 186
    }

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

孙龙's avatar
up
cf2e8c96
 
孙龙 committed 5 years ago
188 189 190 191 192 193 194 195 196 197
    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);
    }


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