-
Notifications
You must be signed in to change notification settings - Fork 0
/
management-account.php
140 lines (103 loc) · 2.87 KB
/
management-account.php
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
require 'common.php';
$action=isset($_GET['action'])?$_GET['action']:'';
//获取余额的接口
if($action == 'getRest'){
connect_mydb();
select_mydb();
$sql = "SELECT * FROM accounts";
$result=fetch_all($sql);
$sum=0;
for($i=0;$i<count($result);$i++){
if($result[$i]['type'] == 1){
$sum+=$result[$i]['money'];
}
elseif ($result[$i]['type']==0){
$sum-=$result[$i]['money'];
}
}
echo $sum;
mysqli_close($mydb);
}
//查询账目
else if($action=='getTotal'){
connect_mydb();
select_mydb();
$sql = "SELECT * FROM accounts";
$result=fetch_all($sql);
$result=json_encode($result);
echo $result;
mysqli_close($mydb);
}
//查询账目细节
else if($action=='getDetail'){
connect_mydb();
select_mydb();
$id=_POST('id');
$sql = "SELECT * FROM accounts WHERE id='$id'";
$result=fetch_array($sql);
$result=json_encode($result);
mysqli_close($mydb);
echo $result;
}
//添加账目
else if($action == 'addAccount'){
$title=_POST('title');
$time=_POST('time');
$recorder=$_COOKIE['realname'];
$detail=_POST('detail');
$type = _POST('type');
$money = _POST('money');
if($type == '支出'){
$type = 0;
}
elseif ($type == '收入'){
$type = 1;
}
connect_mydb();
select_mydb();
$sql = "insert into
accounts (title,time,recorder,detail,type,money)
VALUES ('$title','$time','$recorder','$detail','$type','$money');";
query($sql);
echo '<script type="text/javascript">window.location.href="account-management.php"</script>';
mysqli_close($mydb);
}
//删除账目
else if($action=='deleteAccount'){
$id=_POST('id');
connect_mydb();
select_mydb();
$sql="delete from
accounts
WHERE id='$id'";
query($sql);
mysqli_close($mydb);
echo '<script type="text/javascript">window.location.href="account-management.php"</script>';
}
//修改账目
else if($action=='modifyAccount'){
$id=_POST('id');
$title=_POST('title');
$time=_POST('time');
$recorder=$_COOKIE['account'];
$detail=_POST('detail');
$type = _POST('type');
$money = _POST('money');
if($type == '支出'){
$type = 0;
}
elseif ($type == '收入'){
$type = 1;
}
$sql = "update accounts
set title='$title',time='$time', recorder='$recorder',detail='$detail',
type = '$type',money='$money'
WHERE id='$id';";
connect_mydb();
select_mydb();
query($sql);
mysqli_close($mydb);
echo '<script type="text/javascript">window.location.href="account-management.php"</script>';
}
?>