|
@@ -30,8 +30,16 @@ class StatisticsController extends Controller
|
30
|
30
|
|
31
|
31
|
$stime = $request->input('stime');
|
32
|
32
|
$etime = $request->input('etime');
|
|
33
|
+ $team_id = (int)$request->input('team_id');
|
33
|
34
|
|
34
|
|
- $count = CustTotal::select(DB::raw('count(distinct dtime) as total'))->where(function($query) use($stime, $etime){
|
|
35
|
+ //假如有团队筛选,检索销售队员
|
|
36
|
+ $sale_ids = null;
|
|
37
|
+ if($team_id>0){
|
|
38
|
+ $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ $count = CustTotal::select(DB::raw('count(distinct dtime) as total'))->where(function($query) use($team_id, $stime, $etime){
|
|
42
|
+ if($team_id) $query->where('team_id', '=', $team_id);
|
35
|
43
|
if($stime) $query->where('dtime', '>=', $stime);
|
36
|
44
|
if($etime) $query->where('dtime', '<=', $etime);
|
37
|
45
|
})->where('is_del',0)->first();
|
|
@@ -44,7 +52,8 @@ class StatisticsController extends Controller
|
44
|
52
|
$pages = 1;
|
45
|
53
|
}
|
46
|
54
|
|
47
|
|
- $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, dtime'))->where(function($query) use($stime, $etime){
|
|
55
|
+ $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, dtime'))->where(function($query) use($team_id, $stime, $etime){
|
|
56
|
+ if($team_id) $query->where('team_id', '=', $team_id);
|
48
|
57
|
if($stime) $query->where('dtime', '>=', $stime);
|
49
|
58
|
if($etime) $query->where('dtime', '<=', $etime);
|
50
|
59
|
})->where('is_del',0)->groupBy('dtime')->orderBy('dtime', 'desc')->offset($offset)->limit($pageSize)->get();
|
|
@@ -53,7 +62,9 @@ class StatisticsController extends Controller
|
53
|
62
|
#进粉成本
|
54
|
63
|
$v['cost_fan'] = $v['total_fan_add']>0? round($v['total_cost'] / $v['total_fan_add'], 2) : '';
|
55
|
64
|
#当日微信粉
|
56
|
|
- $custDetail = CustDetail::select(DB::raw('sum(fan_add) as wx_fan_add, sum(new_reply) as total_new_reply, sum(old_consult) as total_old_consult'))->where('dtime', $v['dtime'])->where('is_del', 0)->first();
|
|
65
|
+ $custDetail = CustDetail::select(DB::raw('sum(fan_add) as wx_fan_add, sum(new_reply) as total_new_reply, sum(old_consult) as total_old_consult'))->where('dtime', $v['dtime'])->where('is_del', 0)->where(function($query) use ($team_id, $sale_ids){
|
|
66
|
+ if($team_id>0 && isset($sale_ids)) $query->whereIn('admin_id', $sale_ids);
|
|
67
|
+ })->first();
|
57
|
68
|
$v['wx_fan_add'] = $custDetail->wx_fan_add; //当日微信粉数
|
58
|
69
|
$v['total_new_reply'] = $custDetail->total_new_reply; //当日微信新粉回复
|
59
|
70
|
$v['total_old_consult'] = $custDetail->total_old_consult; //当日微信老粉询价
|
|
@@ -62,18 +73,25 @@ class StatisticsController extends Controller
|
62
|
73
|
#当日微信粉成本
|
63
|
74
|
$v['cost_wx_fan'] = $v['wx_fan_add']>0? round($v['total_cost'] / $v['wx_fan_add'], 2) : '';
|
64
|
75
|
#当日订单数、销售额
|
65
|
|
- $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->first();
|
|
76
|
+ $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where(function($query) use($team_id){
|
|
77
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
78
|
+ })->first();
|
66
|
79
|
$v['order_count'] = $order->order_count;
|
67
|
80
|
$v['order_amount'] = $order->order_amount;
|
68
|
81
|
|
69
|
82
|
}
|
70
|
83
|
|
|
84
|
+ $teamList = DB::table('teams')->select('id', 'name')->get();
|
|
85
|
+ $teamList = json_decode(json_encode($teamList), true);
|
|
86
|
+
|
71
|
87
|
return view('statistics/fanDay', ['result' =>$result,
|
72
|
88
|
'page' =>$page,
|
73
|
89
|
'count' =>$count,
|
74
|
90
|
'pages' =>$pages,
|
|
91
|
+ 'teamlist' =>$teamList,
|
75
|
92
|
'stime' =>$stime,
|
76
|
93
|
'etime' =>$etime,
|
|
94
|
+ 'team_id' =>$team_id,
|
77
|
95
|
]);
|
78
|
96
|
}
|
79
|
97
|
|
|
@@ -81,8 +99,16 @@ class StatisticsController extends Controller
|
81
|
99
|
|
82
|
100
|
$stime = $request->input('stime');
|
83
|
101
|
$etime = $request->input('etime');
|
|
102
|
+ $team_id = (int)$request->input('team_id');
|
|
103
|
+
|
|
104
|
+ //假如有团队筛选,检索销售队员
|
|
105
|
+ $sale_ids = null;
|
|
106
|
+ if($team_id>0){
|
|
107
|
+ $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
|
|
108
|
+ }
|
84
|
109
|
|
85
|
|
- $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, dtime'))->where(function($query) use($stime, $etime){
|
|
110
|
+ $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, dtime'))->where(function($query) use($team_id, $stime, $etime){
|
|
111
|
+ if($team_id) $query->where('team_id', '=', $team_id);
|
86
|
112
|
if($stime) $query->where('dtime', '>=', $stime);
|
87
|
113
|
if($etime) $query->where('dtime', '<=', $etime);
|
88
|
114
|
})->where('is_del',0)->groupBy('dtime')->orderBy('dtime', 'desc')->get();
|
|
@@ -134,7 +160,9 @@ class StatisticsController extends Controller
|
134
|
160
|
#进粉成本
|
135
|
161
|
$v['cost_fan'] = $v['total_fan_add']>0 ? round($v['total_cost'] / $v['total_fan_add'], 2) : '';
|
136
|
162
|
#当日微信粉
|
137
|
|
- $custDetail = CustDetail::select(DB::raw('sum(fan_add) as wx_fan_add, sum(new_reply) as total_new_reply, sum(old_consult) as total_old_consult'))->where('dtime', $v['dtime'])->where('is_del', 0)->first();
|
|
163
|
+ $custDetail = CustDetail::select(DB::raw('sum(fan_add) as wx_fan_add, sum(new_reply) as total_new_reply, sum(old_consult) as total_old_consult'))->where('dtime', $v['dtime'])->where('is_del', 0)->where(function($query) use ($team_id, $sale_ids){
|
|
164
|
+ if($team_id>0 && isset($sale_ids)) $query->whereIn('admin_id', $sale_ids);
|
|
165
|
+ })->first();
|
138
|
166
|
$v['wx_fan_add'] = $custDetail->wx_fan_add; //当日微信粉数
|
139
|
167
|
$v['total_new_reply'] = $custDetail->total_new_reply; //当日微信新粉回复
|
140
|
168
|
$v['total_old_consult'] = $custDetail->total_old_consult; //当日微信老粉询价
|
|
@@ -143,7 +171,9 @@ class StatisticsController extends Controller
|
143
|
171
|
#当日微信粉成本
|
144
|
172
|
$v['cost_wx_fan'] = $v['wx_fan_add']>0 ? round($v['total_cost'] / $v['wx_fan_add'], 2) : '';
|
145
|
173
|
#当日订单数、销售额
|
146
|
|
- $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->first();
|
|
174
|
+ $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where(function($query) use($team_id){
|
|
175
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
176
|
+ })->first();
|
147
|
177
|
$v['order_count'] = $order->order_count;
|
148
|
178
|
$v['order_amount'] = $order->order_amount;
|
149
|
179
|
|
|
@@ -182,8 +212,16 @@ class StatisticsController extends Controller
|
182
|
212
|
|
183
|
213
|
$stime = $request->input('stime');
|
184
|
214
|
$etime = $request->input('etime');
|
|
215
|
+ $team_id = (int)$request->input('team_id');
|
185
|
216
|
|
186
|
|
- $count = CustTotal::where(function($query) use($stime, $etime){
|
|
217
|
+ //假如有团队筛选,检索销售队员
|
|
218
|
+ $sale_ids = null;
|
|
219
|
+ if($team_id>0){
|
|
220
|
+ $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ $count = CustTotal::where(function($query) use($team_id, $stime, $etime){
|
|
224
|
+ if($team_id) $query->where('team_id', '=', $team_id);
|
187
|
225
|
if($stime) $query->where('dtime', '>=', $stime);
|
188
|
226
|
if($etime) $query->where('dtime', '<=', $etime);
|
189
|
227
|
})->where('is_del',0)->count();
|
|
@@ -195,21 +233,28 @@ class StatisticsController extends Controller
|
195
|
233
|
$pages = 1;
|
196
|
234
|
}
|
197
|
235
|
|
198
|
|
- $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, dtime'))->where(function($query) use($stime, $etime){
|
|
236
|
+ $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, dtime'))->where(function($query) use($team_id, $stime, $etime){
|
|
237
|
+ if($team_id) $query->where('team_id', '=', $team_id);
|
199
|
238
|
if($stime) $query->where('dtime', '>=', $stime);
|
200
|
239
|
if($etime) $query->where('dtime', '<=', $etime);
|
201
|
240
|
})->where('is_del',0)->groupBy('dtime')->orderBy('dtime', 'desc')->offset($offset)->limit($pageSize)->get();
|
202
|
241
|
$result = json_decode(json_encode($result),true);
|
203
|
242
|
foreach($result as $k=>&$v){
|
204
|
243
|
#当日微信好友数量
|
205
|
|
- $custDetail = CustDetail::select(DB::raw('sum(fan_add) as wx_fan_add'))->where('dtime', $v['dtime'])->where('is_del', 0)->first();
|
|
244
|
+ $custDetail = CustDetail::select(DB::raw('sum(fan_add) as wx_fan_add'))->where('dtime', $v['dtime'])->where('is_del', 0)->where(function($query) use ($team_id, $sale_ids){
|
|
245
|
+ if($team_id>0 && isset($sale_ids)) $query->whereIn('admin_id', $sale_ids);
|
|
246
|
+ })->first();
|
206
|
247
|
$v['wx_fan_add'] = $custDetail->wx_fan_add; //当日微信粉数
|
207
|
248
|
|
208
|
249
|
#当日订单总计:
|
209
|
|
- $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, sum(cost) as order_cost'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->first();
|
|
250
|
+ $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, sum(cost) as order_cost'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where(function($query) use($team_id){
|
|
251
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
252
|
+ })->first();
|
210
|
253
|
#当日新粉成单:
|
211
|
254
|
$phones = DB::table('customers')->where('fanTime', $v['dtime'])->lists('phone');
|
212
|
|
- $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->first();
|
|
255
|
+ $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->where(function($query) use($team_id){
|
|
256
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
257
|
+ })->first();
|
213
|
258
|
// 1.当日新粉成单数
|
214
|
259
|
$v['new_order_count'] = $new_order->order_count;
|
215
|
260
|
// 2.当日新粉成交额
|
|
@@ -222,7 +267,9 @@ class StatisticsController extends Controller
|
222
|
267
|
$v['order_amount'] = $order->order_amount;
|
223
|
268
|
|
224
|
269
|
#复购单数、复购成交额
|
225
|
|
- $fugou = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where('is_fugou', 1)->first();
|
|
270
|
+ $fugou = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where('is_fugou', 1)->where(function($query) use($team_id){
|
|
271
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
272
|
+ })->first();
|
226
|
273
|
$v['fugou_order_count'] = $fugou->order_count;
|
227
|
274
|
$v['fugou_order_amount'] = $fugou->order_amount;
|
228
|
275
|
#货品成本
|
|
@@ -234,12 +281,17 @@ class StatisticsController extends Controller
|
234
|
281
|
|
235
|
282
|
}
|
236
|
283
|
|
|
284
|
+ $teamList = DB::table('teams')->select('id', 'name')->get();
|
|
285
|
+ $teamList = json_decode(json_encode($teamList), true);
|
|
286
|
+
|
237
|
287
|
return view('statistics/orderDay', ['result' =>$result,
|
238
|
288
|
'page' =>$page,
|
239
|
289
|
'count' =>$count,
|
240
|
290
|
'pages' =>$pages,
|
|
291
|
+ 'teamlist' =>$teamList,
|
241
|
292
|
'stime' =>$stime,
|
242
|
293
|
'etime' =>$etime,
|
|
294
|
+ 'team_id' =>$team_id,
|
243
|
295
|
]);
|
244
|
296
|
}
|
245
|
297
|
|
|
@@ -247,8 +299,16 @@ class StatisticsController extends Controller
|
247
|
299
|
|
248
|
300
|
$stime = $request->input('stime');
|
249
|
301
|
$etime = $request->input('etime');
|
|
302
|
+ $team_id = (int)$request->input('team_id');
|
|
303
|
+
|
|
304
|
+ //假如有团队筛选,检索销售队员
|
|
305
|
+ $sale_ids = null;
|
|
306
|
+ if($team_id>0){
|
|
307
|
+ $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
|
|
308
|
+ }
|
250
|
309
|
|
251
|
|
- $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, dtime'))->where(function($query) use($stime, $etime){
|
|
310
|
+ $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, dtime'))->where(function($query) use($team_id, $stime, $etime){
|
|
311
|
+ if($team_id) $query->where('team_id', '=', $team_id);
|
252
|
312
|
if($stime) $query->where('dtime', '>=', $stime);
|
253
|
313
|
if($etime) $query->where('dtime', '<=', $etime);
|
254
|
314
|
})->where('is_del',0)->groupBy('dtime')->orderBy('dtime', 'desc')->get();
|
|
@@ -302,14 +362,20 @@ class StatisticsController extends Controller
|
302
|
362
|
foreach ($result as $k => $v)
|
303
|
363
|
{
|
304
|
364
|
#当日微信好友数量
|
305
|
|
- $custDetail = CustDetail::select(DB::raw('sum(fan_add) as wx_fan_add'))->where('dtime', $v['dtime'])->where('is_del', 0)->first();
|
|
365
|
+ $custDetail = CustDetail::select(DB::raw('sum(fan_add) as wx_fan_add'))->where('dtime', $v['dtime'])->where('is_del', 0)->where(function($query) use ($team_id, $sale_ids){
|
|
366
|
+ if($team_id>0 && isset($sale_ids)) $query->whereIn('admin_id', $sale_ids);
|
|
367
|
+ })->first();
|
306
|
368
|
$v['wx_fan_add'] = $custDetail->wx_fan_add; //当日微信粉数
|
307
|
369
|
|
308
|
370
|
#当日订单总计:
|
309
|
|
- $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, sum(cost) as order_cost'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->first();
|
|
371
|
+ $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, sum(cost) as order_cost'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where(function($query) use($team_id){
|
|
372
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
373
|
+ })->first();
|
310
|
374
|
#当日新粉成单:
|
311
|
375
|
$phones = DB::table('customers')->where('fanTime', $v['dtime'])->lists('phone');
|
312
|
|
- $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->first();
|
|
376
|
+ $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->where(function($query) use($team_id){
|
|
377
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
378
|
+ })->first();
|
313
|
379
|
// 1.当日新粉成单数
|
314
|
380
|
$v['new_order_count'] = $new_order->order_count;
|
315
|
381
|
// 2.当日新粉成交额
|
|
@@ -322,7 +388,9 @@ class StatisticsController extends Controller
|
322
|
388
|
$v['order_amount'] = $order->order_amount;
|
323
|
389
|
|
324
|
390
|
#复购单数、复购成交额
|
325
|
|
- $fugou = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where('is_fugou', 1)->first();
|
|
391
|
+ $fugou = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where('is_fugou', 1)->where(function($query) use($team_id){
|
|
392
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
393
|
+ })->first();
|
326
|
394
|
$v['fugou_order_count'] = $fugou->order_count;
|
327
|
395
|
$v['fugou_order_amount'] = $fugou->order_amount;
|
328
|
396
|
#货品成本
|