feat: 新增明细
This commit is contained in:
parent
b1218a46ff
commit
5eb66a1c75
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\admin\api\v1;
|
||||
|
||||
|
||||
use support\Request;
|
||||
use App\Utils\ApiResponse;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
use app\model\UserReward;
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("积分明细控制器")
|
||||
* @Apidoc\Group("admin")
|
||||
*/
|
||||
class UserRewardController
|
||||
{
|
||||
/**
|
||||
* @Apidoc\Title("1.0 获取系统所有积分明细")
|
||||
* @Apidoc\Url("admin/api/v1/userReward/lists")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
public function lists(Request $request)
|
||||
{
|
||||
// 获取请求的参数
|
||||
$data = $request->post();
|
||||
|
||||
// 构建查询构造器
|
||||
$query = UserReward::query();
|
||||
|
||||
if (isset($data['updatedat']) && is_array($data['updatedat']) && count($data['updatedat']) == 2) {
|
||||
// 直接从数组中获取开始和结束日期
|
||||
$startDate = $data['updatedat'][0];
|
||||
$endDate = $data['updatedat'][1];
|
||||
|
||||
if ($startDate === $endDate) {
|
||||
// 如果开始日期和结束日期相同,则查询这一天的所有记录
|
||||
$query->whereDate('updated_at', '=', $startDate);
|
||||
} else {
|
||||
// 否则查询日期范围内的记录
|
||||
$query->whereBetween('updated_at', [$startDate . ' 00:00:00', $endDate . ' 23:59:59']);
|
||||
}
|
||||
}
|
||||
|
||||
// 根据 username 进行模糊查询
|
||||
if (!empty($data['username'])) {
|
||||
$query->where('username', 'like', '%' . $data['username'] . '%');
|
||||
}
|
||||
$query->orderBy('id', 'desc');
|
||||
// 执行查询并返回数据
|
||||
$users = $query->paginate($data['pageSize'], ['*'], 'page', $data['current']);
|
||||
|
||||
// 格式化结果为数组
|
||||
return ApiResponse::success(200, $users);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue