Parcourir la Source

导入地域投入

sunhao il y a 5 ans
Parent
commit
d1dca16d45

+ 17 - 0
app/AdCost.php

@@ -0,0 +1,17 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: Administrator
5
+ * Date: 2017/12/5
6
+ * Time: 15:07
7
+ */
8
+
9
+namespace App;
10
+use Illuminate\Database\Eloquent\Model;
11
+
12
+class AdCost extends Model
13
+{
14
+    public $timestamps = false;
15
+    protected $table = "ad_cost";
16
+   
17
+}

+ 104 - 0
app/Http/Controllers/Admin/CustReportController.php

@@ -11,10 +11,15 @@ use App\Http\Controllers\Controller;
11 11
 use App\Logs;
12 12
 use App\CustTotal;
13 13
 use App\CustDetail;
14
+use App\AdCost;
14 15
 use App\Oplog;
15 16
 use Illuminate\Http\Request;
16 17
 use Illuminate\Support\Facades\DB;
17 18
 
19
+use PHPExcel_Reader_Excel2007;
20
+use PHPExcel_Reader_Excel5;
21
+use PHPExcel_Reader_CSV;
22
+
18 23
 class custReportController extends Controller
19 24
 {
20 25
 	public function totalindex(Request $request){
@@ -624,5 +629,104 @@ class custReportController extends Controller
624 629
         echo $data_str;
625 630
         exit;       
626 631
     }
632
+
633
+    /**
634
+     * 地域投入数据
635
+     */
636
+    public function disCostList(Request $request){
637
+        $page = (int)$request->input('page');
638
+        $pageSize = 20;
639
+        if($page<=0){
640
+            $page = 1;
641
+        }
642
+
643
+        $offset = ($page-1) * $pageSize;
644
+        $stime = $request->input('stime');
645
+        $etime = $request->input('etime');
646
+
647
+        $count = AdCost::where(function($query) use($stime, $etime){
648
+            if($stime) $query->where('ad_time', '>=', $stime);
649
+            if($etime) $query->where('ad_time', '<=', $etime);
650
+        })->count();
651
+        if ($count > 1) {
652
+            // 总页数
653
+            $pages = ceil($count/$pageSize);
654
+        }else{
655
+            // 总页数
656
+            $pages = 1;
657
+        }
658
+
659
+        $result = AdCost::where(function($query) use($stime, $etime){
660
+            if($stime) $query->where('ad_time', '>=', $stime);
661
+            if($etime) $query->where('ad_time', '<=', $etime);
662
+        })->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
663
+        $result = json_decode(json_encode($result),true);
664
+
665
+        $today = date('Y-m-d');
666
+        return view('custreport/discostlist', ['result' =>$result,
667
+            'page'              =>$page,
668
+            'count'             =>$count,
669
+            'pages'             =>$pages,                           
670
+            'stime'             =>$stime,
671
+            'etime'             =>$etime,
672
+            'today'             =>$today,
673
+            ]);
674
+    }
675
+
676
+    /**
677
+     * excel导入每日地域投入信息
678
+     * @param Request $request
679
+     */
680
+    public function importDisCost(Request $request) {
681
+        $wexin_appid = trim($request->input('wexin_appid'));
682
+        $ad_time = $request->input('ad_time');
683
+
684
+        $excelFile = $request->file('dataFile');
685
+        //实例化Excel读取类
686
+        $objReader = new PHPExcel_Reader_Excel2007();
687
+
688
+        if(!$objReader->canRead($excelFile)){
689
+            $objReader = new PHPExcel_Reader_Excel5();
690
+            if(!$objReader->canRead($excelFile)){
691
+                $objReader = new PHPExcel_Reader_CSV();
692
+                $objReader->setInputEncoding('UTF-8');
693
+                $objReader->setDelimiter(',');
694
+                if(!$objReader->canRead($excelFile)){
695
+                    echo "\n".'无法识别的Excel文件!';
696
+                    return false;
697
+                }
698
+            }
699
+        }
700
+        $objPHPExcel=$objReader->load($excelFile);
701
+        $worksheet=$objPHPExcel->getSheet(0);//获取第一个工作表
702
+        $highestRow=$worksheet->getHighestRow();//取得总行数
703
+        $highestColumn=$worksheet->getHighestColumn(); //取得总列数
704
+
705
+        $lines = $highestRow - 1;
706
+        if ($lines <= 0) {
707
+            //'Excel表格中没有数据';
708
+            return false;
709
+        }
710
+
711
+        $errorArr=[];
712
+        $okStr = '';
713
+        for ($row = 2; $row <= $highestRow; ++$row) {
714
+            $params  = array(); 
715
+            $params['wexin_appid'] = $wexin_appid;
716
+            $params['ad_time'] = $ad_time;
717
+            $params['city'] = trim($worksheet->getCellByColumnAndRow(0, $row)->getValue());
718
+            $params['cost'] = trim($worksheet->getCellByColumnAndRow(1, $row)->getValue());
719
+            $params['exposure_times'] = intval($worksheet->getCellByColumnAndRow(2, $row)->getValue());
720
+            $params['click_times'] = intval($worksheet->getCellByColumnAndRow(3, $row)->getValue());
721
+            $params['click_rate'] = trim($worksheet->getCellByColumnAndRow(4, $row)->getValue());
722
+            $params['conversion_times'] = intval($worksheet->getCellByColumnAndRow(5, $row)->getValue());
723
+            $params['conversion_cost'] = trim($worksheet->getCellByColumnAndRow(6, $row)->getValue());
724
+
725
+            $result = AdCost::insert($params);
726
+        }
727
+
728
+        return redirect('admin/custreport/disCostList')->with('info','导入成功');       
729
+
730
+    }
627 731
 }
