From c14cbf149201e6ae0aed1c9ca76e5e16361d7875 Mon Sep 17 00:00:00 2001 From: bean Date: Fri, 30 Aug 2024 14:55:33 +0700 Subject: [PATCH 1/2] fix: wrong ogif rank query (#745) Co-authored-by: baenv --- pkg/store/eventspeaker/event_speaker.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/store/eventspeaker/event_speaker.go b/pkg/store/eventspeaker/event_speaker.go index 0bc838d2..e5ce312e 100644 --- a/pkg/store/eventspeaker/event_speaker.go +++ b/pkg/store/eventspeaker/event_speaker.go @@ -88,22 +88,22 @@ type SpeakerStats struct { func (s *store) GetSpeakerStats(db *gorm.DB, discordID string, after *time.Time, topic string) (SpeakerStats, error) { var stats SpeakerStats - subQuery := db.Table("event_speakers"). - Select("discord_accounts.discord_id, COUNT(event_speakers.topic) as total_speak_count"). + query := db.Table("event_speakers"). + Select("discord_accounts.discord_id, COUNT(event_speakers.topic) as total_speak_count, RANK() OVER (ORDER BY COUNT(event_speakers.topic) DESC) as speak_rank"). Joins("JOIN discord_accounts ON event_speakers.discord_account_id = discord_accounts.id"). Joins("JOIN events ON events.id = event_speakers.event_id") if after != nil { - subQuery = subQuery.Where("events.date > ?", after) + query = query.Where("events.date > ?", after) } if topic != "" { - subQuery = subQuery.Where("LOWER(event_speakers.topic) LIKE LOWER(?)", "%"+topic+"%") + query = query.Where("LOWER(event_speakers.topic) LIKE LOWER(?)", "%"+topic+"%") } - subQuery = subQuery.Group("discord_accounts.discord_id") + query = query.Group("discord_accounts.discord_id") - err := db.Table("(?) as subquery", subQuery). - Select("total_speak_count, RANK() OVER (ORDER BY total_speak_count DESC) as speak_rank"). + err := db.Table("(?) as speaker_counts", query). + Select("total_speak_count, speak_rank"). Where("discord_id = ?", discordID). Scan(&stats).Error From b7cb2f540a67c4d33c9d5ee5230a73b2633d1c53 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Sun, 1 Sep 2024 01:31:04 +0700 Subject: [PATCH 2/2] fix: store commision error (#746) --- pkg/controller/invoice/commission.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/controller/invoice/commission.go b/pkg/controller/invoice/commission.go index 64ca3a61..58557ea6 100644 --- a/pkg/controller/invoice/commission.go +++ b/pkg/controller/invoice/commission.go @@ -190,6 +190,9 @@ func (c *controller) getPICs(invoice *model.Invoice, projectMembers []*model.Pro continue } + if salePersonDetail.Referrer == nil { + continue + } saleReferers = append(saleReferers, pic{ ID: salePersonDetail.Referrer.ID, CommissionRate: decimal.NewFromInt(saleReferralCommissionRate),