wkyuer hai 5 meses
pai
achega
ecd1511d57

+ 2 - 2
internal/cmd/cmd.go

@@ -24,8 +24,8 @@ var (
 					service.Middleware().LoginFilter,               //登录过滤
 				)
 				s.Group("/product", func(group *ghttp.RouterGroup) {
-					group.GET("/list", controller.GetProductListHandler) //商品表列表
-					group.GET("/getPrice", controller.EmptyHandler)      //获取价格
+					group.GET("/list", controller.GetProductListHandler)      //商品表列表
+					group.GET("/getPrice", controller.GetProductPriceHandler) //获取价格
 				})
 
 				s.Group("/order", func(group *ghttp.RouterGroup) {

+ 6 - 0
internal/consts/consts.go

@@ -1,5 +1,11 @@
 package consts
 
+import "github.com/gogf/gf/v2/errors/gcode"
+
 const (
 	ContextKey = "ContextKey"
 )
+
+var (
+	c = gcode.New(300, "", "")
+)

+ 3 - 2
internal/controller/productHandler.go

@@ -1,16 +1,17 @@
 package controller
 
 import (
+	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/net/ghttp"
 	"jyOrderManager/internal/service"
 )
 
 // GetProductListHandler 获取商品列表
 func GetProductListHandler(r *ghttp.Request) {
-	service.Product().GetList(1)
+
 }
 
 // GetProductPriceHandler 获取商品价格
 func GetProductPriceHandler(r *ghttp.Request) {
-
+	g.Dump(service.Product().GetPriceConfig("cjdy001"))
 }

+ 2 - 2
internal/logic/product/jyProductInterface.go

@@ -1,8 +1,8 @@
 package product
 
 type JyProduct interface {
-	GetPrice(param interface{}) (int64, error) //查询价格
-	Check(param interface{}) error             //参数校验
+	GetPrice(peoductCode string) (int64, error) //查询价格
+	Check(param interface{}) error              //参数校验
 	//Save(ctx context.Context, param interface{}) error  //保存
 	//Update(ctx context.Context, param interface{}) error //更新
 	OpenService(productDetailId int64) error //开通服务

+ 70 - 3
internal/logic/product/subvip.go

@@ -1,18 +1,85 @@
 package product
 
+import (
+	"github.com/gogf/gf/v2/errors/gcode"
+	"github.com/gogf/gf/v2/errors/gerror"
+	"github.com/gogf/gf/v2/util/gconv"
+	"jyOrderManager/internal/model"
+	"jyOrderManager/internal/service"
+)
+
 type (
 	jySubVipProduct struct {
 	}
+
+	priceSetting struct {
+		Moth   int64 `json:"moth"`
+		Season int64 `json:"season"`
+		Year   int64 `json:"year"`
+	}
 )
 
-func (p *jySubVipProduct) Check(param interface{}) error {
+func (p *jySubVipProduct) CheckParam(param model.SubVipParams) error {
 
 	return nil
 }
 
-func (p *jySubVipProduct) GetPrice(param interface{}) (int64, error) {
+func (p *jySubVipProduct) GetPrice(param model.SubVipParams) (int64, error) {
+	var (
+		fPrice   int64
+		totalNum = param.SPayAccountNumber + param.SGiftAccountNumber
+	)
+	sVal, err := service.Product().GetPriceConfig(param.ProductCode)
+	if err != nil {
+		return 0, err
+	}
+	var thisPriceSetting priceSetting
+	if err := gconv.Struct(sVal.Rule, &thisPriceSetting); err != nil {
+		return 0, gerror.NewCode(gcode.CodeValidationFailed, "价格格式配置异常")
+	}
+
+	if param.PayCycleType == param.GifCycleType { //购买周期和送的周期一样
+		p, err := thisPriceSetting.GetPrice(param.GifCycle+param.PayCycle, param.GifCycleType)
+		if err != nil {
+			return 0, err
+		}
+		fPrice = p * gconv.Int64(totalNum)
+	} else {
+		var (
+			p1, p2 int64
+			err    error
+		)
+		p1, err = thisPriceSetting.GetPrice(param.PayCycleType, param.PayCycleType)
+		if err != nil {
+			return p1, err
+		}
+		p2, err = thisPriceSetting.GetPrice(param.GifCycle, param.GifCycleType)
+		if err != nil {
+			return p2, err
+		}
+		fPrice = (p1 + p2) * gconv.Int64(totalNum)
+	}
+	return fPrice, nil
+}
 
-	return -1, nil
+func (ps *priceSetting) GetPrice(num, cycleType int) (int64, error) {
+	switch cycleType { // 1-天 2-月  3-季 4-年
+	case 1:
+		return ps.Moth / 30 * gconv.Int64(num), nil
+	case 2:
+		if num >= 12 && ps.Year > 0 {
+			return ps.Year / 12 * gconv.Int64(num), nil
+		}
+		if num >= 3 && ps.Season > 0 {
+			return ps.Season / 3 * gconv.Int64(num), nil
+		}
+		return ps.Moth * gconv.Int64(num), nil
+	case 3:
+		return ps.Season * gconv.Int64(num), nil
+	case 4:
+		return ps.Year * gconv.Int64(num), nil
+	}
+	return -1, gerror.NewCode(gcode.CodeInvalidParameter, "位置时间参数")
 }
 
 func (p *jySubVipProduct) OpenService(param interface{}) {

+ 16 - 5
internal/logic/productManager/productManager.go

@@ -2,8 +2,11 @@ package productManager
 
 import (
 	"context"
+	"github.com/gogf/gf/v2/errors/gcode"
+	"github.com/gogf/gf/v2/errors/gerror"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/os/gctx"
+	"github.com/gogf/gf/v2/util/gconv"
 	"jyOrderManager/internal/model"
 	"jyOrderManager/internal/service"
 )
@@ -48,6 +51,7 @@ func getInitJyProduct(ctx context.Context) (*sProductManager, error) {
 	if err := productList.Structs(&productArray); err != nil {
 		return nil, err
 	}
+
 	for _, class := range productCLass {
 		var topRoot *model.ProductTop
 		for _, top := range productRoot {
@@ -80,12 +84,19 @@ func getInitJyProduct(ctx context.Context) (*sProductManager, error) {
 }
 
 // GetList 获取商品列表
-func (p *sProductManager) GetList(classId int) map[string]interface{} {
-
+func (p *sProductManager) GetList() map[string]interface{} {
 	return nil
 }
 
-// GetPrice 根据产品code及请求参数获取价格
-func (p *sProductManager) GetPrice(productCode string, param interface{}) {
-
+// GetPriceConfig 根据产品code及请求参数获取价格
+func (p *sProductManager) GetPriceConfig(productCode string) (*model.PriceConfig, error) {
+	product, ok := p.ProductCodeMapping[productCode]
+	if !ok {
+		return nil, gerror.NewCode(gcode.CodeValidationFailed)
+	}
+	var rData model.PriceConfig
+	if err := gconv.Struct(product.Price, &rData); err != nil {
+		return nil, err
+	}
+	return &rData, nil
 }

+ 12 - 8
internal/model/orderParams.go

@@ -1,6 +1,13 @@
 package model
 
 type (
+	ProductCommonParam struct {
+		ProductCode string `json:"product_code"` //产品code
+		Phone       string `json:"phone"`        //开通手机号
+		Amount      string `json:"amount"`       //合同金额
+		Tactics     int    //策略 1仅购买 2仅赠送 3购买+赠送
+	}
+
 	OrderParams struct {
 		OrderStatus    int    `form:"order_status" json:"orderStatus,omitempty"`      // 订单状态  0 未完成 1 已完成
 		BuySubject     string `form:"buySubject" json:"buySubject"`                   // 购买主体  1 个人, 2公司
@@ -69,23 +76,20 @@ type (
 		SupServiceId         []string `json:"supServiceId,omitempt"`        // 补充服务 服务id
 	}
 
-	//CreateVipParams 超级订阅
-	CreateVipParams struct {
+	//SubVipParams 超级订阅
+	SubVipParams struct {
+		*ProductCommonParam
 		ProductType        string `json:"productType,omitempty"`                        //产品类型
 		BillingMode        string `json:"billingMode"`                                  //策略 购买 赠送
 		RecordPayType      string `form:"recordPayType" json:"recordPayType,omitempty"` //付费类型 购买 续费 升级 试用
 		LinkedOrderId      string `json:"linkedOrderId,omitempty"`                      //关联订单明细id
-		ProductStandard    int    `json:"productStandard"`                              //产品规格 购买省份数量
-		PAccountNumber     int    `json:"pAccountNumber"`                               //主账号数量
 		SPayAccountNumber  int    `json:"sPayAccountNumber"`                            //子账号付费数量
 		SGiftAccountNumber int    `json:"sGiftAccountNumber"`                           //子账号赠送数量
 		PayCycle           int    `json:"payCycle"`                                     //付费购买周期
-		PayCycleType       int    `json:"payCycleType"`                                 //付费周期类型:0-月 1-天
+		PayCycleType       int    `json:"payCycleType"`                                 //付费周期类型:0-月 1-天 2-年 3-季
 		GifCycle           int    `json:"gifCycle"`                                     //赠送周期
-		GifCycleType       int    `json:"gifCycleType"`                                 //赠送周期类型:0-月 1-天
+		GifCycleType       int    `json:"gifCycleType"`                                 //赠送周期类型:0-月 1-天 2-年 3-季
 		PaybackOpenServer  bool   `json:"paybackOpenServer,omitempty"`                  //是否全额回款开通
-		Phone              string `form:"phone" json:"phone,omitempty"`                 //开通手机号
-		OrderMoney         int    `form:"orderMoney" json:"orderMoney,omitempty"`       //标准售价
 		PayMoney           int    `form:"payMoney" json:"payMoney,omitempty"`           //合同金额
 	}
 

+ 8 - 11
internal/model/product.go

@@ -20,17 +20,14 @@ type (
 		Id             int64 `json:"id"`
 		ProductClassId int64 `json:"product_class_id"`
 		Code           string
-		Name           string //产品名称
-		UnitName       string //单位名称、数量名称
-		UnitNum        int    //数量
-		Cycle          string //有效周期
-		Price          string //计价规则
+		Name           string                 //产品名称
+		UnitName       string                 //单位名称、数量名称
+		UnitNum        int                    //数量
+		Cycle          string                 //有效周期
+		Price          map[string]interface{} `json:"price"` //计价规则
 	}
-	ProductCommonParam struct {
-		ProductCode string `json:"product_code"` //产品code
-		Phone       string `json:"phone"`        //开通手机号
-		Amount      string `json:"amount"`       //合同金额
-		BuySubject  string `json:"buy_subject"`  //购买主体
-		Tactics     int    //策略 1仅购买 2仅赠送 3购买+赠送
+	PriceConfig struct {
+		Mode int    `json:"mode"`
+		Rule string `json:"rule"`
 	}
 )

+ 4 - 2
internal/service/product.go

@@ -4,12 +4,14 @@
 // ================================================================================
 package service
 
+import "jyOrderManager/internal/model"
+
 type (
 	IProduct interface {
 		// CheckParam 校验参数
-		GetList(classId int) map[string]interface{}
+		GetList() map[string]interface{}
 		// GetPrice 获取用户身份
-		GetPrice(productCode string, param interface{})
+		GetPriceConfig(productCode string) (*model.PriceConfig, error)
 	}
 )
 

+ 1 - 0
main.go

@@ -10,4 +10,5 @@ import (
 
 func main() {
 	cmd.Main.Run(gctx.GetInitCtx())
+
 }