add
This commit is contained in:
85
app/api/model/UserPrizeExchange.php
Normal file
85
app/api/model/UserPrizeExchange.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserPrizeExchange extends Model
|
||||
{
|
||||
public static function pages($params, $userId)
|
||||
{
|
||||
// 提取查询参数
|
||||
$foreignId = isset($params['foreignId']) ? (int)$params['foreignId'] : null;
|
||||
$foreignType = $params['foreignType'] ?? '';
|
||||
$userName = $params['userName'] ?? '';
|
||||
$prizeName = $params['prizeName'] ?? '';
|
||||
$status = isset($params['status']) ? (int)$params['status'] : null;
|
||||
$phone = $params['phone'] ?? '';
|
||||
$remark = $params['remark'] ?? '';
|
||||
$beginDate = $params['beginDate'] ?? '';
|
||||
$endDate = $params['endDate'] ?? '';
|
||||
|
||||
$db = Db::connect(config('database.search_library'));
|
||||
// 构建查询条件
|
||||
$query = $db->name('user_prize_exchange');
|
||||
|
||||
if (!is_null($foreignId)) {
|
||||
$query = $query->where('foreign_id', $foreignId);
|
||||
}
|
||||
|
||||
if (!empty($foreignType)) {
|
||||
$query = $query->where('foreign_type', $foreignType);
|
||||
}
|
||||
|
||||
if (!is_null($userId)) {
|
||||
$query = $query->where('user_id', $userId);
|
||||
}
|
||||
|
||||
if (!empty($userName)) {
|
||||
$query = $query->where('user_name', 'like', "%{$userName}%");
|
||||
}
|
||||
|
||||
if (!empty($prizeName)) {
|
||||
$query = $query->where('prize_name', 'like', "%{$prizeName}%");
|
||||
}
|
||||
|
||||
if (!is_null($status)) {
|
||||
$query = $query->where('status', $status);
|
||||
}
|
||||
|
||||
if (!empty($phone)) {
|
||||
$query = $query->where('phone', 'like', "%{$phone}%");
|
||||
}
|
||||
|
||||
if (!empty($remark)) {
|
||||
$query = $query->where('remark', 'like', "%{$remark}%");
|
||||
}
|
||||
|
||||
if (!empty($beginDate)) {
|
||||
$query = $query->where('create_time', '>=', "{$beginDate} 00:00:00");
|
||||
}
|
||||
|
||||
if (!empty($endDate)) {
|
||||
$query = $query->where('create_time', '<=', "{$endDate} 23:59:59");
|
||||
}
|
||||
$count = $query->count();
|
||||
// 设置排序
|
||||
$query = $query->order('id', 'desc');
|
||||
|
||||
// 分页参数
|
||||
$pageNum = isset($params['page']) ? (int)$params['page'] : 1;
|
||||
$pageSize = isset($params['limit']) ? (int)$params['limit'] : 10;
|
||||
|
||||
// 执行分页查询
|
||||
$list = $query->limit(page($pageNum, $pageSize), $pageSize)->select()->toArray();
|
||||
|
||||
return returnSuccessData([
|
||||
'currPage' => $pageNum,
|
||||
'pageSize' => $pageSize,
|
||||
'list' => ($list),
|
||||
'totalCount' => $count,
|
||||
'totalPage' => ceil($count / $pageSize),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user