35 lines
865 B
Go
35 lines
865 B
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"relynolli-server/internal"
|
|
)
|
|
|
|
type StorageOrder interface {
|
|
GetTotal(ctx context.Context, fuserId int64) (*TotalQuery, error)
|
|
}
|
|
|
|
func NewStorageOrder() StorageOrder {
|
|
if instance == nil {
|
|
instance = &storage{
|
|
db: internal.InitDatabase().GetInstance(),
|
|
rdb: internal.InitRedis(),
|
|
}
|
|
}
|
|
return instance
|
|
}
|
|
|
|
type TotalQuery struct {
|
|
Total float64 `bun:"total" json:"total"`
|
|
}
|
|
|
|
func (s *storage) GetTotal(ctx context.Context, fuserId int64) (*TotalQuery, error) {
|
|
model := new(TotalQuery)
|
|
stmt := `select sum(price.PRICE * cart.quantity) as total from api_cart cart left join b_catalog_price price on cart.product_id = price.PRODUCT_ID and cart.price_type_id = price.CATALOG_GROUP_ID where fuser_id = ?`
|
|
err := s.db.NewRaw(stmt, fuserId).Scan(ctx, model)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return model, nil
|
|
}
|