|
@@ -29,33 +29,42 @@ class RoiSalerTotalHistory extends Command {
|
29
|
29
|
4 => '45',
|
30
|
30
|
5 => '60',
|
31
|
31
|
);
|
|
32
|
+ //获取团队
|
|
33
|
+ $team_ids = $this->getTeams();
|
32
|
34
|
//获取各个团队销售id
|
33
|
|
- $salerIds = $this->getTeamSalers();
|
|
35
|
+ $salerIds = $this->getTeamSalers($team_ids);
|
34
|
36
|
for($i=1;$i<6;$i++){
|
35
|
37
|
$j_min = $timeArr[$i];
|
36
|
|
- for($j=69; $j>=$j_min; $j--){
|
|
38
|
+ for($j=72; $j>=$j_min; $j--){
|
37
|
39
|
$stime = date('Y-m-d', strtotime('-'.$j.' day'));
|
38
|
40
|
$e = $j-$j_min;
|
39
|
41
|
$etime = $date = date('Y-m-d', strtotime('-'.$e.' day'));
|
40
|
42
|
|
41
|
43
|
//计算date i天内的roi
|
42
|
|
- $custTotal = CustTotal::select('total_cost', 'total_fan_add', 'team_id')->whereIn('team_id', [1,3,5])->where('is_del',0)->where('dtime', $stime)->get();
|
|
44
|
+ $custTotal = CustTotal::select('total_cost', 'total_fan_add', 'team_id')->whereIn('team_id', $team_ids)->where('is_del',0)->where('dtime', $stime)->get();
|
43
|
45
|
$custTotal = json_decode(json_encode($custTotal), true);
|
44
|
46
|
|
45
|
47
|
foreach($custTotal as $k=>$v){
|
46
|
48
|
$saler_ids = $salerIds[$v['team_id']];
|
47
|
|
-
|
48
|
|
- foreach($result as $k=>$v){
|
|
49
|
+ //团队当日销售总加粉
|
|
50
|
+ $wx_fan_total = CustDetail::whereIn('admin_id', $saler_ids)->where('is_del', 0)->where('dtime', $stime)->sum('fan_add');
|
|
51
|
+ //团队销售上报加粉
|
|
52
|
+ $result = CustDetail::select('fan_add', 'admin_id')->whereIn('admin_id', $saler_ids)->where('is_del', 0)->where('dtime', $stime)->get();
|
|
53
|
+ $result = json_decode(json_encode($result), true);
|
|
54
|
+ foreach($result as $key=>$detail){
|
49
|
55
|
$data = array();
|
|
56
|
+ $data['cost'] = round($detail['fan_add']/$wx_fan_total * $v['total_cost'], 2);
|
|
57
|
+ $data['gzh_count'] = round($detail['fan_add']/$wx_fan_total * $v['total_fan_add']);
|
|
58
|
+
|
50
|
59
|
$data['ad_time'] = $stime;
|
51
|
60
|
$data['type'] = $i;
|
52
|
61
|
//新粉收入
|
53
|
62
|
//当日加粉
|
54
|
63
|
$phones = DB::table('customers')->where('fanTime', $stime)->lists('phone');
|
55
|
64
|
#当日加粉15日订单总计:
|
56
|
|
- $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, count(distinct(receiverMobile)) as cust_count'))->whereIn('receiverMobile', $phones)->where('createTime', '>=', $stime)->where('createTime', '<', $etime)->where('is_del', 0)->where('team_id', $v['team_id'])->first();
|
|
65
|
+ $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, count(distinct(receiverMobile)) as cust_count'))->whereIn('receiverMobile', $phones)->where('createTime', '>=', $stime)->where('createTime', '<', $etime)->where('is_del', 0)->where('admin_id', $detail['admin_id'])->first();
|
57
|
66
|
#当日新粉成单:
|
58
|
|
- $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $stime)->where('createTime','<=', $stime.' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->where('team_id', $v['team_id'])->first();
|
|
67
|
+ $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $stime)->where('createTime','<=', $stime.' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->where('admin_id', $detail['admin_id'])->first();
|
59
|
68
|
|
60
|
69
|
// 1.当日新粉成单数
|
61
|
70
|
$data['new_fan_order_count'] = $new_order->order_count;
|
|
@@ -65,15 +74,10 @@ class RoiSalerTotalHistory extends Command {
|
65
|
74
|
$data['order_amount'] = $order->order_amount;
|
66
|
75
|
// 15日总单数
|
67
|
76
|
$data['order_count'] = $order->order_count;
|
68
|
|
-
|
69
|
77
|
$data['cust_count'] = $order->cust_count;
|
70
|
78
|
|
71
|
|
- //销售
|
72
|
|
- $saler_ids = $salerIds[$v['team_id']];
|
73
|
|
- $data['fan_count'] = CustDetail::where('dtime', $stime)->where('is_del', 0)->whereIn('admin_id', $saler_ids)->sum('fan_add');
|
74
|
|
- $data['gzh_count'] = $v['total_fan_add'];
|
75
|
|
- $data['cost'] = $v['total_cost'];
|
76
|
|
- $data['team_id'] = $v['team_id'];
|
|
79
|
+ $data['fan_count'] = $detail['fan_add'];
|
|
80
|
+ $data['admin_id'] = $detail['admin_id'];
|
77
|
81
|
//插入数据
|
78
|
82
|
$res = $this->insertData($data);
|
79
|
83
|
}
|
|
@@ -88,14 +92,19 @@ class RoiSalerTotalHistory extends Command {
|
88
|
92
|
*
|
89
|
93
|
*/
|
90
|
94
|
public function insertData($data){
|
91
|
|
- return DB::table('roi_team_total')->insert($data);
|
|
95
|
+ return DB::table('roi_saler_total')->insert($data);
|
92
|
96
|
}
|
93
|
97
|
|
94
|
|
- public function getTeamSalers(){
|
|
98
|
+ public function getTeamSalers($team_ids){
|
95
|
99
|
$data = array();
|
96
|
|
- $data[1] = DB::table('admin')->where('team_id', 1)->lists('id');
|
97
|
|
- $data[3] = DB::table('admin')->where('team_id', 3)->lists('id');
|
98
|
|
- $data[5] = DB::table('admin')->where('team_id', 5)->lists('id');
|
|
100
|
+ foreach($team_ids as $team_id){
|
|
101
|
+ $data[$team_id] = DB::table('admin')->where('team_id', $team_id)->lists('id');
|
|
102
|
+ }
|
|
103
|
+ return $data;
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ public function getTeams(){
|
|
107
|
+ $data = DB::table('teams')->where('type', 1)->lists('id');
|
99
|
108
|
return $data;
|
100
|
109
|
}
|
101
|
110
|
|