diff --git a/internal/dao/bundleDao.go b/internal/dao/bundleDao.go index 1b1e9bf..987fd20 100644 --- a/internal/dao/bundleDao.go +++ b/internal/dao/bundleDao.go @@ -160,7 +160,7 @@ func BundleListV2(req *bundle.BundleListRequest) (res *bundle.BundleListResponse if err = query.Preload("BundleToValueAddService").Find(&bundles).Error; err != nil { return res, commonErr.ReturnError(err, msg.ErrorGetBundleList, "获取套餐列表失败: ") } - if bundles != nil && len(bundles) > 0 { + if len(bundles) > 0 { for _, bundleProfile := range bundles { selectValueAddService := make([]*bundle.SelectValueAddService, 0) if bundleProfile.BundleToValueAddService != nil { @@ -172,7 +172,7 @@ func BundleListV2(req *bundle.BundleListRequest) (res *bundle.BundleListResponse } } bundleProfileLang := []*bundle.BundleProfileLang{} - if bundleProfile.BundleProfileLang != nil && len(bundleProfile.BundleProfileLang) > 0 { + if len(bundleProfile.BundleProfileLang) > 0 { for _, lang := range bundleProfile.BundleProfileLang { bpl := &bundle.BundleProfileLang{ Uuid: lang.UUID, @@ -385,7 +385,7 @@ func BundleListH5V2(req *bundle.BundleListRequest) (res *bundle.BundleListRespon if err = query.Preload("BundleToValueAddService").Find(&bundles).Error; err != nil { return res, commonErr.ReturnError(err, msg.ErrorGetBundleList, "获取套餐列表失败: ") } - if bundles != nil && len(bundles) > 0 { + if len(bundles) > 0 { for _, bundleProfile := range bundles { selectValueAddService := make([]*bundle.SelectValueAddService, 0) if bundleProfile.BundleToValueAddService != nil { @@ -397,7 +397,7 @@ func BundleListH5V2(req *bundle.BundleListRequest) (res *bundle.BundleListRespon } } bundleProfileLang := []*bundle.BundleProfileLang{} - if bundleProfile.BundleProfileLang != nil && len(bundleProfile.BundleProfileLang) > 0 { + if len(bundleProfile.BundleProfileLang) > 0 { for _, lang := range bundleProfile.BundleProfileLang { bpl := &bundle.BundleProfileLang{ Uuid: lang.UUID, diff --git a/internal/logic/bundleLogic.go b/internal/logic/bundleLogic.go index 04bd161..959aae5 100644 --- a/internal/logic/bundleLogic.go +++ b/internal/logic/bundleLogic.go @@ -259,7 +259,7 @@ func BundleDetailV2(req *bundle.BundleDetailRequest) (res *bundle.BundleDetailRe bundleProfile.CreatedAt = detail.CreatedAt.Format("2006-01-02 15:04:05") bundleProfile.UpdatedAt = detail.UpdatedAt.Format("2006-01-02 15:04:05") bundleProfile.Contract = detail.Contract - if detail.BundleToValueAddService != nil && len(detail.BundleToValueAddService) > 0 { + if len(detail.BundleToValueAddService) > 0 { for _, valueAddService := range detail.BundleToValueAddService { valueAddDetail, err := dao.ValueAddServiceDetailByUuidAndLanguage(valueAddService.ValueUid, req.Language) if err != nil { @@ -274,7 +274,7 @@ func BundleDetailV2(req *bundle.BundleDetailRequest) (res *bundle.BundleDetailRe selectValueAddServices = append(selectValueAddServices, selectValueAddService) } } - if detail.BundleProfileLang != nil && len(detail.BundleProfileLang) > 0 { + if len(detail.BundleProfileLang) > 0 { for _, lang := range detail.BundleProfileLang { bundleProfileLang := &bundle.BundleProfileLang{ Uuid: lang.UUID, @@ -297,7 +297,7 @@ func BundleDetailV2(req *bundle.BundleDetailRequest) (res *bundle.BundleDetailRe } } - if selectValueAddServices != nil && len(selectValueAddServices) > 0 { + if len(selectValueAddServices) > 0 { bundleProfile.SelectValueAddService = selectValueAddServices } bundleProfile.BundleProfileLang = bundleProfileLangs @@ -341,8 +341,8 @@ func BundleLangDetailV2(req *bundle.BundleDetailRequest) (res *bundle.BundleProf } return } -func HandleShelf(req *bundle.HandShelfRequest) (res *bundle.CommonResponse, err error) { - res = new(bundle.CommonResponse) +func HandleShelf(req *bundle.HandShelfRequest) (*bundle.CommonResponse, error) { + res := new(bundle.CommonResponse) if req.Uuid == "" { return res, errors.New("缺少套餐UUID") } @@ -354,10 +354,10 @@ func HandleShelf(req *bundle.HandShelfRequest) (res *bundle.CommonResponse, err return res, errors.New("获取套餐信息失败") } if detail.ShelfStatus == req.ShelfStatus { - if detail.ShelfStatus == 1 { + switch detail.ShelfStatus { + case 1: return res, errors.New("套餐已上架,请勿重复操作") - } - if detail.ShelfStatus == 2 { + case 2: return res, errors.New("套餐已下架,请勿重复操作") } } @@ -398,12 +398,12 @@ func HandleShelf(req *bundle.HandShelfRequest) (res *bundle.CommonResponse, err return res, errors.New("缺失可用时长服务类型") } //校验币种 - valueAddServices, err := dao.BatchValueAddServiceDetailTx(tx, valueAddUuids) - if err != nil { + valueAddServices, er := dao.BatchValueAddServiceDetailTx(tx, valueAddUuids) + if er != nil { return res, errors.New("查询增值服务详情失败") } for _, valueAddService := range valueAddServices { - if valueAddService.ValueAddServiceLang != nil && len(valueAddService.ValueAddServiceLang) > 0 { + if len(valueAddService.ValueAddServiceLang) > 0 { for _, lang := range valueAddService.ValueAddServiceLang { if langToPriceType[lang.Language] != lang.PriceType { return res, errors.New("所选增值服务币种与套餐币种不一致") @@ -486,7 +486,7 @@ func saveBundleHistory(tx *gorm.DB, bundleUuid string, operator string, operator bundleToValueAddService := data.BundleToValueAddService data.BundleToValueAddService = nil var valueUuid []string - if bundleToValueAddService != nil && len(bundleToValueAddService) > 0 { + if len(bundleToValueAddService) > 0 { for _, v := range bundleToValueAddService { valueUuid = append(valueUuid, v.ValueUid) } diff --git a/internal/logic/valueAddBundleLogic.go b/internal/logic/valueAddBundleLogic.go index 553bc0c..e719916 100644 --- a/internal/logic/valueAddBundleLogic.go +++ b/internal/logic/valueAddBundleLogic.go @@ -272,7 +272,7 @@ func SaveValueAddService(in *bundle.ValueAddServiceLang) (res *bundle.SaveRespon } } else { // 已存在,进行更新 - if err := saveValueAddServiceHistory(tx, in.Uuid); err != nil { + if err = saveValueAddServiceHistory(tx, in.Uuid); err != nil { return res, errors.New("保存增值服务历史记录失败") } //中文状态下,更新主表和语言表 @@ -306,7 +306,7 @@ func SaveValueAddService(in *bundle.ValueAddServiceLang) (res *bundle.SaveRespon return res, errors.New("获取套餐信息失败") } bundleUuids := []string{} - if data != nil && len(data) > 0 { + if len(data) > 0 { for _, bundle := range data { bundleUuids = append(bundleUuids, bundle.BundleUuid) } @@ -349,19 +349,22 @@ func ValueAddServiceList(req *bundle.ValueAddServiceListRequest) (res *bundle.Va CreatedAt: time.Unix(serviceLang.CreatedAt, 0).Format("2006-01-02 15:04:05"), UpdatedAt: time.Unix(serviceLang.UpdatedAt, 0).Format("2006-01-02 15:04:05"), } - if serviceLang.Options != nil && len(serviceLang.Options) > 0 { + if len(serviceLang.Options) > 0 { var options []*bundle.ValueAddPriceOptions for _, option := range serviceLang.Options { var saveAmount decimal.Decimal - if serviceLang.PriceMode == 1 { + switch serviceLang.PriceMode { + case 1: original := decimal.NewFromFloat(float64(serviceLang.OriginalPrice)) price := decimal.NewFromFloat(float64(option.Price)) num := decimal.NewFromInt(int64(option.Num)) saveAmount = original.Sub(price).Mul(num) - } else if serviceLang.PriceMode == 2 { + case 2: //original := decimal.NewFromFloat(float64(serviceLang.OriginalPrice)) //price := decimal.NewFromFloat(float64(option.Price)) saveAmount = decimal.NewFromInt(int64(0)) + default: + return nil, errors.New("无效的价格模式") } options = append(options, &bundle.ValueAddPriceOptions{ Id: int64(option.Id), @@ -405,19 +408,21 @@ func ValueAddServiceDetail(req *bundle.ValueAddServiceDetailRequest) (res *bundl valueAddService.ServiceType = detail.ServiceType for _, serviceLang := range detail.ValueAddServiceLang { langOptions := []*bundle.ValueAddPriceOptions{} - if serviceLang.Options != nil && len(serviceLang.Options) > 0 { + if len(serviceLang.Options) > 0 { for _, opt := range serviceLang.Options { var saveAmount decimal.Decimal - if serviceLang.PriceMode == 1 { + switch serviceLang.PriceMode { + case 1: original := decimal.NewFromFloat(float64(serviceLang.OriginalPrice)) price := decimal.NewFromFloat(float64(opt.Price)) num := decimal.NewFromInt(int64(opt.Num)) saveAmount = original.Sub(price).Mul(num) - } else if serviceLang.PriceMode == 2 { + case 2: //original := decimal.NewFromFloat(float64(serviceLang.OriginalPrice)) //price := decimal.NewFromFloat(float64(opt.Price)) saveAmount = decimal.NewFromInt(int64(0)) - + default: + return nil, errors.New("无效的价格模式") } langOptions = append(langOptions, &bundle.ValueAddPriceOptions{ Id: int64(opt.Id), @@ -486,19 +491,21 @@ func ValueAddServiceDetailByUuidAndLanguage(req *bundle.ValueAddServiceDetailReq return res, errors.New("增值服务不存在") } langOptions := []*bundle.ValueAddPriceOptions{} - if detail.Options != nil && len(detail.Options) > 0 { + if len(detail.Options) > 0 { for _, opt := range detail.Options { var saveAmount decimal.Decimal - if detail.PriceMode == 1 { + switch detail.PriceMode { + case 1: original := decimal.NewFromFloat(float64(detail.OriginalPrice)) price := decimal.NewFromFloat(float64(opt.Price)) num := decimal.NewFromInt(int64(opt.Num)) saveAmount = original.Sub(price).Mul(num) - } else if detail.PriceMode == 2 { + case 2: //original := decimal.NewFromFloat(float64(detail.OriginalPrice)) //price := decimal.NewFromFloat(float64(opt.Price)) saveAmount = decimal.NewFromInt(int64(0)) - + default: + return nil, errors.New("无效的价格模式") } langOptions = append(langOptions, &bundle.ValueAddPriceOptions{ Id: int64(opt.Id), @@ -559,7 +566,7 @@ func CalculatePrice(req *bundle.CalculatePriceRequest) (res *bundle.CalculatePri } func BatchGetValueAddServiceLang(req *bundle.BatchGetValueAddServiceLangRequest) (res *bundle.BatchGetValueAddServiceLangResponse, err error) { res = &bundle.BatchGetValueAddServiceLangResponse{} - if req.Uuids == nil || len(req.Uuids) == 0 { + if len(req.Uuids) == 0 { return res, errors.New("缺少套餐UUID") } if req.Language == "" { @@ -571,18 +578,21 @@ func BatchGetValueAddServiceLang(req *bundle.BatchGetValueAddServiceLangRequest) } for _, v := range detail { langOptions := []*bundle.ValueAddPriceOptions{} - if v.Options != nil && len(v.Options) > 0 { + if len(v.Options) > 0 { for _, opt := range v.Options { var saveAmount decimal.Decimal - if v.PriceMode == 1 { + switch v.PriceMode { + case 1: original := decimal.NewFromFloat(float64(v.OriginalPrice)) price := decimal.NewFromFloat(float64(opt.Price)) num := decimal.NewFromInt(int64(opt.Num)) saveAmount = original.Sub(price).Mul(num) - } else if v.PriceMode == 2 { + case 2: //original := decimal.NewFromFloat(float64(v.OriginalPrice)) //price := decimal.NewFromFloat(float64(opt.Price)) saveAmount = decimal.NewFromInt(int64(0)) + default: + return nil, errors.New("无效的价格模式") } langOptions = append(langOptions, &bundle.ValueAddPriceOptions{ Id: int64(opt.Id),