1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
 
namespace app\operations\controller\plus\business;
 
use app\common\service\business\Poster;
use app\operations\model\plus\business\Template as BusinessTemplate;
use app\operations\controller\Controller;
 
class Template extends Controller
{
    public function index()
    {
        $list = (new BusinessTemplate())->getList();
        return $this->renderSuccess('', compact('list'));
    }
 
    public function edit()
    {
        $template_id = input('template_id');
        $model = (new BusinessTemplate())->where('template_id', $template_id)->find();
        if (request()->isGet()) {
            $data = json_decode($model['style'], true);
            empty($data['position']) ? $data['position'] = [] : '';
            empty($data['is_business']) ? $data['is_business'] = 0 : '';
            empty($data['positionNum']) ? $data['positionNum'] = 0 : '';
            empty($data['icon']) ? $data['icon'] = [] : '';
            $data = json_encode($data, JSON_UNESCAPED_UNICODE);
            return $this->renderSuccess('', compact('data'));
        }
        $dealer = ['business_card_id' => $template_id, 'name' => 'XXX', 'unit' => [], 'duties' => [], 'address' => [], 'mobile' => 'xxxxxxxxxxx', 'wechat' => 'xxxxxxxxxxx', 'mailbox' => 'xxxxxxxxxxx@.xxx.com', 'phone' => 'xxx-xxx-xxx', 'website' => 'xxxxxxxxxxxxxx.com', 'fax' => 'xxx-xxx', 'zip_code' => 'xxxxxx', 'template_id' => $template_id, 'wxapp_id' => 10001];
        $param = request()->param();
        $imageInfo = getimagesize($param['template']['backdrop']['src']);
        $param['template']['backdrop']['height'] = $imageInfo[1];
        $param['template']['backdrop']['width'] = $imageInfo[0];
        foreach ($param['template']['unit'] as $key => $value) {
            // 写入公司
            $dealer['unit'][] = 'xxxxx公司';
        }
        // 写入职位
        //$dealer['duties'][] = '职位';
            // 写入职位
        $dealer['duties'][] = '职位';
        
        // 写入地址
        $dealer['address'][] = '广西壮族自治区南宁市江南区壮锦大道八桂绿城·龙湖御景-A栋-2单元xxx号';
        
        
        $Qrcode = new Poster($dealer);
        $paramL['image'] = $Qrcode->getImageE($param['template'], $template_id);
        $paramL['style'] = json_encode($param['template'], JSON_UNESCAPED_UNICODE);
        if ($model->add($paramL)) {
            return $this->renderSuccess('编辑成功');
        }
        return $this->renderError('编辑失败');
    }
 
    public function add()
    {
 
        $model = new BusinessTemplate();
        if (request()->isGet()) {
            $data = ["backdrop" => [
                "src" => $model::$base_url."/image/team/business.png",
                'type' => 'backdrop'
            ],
                "is_business" => 0,
                "name" => [
                    "fontSize" => 14,
                    "color" => "#000000",
                    "left" => 170,
                    "top" => 70,
                    "fontWeight" => 400,
                    'type' => 'text'
                ],
                "avatar" => [
                    "width" => 70,
                    "style" => "circle",
                    "left" => 37,
                    "top" => 37,
                    "display" => 1,
                    "src" => $model::$base_url."/image/agent/avatar.jpg",
                    'type' => 'avatar'
                ],
                "logo" => [
                    "width" => 70,
                    "height" => 70,
                    "style" => "square",
                    "left" => 22,
                    "src" => $model::$base_url."/image/diy/logo_top.png",
                    "top" => 140,
                    "display" => 1,
                    'type' => 'image'
                ],
                "mobile" => [
                    "fontSize" => 14,
                    "color" => "#000000",
                    "left" => 170,
                    "top" => 180,
                    "fontWeight" => 400
                ],
                "address" => [
                    ["fontSize" => 14,
                        "color" => "#000000",
                        "left" => 170,
                        "top" => 380,
                        "fontWeight" => 400,
                        'type' => 'text']
                ],
                "unit" => [
                    ["fontSize" => 14,
                        "color" => "#000000",
                        "left" => 367,
                        "top" => 120,
                        "fontWeight" => 100,
                        'type' => 'text']
                ],
                "duties" => [
                    ["fontSize" => 14,
                        "color" => "#000000",
                        "left" => 170,
                        "top" => 120,
                        "fontWeight" => 400,
                        'type' => 'text']
                ],
                "position" => [
                ],
                "wechat" => [
                    "fontSize" => 14,
                    "color" => "#000000",
                    "left" => 170,
                    "top" => 230,
                    "fontWeight" => 400,
                    'type' => 'text'
                ],
                "mailbox" => [
                    "fontSize" => 14,
                    "color" => "#000000",
                    "left" => 170,
                    "top" => 330,
                    "fontWeight" => 400,
                    'type' => 'text'
                ],
                "phone" => [
                    "fontSize" => 14,
                    "color" => "#000000",
                    "left" => 170,
                    "top" => 280,
                    "fontWeight" => 400,
                    'type' => 'text'
                ],
                'positionNum' => 0,
                "iconL" => [],
 
            ];
            return $this->renderSuccess('', [
                'data' => json_encode($data, JSON_UNESCAPED_UNICODE)
            ]);
        }
        $param = request()->param();
        $imageInfo = getimagesize($param['template']['backdrop']['src']);
        $param['template']['backdrop']['height'] = $imageInfo[1];
        $param['template']['backdrop']['width'] = $imageInfo[0];
        $paramL['style'] = json_encode($param['template'], JSON_UNESCAPED_UNICODE);
        if ($model->add($paramL)) {
            $template_id = $model->template_id;
            $dealer = ['business_card_id' => $template_id, 'name' => 'XXX', 'unit' => [], 'duties' => [], 'address' => [], 'mobile' => 'xxxxxxxxxxx', 'wechat' => 'xxxxxxxxxxx', 'mailbox' => 'Xxxxxxxxxxxxxxxxx', 'phone' => 'xxx-xxx-xxx', 'website' => 'xxxxxxxxxxxxxx.com', 'fax' => 'xxx-xxx', 'zip_code' => 'xxxxxx', 'template_id' => $template_id, 'wxapp_id' => 10001];
            foreach ($param['template']['unit'] as $key => $value) {
                // 写入公司
                $dealer['unit'][] = 'xxxxx公司' . ($key + 1);
            }
            // 写入职位
            $dealer['duties'][] = '职位';
            // 写入地址
            $dealer['address'][] = '地址1号';
            $Qrcode = new Poster($dealer);
            $paramI['image'] = $Qrcode->getImageE($param['template'], $template_id);
            $modelBusiness = (new BusinessTemplate())->where(['template_id' => $template_id])->find();
            $modelBusiness->where(['template_id' => $template_id])->update($paramI);
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError('添加失败');
    }
 
    public function delete($template_id)
    {
        if ((new BusinessTemplate())->where(['template_id' => $template_id])->delete()) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError('删除失败');
    }
 
}