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

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

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

孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
22 23
    // 模板列表
    public function labelList($request)
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
24
    {
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
        $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",'');
        $admin_id = $request->user->userId;
        $perm = new PermController;
        // 用户角色
        $role = $perm->getUserRole($request);
        $query = TemplateListModel::select('*')->CreateUserId($admin_id,$role,$create_username)->TemplateName($template_name)
            ->Status($status)
            ->SearchTime($begin_time,$end_time)
            ->OrderBy("id","desc");
        $query = $query->paginate($limit,[],'page',$page);
        $list = $query->toArray();
//        dump($list);
        return ['code'=>0, 'count'=>$list['total'],'data'=>$list["data"]];
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
44 45
    }

孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
46 47
    // 标签使用记录
    public function record($request)
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
48
    {
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
49 50 51 52 53 54 55
        $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
56 57


孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
        $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
74
            $arr[$k]["createUser"] =  $item->saleOrder ? $item->saleOrder->createUser : '';
孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
75 76 77 78 79
            $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
80 81
    }

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

    /*
     * 模板列表修改状态
     */
    public function template_status($request){
        $id = $request->input("id",0);
        $status = $request->input("status",0);
        $perm = new PermController;
        // 用户角色
        $role = $perm->getUserRole($request);
        $tmpl = TemplateListModel::where("create_userid",$request->user->userId)->find($id);
        if($tmpl){
            $tmpl->status = ($tmpl->status == -1) ? 1 :-1;
            $tmpl->save();
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
96
            //此处推送到erp
孙龙's avatar
up
fdf03ae1
 
孙龙 committed 5 years ago
97
            $this->pushTemplateErp();
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
98

孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
99 100 101 102
            return $this->ajaxReturn(0,"修改成功");
        }else{
            return $this->ajaxReturn(-1,"没找到与自己对应的模板");
        }
孙龙's avatar
init
1f46a6ed
 
孙龙 committed 5 years ago
103 104
    }

孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    /*
     * 模板列表修改状态
     */
    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){
            return $this->ajaxReturn(-1,"没找到与自己对应的模板");
        }
        $tmpl->template_name = $template_name;
        $tmpl->save();

        //此处推送到erp



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


孙龙's avatar
init
29756f12
 
孙龙 committed 5 years ago
129 130 131 132 133 134 135

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

孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
138 139 140 141

    protected function pushTemplateErp(){
        try{
            //登录
孙龙's avatar
up
fdf03ae1
 
孙龙 committed 5 years ago
142
            $soap = new \SoapClient(env("ERP_DOMAIN").'/ormrpc/services/EASLogin?wsdl');
孙龙's avatar
up
69b35c0a
 
孙龙 committed 5 years ago
143
            $res = $soap->login( 'TC', 'unicom', 'eas', env('ERP_DB_NAME'),  'L2', 1, 'BaseDB');
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
144
            //接口
孙龙's avatar
up
fdf03ae1
 
孙龙 committed 5 years ago
145
            $this->erp = new \SoapClient(ENV("ERP_DOMAIN").'/ormrpc/services/WSIchuntjKFacade?wsdl');
孙龙's avatar
up
69b35c0a
 
孙龙 committed 5 years ago
146
            $tmp = $this->erp->createIssueLabel(json_encode([
孙龙's avatar
UP
7d274507
 
孙龙 committed 5 years ago
147
                "templateId"=>1,
孙龙's avatar
up
fdf03ae1
 
孙龙 committed 5 years ago
148 149 150 151
                "templateNmae"=>"aaaa",
                "createUser"=>"bbbb",
                "status"=>1,
            ]));
孙龙's avatar
up
69b35c0a
 
孙龙 committed 5 years ago
152
            dump($tmp);
孙龙's avatar
up
be847d8f
 
孙龙 committed 5 years ago
153
            return true;
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
154
        }catch(\Exception $e){
孙龙's avatar
up
69b35c0a
 
孙龙 committed 5 years ago
155
            dump($e);
孙龙's avatar
up
be847d8f
 
孙龙 committed 5 years ago
156 157
            return false;
//        dump($e->getMessage());
孙龙's avatar
up
e6c192c5
 
孙龙 committed 5 years ago
158 159 160
        }
    }

孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
161 162 163 164 165 166

    /*
     * 添加模板
     */
    public function add_template($request){
        $template_name = $request->input("designName",'');
孙龙's avatar
up
30e1e1d6
 
孙龙 committed 5 years ago
167
        $html = $request->input("htmlp",'');
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
        $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
188 189 190 191 192 193 194 195 196
        $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
197
                return $this->ajaxReturn(-1,"该模板已经被主人禁用了");
孙龙's avatar
up
3d487875
 
孙龙 committed 5 years ago
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
            }

            $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
216
                    if($templateExtend === false){
孙龙's avatar
up
3d487875
 
孙龙 committed 5 years ago
217 218 219 220 221 222 223 224 225 226 227 228 229
                        throw new \Exception("修改模板属性失败",-1);
                    }
                });
                return $this->ajaxReturn(0,"修改模板成功");
            }catch(\Exception $e){
                return $this->ajaxReturn(-1,$e->getMessage());
            }
            exit;
        }

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

        //新增模板
孙龙's avatar
up
086e8785
 
孙龙 committed 5 years ago
230 231 232 233 234 235 236
        $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
237 238 239 240
        try{
            DB::Connection("label")->transaction(function () use($data,$request) {
                //创建模板
                $templateList = TemplateListModel::create([
孙龙's avatar
up
086e8785
 
孙龙 committed 5 years ago
241
                    "template_name"=>trim($data['template_name']),
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
                    "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
809dcce0
 
孙龙 committed 5 years ago
260
            return $this->ajaxReturn(0,"添加模板成功");
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
261
        }catch(\Exception $e){
孙龙's avatar
up
086e8785
 
孙龙 committed 5 years ago
262
            return $this->ajaxReturn(-1,$e->getMessage());
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
263 264 265
        }


孙龙's avatar
up
30e1e1d6
 
孙龙 committed 5 years ago
266 267
    }

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

孙龙's avatar
up
30e1e1d6
 
孙龙 committed 5 years ago
269 270 271
    /**
     * 编辑模板 获取模板详情
     */
孙龙's avatar
up
42c88eac
 
孙龙 committed 5 years ago
272 273 274 275 276 277
    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
278
        $templateInfo = TemplateListModel::where("id",intval($id))->select("id","template_name","status")->first();
孙龙's avatar
up
cc27fb0a
 
孙龙 committed 5 years ago
279
        if($templateInfo->status <= 0){
孙龙's avatar
up
77292988
 
孙龙 committed 5 years ago
280
            return $this->ajaxReturn(-1,"该模板已经被主人禁用了");
孙龙's avatar
up
cc27fb0a
 
孙龙 committed 5 years ago
281
        }
孙龙's avatar
up
3d487875
 
孙龙 committed 5 years ago
282
        $templateInfo->template_extend = isset($templateInfo->template_extend) ? $templateInfo->template_extend : null;
孙龙's avatar
up
42c88eac
 
孙龙 committed 5 years ago
283
        return $this->ajaxReturn(0,"ok",$templateInfo);
孙龙's avatar
up
76355e8a
 
孙龙 committed 5 years ago
284 285 286
    }


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