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
  • ApiController.php
ApiController.php 2.46 KB
孙龙's avatar
标签
bb31d074
 
孙龙 committed 2 years ago
1 2 3 4 5 6
<?php
namespace App\Http\Controllers;



use App\Model\TemplateExtendModel;
孙龙's avatar
获取销售的标签列表
1e758226
 
孙龙 committed 2 years ago
7 8
use App\Services\LabelService;
use Illuminate\Http\Request;
孙龙's avatar
标签
bb31d074
 
孙龙 committed 2 years ago
9 10 11 12 13

Class ApiController extends Controller
{


孙龙's avatar
获取销售的标签列表
1e758226
 
孙龙 committed 2 years ago
14
    public function getUserLabels(Request $request){
孙龙's avatar
标签
bb31d074
 
孙龙 committed 2 years ago
15

孙龙's avatar
获取销售的标签列表
1e758226
 
孙龙 committed 2 years ago
16 17
        $user_id = $request->input("user_id",0);
        $list = LabelService::getUserLabels($user_id);
孙龙's avatar
标签
bb31d074
 
孙龙 committed 2 years ago
18 19 20 21 22 23 24 25 26 27 28 29 30 31

        $list = collect($list)->toArray();
        $arr = [];
        foreach($list as $k=>$item){
            $arr[$k]["template_id"] = $item->id;
            $arr[$k]["template_name"] = $item->template_name;
            $arr[$k]["html"] = $item->html;
            $arr[$k]["attribute"] = $item->attribute;
        }
        return ['code'=>0, 'count'=>count($arr),'data'=>$arr];

    }


孙龙's avatar
打印
404e6f9f
 
孙龙 committed 2 years ago
32 33 34 35 36 37 38
    /**
     * Notes:erp发送数据 准备打印数据
     * User: sl
     * Date: 2023-02-20 15:35
     * @param Request $request
     */
    public function tryPrintLabel(Request $request){
孙龙's avatar
打印标签
e00dcea4
 
孙龙 committed 2 years ago
39 40 41 42 43 44 45 46 47
        $list = $request->input("list",[]);

        if(empty($list)){
            return $this->setError("请求平台打印失败:打印数据不能为空");
        }

        foreach($list as &$item){
            if(intval($item["print_num"]) <= 0){
                $item["print_num"] = 1;
孙龙's avatar
优化
2545d96b
 
孙龙 committed a year ago
48 49
            }elseif(intval($item["print_num"]) >= 50){
                $item["print_num"] = 50;//单个明细限制100
孙龙's avatar
打印标签
e00dcea4
 
孙龙 committed 2 years ago
50 51 52 53 54 55 56 57 58 59 60 61 62
            }
        }
        if(count($list) > 150){//所有型号数限制150
            return $this->setError("请求平台打印失败:型号明细总数超过150了");
        }

        $templateIdList = array_pluck($list,"template_id");
        $templateIdListSearch = LabelService::getTemplateIds($templateIdList);
        foreach($templateIdList as $temptId){
            if(!in_array($temptId,$templateIdListSearch)){
                return $this->setError(sprintf("请求平台打印失败:标签模板id:%s不存在",$temptId));
            }
        }
孙龙's avatar
打印
404e6f9f
 
孙龙 committed 2 years ago
63
        $data = json_encode($list);
孙龙's avatar
标签
3977458d
 
孙龙 committed 2 years ago
64 65
        $key = LabelService::tryPrintLabel($data);
        if(empty($key)){
孙龙's avatar
打印标签
e00dcea4
 
孙龙 committed 2 years ago
66
            return $this->setError("请求平台打印失败");
孙龙's avatar
标签
3977458d
 
孙龙 committed 2 years ago
67
        }else{
孙龙's avatar
打印标签
e00dcea4
 
孙龙 committed 2 years ago
68 69 70
            return $this->setSuccessData(
                ["url" => config("website.erp_print_url")."/api/print_label?key=".(string)$key],0,0,"请求打印成功"
            );
孙龙's avatar
标签
3977458d
 
孙龙 committed 2 years ago
71
        }
孙龙's avatar
打印
404e6f9f
 
孙龙 committed 2 years ago
72 73 74 75
    }


    public function printLabel(Request $request){
孙龙's avatar
标签
3977458d
 
孙龙 committed 2 years ago
76 77
        $key  = $request->input("key","");
        $html = LabelService::printLabel($key);
孙龙's avatar
打印
404e6f9f
 
孙龙 committed 2 years ago
78

孙龙's avatar
标签
3977458d
 
孙龙 committed 2 years ago
79 80
        $info["html"] = $html;
        return view('web.print.prints',$info);
孙龙's avatar
打印
404e6f9f
 
孙龙 committed 2 years ago
81 82 83
    }


孙龙's avatar
标签
bb31d074
 
孙龙 committed 2 years ago
84 85

}