628 732
 

+ 3 - 0
app/Http/Controllers/Admin/OrderController.php

@@ -576,10 +576,13 @@ class OrderController extends Controller
576 576
                 //if( $order['status'] == 1 ) $this->sendRemind($self_id, $res, 1);
577 577
             }
578 578
             
579
+            /*
579 580
             $last_url = $request->input('last_url');
580 581
             if(!empty($last_url)){
581 582
                 header('Location:'.$last_url);exit;
582 583
             }
584
+            */            
585
+
583 586
             return redirect('/admin/order/index')->with('info', '添加成功'); 
584 587
         }
585 588
 

+ 5 - 0
app/Http/routes.php

@@ -94,6 +94,10 @@ Route::group(['prefix' => 'admin'], function(){
94 94
         Route::get('/custreport/totaledit/{id}', 'Admin\CustReportController@totaledit');
95 95
         Route::post('/custreport/totalupdate', 'Admin\CustReportController@totalupdate');
96 96
         Route::get('/custreport/totaldelete/{id}', 'Admin\CustReportController@totaldelete');
97
+         //录入地域投入信息
98
+        Route::post('/custreport/importDisCost', 'Admin\CustReportController@importDisCost');
99
+        //地域投入信息表
100
+        Route::get('/custreport/disCostList', 'Admin\CustReportController@disCostList');
97 101
 
98 102
         //数据报表
99 103
         //当日数据统计
@@ -117,6 +121,7 @@ Route::group(['prefix' => 'admin'], function(){
117 121
         Route::get('/statistics/orderSaleRank', 'Admin\StatisticsController@orderSaleRank');
118 122
         //实时订单地域分布
119 123
         Route::get('/statistics/orderDistrict', 'Admin\StatisticsController@orderDistrict');
124
+
120 125
     });
121 126
     
122 127
 });

+ 3 - 0
resources/views/admin/index.blade.php

@@ -77,6 +77,9 @@
77 77
                     <ul>                       
