sunhao %!s(int64=5) %!d(string=před) roky
rodič
revize
1c072b7349

+ 17 - 17
app/Http/Controllers/Admin/TemplateController.php

@@ -735,12 +735,12 @@ class TemplateController extends Controller
735 735
             $metime = date('Y-m-1', strtotime($etime.' +1 month'));
736 736
         }
737 737
         $_start = '2019-11-01';
738
-        $count = TemplatesLog::select(DB::raw('left(create_time,7) as month,admin_id'))->where('create_time', '>', $_start)->where(function($query) use($admin_id, $mstime, $metime, $sale_ids){
738
+        $count = TemplatesLog::select(DB::raw('mdate,admin_id'))->where('create_time', '>', $_start)->where(function($query) use($admin_id, $mstime, $metime, $sale_ids){
739 739
             if($admin_id>0) $query->where('admin_id', $admin_id);
740 740
             if($mstime) $query->where('create_time', '>=', $mstime);
741 741
             if($metime) $query->where('create_time', '<', $metime);
742 742
             if($sale_ids !== null) $query->whereIn('admin_id', $sale_ids);
743
-        })->groupBy('month')->groupBy('admin_id')->get();
743
+        })->groupBy('mdate')->groupBy('admin_id')->get();
744 744
         $count = count($count);
745 745
         if ($count > 1) {
746 746
             // 总页数
@@ -750,19 +750,19 @@ class TemplateController extends Controller
750 750
             $pages = 1;
751 751
         }
752 752
 
753
-        $result = TemplatesLog::select(DB::raw('left(create_time,7) as month,admin_id,count(1) as tcount, count(if(type=1,true,null)) as pv_count'))->where('create_time', '>', $_start)->where(function($query) use($admin_id, $mstime, $metime, $sale_ids){
753
+        $result = TemplatesLog::select(DB::raw('mdate,admin_id,count(1) as tcount, count(if(type=1,true,null)) as pv_count'))->where('create_time', '>', $_start)->where(function($query) use($admin_id, $mstime, $metime, $sale_ids){
754 754
             if($admin_id>0) $query->where('admin_id', $admin_id);
755 755
             if($mstime) $query->where('create_time', '>=', $mstime);
756 756
             if($metime) $query->where('create_time', '<', $metime);
757 757
             if($sale_ids !== null) $query->whereIn('admin_id', $sale_ids);
758
-        })->groupBy('month')->groupBy('admin_id')->orderBy('month', 'desc')->get();
758
+        })->groupBy('mdate')->groupBy('admin_id')->orderBy('mdate', 'desc')->get();
759 759
         $result = json_decode(json_encode($result), true);
