mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
bonus logs
This commit is contained in:
@@ -16,5 +16,6 @@ enum PermissionEnum: string {
|
||||
case MANAGE_USER_BASIC_INFO = "prfmanage";
|
||||
case MANAGE_USER_CONFIDENTIAL_INFO = "cruprfmanage";
|
||||
case VIEW_USER_CONFIDENTIAL_INFO = "userprofile";
|
||||
case VIEW_USER_HISTORY = "viewhistory";
|
||||
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class BonusLogResource extends Resource
|
||||
})
|
||||
,
|
||||
SelectFilter::make('business_type')
|
||||
->options(BonusLogs::listStaticProps(Arr::except(BonusLogs::$businessTypes, BonusLogs::$businessTypeBonus), 'bonus-log.business_types', true))
|
||||
->options(BonusLogs::listBusinessTypeOptions(BonusLogs::CATEGORY_COMMON))
|
||||
->label(__('bonus-log.fields.business_type'))
|
||||
->searchable(true)
|
||||
,
|
||||
|
||||
@@ -4,14 +4,17 @@ namespace App\Models;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class BonusLogs extends NexusModel
|
||||
{
|
||||
protected $table = 'bonus_logs';
|
||||
|
||||
protected $fillable = ['uid', 'business_type', 'old_total_value', 'value', 'new_total_value', 'comment'];
|
||||
protected $fillable = ['uid', 'business_type', 'old_total_value', 'value', 'new_total_value', 'comment', 'created_at', 'updated_at'];
|
||||
|
||||
public $timestamps = true;
|
||||
const CATEGORY_COMMON = 'common';
|
||||
const CATEGORY_SEEDING = 'seeding';
|
||||
|
||||
const DEFAULT_BONUS_CANCEL_ONE_HIT_AND_RUN = 10000;
|
||||
const DEFAULT_BONUS_BUY_ATTENDANCE_CARD = 1000;
|
||||
@@ -100,7 +103,7 @@ class BonusLogs extends NexusModel
|
||||
self::BUSINESS_TYPE_SEEDING_MEDAL_ADDITION => ['text' => 'Seeding medal addition'],
|
||||
];
|
||||
|
||||
public static array $businessTypeBonus = [
|
||||
public static array $businessTypeSeeding = [
|
||||
self::BUSINESS_TYPE_SEEDING_BASIC,
|
||||
self::BUSINESS_TYPE_SEEDING_DONOR_ADDITION,
|
||||
self::BUSINESS_TYPE_SEEDING_OFFICIAL_ADDITION,
|
||||
@@ -108,6 +111,28 @@ class BonusLogs extends NexusModel
|
||||
self::BUSINESS_TYPE_SEEDING_MEDAL_ADDITION
|
||||
];
|
||||
|
||||
public static function listBusinessTypeOptions($category = ''): array
|
||||
{
|
||||
$source = BonusLogs::$businessTypes;
|
||||
if ($category == self::CATEGORY_COMMON) {
|
||||
$source = Arr::except(BonusLogs::$businessTypes, BonusLogs::$businessTypeSeeding);
|
||||
} else if ($category == self::CATEGORY_SEEDING) {
|
||||
$source = Arr::only(BonusLogs::$businessTypes, BonusLogs::$businessTypeSeeding);
|
||||
}
|
||||
return self::listStaticProps($source, 'bonus-log.business_types', true);
|
||||
}
|
||||
|
||||
public static function listCategoryOptions(bool $includeSeeding): array
|
||||
{
|
||||
$result = [
|
||||
self::CATEGORY_COMMON => nexus_trans('bonus-log.category_common')
|
||||
];
|
||||
if ($includeSeeding) {
|
||||
$result[self::CATEGORY_SEEDING] = nexus_trans('bonus-log.category_seeding');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getBusinessTypeTextAttribute()
|
||||
{
|
||||
return nexus_trans('bonus-log.business_types.' . $this->business_type);
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Models\UserMedal;
|
||||
use App\Models\UserMeta;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Nexus\Database\ClickHouse;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class BonusRepository extends BaseRepository
|
||||
@@ -362,5 +363,51 @@ class BonusRepository extends BaseRepository
|
||||
});
|
||||
}
|
||||
|
||||
public function getCount(int $userId, string $category, int $businessType = 0): int
|
||||
{
|
||||
if ($category == BonusLogs::CATEGORY_COMMON) {
|
||||
$query = BonusLogs::query()->where('uid', $userId);
|
||||
if ($businessType > 0) {
|
||||
$query->where('business_type', $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;
|
||||
}
|
||||
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)
|
||||
{
|
||||
if ($category == BonusLogs::CATEGORY_COMMON) {
|
||||
$query = BonusLogs::query()->where('uid', $userId);
|
||||
if ($businessType > 0) {
|
||||
$query->where('business_type', $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;
|
||||
}
|
||||
$offset = ($page - 1) * $perPage;
|
||||
$rows = ClickHouse::list("$sql order by created_at desc limit $offset, $perPage", $binds);
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
$result[] = new BonusLogs($row);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
throw new \InvalidArgumentException("Invalid category: $category");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user