sunhao %!s(int64=5) %!d(string=hace) años
padre
commit
2e70ee8998

+ 110 - 0
app/Http/Controllers/Admin/StatisticsController.php

@@ -3683,7 +3683,117 @@ class StatisticsController extends Controller
3683 3683
         return redirect('/admin/salerTargets/index')->with('info', '修改模板成功');
3684 3684
     }
3685 3685
 
3686
+     /**
3687
+     * 销售月业绩完成度报表导出
3688
+     */
3689
+    public function salerTargetProgress_export(Request $request){
3690
+        $team_id = (int)$request->input('team_id');
3691
+        $admin_id = (int)$request->input('admin_id');
3692
+        $mstime = $request->input('stime');
3693
+        $metime = $request->input('etime');
3694
+
3695
+        //假如有团队筛选,检索销售队员
3696
+        $sale_ids = null;
3697
+        if($team_id>0 && !$admin_id){
3698
+            $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
3699
+        }
3700
+
3701
+        $result = DB::table('saler_targets')->where(function($query) use($admin_id, $sale_ids, $mstime, $metime){
3702
+            if($admin_id) $query->where('admin_id', $admin_id);
3703
+            if(!empty($sale_ids)) $query->whereIn('admin_id', $sale_ids);
3704
+            if(!empty($mstime)) $query->where('month', '>=', $mstime);
3705
+            if(!empty($metime)) $query->where('month', '<', $metime);
3706
+        })->orderBy('month', 'desc')->get();
3707
+
3708
+        if($mstime){
3709
+            $stime = date('Y-m-01', strtotime($mstime));
3710
+        }else{
3711
+            $stime = null;
3712
+        }
3713
+        if($metime){
3714
+            $etime = date('Y-m-01', strtotime($metime. ' 1 month')); 
3715
+        }else{
3716
+            $etime = null;
3717
+        }
3718
+
3719
+        //月份天数数组:
3720
+        $m_day = [1=>31,2=>28,3=>31,4=>30,5=>31,6=>30,7=>31,8=>31,9=>30,10=>31,11=>30,12=>31];
3721
+        if(date('Y') % 4 == 0){
3722
+            $m_day[2] = 29;
3723
+        }
3724
+        $result = json_decode(json_encode($result), true);
3725
+        foreach($result as $k=>&$v){
3726
+            $m_stime = date('Y-m-01', strtotime($v['month']));
3727
+            $m_etime = date('Y-m-01', strtotime($m_stime. ' 1 month'));
3686 3728
 
3729
+            //总单数
3730
+            $order = Order::select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('admin_id', $v['admin_id'])->where('is_del', 0)->where('createTime','>=',$m_stime)->where('createTime', '<', $m_etime)->first();
3731
+            $v['order_count'] = $order->order_count;
3732
+            $v['order_amount'] = $order->order_amount;
3733
+            //销售额完成率
3734
+            $v['target_rate'] = $v['amount']>0 ? round( $order->order_amount / $v['amount'] , 4) : '';
3735
+            //时间进度
3736
+            //当前月
3737
+            $tmonth = date('Y-m');
3738
+            $m = date('m');
3739
+            $d = date('d');
3740
+            $days = $m_day[$m];
3741
+            if( $v['month'] == $tmonth ){               
3742
+                $v['time_rate'] = round($d / $days, 4);
3743
+                //剩余每天任务
3744
+                if( $v['target_rate'] >= 1){
3745
+                    $v['day_remain'] = '';
3746
+                }else{
3747
+                    $v['day_remain'] = round( ($v['amount'] - $order->order_amount) / $days, 4 );
3748
+                }
3749
+            }elseif( $v['month'] < $tmonth ){
3750
+                $v['time_rate'] = 1;
3751
+                $v['day_remain'] = '';
3752
+            }elseif( $v['month'] > $tmonth ){
3753
+                $v['time_rate'] = 0;
3754
+                $v['day_remain'] = round( $v['amount'] / $days, 4 );
3755
+            }
3756
+
3757
+            //粉数数据
3758
+            $fan_count = DB::table('cust_day_detail')->select(DB::raw('sum(fan_add) as fan_count, sum(new_reply) as new_reply_count, sum(new_consult) as new_consult_count, admin_name'))->where('dtime', '>=', $m_stime)->where('dtime', '<', $m_etime)->where('admin_id', $v['admin_id'])->where('is_del', 0)->first();
3759
+            $v['fan_count'] = $fan_count->fan_count;
3760
+            $v['new_reply_count'] = $fan_count->new_reply_count;
3761
+            $v['new_consult_count'] = $fan_count->new_consult_count;
3762
+            $v['admin_name'] = $fan_count->admin_name;
3763
+            if(empty($v['admin_name'])){
3764
+                $v['admin_name'] = DB::table('admin')->where('id', $v['admin_id'])->pluck('username');
3765
+            }
3766
+
3767
+            //新粉成单            
3768
+            $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->leftJoin('customers as cu','cu.phone', '=', 'order.receiverMobile')->whereRaw('left(order.createTime, 10) = cu.fanTime')->where('order.is_del', 0)->where('cu.fanTime','>=',$m_stime)->where('cu.fanTime', '<', $m_etime)->where('admin_id', $v['admin_id'])->first();
3769
+            $v['new_order_count'] = $new_order->order_count;
3770
+            $v['new_order_amount'] = $new_order->order_amount;
3771
+            //老粉成单
3772
+            $v['old_order_count'] = $order->order_count - $new_order->order_count;
3773
+            $v['old_order_amount'] = $order->order_amount - $new_order->order_amount;
3774
+            //复购单数
3775
+            //总单数
3776
+            $fugou_order = Order::select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('admin_id', $v['admin_id'])->where('is_del', 0)->where('createTime','>=',$m_stime)->where('createTime', '<', $m_etime)->where('is_fugou', 1)->first();
3777
+            $v['fugou_order_count'] = $fugou_order->order_count;
3778
+            $v['fugou_order_amount'] = $fugou_order->order_amount;
3779
+
3780
+            //新粉转化
3781
+            $phones = DB::table('customers')->select(DB::raw('distinct(customers.phone)'))->leftJoin('order', 'customers.phone', '=', 'order.receiverMobile')->where('customers.fanTime','>=',$m_stime)->where('customers.fanTime','<',$m_etime)->where('order.admin_id', $v['admin_id'])->get();
3782
+
3783
+            $new_orderfan_count = count($phones);
3784
+
3785
+            $v['new_fan_rate'] = $fan_count->fan_count>0 ? round( $new_orderfan_count / $fan_count->fan_count, 4 ) : '';
3786
+            //客单价
3787
+            $v['order_amount_avg'] = $v['order_count'] > 0 ? round( $v['order_amount'] / $v['order_count'], 4 ) : '';
3788
+        }
3789
+
3790
+        $indexKey = ['admin_name','month','order_count','order_amount','amount','target_rate','time_rate','day_remain', 'fan_count', 'new_reply_count', 'new_consult_count', 'new_order_count', 'new_order_amount', 'old_order_count', 'old_order_amount', 'fugou_order_count', 'fugou_order_amount', 'order_count', 'order_amount', 'new_fan_rate', 'order_amount_avg'];
3791
+        $title = ['销售', '月份', '总订单', '总销售额', '目标销售额','销售额完成率', '时间进度', '剩余每天销售任务', '粉丝数', '初步响应', '单品咨询', '新粉成单', '新粉流水', '老粉成单', '老粉流水', '复购成单', '复购流水', '总订单', '总流水', '新粉丝转化', '客单价'];
3792
+        
3793
+        $filename = 'xiaoshouyuebao_'.date('Y-m-d_H').'.xlsx';
3794
+        return Order::export_excel($result, $filename, $indexKey, $title);
3795
+    }
3796
+                                                                                
3687 3797
 }
