sunhao 5 years ago
parent
commit
386608e023

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

@@ -11,6 +11,8 @@ use App\Admin;
11 11
 use Illuminate\Http\Request;
12 12
 use App\Templates;
13 13
 use App\TemplatesSalers;
14
+use App\TemplatesSource;
15
+use App\TemplatesSourceSalers;
14 16
 use App\AdminRole;
15 17
 use App\TemplatesLog;
16 18
 use App\CustDetail;
@@ -396,8 +398,138 @@ class TemplateController extends Controller
396 398
         $indexKey = ['day','admin_name','pv_count','long_count','fan_add','click_rate','change_rate','new_reply','new_consult','old_consult'];
397 399
         $title = ['日期', '销售名', 'PV量', '长按次数', '加粉数', '点击率', '转化率', '新粉回复数', '新粉询价数', '老粉询价数'];
398 400
         $filename = 'xiaoshoudaofen_'.date('Y-m-d_H').'.xlsx';
399
-        return Order::export_excel($result, $filename, $indexKey, $title);
400
-       
401
+        return Order::export_excel($result, $filename, $indexKey, $title);  
402
+    }
403
+
404
+    /*
405
+     * @return \Illuminate\View\View
406
+     */
407
+    public function sourceindex(Request $request)
408
+    {
409
+        $page = (int)$request->input('page');
410
+        $pageSize = 20;
411
+        if($page<=0){
412
+            $page = 1;
413
+        }
414
+
415
+        $offset = ($page-1) * $pageSize;
416
+
417
+        $count = TemplatesSource::where('is_del',0)->count();
418
+        if ($count > 1) {
419
+            // 总页数
420
+            $pages = ceil($count/$pageSize);
421
+        }else{
422
+            // 总页数
423
+            $pages = 1;
424
+        }
425
+
426
+        $result = TemplatesSource::where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
427
+        $result = json_decode(json_encode($result),true);
428
+
429
+        foreach($result as $k=>&$v){
430
+            # 获取销售
431
+            $salers = TemplatesSourceSalers::select('templates_source_salers.*', 'admin.realname as admin_name')->leftJoin('admin', 'admin.id', '=', 'templates_source_salers.admin_id')->where('templates_source_salers.t_id', $v['id'])->where('templates_source_salers.is_del', 0)->get();
432
+            $v['salers'] = $salers;            
433
+            $v['salers_k'] = count($salers); 
434
+            # 获取模板图
435
+            $v['img'] = Templates::where('id', $v['t_id'])->pluck('img');
436
+        }
437
+
438
+        return view('template/sourceindex', ['result' =>$result,
439
+            'page'              =>$page,
440
+            'count'             =>$count,
441
+            'pages'             =>$pages,                   
442
+            ]);
443
+    }
444
+
445
+    /**
446
+     * @return \Illuminate\View\View
447
+     */
448
+    public function sourcecreate()
449
+    {
450
+        return view('template/sourcecreate');
451
+    }
452
+
453
+    /**
454
+     * @param Request $request
455
+     * @return \Illuminate\Http\RedirectResponse
456
+     */
457
+    public function sourcestore(Request $request)
458
+    {
459
+        $this->validate($request, [
460
+            't_id' => 'required',           
461
+        ], [
462
+            't_id.required' => '模板不能为空',
463
+            
464
+        ]);
465
+        $template = new TemplatesSource();
466
+        $template->t_id = intval($request->input('t_id'));
467
+        $template->note = trim($request->input('note'));
468
+    
469
+        //图片上传 阿里云oss       
470
+        if ($request->hasFile('img') && $request->file('img')->isValid()) {
471
+            $file = $request->file('img');
472
+            $ossClient=new oss();
473
+            // 上传阿里云
474
+            $file = $ossClient->upload($file->getClientOriginalExtension(), $file->getRealPath(), 'upload/seafoodPic'.date("Y-m-d",time()).'/'.date('His'));
475
+            $img=$file['oss-request-url'];
476
+            $template->back_img=str_replace("kx-youhuiquan.oss-cn-beijing.aliyuncs.com","imgs.726p.com",$img);
477
+        }
478
+
479
+        if($template->save()){
480
+            //生成连接
481
+            $template->url = $this->createSourceUrl($template->t_id, $template->id);
482
+            $template->save();
483
+        }
484
+
485
+        return redirect('/admin/template/sourceindex')->with('info', '添加模板成功');
486
+    }
487
+
488
+    /**
489
+     * @param $id
490
+     * @return \Illuminate\View\View
491
+     */
492
+    public function sourceedit($id)
493
+    {
494
+        $template = TemplatesSource::findOrFail($id);
495
+        return view('template/sourceedit', ['template' => $template, 'id'=>$id]);
496
+    }
497
+
498
+    /**
499
+     * @param Request $request
500
+     * @return \Illuminate\Http\RedirectResponse
501
+     */
502
+    public function sourceupdate(Request $request)
503
+    {
504
+        $id = (int)$request->input('id');
505
+        $this->validate($request, [
506
+            't_id' => 'required',           
507
+        ], [
508
+            't_id.required' => '模板不能为空',
509
+            
510
+        ]);
511
+
512
+        $template = TemplatesSource::findOrFail($id);
513
+        $t_id = (int)$request->input('t_id');
514
+        if( $template->t_id != $t_id ){
515
+            //模板更改,生成新连接
516
+            $template->t_id = $t_id;
517
+            $template->url = $this->createSourceUrl($t_id, $template->id);
518
+        }
519
+        $template->note = trim($request->input('note'));
520
+    
521
+        //图片上传 阿里云oss       
522
+        if ($request->hasFile('img') && $request->file('img')->isValid()) {
523
+            $file = $request->file('img');
524
+            $ossClient=new oss();
525
+            // 上传阿里云
526
+            $file = $ossClient->upload($file->getClientOriginalExtension(), $file->getRealPath(), 'upload/seafoodPic'.date("Y-m-d",time()).'/'.date('His'));
527
+            $img=$file['oss-request-url'];
528
+            $template->back_img=str_replace("kx-youhuiquan.oss-cn-beijing.aliyuncs.com","imgs.726p.com",$img);
529
+        }
530
+
531
+        $template->save();
532
+        return redirect('/admin/template/sourceindex')->with('info', '修改成功');
401 533
     }