78 78
                         <li @if(!isset($res['custreport/detail'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/custreport/detailindex')}}" data-title="销售上报加粉数据" href="javascript:void(0)">销售上报加粉数据</a></li>                        
79 79
                     </ul>
80
+                    <ul>                       
81
+                        <li @if(!isset($res['custreport/disCostList'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/custreport/disCostList')}}" data-title="上报地域投入数据" href="javascript:void(0)">上报地域投入数据</a></li>                        
82
+                    </ul>
80 83
                 </dd>
81 84
             </dl>
82 85
 

+ 185 - 0
resources/views/custreport/discostlist.blade.php

@@ -0,0 +1,185 @@
1
+@extends('admin/master')
2
+@section('content')
3
+    <body>
4
+    <div class="page-container">
5
+        <div>
6
+            <div>                              
7
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="开始时间"/>
8
+                <input id="stime" type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" style="width:12%;text-align:center;margin-left: -5px" name="stime" value="{{$stime?$stime:''}}">
9
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="结束时间"/>
10
+                <input id="etime"type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" style="width:12%;text-align:center;margin-left: -5px" name="etime" value="{{$etime?$etime:''}}">
11
+                               
12
+                <a class="btn btn-primary radius"  style="margin-left: 5px" onclick="user_search()" href="javascript:;">搜索</a>
13
+                <a class="btn btn-primary radius" onclick="importExcel('数据导入')" href="javascript:;"> 导入订单</a>
14
+                
15
+            </div>
16
+        </div>
17
+        
18
+        <div class="mt-20">
19
+            <table class="table table-border table-bordered table-bg table-hover table-sort">
20
+                <thead>
21
+                <tr class="text-c">
22
+                    <th width="8%">日期</th>
23
+                    <th width="8%">微信Appid</th>
24
+                    <th width="8%">城市</th>
25
+                    <th width="8%">花费(元)</th>
26
+                    <th width="8%">曝光次数</th>
27
+                    <th width="8%">点击次数</th>
28
+                    <th width="8%">点击率</th>
29
+                    <th width="8%">转化目标量</th>
30
+                    <th width="8%">转化目标成本</th>                                                                  
31
+                    <th width="8%">创建时间</th>                                                                  
32
+                    <!--th width="6%">操作</th-->                  
33
+                </tr>
34
+                </thead>
35
+                <tbody>
36
+                @if($result)
37
+                    @foreach($result as $a)
38
+                        <tr class="text-c" style=" text-align:center;">                           
39
+                            <td>{{$a['ad_time']}}</td>                            
40
+                            <td>{{$a['wexin_appid']}}</td>                            
41
+                            <td>{{$a['city']}}</td>                            
42
+                            <td>{{$a['cost']}}</td>                            
43
+                            <td>{{$a['exposure_times']}}</td>                            
44
+                            <td>{{$a['click_times']}}</td>                            
45
+                            <td>{{$a['click_rate']}}</td>                            
46
+                            <td>{{$a['conversion_times']}}</td>                            
47
+                            <td>{{$a['conversion_cost']}}</td>                            
48
+                            <td>{{$a['add_time']}}</td>                                                                                                                                                                 
49
+                            <!--td>
50
+                                <a style="text-decoration:none" onClick='custreport_edit("编辑","{{$a['id']}}")' href="javascript:;" title="编辑"><span class="btn btn-primary radius">编辑</span></a>
51
+                                <a style="text-decoration:none" onClick='custreport_del("删除","{{$a['id']}}")' href="javascript:;" title="删除"><span class="btn btn-primary radius">删除</span></a>
52
+                            </td-->                             
53
+                        </tr>
54
+                    @endforeach
55
+                @endif
56
+                </tbody>
57
+            </table>
58
+        </div>
59
+        <!--弹出层 推入分组-->
60
+        <div id="modal-demo1" class="modal fade" tabnonautomatic_index="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
61
+            <div class="modal-dialog">
62
+                <div class="modal-content radius">
63
+                    <div class="modal-body" style="height:280px">
64
+                        <div class="cl pd-5 bg-1 bk-gray mt-20">
65
+                            
66
+                            <form class="form form-horizontal" method="POST" action="/admin/custreport/importDisCost" enctype="multipart/form-data">
67
+                                <input type="hidden" name="_token" value="{{ csrf_token() }}" />
68
+
69
+                                <div class="row cl">
70
+                                <label class="form-label col-xs-4 col-sm-2">
71
+                                    微信appid:</label>
72
+                                    <div class="formControls col-xs-6 col-sm-6">
73
+                                        <input type="text" class="input-text" value="" placeholder="" name="wexin_appid">
74
+                                    </div>
75
+                                </div>
76
+
77
+                                <div class="row cl">
78
+                                <label class="form-label col-xs-4 col-sm-2">
79
+                                    日期:</label>
80
+                                    <div class="formControls col-xs-6 col-sm-6">
81
+                                        <input id="ad_time" type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" style="width:50%;text-align:center;" name="ad_time" value="{{$today?$today:''}}">
82
+                                    </div>
83
+                                </div>
84
+
85
+                                <div class="row cl">
86
+                                <label class="form-label col-xs-4 col-sm-2">
87
+                                    文件:</label>
88
+                                    <div class="formControls col-xs-6 col-sm-6">
89
+                                        <input id="file" type="file" class="form-control" name="dataFile" required>
90
+                                    </div>
91
+                                </div>
92
+
93
+                                <div class="row cl">
94
+                                    <div class="col-9 col-offset-2">
95
+                                        <button type="submit" class="btn btn-primary radius">确定</button>
96
+                                        <button class="btn radius" data-dismiss="modal" aria-hidden="true">关闭</button>
97
+                                    </div>
98
+                                </div>
99
+                            </form>
100
+                        </div>
101
+                        <br>
102
+                        {{--<div style="float:right">--}}
103
+                            {{--<button class="btn btn-primary radius" onclick='submits(this,"{{$page}}")' value="&nbsp;&nbsp;确定&nbsp;&nbsp;">&nbsp;&nbsp;确定&nbsp;&nbsp;</button>&nbsp;--}}
104
+                            {{--<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>--}}
105
+                        {{--</div>--}}
106
+                    </div>
107
+                </div>
108
+            </div>
109
+        </div>
110
+        <div id="page" class="page_div"></div>
111
+    </div>
112
+    
113
+    <!--_footer 作为公共模版分离出去-->
114
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
115
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
116
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
117
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
118
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
119
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
120
+    <!--/_footer 作为公共模版分离出去-->
121
+    <!--/_footer 作为公共模版分离出去-->
122
+     <script type="text/javascript">
123
+        /*广告-添加*/
124
+        function custreport_add(title){
125
+            location.href="/admin/custreport/totalcreate";
126
+        }
127
+        /*广告-编辑*/
128
+        function custreport_edit(title,id){
129
+            location.href="/admin/custreport/totaledit/"+id;
130
+        }
131
+        /*广告-设为首页显示*/
132
+        function up(obj,id){
133
+            layer.confirm('确认要设为首页显示吗?',function(index){
134
+                location.href='/admin/custreport/up/'+id;
135
+            });
136
+        }
137
+        /*广告-移除*/
138
+        function custreport_del(obj,id){
139
+            layer.confirm('确认要删除吗?',function(index){
140
+                location.href='/admin/custreport/totaldelete/'+id;
141
+            });
142
+        }
143
+        /*广告-设为首页隐藏*/
144
+        function down(obj,id){
145
+            layer.confirm('确认要设为首页隐藏吗?',function(index){
146
+                location.href='/admin/custreport/down/'+id;
147
+            });
148
+        }
149
+        function user_search(){
150
+            var stime = $('#stime').val();
151
+            var etime = $('#etime').val();
152
+
153
+            location.href = 'disCostList?stime='+stime+'&etime='+etime;
154
+        }
155
+        //导出
156
+        function custreport_export(){
157
+            var stime = $('#stime').val();
158
+            var etime = $('#etime').val();
159
+            var team_id = $('#team_id').val();
160
+            location.href = '/admin/custreport/total_export?stime='+stime+'&etime='+etime+'&team_id='+team_id;
161
+        }
162
+
163
+        //批量导入
164
+        function importExcel(){
165
+            $("#modal-demo1").modal("show");
166
+        }
167
+       
168
+        /*分页*/
169
+        
170
+        $("#page").paging({
171
+            pageNo:{{$page}},
172
+            totalPage: {{$pages}},
173
+            totalSize: {{$count}},
174
+            callback: function(num) {
175
+                var stime = $('#stime').val();
176
+                var etime = $('#etime').val();
177
+                location.href='disCostList?page='+num+'&stime='+stime+'&etime='+etime;
178
+            }
179
+        })
180
+        
181
+    </script>
182
+   
183
+    </body>
184
+
185
+@endsection

+ 6 - 3
resources/views/order/ordercreate.blade.php

@@ -265,8 +265,8 @@
265 265
         
266 266
             <div class="row cl">
267 267
                 <div class="col-9 col-offset-2">
268
-                    <button class="btn btn-primary radius" type="" onclick="return to_submit()" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">&nbsp;&nbsp;保存&nbsp;&nbsp;</button>&nbsp;
269
-                    <button class="btn btn-primary radius" type="" onclick="return to_verify()" value="&nbsp;&nbsp;保存并提审&nbsp;&nbsp;">&nbsp;&nbsp;保存并提审&nbsp;&nbsp;</button>&nbsp;
268
+                    <button class="btn btn-primary radius" onclick="to_submit()" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">&nbsp;&nbsp;保存&nbsp;&nbsp;</button>&nbsp;
269
+                    <button class="btn btn-primary radius" onclick="to_verify()" value="&nbsp;&nbsp;保存并提审&nbsp;&nbsp;">&nbsp;&nbsp;保存并提审&nbsp;&nbsp;</button>&nbsp;
270 270
                     <button class="btn btn-default" type="reset" onclick="return_index();">&nbsp;&nbsp;返回&nbsp;&nbsp;</button>&nbsp;
271 271
                 </div>
272 272
             </div>
@@ -414,8 +414,9 @@
414 414
         }
415 415
 
416 416
         function to_verify(){
417
-	    $(".btn").attr("disabled",true);
417
+	        $(".btn").attr("disabled",true);
418 418
             $("input[name=status]").val('1');
419
+            //console.log('disabled')
419 420
             $("#order-form").submit();
420 421
             return true;
421 422
         }
@@ -423,6 +424,8 @@
423 424
 	function to_submit(){
424 425
             $(".btn").attr("disabled",true);
425 426
             $("input[name=status]").val('0');
427
+            //console.log('disabled1')
428
+
426 429
             $("#order-form").submit();
427 430
             return true;
428 431
         }