3688 3798
   
3689 3799
   

+ 1 - 0
app/Http/routes.php

@@ -168,6 +168,7 @@ Route::group(['prefix' => 'admin'], function(){
168 168
         Route::get('/statistics/salerBonus_export', 'Admin\StatisticsController@salerBonus_export');
169 169
         //销售月业绩完成度
170 170
         Route::get('/statistics/salerTargetProgress', 'Admin\StatisticsController@salerTargetProgress');
171
+        Route::get('/statistics/salerTargetProgress_export', 'Admin\StatisticsController@salerTargetProgress_export');
171 172
         Route::get('statistics/salerTargetCreate',    'Admin\StatisticsController@salerTargetCreate');
172 173
         Route::post('statistics/salerTargetStore',    'Admin\StatisticsController@salerTargetStore');
173 174
         Route::get('statistics/salerTargetEdit/{id}', 'Admin\StatisticsController@salerTargetEdit');

+ 1 - 1
resources/views/statistics/salerTargetProgress.blade.php

@@ -26,7 +26,7 @@
26 26
                
27 27
                 
28 28
                 <a class="btn btn-primary radius"  style="margin-left: 5px" onclick="user_search()" href="javascript:;">搜索</a>   
29
-                <!--a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont"></i> 导出数据</a-->
29
+                <a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont"></i> 导出数据</a>
30 30
                 
31 31
             </div>
32 32
         </div>