forked from qq547057827/apijson-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex.php
154 lines (129 loc) · 5.5 KB
/
Index.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
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace app\index\controller;
use think\Request;
use think\Db;
class Index
{
public function index()
{
return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V5.1<br/><span style="font-size:30px">12载初心不改(2006-2018) - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
}
public function get(Request $request)
{
$param = $request->param();
// $GLOBALS['allData'] = [];
$allData = [];
$data = null;
// sy_user: {
// id: 55,
// "@column":"id, balance, intergral, icon, is_vip, mobile, surename, username"
// }
foreach ($param as $table => $where) {
if (endsWith($table, '[]')) {
$content = $where;
$sub = $table;
foreach ($content as $table => $where) {
// 这里应该使用递归 start
if (endsWith($table, '[]')) {
$content = $where;
$sub = $table;
foreach ($content as $table => $where) {
$data = Db::table($table);
foreach ($where as $field => $condition) {
if ($field === "@column") {
$data = $data->field($condition);
continue;
}
if (endsWith($field, '@')) {
$field = substr($field, 0, -1);
list($items, $withTable, $withKey) = explode("/", $condition);
foreach ($allData[$items] as $keyNum => $item) {
$data1 = clone $data;
$data1 = $data1->where($field, $allData[$items][$keyNum][$withKey]);
$allData[$items][$keyNum][$sub] = $data1->select();
// $allData[$items][$keyNum][$sub] = $data->select();
// $allData[$items][$keyNum][$sub] = $data->getLastSql();
}
continue;
}
}
}
continue;
}
// 这里应该使用递归 end
$data = Db::table($table);
// $data = clone $data1;
foreach ($where as $field => $condition) {
if (endsWith($field, '@')) {
$field = substr($field, 0, -1);
// list($withTable, $withKey) = explode("/", $condition);
// list($items, $withTable, $withKey) = explode("/", $condition);
$explodeArr = explode("/", $condition);
if (count($explodeArr) == 3) {
// list($items, $withTable, $withKey) = $explodeArr;
// // $data = $data->where($field, $allData[$items][$withTable][$withKey]);
// $allData['aaaaa'] = $allData[$items][$withTable][$withKey];
$allData['aaaaa'] = $explodeArr;
}elseif (count($explodeArr) == 2) {
list($withTable, $withKey) = $explodeArr;
$data = $data->where($field, $allData[$withTable][$withKey]);
}
continue;
}
if ($field === "@column") {
$data = $data->field($condition);
continue;
}
$data = $data->where($field, $condition);
// $allData['dddd'] .= $allData['dddd'] ? $allData['dddd'] : $table;
$allData['sub'] = $sub;
$allData['table'] = $table;
// $allData[$sub][$table] = $data->select();
}
// $allData[$sub][$table] = $data->select();
$allData[$sub] = $data->order('id','desc')->select();
}
continue;
}
$data = Db::table($table);
foreach ($where as $field => $condition) {
if ($field === "@column") {
$data = $data->field($condition);
continue;
}
$data = $data->where($field, $condition);
}
$allData[$table] = $data->find();
}
return json($allData);
}
public function post(Request $request)
{
// config('app.app_trace', false);
$allowField = [
// 'username' => 'username',
// 'surename' => 'surename',
// 'mobile' => 'mobile',
// 'openid' => 'openid',
// 'icon' => 'icon',
];
$param = $request->param();
$tableName = array_key_first($param);
$data = Db::table($tableName)->insertGetId($param[$tableName]);
$result = Db::table($tableName)->find($data);
return json($result);
}
public function delete(Request $request)
{
$param = $request->param();
$tableName = array_key_first($param);
$result = Db::table($tableName)->delete($param[$tableName]['ids']);
return $result;
}
public function put(Request $request)
{
$param = $request->param();
$tableName = array_key_first($param);
return Db::table($tableName)->update($param[$tableName]);
}
}