|
@@ -17,6 +17,7 @@ use App\DistrictRoi7;
|
17
|
17
|
use App\DistrictRoi30;
|
18
|
18
|
use App\DistrictRoi15;
|
19
|
19
|
use App\DistrictRoi45;
|
|
20
|
+use App\SalerTargets;
|
20
|
21
|
use Illuminate\Http\Request;
|
21
|
22
|
use Illuminate\Support\Facades\DB;
|
22
|
23
|
|
|
@@ -3457,6 +3458,232 @@ class StatisticsController extends Controller
|
3457
|
3458
|
return $ret;
|
3458
|
3459
|
}
|
3459
|
3460
|
|
|
3461
|
+ /**
|
|
3462
|
+ * 销售月业绩完成度报表
|
|
3463
|
+ */
|
|
3464
|
+ public function salerTargetProgress(Request $request){
|
|
3465
|
+ $team_id = (int)$request->input('team_id');
|
|
3466
|
+ $admin_id = (int)$request->input('admin_id');
|
|
3467
|
+ $mstime = $request->input('stime');
|
|
3468
|
+ $metime = $request->input('etime');
|
|
3469
|
+
|
|
3470
|
+ //假如有团队筛选,检索销售队员
|
|
3471
|
+ $sale_ids = null;
|
|
3472
|
+ if($team_id>0 && !$admin_id){
|
|
3473
|
+ $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
|
|
3474
|
+ }
|
|
3475
|
+
|
|
3476
|
+ $page = (int)$request->input('page');
|
|
3477
|
+ $pageSize = 20;
|
|
3478
|
+ if($page<=0){
|
|
3479
|
+ $page = 1;
|
|
3480
|
+ }
|
|
3481
|
+ $offset = ($page-1) * $pageSize;
|
|
3482
|
+
|
|
3483
|
+ $count = DB::table('saler_targets')->where(function($query) use($admin_id, $sale_ids, $mstime, $metime){
|
|
3484
|
+ if($admin_id) $query->where('admin_id', $admin_id);
|
|
3485
|
+ if(!empty($sale_ids)) $query->whereIn('admin_id', $sale_ids);
|
|
3486
|
+ if(!empty($mstime)) $query->where('month', '>=', $mstime);
|
|
3487
|
+ if(!empty($metime)) $query->where('month', '<', $metime);
|
|
3488
|
+ })->count();
|
|
3489
|
+
|
|
3490
|
+ if ($count > 1) {
|
|
3491
|
+ // 总页数
|
|
3492
|
+ $pages = ceil($count/$pageSize);
|
|
3493
|
+ }else{
|
|
3494
|
+ // 总页数
|
|
3495
|
+ $pages = 1;
|
|
3496
|
+ }
|
|
3497
|
+
|
|
3498
|
+ $result = DB::table('saler_targets')->where(function($query) use($admin_id, $sale_ids, $mstime, $metime){
|
|
3499
|
+ if($admin_id) $query->where('admin_id', $admin_id);
|
|
3500
|
+ if(!empty($sale_ids)) $query->whereIn('admin_id', $sale_ids);
|
|
3501
|
+ if(!empty($mstime)) $query->where('month', '>=', $mstime);
|
|
3502
|
+ if(!empty($metime)) $query->where('month', '<', $metime);
|
|
3503
|
+ })->orderBy('month', 'desc')->offset($offset)->limit($pageSize)->get();
|
|
3504
|
+
|
|
3505
|
+ if($mstime){
|
|
3506
|
+ $stime = date('Y-m-01', strtotime($mstime));
|
|
3507
|
+ }else{
|
|
3508
|
+ $stime = null;
|
|
3509
|
+ }
|
|
3510
|
+ if($metime){
|
|
3511
|
+ $etime = date('Y-m-01', strtotime($metime. ' 1 month'));
|
|
3512
|
+ }else{
|
|
3513
|
+ $etime = null;
|
|
3514
|
+ }
|
|
3515
|
+
|
|
3516
|
+ //月份天数数组:
|
|
3517
|
+ $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];
|
|
3518
|
+ if(date('Y') % 4 == 0){
|
|
3519
|
+ $m_day[2] = 29;
|
|
3520
|
+ }
|
|
3521
|
+ $result = json_decode(json_encode($result), true);
|
|
3522
|
+ foreach($result as $k=>&$v){
|
|
3523
|
+ $m_stime = date('Y-m-01', strtotime($v['month']));
|
|
3524
|
+ $m_etime = date('Y-m-01', strtotime($m_stime. ' 1 month'));
|
|
3525
|
+
|
|
3526
|
+ //总单数
|
|
3527
|
+ $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();
|
|
3528
|
+ $v['order_count'] = $order->order_count;
|
|
3529
|
+ $v['order_amount'] = $order->order_amount;
|
|
3530
|
+ //销售额完成率
|
|
3531
|
+ $v['target_rate'] = $v['amount']>0 ? round( $order->order_amount / $v['amount'] , 4) : '';
|
|
3532
|
+ //时间进度
|
|
3533
|
+ //当前月
|
|
3534
|
+ $tmonth = date('Y-m');
|
|
3535
|
+ $m = date('m');
|
|
3536
|
+ $d = date('d');
|
|
3537
|
+ $days = $m_day[$m];
|
|
3538
|
+ if( $v['month'] == $tmonth ){
|
|
3539
|
+ $v['time_rate'] = round($d / $days, 4);
|
|
3540
|
+ //剩余每天任务
|
|
3541
|
+ if( $v['target_rate'] >= 1){
|
|
3542
|
+ $v['day_remain'] = '';
|
|
3543
|
+ }else{
|
|
3544
|
+ $v['day_remain'] = round( ($v['amount'] - $order->order_amount) / $days, 4 );
|
|
3545
|
+ }
|
|
3546
|
+ }elseif( $v['month'] < $tmonth ){
|
|
3547
|
+ $v['time_rate'] = 1;
|
|
3548
|
+ $v['day_remain'] = '';
|
|
3549
|
+ }elseif( $v['month'] > $tmonth ){
|
|
3550
|
+ $v['time_rate'] = 0;
|
|
3551
|
+ $v['day_remain'] = round( $v['amount'] / $days, 4 );
|
|
3552
|
+ }
|
|
3553
|
+
|
|
3554
|
+ //粉数数据
|
|
3555
|
+ $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();
|
|
3556
|
+ $v['fan_count'] = $fan_count->fan_count;
|
|
3557
|
+ $v['new_reply_count'] = $fan_count->new_reply_count;
|
|
3558
|
+ $v['new_consult_count'] = $fan_count->new_consult_count;
|
|
3559
|
+ $v['admin_name'] = $fan_count->admin_name;
|
|
3560
|
+ if(empty($v['admin_name'])){
|
|
3561
|
+ $v['admin_name'] = DB::table('admin')->where('id', $v['admin_id'])->pluck('username');
|
|
3562
|
+ }
|
|
3563
|
+
|
|
3564
|
+ //新粉成单
|
|
3565
|
+ $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();
|
|
3566
|
+ $v['new_order_count'] = $new_order->order_count;
|
|
3567
|
+ $v['new_order_amount'] = $new_order->order_amount;
|
|
3568
|
+ //老粉成单
|
|
3569
|
+ $v['old_order_count'] = $order->order_count - $new_order->order_count;
|
|
3570
|
+ $v['old_order_amount'] = $order->order_amount - $new_order->order_amount;
|
|
3571
|
+ //复购单数
|
|
3572
|
+ //总单数
|
|
3573
|
+ $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();
|
|
3574
|
+ $v['fugou_order_count'] = $fugou_order->order_count;
|
|
3575
|
+ $v['fugou_order_amount'] = $fugou_order->order_amount;
|
|
3576
|
+
|
|
3577
|
+ //新粉转化
|
|
3578
|
+ $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();
|
|
3579
|
+
|
|
3580
|
+ $new_orderfan_count = count($phones);
|
|
3581
|
+
|
|
3582
|
+ $v['new_fan_rate'] = $fan_count->fan_count>0 ? round( $new_orderfan_count / $fan_count->fan_count, 4 ) : '';
|
|
3583
|
+ //客单价
|
|
3584
|
+ $v['order_amount_avg'] = $v['order_count'] > 0 ? round( $v['order_amount'] / $v['order_count'], 4 ) : '';
|
|
3585
|
+ }
|
|
3586
|
+
|
|
3587
|
+ $teamList = DB::table('teams')->select('id', 'name')->get();
|
|
3588
|
+ $teamList = json_decode(json_encode($teamList), true);
|
|
3589
|
+ $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
|
|
3590
|
+ $adminList = json_decode(json_encode($adminList), true);
|
|
3591
|
+
|
|
3592
|
+ return view('statistics/salerTargetProgress', ['result'=>$result,
|
|
3593
|
+ 'page' =>$page,
|
|
3594
|
+ 'count' =>$count,
|
|
3595
|
+ 'pages' =>$pages,
|
|
3596
|
+ 'teamlist' =>$teamList,
|
|
3597
|
+ 'adminlist' =>$adminList,
|
|
3598
|
+ 'team_id' =>$team_id,
|
|
3599
|
+ 'admin_id' =>$admin_id,
|
|
3600
|
+ 'stime' =>$mstime,
|
|
3601
|
+ 'etime' =>$metime,
|
|
3602
|
+ ]);
|
|
3603
|
+ }
|
|
3604
|
+
|
|
3605
|
+ /**
|
|
3606
|
+ * @return \Illuminate\View\View
|
|
3607
|
+ */
|
|
3608
|
+ public function salerTargetCreate()
|
|
3609
|
+ {
|
|
3610
|
+ $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
|
|
3611
|
+ $adminList = json_decode(json_encode($adminList), true);
|
|
3612
|
+ $teamList = DB::table('teams')->select('id', 'name')->get();
|
|
3613
|
+ $teamList = json_decode(json_encode($teamList), true);
|
|
3614
|
+ return view('statistics/salerTargetCreate',['adminlist'=>$adminList, 'teamlist'=>$teamList]);
|
|
3615
|
+ }
|
|
3616
|
+
|
|
3617
|
+ /**
|
|
3618
|
+ * @param Request $request
|
|
3619
|
+ * @return \Illuminate\Http\RedirectResponse
|
|
3620
|
+ */
|
|
3621
|
+ public function salerTargetStore(Request $request)
|
|
3622
|
+ {
|
|
3623
|
+ $this->validate($request, [
|
|
3624
|
+ 'admin_id' => 'required',
|
|
3625
|
+ 'month' => 'required',
|
|
3626
|
+ 'amount' => 'required',
|
|
3627
|
+ ], [
|
|
3628
|
+ 'admin_id.required' => '销售不能为空',
|
|
3629
|
+ 'month.required' => '日期不能为空',
|
|
3630
|
+ 'amount.required' => '销售额不能为空',
|
|
3631
|
+
|
|
3632
|
+ ]);
|
|
3633
|
+ $salerTargets = new SalerTargets();
|
|
3634
|
+ $salerTargets->admin_id = intval($request->input('admin_id'));
|
|
3635
|
+ $salerTargets->month = trim($request->input('month'));
|
|
3636
|
+ $salerTargets->amount = trim($request->input('amount'));
|
|
3637
|
+
|
|
3638
|
+ $salerTargets->save();
|
|
3639
|
+ return redirect('/admin/statistics/salerTargetProgress')->with('info', '添加成功');
|
|
3640
|
+ }
|
|
3641
|
+
|
|
3642
|
+ /**
|
|
3643
|
+ * @param $id
|
|
3644
|
+ * @return \Illuminate\View\View
|
|
3645
|
+ */
|
|
3646
|
+ public function salerTargetEdit($id)
|
|
3647
|
+ {
|
|
3648
|
+ $salerTargets = salerTargetss::findOrFail($id);
|
|
3649
|
+ return view('salerTargets/edit', ['salerTargets' => $salerTargets, 'id'=>$id]);
|
|
3650
|
+ }
|
|
3651
|
+
|
|
3652
|
+ /**
|
|
3653
|
+ * @param Request $request
|
|
3654
|
+ * @return \Illuminate\Http\RedirectResponse
|
|
3655
|
+ */
|
|
3656
|
+ public function salerTargetUpdate(Request $request)
|
|
3657
|
+ {
|
|
3658
|
+ $id = (int)$request->input('id');
|
|
3659
|
+ $this->validate($request, [
|
|
3660
|
+ 'url' => 'required|unique:salerTargetss,url,'.$id.',id',
|
|
3661
|
+ ], [
|
|
3662
|
+ 'url.required' => '模板链接不能为空',
|
|
3663
|
+ 'url.unique' => '该模板链接已存在',
|
|
3664
|
+
|
|
3665
|
+ ]);
|
|
3666
|
+
|
|
3667
|
+ $salerTargets = salerTargetss::findOrFail($id);
|
|
3668
|
+ $salerTargets->url = trim($request->input('url'));
|
|
3669
|
+ $salerTargets->note = trim($request->input('note'));
|
|
3670
|
+
|
|
3671
|
+ //图片上传 阿里云oss
|
|
3672
|
+ if ($request->hasFile('img') && $request->file('img')->isValid()) {
|
|
3673
|
+ $file = $request->file('img');
|
|
3674
|
+ $ossClient=new oss();
|
|
3675
|
+ // 上传阿里云
|
|
3676
|
+ $file = $ossClient->upload($file->getClientOriginalExtension(), $file->getRealPath(), 'upload/seafoodPic'.date("Y-m-d",time()).'/'.date('His'));
|
|
3677
|
+ $img=$file['oss-request-url'];
|
|
3678
|
+ $salerTargets->img=str_replace("kx-youhuiquan.oss-cn-beijing.aliyuncs.com","imgs.726p.com",$img);
|
|
3679
|
+ }
|
|
3680
|
+
|
|
3681
|
+ $salerTargets->save();
|
|
3682
|
+ return redirect('/admin/salerTargets/index')->with('info', '修改模板成功');
|
|
3683
|
+ }
|
|
3684
|
+
|
|
3685
|
+
|
|
3686
|
+
|
3460
|
3687
|
}
|
3461
|
3688
|
|
3462
|
3689
|
|