760 760
         foreach($result as $k=>&$v){
761 761
             //起止时间
762
-            $s_time = date('Y-m-1', strtotime($v['month']));
763
-            $e_time = date('Y-m-1', strtotime($v['month'].' +1 month'));
762
+            $s_time = date('Y-m-1', strtotime($v['mdate']));
763
+            $e_time = date('Y-m-1', strtotime($v['mdate'].' +1 month'));
764 764
             //获取销售当月加粉情况
765
-            $custDetail = CustDetail::select(DB::raw('sum(fan_add) as fan_add'))->whereRaw('left(dtime,7)="'.$v['month'].'"')->where('admin_id', $v['admin_id'])->where('is_del', 0)->first();
765
+            $custDetail = CustDetail::select(DB::raw('sum(fan_add) as fan_add'))->whereRaw('left(dtime,7)="'.$v['mdate'].'"')->where('admin_id', $v['admin_id'])->where('is_del', 0)->first();
766 766
             if(!empty($custDetail)){
767 767
                 $v['fan_add'] = $custDetail->fan_add;
768 768
             }else{
@@ -776,8 +776,8 @@ class TemplateController extends Controller
776 776
             $v['change_rate'] = $v['pv_count']>0 && $v['fan_add']>0 ? round( $v['fan_add'] / $v['pv_count'], 4 ) * 100 . '%' : '';
777 777
 
778 778
             //1.获取当月新粉
779
-            $phones = DB::table('customers')->whereRaw('left(fanTime,7)="'.$v['month'].'"')->lists('phone');
780
-            $order = Order::select(DB::raw('count(1) as order_count, count(distinct(receiverMobile)) as cust_count, sum(receivedAmount) as order_amount'))->where('admin_id', $v['admin_id'])->whereIn('receiverMobile', $phones)->whereRaw('left(createTime,7)="'.$v['month'].'"')->where('is_del', 0)->first();
779
+            $phones = DB::table('customers')->whereRaw('left(fanTime,7)="'.$v['mdate'].'"')->lists('phone');
780
+            $order = Order::select(DB::raw('count(1) as order_count, count(distinct(receiverMobile)) as cust_count, sum(receivedAmount) as order_amount'))->where('admin_id', $v['admin_id'])->whereIn('receiverMobile', $phones)->whereRaw('left(createTime,7)="'.$v['mdate'].'"')->where('is_del', 0)->first();
781 781
             //当月新粉下单单数
782 782
             $v['order_count'] = $order->order_count;
783 783
             //当月新粉下单人数
@@ -790,7 +790,7 @@ class TemplateController extends Controller
790 790
             $v['new_order_rate'] = $v['fan_add']>0 ? round($v['cust_count'] / $v['fan_add'], 4) * 100 . '%' : '';
791 791
             //新粉复购率
792 792
             //复购用户数 = 下单超过一单的用户数
793
-            $order_cust_fugou = Order::select(DB::raw('count(1) as counts,receiverMobile'))->where('admin_id', $v['admin_id'])->whereIn('receiverMobile', $phones)->where('is_del', 0)->whereRaw('left(createTime,7)="'.$v['month'].'"')->groupBy('receiverMobile')->having('counts', '>', 1)->get();
793
+            $order_cust_fugou = Order::select(DB::raw('count(1) as counts,receiverMobile'))->where('admin_id', $v['admin_id'])->whereIn('receiverMobile', $phones)->where('is_del', 0)->whereRaw('left(createTime,7)="'.$v['mdate'].'"')->groupBy('receiverMobile')->having('counts', '>', 1)->get();
794 794
             $customer_fugou_count = count($order_cust_fugou);
795 795
             $v['cust_fugou_rate'] = $v['cust_count']>0 ? round($customer_fugou_count / $v['cust_count'], 4) * 100 . '%' : '';
796 796
             //新粉订单复购率
@@ -862,16 +862,16 @@ class TemplateController extends Controller
862 862
             $metime = date('Y-m-1', strtotime($etime.' +1 month'));
863 863
         }
864 864
         $_start = '2019-11-01';
865
-        $result = TemplatesLog::select(DB::raw('left(create_time,7) as month,admin_id,count(1) as tcount, count(if(type=1,true,null)) as pv_count'))->where('create_time', '>', $_start)->where(function($query) use($admin_id, $mstime, $metime, $sale_ids){
865
+        $result = TemplatesLog::select(DB::raw('mdate,admin_id,count(1) as tcount, count(if(type=1,true,null)) as pv_count'))->where('create_time', '>', $_start)->where(function($query) use($admin_id, $mstime, $metime, $sale_ids){
866 866
             if($admin_id>0) $query->where('admin_id', $admin_id);
867 867
             if($mstime) $query->where('create_time', '>=', $mstime);
868 868
             if($metime) $query->where('create_time', '<', $metime);
869 869
             if($sale_ids !== null) $query->whereIn('admin_id', $sale_ids);
870
-        })->groupBy('month')->groupBy('admin_id')->orderBy('month', 'desc')->get();
870
+        })->groupBy('mdate')->groupBy('admin_id')->orderBy('mdate', 'desc')->get();
871 871
         $result = json_decode(json_encode($result), true);
872 872
         foreach($result as $k=>&$v){
873 873
             //获取销售当月加粉情况
874
-            $custDetail = CustDetail::select(DB::raw('sum(fan_add) as fan_add'))->whereRaw('left(dtime,7)="'.$v['month'].'"')->where('admin_id', $v['admin_id'])->where('is_del', 0)->first();
874
+            $custDetail = CustDetail::select(DB::raw('sum(fan_add) as fan_add'))->whereRaw('left(dtime,7)="'.$v['mdate'].'"')->where('admin_id', $v['admin_id'])->where('is_del', 0)->first();
875 875
             if(!empty($custDetail)){
876 876
                 $v['fan_add'] = $custDetail->fan_add;
877 877
             }else{
@@ -885,8 +885,8 @@ class TemplateController extends Controller
885 885
             $v['change_rate'] = $v['pv_count']>0 && $v['fan_add']>0 ? round( $v['fan_add'] / $v['pv_count'], 4 ) * 100 . '%' : '';
886 886
 
887 887
             //1.获取当月新粉
888
-            $phones = DB::table('customers')->whereRaw('left(fanTime,7)="'.$v['month'].'"')->lists('phone');
889
-            $order = Order::select(DB::raw('count(1) as order_count, count(distinct(receiverMobile)) as cust_count, sum(receivedAmount) as order_amount'))->where('admin_id', $v['admin_id'])->whereIn('receiverMobile', $phones)->whereRaw('left(createTime,7)="'.$v['month'].'"')->where('is_del', 0)->first();
888
+            $phones = DB::table('customers')->whereRaw('left(fanTime,7)="'.$v['mdate'].'"')->lists('phone');
889
+            $order = Order::select(DB::raw('count(1) as order_count, count(distinct(receiverMobile)) as cust_count, sum(receivedAmount) as order_amount'))->where('admin_id', $v['admin_id'])->whereIn('receiverMobile', $phones)->whereRaw('left(createTime,7)="'.$v['mdate'].'"')->where('is_del', 0)->first();
890 890
             //当月新粉下单单数
891 891
             $v['order_count'] = $order->order_count;
892 892
             //当月新粉下单人数
@@ -899,7 +899,7 @@ class TemplateController extends Controller
899 899
             $v['new_order_rate'] = $v['fan_add']>0 ? round($v['cust_count'] / $v['fan_add'], 4) * 100 . '%' : '';
900 900
             //新粉复购率
901 901
             //复购用户数 = 下单超过一单的用户数
902
-            $order_cust_fugou = Order::select(DB::raw('count(1) as counts,receiverMobile'))->where('admin_id', $v['admin_id'])->whereIn('receiverMobile', $phones)->where('is_del', 0)->whereRaw('left(createTime,7)="'.$v['month'].'"')->groupBy('receiverMobile')->having('counts', '>', 1)->get();
902
+            $order_cust_fugou = Order::select(DB::raw('count(1) as counts,receiverMobile'))->where('admin_id', $v['admin_id'])->whereIn('receiverMobile', $phones)->where('is_del', 0)->whereRaw('left(createTime,7)="'.$v['mdate'].'"')->groupBy('receiverMobile')->having('counts', '>', 1)->get();
903 903
             $customer_fugou_count = count($order_cust_fugou);
904 904
             $v['cust_fugou_rate'] = $v['cust_count']>0 ? round($customer_fugou_count / $v['cust_count'], 4) * 100 . '%' : '';
905 905
             //新粉订单复购率
@@ -912,7 +912,7 @@ class TemplateController extends Controller
912 912
         $sort_c = array_column($result, 'avg_amount');
913 913
         array_multisort($sort_c,SORT_DESC,$result);
914 914
 
915
-        $indexKey = ['month','admin_name','pv_count','long_count','fan_add','cust_count','order_count','fugou_order_count','order_amount','change_rate','new_order_rate','cust_fugou_rate','order_fugou_rate','avg_amount'];
915
+        $indexKey = ['mdate','admin_name','pv_count','long_count','fan_add','cust_count','order_count','fugou_order_count','order_amount','change_rate','new_order_rate','cust_fugou_rate','order_fugou_rate','avg_amount'];
916 916
         $title = ['月份', '销售名', '当月PV量', '当月长按次数', '当月上报加粉数', '当月新粉下单人数', '新粉下单单数', '当月粉丝复购单数', '当月粉丝总销售额', '粉丝转化率', '新粉下单率', '新粉复购率', '新粉订单复购率', '当月粉丝人均销售额'];
917 917
         $filename = 'daofenyuebao_'.date('Y-m-d_H').'.xlsx';
918 918
         return Order::export_excel($result, $filename, $indexKey, $title);  

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

@@ -57,7 +57,7 @@
57 57
                 @if($result)
58 58
                     @foreach($result as $a)
59 59
                         <tr class="text-c" style=" text-align:center;">                           
60
-                            <td>{{$a['month']}}</td>                                                                                   
60
+                            <td>{{$a['mdate']}}</td>                                                                                   
61 61
                             <td>{{$a['admin_name']}}</td>                                                                                   
62 62
                             <td>{{$a['pv_count']}}</td>                                                                                   
63 63
                             <td>{{$a['long_count']}}</td>