['text' => 'Cancel H&R'], self::BUSINESS_TYPE_BUY_MEDAL => ['text' => 'Buy medal'], self::BUSINESS_TYPE_BUY_ATTENDANCE_CARD => ['text' => 'Buy attendance card'], self::BUSINESS_TYPE_STICKY_PROMOTION => ['text' => 'Buy torrent sticky promotion'], self::BUSINESS_TYPE_POST_REWARD => ['text' => 'Reward post'], self::BUSINESS_TYPE_EXCHANGE_UPLOAD => ['text' => 'Exchange upload'], self::BUSINESS_TYPE_EXCHANGE_INVITE => ['text' => 'Exchange invite'], self::BUSINESS_TYPE_CUSTOM_TITLE => ['text' => 'Custom title'], self::BUSINESS_TYPE_BUY_VIP => ['text' => 'Buy VIP'], self::BUSINESS_TYPE_GIFT_TO_SOMEONE => ['text' => 'Gift to someone'], self::BUSINESS_TYPE_NO_AD => ['text' => 'No ad'], self::BUSINESS_TYPE_GIFT_TO_LOW_SHARE_RATIO => ['text' => 'Gift to low share ratio'], self::BUSINESS_TYPE_LUCKY_DRAW => ['text' => 'Lucky draw'], self::BUSINESS_TYPE_EXCHANGE_DOWNLOAD => ['text' => 'Exchange download'], self::BUSINESS_TYPE_BUY_TEMPORARY_INVITE => ['text' => 'Buy temporary invite'], self::BUSINESS_TYPE_BUY_RAINBOW_ID => ['text' => 'Buy rainbow ID'], self::BUSINESS_TYPE_BUY_CHANGE_USERNAME_CARD => ['text' => 'Buy change username card'], self::BUSINESS_TYPE_GIFT_MEDAL => ['text' => 'Gift medal to someone'], self::BUSINESS_TYPE_BUY_TORRENT => ['text' => 'Buy torrent'], self::BUSINESS_TYPE_TASK_NOT_PASS_DEDUCT => ['text' => 'Task failure penalty'], self::BUSINESS_TYPE_TASK_PASS_REWARD => ['text' => 'Task success reward'], self::BUSINESS_TYPE_REWARD_TORRENT => ['text' => 'Reward torrent'], self::BUSINESS_TYPE_CLAIMED_UNREACHED => ['text' => 'Claimed torrent unreached'], self::BUSINESS_TYPE_SELF_ENABLE => ['text' => 'Self enable'], self::BUSINESS_TYPE_ROLE_WORK_SALARY => ['text' => 'Role work salary'], self::BUSINESS_TYPE_TORRENT_BE_DOWNLOADED => ['text' => 'Torrent be downloaded'], self::BUSINESS_TYPE_RECEIVE_REWARD => ['text' => 'Receive reward'], self::BUSINESS_TYPE_RECEIVE_GIFT => ['text' => 'Receive gift'], self::BUSINESS_TYPE_UPLOAD_TORRENT => ['text' => 'Upload torrent'], self::BUSINESS_TYPE_TORRENT_BE_REWARD => ['text' => 'Torrent be reward'], self::BUSINESS_TYPE_CLAIMED_REACHED => ['text' => 'Claimed torrent reached'], self::BUSINESS_TYPE_SEEDING_BASIC => ['text' => 'Seeding basic'], self::BUSINESS_TYPE_SEEDING_DONOR_ADDITION => ['text' => 'Seeding donor addition'], self::BUSINESS_TYPE_SEEDING_OFFICIAL_ADDITION => ['text' => 'Seeding official addition'], self::BUSINESS_TYPE_SEEDING_HAREM_ADDITION => ['text' => 'Seeding harem addition'], self::BUSINESS_TYPE_SEEDING_MEDAL_ADDITION => ['text' => 'Seeding medal addition'], ]; public static array $businessTypeSeeding = [ self::BUSINESS_TYPE_SEEDING_BASIC, self::BUSINESS_TYPE_SEEDING_DONOR_ADDITION, self::BUSINESS_TYPE_SEEDING_OFFICIAL_ADDITION, self::BUSINESS_TYPE_SEEDING_HAREM_ADDITION, 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); } public static function getBonusForCancelHitAndRun() { $result = Setting::get('bonus.cancel_hr'); return $result ?? self::DEFAULT_BONUS_CANCEL_ONE_HIT_AND_RUN; } public static function getBonusForBuyAttendanceCard() { $result = Setting::get('bonus.attendance_card'); return $result ?? self::DEFAULT_BONUS_BUY_ATTENDANCE_CARD; } public static function getBonusForBuyTemporaryInvite() { $result = Setting::get('bonus.one_tmp_invite'); return $result ?? self::DEFAULT_BONUS_BUY_TEMPORARY_INVITE; } public static function getBonusForBuyRainbowId() { $result = Setting::get('bonus.rainbow_id'); return $result ?? self::DEFAULT_BONUS_BUY_RAINBOW_ID; } public static function getBonusForBuyChangeUsernameCard() { $result = Setting::get('bonus.change_username_card'); return $result ?? self::DEFAULT_BONUS_BUY_CHANGE_USERNAME_CARD; } public static function add(int $userId, float $old, float $delta, float $new, string $comment, int $businessType) { if (!isset(self::$businessTypes[$businessType])) { throw new \InvalidArgumentException("Invalid business type: $businessType"); } $nowStr = Carbon::now()->toDateTimeString(); return self::query()->create([ 'business_type' => $businessType, 'uid' => $userId, 'old_total_value' => $old, 'value' => $delta, 'new_total_value' => $new, 'comment' => sprintf("[%s]%s", self::$businessTypes[$businessType]['text'], $comment ? " $comment" : ""), 'created_at' => $nowStr, 'updated_at' => $nowStr, ]); } }