1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package merchant
- import (
- "eta/eta_mini_ht_api/common/utils/page"
- "eta/eta_mini_ht_api/models/merchant"
- "time"
- )
- type UserAccessDTO struct {
- ID int
- TemplateUserId int
- ProductID int
- ProductType string
- BeginDate string
- EndDate string
- }
- var (
- productMap = map[string]merchant.MerchantProductType{
- "package": merchant.Package,
- "video": merchant.Video,
- "audio": merchant.Audio,
- "report": merchant.Report,
- }
- )
- func convertToUserAccessDTO(userSubscriptionAccessList merchant.UserSubscriptionAccessList) UserAccessDTO {
- return UserAccessDTO{
- ID: userSubscriptionAccessList.ID,
- TemplateUserId: userSubscriptionAccessList.TemplateUserId,
- ProductID: userSubscriptionAccessList.ProductID,
- ProductType: string(userSubscriptionAccessList.ProductType),
- BeginDate: userSubscriptionAccessList.BeginDate.Format(time.DateOnly),
- EndDate: userSubscriptionAccessList.EndDate.Format(time.DateOnly),
- }
- }
- func OpenProduct(templateUserId int, productOrderNo string, product MerchantProductDTO) error {
- userAccess := merchant.UserSubscriptionAccessList{
- TemplateUserId: templateUserId,
- ProductID: product.Id,
- ProductName: product.Title,
- ProductType: productMap[product.Type],
- BeginDate: time.Now(),
- Status: merchant.SubscribeValid,
- ProductOrderNo: productOrderNo,
- }
- if !product.IsPermanent {
- userAccess.EndDate = time.Now().Add(time.Duration(product.ValidDays) * 24 * time.Hour)
- }
- return merchant.InsertOrUpdateUserSubscribe(userAccess)
- }
- func CloseProduct(templateUserId int, productOrderNo string, product MerchantProductDTO) error {
- userAccess := merchant.UserSubscriptionAccessList{
- TemplateUserId: templateUserId,
- ProductID: product.Id,
- ProductName: product.Title,
- ProductType: productMap[product.Type],
- Status: merchant.SubscribeClose,
- ProductOrderNo: productOrderNo,
- }
- return merchant.CloseUserAccess(userAccess)
- }
- func SubscribeList(templateUserId int, productType string, pageInfo page.PageInfo) (list []UserAccessDTO, err error) {
- offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
- var subscribeList []merchant.UserSubscriptionAccessList
- subscribeList, err = merchant.SubscribeList(templateUserId, productType, pageInfo.LatestId, offset, pageInfo.PageSize)
- if err != nil {
- return
- }
- for _, userSubscriptionAccessList := range subscribeList {
- list = append(list, convertToUserAccessDTO(userSubscriptionAccessList))
- }
- return
- }
- func GetUserSubscribe(templateUserId int, productId int) (dto UserAccessDTO, err error) {
- var subscribe merchant.UserSubscriptionAccessList
- subscribe, err = merchant.GetUserSubscribeById(templateUserId, productId)
- if err != nil {
- return
- }
- dto = convertToUserAccessDTO(subscribe)
- return
- }
- func GetTotalUserPageCountByProductType(productType string, id int) (int64, int64) {
- return merchant.GetTotalUserPageCountByProductType(productType, id)
- }
|