mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
bonus logs show category seeding and common
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user