Browse Source

新模板

sunhao 5 years ago
parent
commit
19910aa18f

+ 10 - 2
app/Http/Controllers/Admin/TemplateController.php

461
     {
461
     {
462
         $this->validate($request, [
462
         $this->validate($request, [
463
             't_id' => 'required',           
463
             't_id' => 'required',           
464
+            'back_img' => 'required',           
464
         ], [
465
         ], [
465
             't_id.required' => '模板不能为空',
466
             't_id.required' => '模板不能为空',
467
+            'back_img.required' => '背景图不能为空',
466
             
468
             
467
         ]);
469
         ]);
468
         $template = new TemplatesSource();
470
         $template = new TemplatesSource();
470
         $template->note = trim($request->input('note'));
472
         $template->note = trim($request->input('note'));
471
     
473
     
472
         $template->back_img = trim($request->input('back_img'));
474
         $template->back_img = trim($request->input('back_img'));
473
-        //图片上传 阿里云oss       
475
+        //图片上传 阿里云oss    
476
+        /*   
474
         if ($request->hasFile('img') && $request->file('img')->isValid()) {
477
         if ($request->hasFile('img') && $request->file('img')->isValid()) {
475
             $file = $request->file('img');
478
             $file = $request->file('img');
476
             $ossClient=new oss();
479
             $ossClient=new oss();
481
             #保存背景图
484
             #保存背景图
482
             TemplatesBackimg::insert(['back_img'=>$template->back_img]);
485
             TemplatesBackimg::insert(['back_img'=>$template->back_img]);
483
         }
486
         }
487
+        */
484
 
488
 
485
         if($template->save()){
489
         if($template->save()){
486
             //生成连接
490
             //生成连接
512
         $id = (int)$request->input('id');
516
         $id = (int)$request->input('id');
513
         $this->validate($request, [
517
         $this->validate($request, [
514
             't_id' => 'required',           
518
             't_id' => 'required',           
519
+            'back_img' => 'required',           
515
         ], [
520
         ], [
516
             't_id.required' => '模板不能为空',
521
             't_id.required' => '模板不能为空',
522
+            'back_img.required' => '背景图不能为空',
517
             
523
             
518
         ]);
524
         ]);
519
 
525
 
526
         }
532
         }
527
         $template->note = trim($request->input('note'));
533
         $template->note = trim($request->input('note'));
528
         $template->back_img = trim($request->input('back_img'));
534
         $template->back_img = trim($request->input('back_img'));
529
-        //图片上传 阿里云oss       
535
+        //图片上传 阿里云oss 
536
+        /*      
530
         if ($request->hasFile('img') && $request->file('img')->isValid()) {
537
         if ($request->hasFile('img') && $request->file('img')->isValid()) {
531
             $file = $request->file('img');
538
             $file = $request->file('img');
532
             $ossClient=new oss();
539
             $ossClient=new oss();
537
             #保存背景图
544
             #保存背景图
538
             TemplatesBackimg::insert(['back_img'=>$template->back_img]);
545
             TemplatesBackimg::insert(['back_img'=>$template->back_img]);
539
         }
546
         }
547
+        */
540
 
548
 
541
         $template->save();
549
         $template->save();
542
         return redirect('/admin/template/sourceindex')->with('info', '修改成功');
550
         return redirect('/admin/template/sourceindex')->with('info', '修改成功');

+ 8 - 4
app/Http/Controllers/Api/TemplateController.php

13
 use Illuminate\Http\Request;
13
 use Illuminate\Http\Request;
14
 use App\Log;
14
 use App\Log;
15
 use App\Templates;
15
 use App\Templates;
16
+use App\TemplatesSource;
16
 use App\TemplatesSalers;
17
 use App\TemplatesSalers;
18
+use App\TemplatesSourceSalers;
17
 use App\Admin;
19
 use App\Admin;
18
 use App\TemplatesLog;
20
 use App\TemplatesLog;
19
 use Illuminate\Support\Facades\Hash;
21
 use Illuminate\Support\Facades\Hash;
26
     public function salerQrcode(Request $request){
28
     public function salerQrcode(Request $request){
27
         $t_id = (int)$request->input('t_id');
29
         $t_id = (int)$request->input('t_id');
28
         if(!$t_id) $t_id = 1;
30
         if(!$t_id) $t_id = 1;
29
-        $result = TemplatesSalers::where('t_id', $t_id)->where('is_del', 0)->where('weight','>',0)->orderBy('weight', 'asc')->lists('weight', 'admin_id');
31
+        //获取背景图
32
+        $back_img = TemplatesSource::where('id', $t_id)->pluck('back_img');
33
+        $result = TemplatesSourceSalers::where('s_id', $t_id)->where('is_del', 0)->where('weight','>',0)->orderBy('weight', 'asc')->lists('weight', 'admin_id');
30
         $saler_id = null;
34
         $saler_id = null;
31
         $rand = 0;
35
         $rand = 0;
32
         //获取最大随机值
36
         //获取最大随机值
48
             //记录行为
52
             //记录行为
49
             $log = array();
53
             $log = array();
50
             $log['t_id'] = $t_id;
54
             $log['t_id'] = $t_id;
51
-            $log['t_url'] = Templates::where('id', $t_id)->pluck('url');
55
+            $log['t_url'] = TemplatesSource::where('id', $t_id)->pluck('url');
52
             $log['admin_id'] = $saler_id;
56
             $log['admin_id'] = $saler_id;
53
             $log['ip'] = $ip;
57
             $log['ip'] = $ip;
54
             TemplatesLog::insert($log);
58
             TemplatesLog::insert($log);
56
 
60
 
57
         $qrcode = Admin::where('id', $saler_id)->pluck('qrcode');
61
         $qrcode = Admin::where('id', $saler_id)->pluck('qrcode');
58
         $qrcodes = Admin::whereIn('id', $saler_ids)->lists('qrcode');
62
         $qrcodes = Admin::whereIn('id', $saler_ids)->lists('qrcode');
59
-        return self::returnValue(['qrcode'=>$qrcode, 'ip'=>$ip, 'saler_id'=>$saler_id, 'qrcodes'=>$qrcodes]);
63
+        return self::returnValue(['qrcode'=>$qrcode, 'ip'=>$ip, 'saler_id'=>$saler_id, 'qrcodes'=>$qrcodes, 'back_img'=>$back_img]);
60
     }
64
     }
61
 
65
 
62
      /**
66
      /**
93
             //记录行为
97
             //记录行为
94
             $log = array();
98
             $log = array();
95
             $log['t_id'] = $t_id;
99
             $log['t_id'] = $t_id;
96
-            $log['t_url'] = Templates::where('id', $t_id)->pluck('url');
100
+            $log['t_url'] = TemplatesSource::where('id', $t_id)->pluck('url');
97
             $log['admin_id'] = $saler_id;
101
             $log['admin_id'] = $saler_id;
98
             $log['ip'] = $ip;
102
             $log['ip'] = $ip;
99
             $log['type'] = 2; //长按
103
             $log['type'] = 2; //长按

+ 1 - 1
resources/views/template/index.blade.php

31
                         <td class="text-c"><img style="width:100px;" src="{{$a['img']}}" /></td>
31
                         <td class="text-c"><img style="width:100px;" src="{{$a['img']}}" /></td>
32
                         <td class="f-14 product-brand-manage">
32
                         <td class="f-14 product-brand-manage">
33
                             <a style="text-decoration:none" onClick='templateedit("编辑","{{$a['id']}}")' href="javascript:;" title="编辑"><span class="btn btn-primary radius">编辑模板</span></a>
33
                             <a style="text-decoration:none" onClick='templateedit("编辑","{{$a['id']}}")' href="javascript:;" title="编辑"><span class="btn btn-primary radius">编辑模板</span></a>
34
-                            <a style="text-decoration:none" onClick='assign("分配销售","{{$a['id']}}")' href="javascript:;" title="分配销售"><span class="btn btn-primary radius">分配销售</span></a>
34
+                            <!--a style="text-decoration:none" onClick='assign("分配销售","{{$a['id']}}")' href="javascript:;" title="分配销售"><span class="btn btn-primary radius">分配销售</span></a-->
35
                             <!--a style="text-decoration:none" class="ml-5" onClick="templatedel(this, '{{$a["id"]}}')" href="javascript:;" title="删除"><span class="btn btn-danger radius">删除</span></a-->
35
                             <!--a style="text-decoration:none" class="ml-5" onClick="templatedel(this, '{{$a["id"]}}')" href="javascript:;" title="删除"><span class="btn btn-danger radius">删除</span></a-->
36
                         </td>
36
                         </td>
37
                     </tr>
37
                     </tr>

+ 14 - 24
resources/views/template/sourcecreate.blade.php

33
         height: 100%;
33
         height: 100%;
34
         left: 0;
34
         left: 0;
35
         top: 0;
35
         top: 0;
36
+        opacity: 0;
36
     }
37
     }
37
     .add_img_title{
38
     .add_img_title{
38
         width: 100px;
39
         width: 100px;
65
             <div class="row cl">
66
             <div class="row cl">
66
                 <label class="form-label col-xs-4 col-sm-2">
67
                 <label class="form-label col-xs-4 col-sm-2">
67
                     选择模板:</label>
68
                     选择模板:</label>
68
-                <div class="formControls col-xs-6 col-sm-6">
69
+                <div class="formControls col-xs-6 col-sm-7">
69
                     @if($templates)
70
                     @if($templates)
70
                     <ul class="templates_ul clear">
71
                     <ul class="templates_ul clear">
71
                         @foreach($templates as $item)
72
                         @foreach($templates as $item)
84
             <div class="row cl">
85
             <div class="row cl">
85
                 <label class="form-label col-xs-4 col-sm-2">
86
                 <label class="form-label col-xs-4 col-sm-2">
86
                     选择背景图:</label>
87
                     选择背景图:</label>
87
-                <div class="formControls col-xs-6 col-sm-6">
88
+                <div class="formControls col-xs-6 col-sm-7">
88
                     @if($back_imgs)
89
                     @if($back_imgs)
89
                     <ul class="templates_ul clear">
90
                     <ul class="templates_ul clear">
90
                         @foreach($back_imgs as $k=>$back_img)
91
                         @foreach($back_imgs as $k=>$back_img)
100
                         <li id='upload_img' class="templates_li">
101
                         <li id='upload_img' class="templates_li">
101
                             <div class="add_div">
102
                             <div class="add_div">
102
                                 <span>+</span>
103
                                 <span>+</span>
103
-                                <input type="file" id="ImgInput" multiple name="img" class="input-file add_img_input" onChange="changeImgID()">
104
+                                <input type="file" id="ImgInput" multiple name="img" class="add_img_input" onChange="changeImgID()">
104
                             </div>
105
                             </div>
105
                             <div class="add_img_title">上传新背景图</div>
106
                             <div class="add_img_title">上传新背景图</div>
106
 
107
 
110
                 </div>
111
                 </div>
111
             </div>
112
             </div>
112
 
113
 
113
-            <!-- <div class="row cl">
114
-                <label class="form-label col-xs-4 col-sm-2">
115
-        </label>
116
-                
117
-                  <input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly>
118
-                  <a href="javascript:void();" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe642;</i> 上传图片</a>
119
-
120
-                <div style="margin-left: 280px;padding: 10px;">文件类型支持:jpg ,png ,ico ,文件大小不能超过1M</div>
121
-            </div> -->
122
-
123
             <div class="row cl">
114
             <div class="row cl">
124
                 <label class="form-label col-xs-4 col-sm-2">
115
                 <label class="form-label col-xs-4 col-sm-2">
125
                     渠道备注:</label>
116
                     渠道备注:</label>
126
-                <div class="formControls col-xs-6 col-sm-6">
117
+                <div class="formControls col-xs-6 col-sm-7">
127
                     <input type="text" class="input-text" value="{{old('note')}}" placeholder="" name="note">
118
                     <input type="text" class="input-text" value="{{old('note')}}" placeholder="" name="note">
128
                 </div>
119
                 </div>
129
             </div>
120
             </div>
130
             
121
             
131
             <div class="row cl">
122
             <div class="row cl">
132
                 <div class="col-9 col-offset-2">
123
                 <div class="col-9 col-offset-2">
124
+
133
                     <button class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>&nbsp;
125
                     <button class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>&nbsp;
134
                     <button class="btn btn-default" type="reset" onclick="return_index();">&nbsp;&nbsp;返回&nbsp;&nbsp;</button>&nbsp;
126
                     <button class="btn btn-default" type="reset" onclick="return_index();">&nbsp;&nbsp;返回&nbsp;&nbsp;</button>&nbsp;
135
                     {{--<a href="javascript:void(0)" class="btn btn-default radius" onclick="redirect('{{url('/admin/admin/all')}}')">返回并查看结果</a>--}}
127
                     {{--<a href="javascript:void(0)" class="btn btn-default radius" onclick="redirect('{{url('/admin/admin/all')}}')">返回并查看结果</a>--}}
128
+                    <font color='red'>(*提交后自动生成推广链接)</font>
136
                 </div>
129
                 </div>
130
+
137
             </div>
131
             </div>
138
         </form>
132
         </form>
139
     </div>
133
     </div>
163
              reader.readAsDataURL(selectedFile);
157
              reader.readAsDataURL(selectedFile);
164
              reader.onload = function () {
158
              reader.onload = function () {
165
                  //当读取完成后回调这个函数,然后此时文件的内容存储到了result中,直接操作即可
159
                  //当读取完成后回调这个函数,然后此时文件的内容存储到了result中,直接操作即可
166
-                 //console.log(this.result)
167
-                 
168
                  $.ajax({
160
                  $.ajax({
169
-                    'url':'/admin/template/uploadBack',
170
-                    'type':'post',
171
-                    'data':{img:this.result,_token:_token},
172
-                    'dataType':'json',
161
+                    url:'/admin/template/uploadBack',
162
+                    type:'post',
163
+                    data:{img:this.result,_token:_token},
173
                     success:function(pic_url){
164
                     success:function(pic_url){
174
-                        alert(pic_url)
175
                         if(pic_url == '0'){
165
                         if(pic_url == '0'){
176
                             alert(pic_url)
166
                             alert(pic_url)
177
                             return false;
167
                             return false;
178
                         }
168
                         }
179
-                        var str = "<li class=\"templates_li\"><img class=\"templates_img\" src=\""+ pic_url +"\"\/><div><input type=\"radio\" id=\"bgImg\" value=\""+pic_url+"\" name=\"back_img\"><label for=\"bgImg\">背景图</label><\/div><\/li>";
169
+                        var str = "<li class=\"templates_li\"><img class=\"templates_img\" src=\""+ pic_url +"\"\/><div><input type=\"radio\" id=\"bgImg\" value=\""+pic_url+"\" name=\"back_img\" checked><label for=\"bgImg\">背景图</label><\/div><\/li>";
180
 
170
 
181
-                        alert(str)
182
                         $("#upload_img").before(str);
171
                         $("#upload_img").before(str);
183
-                    }
172
+                    },
173
+
184
                 })
174
                 })
185
              }
175
              }
186
 
176
 

+ 113 - 22
resources/views/template/sourceedit.blade.php

1
 @extends('admin/master')
1
 @extends('admin/master')
2
 @section('content')
2
 @section('content')
3
+<style>
4
+    .templates_ul{
5
+
6
+    }
7
+    .templates_li{
8
+        float: left;
9
+        width: 25%;
10
+        margin-bottom: 35px;
11
+    }
12
+    .templates_li .templates_img{
13
+        width: 100px;
14
+        height: 177px;
15
+        margin: auto;
16
+        margin-bottom: 10px;
17
+    }
18
+    .add_div{
19
+        width: 100px;
20
+        height: 177px;
21
+        border: 1px solid #ccc;
22
+        font-size: 47px;
23
+        color: #ccc;
24
+        text-align: center;
25
+        border-radius: 5px;
26
+        line-height: 177px;
27
+        cursor: pointer;
28
+        position: relative;
29
+    }
30
+    .add_div .add_img_input{
31
+        position: absolute;
32
+        width: 100%;
33
+        height: 100%;
34
+        left: 0;
35
+        top: 0;
36
+        opacity: 0;
37
+    }
38
+    .add_img_title{
39
+        width: 100px;
40
+        text-align: center;
41
+        padding: 8px 0;
42
+    }
43
+    .clear::after {
44
+        content: ".";
45
+        clear: both;
46
+        display: block;
47
+        overflow: hidden;
48
+        font-size: 0;
49
+        height: 0;
50
+    }
51
+    .clear {
52
+        zoom: 1;
53
+    }
54
+</style>
3
     <body>
55
     <body>
4
     @if(count($errors) > 0)
56
     @if(count($errors) > 0)
5
         <div class="Huialert Huialert-info" id="error">
57
         <div class="Huialert Huialert-info" id="error">
15
             <div class="row cl">
67
             <div class="row cl">
16
                 <label class="form-label col-xs-4 col-sm-2">
68
                 <label class="form-label col-xs-4 col-sm-2">
17
                     选择模板:</label>
69
                     选择模板:</label>
18
-                <div class="formControls col-xs-6 col-sm-6">
70
+                <div class="formControls col-xs-6 col-sm-7">
19
                     @if($templates)
71
                     @if($templates)
20
-                    <ul>
72
+                    <ul class="templates_ul clear">
21
                         @foreach($templates as $item)
73
                         @foreach($templates as $item)
22
-                        <li>
23
-                            <img  style="width:100px;" src="{{$item['img']}}"/>
24
-                            <input type="radio" class="input-text" value="{{$item['id']}}" @if($template['t_id'] == $item['id']) checked @endif name="t_id">{{$item['note']}}
74
+                        <li class="templates_li">
75
+                            <img class="templates_img" src="{{$item['img']}}"/>
76
+                            <div>
77
+                                <input type="radio" id="templates_{{$item['id']}}" value="{{$item['id']}}" @if($template['t_id'] == $item['id']) checked @endif name="t_id">
78
+                                <label for="templates_{{$item['id']}}">{{$item['note']}}</label>
79
+                            </div>
25
                         </li>
80
                         </li>
26
                         @endforeach
81
                         @endforeach
27
                     </ul>
82
                     </ul>
31
             <div class="row cl">
86
             <div class="row cl">
32
                 <label class="form-label col-xs-4 col-sm-2">
87
                 <label class="form-label col-xs-4 col-sm-2">
33
                     选择背景图:</label>
88
                     选择背景图:</label>
34
-                <div class="formControls col-xs-6 col-sm-6">
35
-                        @if($back_imgs)
36
-                        <ul>
37
-                            @foreach($back_imgs as $k=>$back_img)
38
-                            <li>
39
-                                <img  style="width:100px;" src="{{$back_img}}"/>
40
-                                <input type="radio" class="input-text" value="{{$back_img}}" @if($template['back_img'] == $back_img) checked @endif name="back_img">背景图{{$k+1}}
41
-                            </li>
42
-                            @endforeach
43
-                        </ul>
44
-                        @endif
45
-                        <span class="btn-upload">
46
-                          <input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly><a href="javascript:void();" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe642;</i> 上传图片</a>
47
-                          <input type="file" multiple name="img" class="input-file">
48
-                        </span><br>
49
-                    文件类型支持:jpg ,png ,ico ,文件大小不能超过1M
89
+                <div class="formControls col-xs-6 col-sm-7">
90
+                    @if($back_imgs)
91
+                    <ul class="templates_ul clear">
92
+                        @foreach($back_imgs as $k=>$back_img)
93
+                        <li class="templates_li">
94
+                            <img class="templates_img" src="{{$back_img}}"/>
95
+                            <div>
96
+                                <input type="radio" id="bgImg{{$k}}" value="{{$back_img}}" @if($template['back_img'] == $back_img) checked @endif name="back_img">
97
+                                <label for="bgImg{{$k}}">背景图{{$k+1}}</label>
98
+                            </div>
99
+                        </li>
100
+                        @endforeach
101
+
102
+                        <li id='upload_img' class="templates_li">
103
+                            <div class="add_div">
104
+                                <span>+</span>
105
+                                <input type="file" id="ImgInput" multiple name="img" class="add_img_input" onChange="changeImgID()">
106
+                            </div>
107
+                            <div class="add_img_title">上传新背景图</div>
108
+
109
+                        </li>
110
+                    </ul>
111
+                    @endif
50
                 </div>
112
                 </div>
51
             </div>
113
             </div>
114
+
52
             <div class="row cl">
115
             <div class="row cl">
53
                 <label class="form-label col-xs-4 col-sm-2">
116
                 <label class="form-label col-xs-4 col-sm-2">
54
                     渠道备注:</label>
117
                     渠道备注:</label>
55
-                <div class="formControls col-xs-6 col-sm-6">
118
+                <div class="formControls col-xs-6 col-sm-7">
56
                     <input type="text" class="input-text" value="{{$template['note']}}" placeholder="" name="note">
119
                     <input type="text" class="input-text" value="{{$template['note']}}" placeholder="" name="note">
57
                 </div>
120
                 </div>
58
             </div>
121
             </div>
82
         function return_index(){
145
         function return_index(){
83
             location.href='/admin/template/sourceindex';
146
             location.href='/admin/template/sourceindex';
84
         }
147
         }
148
+
149
+        function changeImgID(html) {
150
+             //获取读取我文件的File对象
151
+            var selectedFile = '';
152
+            var _token = "{{ csrf_token() }}";
153
+            selectedFile = document.getElementById('ImgInput').files[0];
154
+             var reader = new FileReader();
155
+             reader.readAsDataURL(selectedFile);
156
+             reader.onload = function () {
157
+                 //当读取完成后回调这个函数,然后此时文件的内容存储到了result中,直接操作即可
158
+                 $.ajax({
159
+                    url:'/admin/template/uploadBack',
160
+                    type:'post',
161
+                    data:{img:this.result,_token:_token},
162
+                    success:function(pic_url){
163
+                        if(pic_url == '0'){
164
+                            alert(pic_url)
165
+                            return false;
166
+                        }
167
+                        var str = "<li class=\"templates_li\"><img class=\"templates_img\" src=\""+ pic_url +"\"\/><div><input type=\"radio\" id=\"bgImg\" value=\""+pic_url+"\" name=\"back_img\" checked><label for=\"bgImg\">背景图</label><\/div><\/li>";
168
+
169
+                        $("#upload_img").before(str);
170
+                    },
171
+
172
+                })
173
+             }
174
+
175
+        }
85
        
176
        
86
     </script>
177
     </script>
87
     </body>
178
     </body>