402 534
 
403 535
 

+ 8 - 0
app/Http/routes.php

@@ -203,6 +203,14 @@ Route::group(['prefix' => 'admin'], function(){
203 203
         //销售模板引流每日报表
204 204
         Route::get('template/templateLogReport',   'Admin\TemplateController@templateLogReport');
205 205
         Route::get('template/templateLogReport_export',   'Admin\TemplateController@templateLogReport_export');
206
+
207
+        Route::get('template/sourceindex',   'Admin\TemplateController@sourceindex');
208
+        Route::get('template/sourcecreate',    'Admin\TemplateController@sourcecreate');
209
+        Route::post('template/sourcestore',    'Admin\TemplateController@sourcestore');
210
+        Route::get('template/sourceedit/{id}', 'Admin\TemplateController@sourceedit');
211
+        Route::post('template/sourceupdate',   'Admin\TemplateController@sourceupdate');
212
+        Route::get('template/sourcedelete/{id}',   'Admin\TemplateController@sourcedel');
213
+
206 214
     });
207 215
     
208 216
 });

+ 14 - 11
resources/views/template/sourceindex.blade.php

@@ -7,17 +7,18 @@
7 7
         </div>
8 8
     @endif
9 9
     <div class="page-container">
10
-        <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"> <a class="btn btn-primary radius" onclick="templateadd('新增')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 新增模板</a></span> </div>
10
+        <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"> <a class="btn btn-primary radius" onclick="templateadd('新增')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 新增渠道</a></span> </div>
11 11
         <div class="mt-20">
12 12
             <table class="table table-border table-bordered table-bg table-hover table-sort">
13 13
                 <thead>
14 14
                 <tr class="text-c">
15 15
                     {{--<th width="25"><input type="checkbox" name="" value=""></th>--}}
16
-                    <th width="5%">模板ID</th>
17
-                    <th width="10%">模板链接</th>
18
-                    <th width="10%">模板描述</th>
19
-                    <th width="8%">模板样式图</th>
20
-                    <th width="8%">正在使用的销售</th>
16
+                    <th width="5%">渠道ID</th>
17
+                    <th width="10%">模板示例图</th>
18
+                    <th width="10%">销售名称</th>
19
+                    <th width="8%">渠道备注</th>
20
+                    <th width="8%">推广链接</th>
21
+                    <th width="8%">生成时间</th>
21 22
                     <th width="10%">操作</th>
22 23
                 </tr>
23 24
                 </thead>
@@ -27,8 +28,6 @@
27 28
                     <tr class="text-c">
28 29
                         {{--<td><input name="" type="checkbox" value=""></td>--}}
29 30
                         <td class="text-c">{{$a['id']}}</td>
30
-                        <td class="text-c">{{$a['url']}}</td>
31
-                        <td class="text-c">{{$a['note']}}</td>
32 31
                         <td class="text-c"><img style="width:100px;" src="{{$a['img']}}" /></td>
33 32
                         <td class="text-c">
34 33
                             @if($a['salers'])
@@ -37,8 +36,12 @@
37 36
                                 @endforeach
38 37
                             @endif
39 38
                         </td>
39
+                        <td class="text-c">{{$a['note']}}</td>
40
+                        <td class="text-c">{{$a['url']}}</td>
41
+                        <td class="text-c">{{$a['create_time']}}</td>
42
+                        
40 43
                         <td class="f-14 product-brand-manage">
41
-                            <a style="text-decoration:none" onClick='templateedit("编辑","{{$a['id']}}")' href="javascript:;" title="编辑"><span class="btn btn-primary radius">编辑模板</span></a>
44
+                            <a style="text-decoration:none" onClick='templateedit("编辑","{{$a['id']}}")' href="javascript:;" title="编辑"><span class="btn btn-primary radius">编辑</span></a>
42 45
                             <a style="text-decoration:none" onClick='assign("分配销售","{{$a['id']}}")' href="javascript:;" title="分配销售"><span class="btn btn-primary radius">分配销售</span></a>
43 46
                             <!--a style="text-decoration:none" class="ml-5" onClick="templatedel(this, '{{$a["id"]}}')" href="javascript:;" title="删除"><span class="btn btn-danger radius">删除</span></a-->
44 47
                         </td>
@@ -66,11 +69,11 @@
66 69
         });
67 70
         /*管理员-添加*/
68 71
         function templateadd(title){
69
-            location.href = '/admin/template/create';
72
+            location.href = '/admin/template/sourcecreate';
70 73
         }
71 74
         /*管理员-编辑*/
72 75
         function templateedit(title,id){
73
-            location.href = "/admin/template/edit/"+id;
76
+            location.href = "/admin/template/sourceedit/"+id;
74 77
         }
75 78
         function assign(title,id){
76 79