bonus logs show category seeding and common

This commit is contained in:
xiaomlove
2026-01-31 19:45:13 +07:00
parent fb440c6d2b
commit 1e997e411c
2 changed files with 71 additions and 42 deletions
+44 -24
View File
@@ -363,51 +363,71 @@ class BonusRepository extends BaseRepository
});
}
public function getCount(int $userId, string $category, int $businessType = 0): int
public function getCount(string $category = '', int $userId = 0, int $businessType = 0): int
{
if ($category == BonusLogs::CATEGORY_COMMON) {
$query = BonusLogs::query()->where('uid', $userId);
if ($businessType > 0) {
$query->where('business_type', $businessType);
}
$query = $this->buildQuery($userId, $businessType);
return $query->count();
} else if ($category == BonusLogs::CATEGORY_SEEDING) {
$whereStr = "uid = :uid";
$binds = ["uid" => $userId];
if ($businessType > 0) {
$whereStr .= " AND business_type = :business_type";
$binds["business_type"] = $businessType;
}
list($whereStr, $binds) = $this->buildWhereStrAndBinds($userId, $businessType);
return ClickHouse::count("bonus_logs", $whereStr, $binds);
}
throw new \InvalidArgumentException("Invalid category: $category");
}
public function getList(int $userId, string $category, int $businessType = 0, int $page = 1, int $perPage = 50)
public function getList(string $category = '', int $userId = 0, int $businessType = 0, int $page = 1, int $perPage = 50)
{
if ($category == BonusLogs::CATEGORY_COMMON) {
$query = BonusLogs::query()->where('uid', $userId);
if ($businessType > 0) {
$query->where('business_type', $businessType);
}
$query = $this->buildQuery($userId, $businessType);
return $query->orderBy("id", "desc")->forPage($page, $perPage)->get();
} else if ($category == BonusLogs::CATEGORY_SEEDING) {
$sql = "select * from bonus_logs where uid = :uid";
$binds = ["uid" => $userId];
if ($businessType > 0) {
$sql .= " AND business_type = :business_type";
$binds["business_type"] = $businessType;
}
list($whereStr, $binds) = $this->buildWhereStrAndBinds($userId, $businessType);
$offset = ($page - 1) * $perPage;
$rows = ClickHouse::list("$sql order by created_at desc limit $offset, $perPage", $binds);
$rows = ClickHouse::list("select * from bonus_logs $whereStr order by created_at desc limit $offset, $perPage", $binds);
$result = [];
$id = 1;//fake id
foreach ($rows as $row) {
$result[] = new BonusLogs($row);
$record = new BonusLogs($row);
$record->id = $id;
$result[] = $record;
$id++;
}
return $result;
}
throw new \InvalidArgumentException("Invalid category: $category");
}
private function buildWhereStrAndBinds(int $userId = 0, int $businessType = 0)
{
$whereArr = [];
$binds = [];
if ($userId > 0) {
$whereArr[] = "uid = :uid";
$binds['uid'] = $userId;
}
if ($businessType > 0) {
$whereArr[] = "business_type = :business_type";
$binds["business_type"] = $businessType;
}
if (empty($whereArr)) {
$whereStr = "";
} else {
$whereStr = sprintf("where %s", implode(' AND ', $whereArr));
}
return [$whereStr, $binds];
}
private function buildQuery(int $userId = 0, int $businessType = 0): Builder
{
$query = BonusLogs::query();
if ($userId > 0) {
$query->where('uid', $userId);
}
if ($businessType > 0) {
$query->where('business_type', $businessType);
}
return $query;
}
}