StatisticalController.php
3.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
namespace app\admin\controller;
use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
class StatisticalController extends AdminBaseController{
/**
* 财务统计
*/
public function financial_list(){
//平台订单金额统计
$where = [
'indent_type' => 1
];
$where2 = [
'indent_type' => 2
];
$where3 = [
'type' => 1
];
if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
$start_time = strtotime($_POST['start_time']);
$end_time = strtotime($_POST['end_time']);
$where['create_time'] = [['>=',$start_time],['<=',$end_time]];
$where2['create_time'] = [['>=',$start_time],['<=',$end_time]];
$where3['time'] = [['>=',$start_time],['<=',$end_time]];
}
$platform = Db::name('indent') -> where($where) -> where("state = 2 or state = 3 or state = 5") -> select();
$platform_money = 0;
foreach ($platform as $key => $val){
$platform_money += $val['money'];
}
$this -> assign('platform_money',$platform_money);
//业务员订单金额统计
$salesman = Db::name('indent') -> where($where2) -> where("state = 2 or state = 3 or state = 5") -> select();
$salesman_money = 0;
foreach ($salesman as $key => $val){
$salesman_money += $val['money'];
}
$this -> assign('salesman_money',$salesman_money);
// 业务员总余额
$users_where = [
'a.create_time' => ['>=', 0],
'a.status' => ['in',[2,3]]
];
$total_balance = Db::name('my_user') -> alias('a')
->field('a.*,b.user_nickname')
->join('user b','a.uid = b.id','LEFT')
->where($users_where)
->order(['a.balance'=>'DESC','a.create_time'=>'DESC'])
->sum('a.balance');
$this -> assign('total_balance',$total_balance);
//显示平台抽成收益
$income = Db::name('income_money') -> where($where3) -> select();
$income_money = 0;
foreach ($income as $key => $val){
$income_money += $val['money'];
}
$this -> assign('income_money',$income_money);
return $this -> fetch();
}
/**
*支出统计
*/
public function spending_list(){
$where = [
'state' => 1
];
if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
$start_time = strtotime($_POST['start_time']);
$end_time = strtotime($_POST['end_time']);
$where['create_time'] = [['>=',$start_time],['<=',$end_time]];
}
$money_expend = Db::name('money_expend') -> where($where) -> select();
$money = 0;
foreach ($money_expend as $key => $val){
$money += $val['money'];
}
$this -> assign('money',$money);
return $this -> fetch();
}
}