Skip to content

Commit 07d292e

Browse files
committed
fix: 🐛 用户列表排序无效
1 parent 91a00da commit 07d292e

File tree

2 files changed

+5
-31
lines changed

2 files changed

+5
-31
lines changed

app/controller/master/User.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function all()
2424
return error($validate->getError());
2525
}
2626

27-
$select = \app\model\User::pagination($params);
27+
$select = (new \app\model\User)->pagination($params);
2828

2929
return msg("ok", "success", $select);
3030
}

app/model/User.php

+4-30
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,19 @@
1818
* @property string $username 用户名
1919
* @mixin \think\Model
2020
*/
21-
class User extends Model
21+
class User extends Base
2222
{
2323
protected $json = ['stars', 'oauth'];
2424
protected $jsonAssoc = true;
2525

26+
protected $searchField = ['username'];
27+
28+
2629
public static function onAfterRead(Model $model)
2730
{
2831
$model->avatar = avatar_cdn($model->avatar);
2932
}
3033

31-
public static function pagination($param)
32-
{
33-
$where = [];
34-
if (!empty($param['username'])) {
35-
$where[] = ["username", 'like', '%' . $param['username'] . '%'];
36-
}
37-
if (!empty($param['id'])) {
38-
$where[] = ["id", 'like', '%' . $param['id'] . '%'];
39-
}
40-
$page = 1;
41-
$limit = 10;
42-
if (!empty($param['page'])) {
43-
$page = intval($param['page']);
44-
}
45-
if (!empty($param['limit'])) {
46-
$limit = intval($param['limit']);
47-
}
48-
49-
$plugin = new User();
50-
$total = $plugin->count();
51-
$select = $plugin->page($page)->limit($limit)->where($where)->select();
52-
53-
$data = [
54-
'total' => $total,
55-
'items' => $select,
56-
];
57-
return $data;
58-
}
59-
6034
public static function get($id)
6135
{
6236
return User::where('id', $id)->cache(30)->findOrEmpty();

0 commit comments

Comments
 (0)