|
@@ -1,6 +1,7 @@
|
|
package productManager
|
|
package productManager
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
"context"
|
|
"context"
|
|
"github.com/gogf/gf/v2/errors/gcode"
|
|
"github.com/gogf/gf/v2/errors/gcode"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
@@ -16,15 +17,22 @@ type (
|
|
ProductRoot []*model.ProductTop
|
|
ProductRoot []*model.ProductTop
|
|
ProductCodeMapping map[string]*model.Product
|
|
ProductCodeMapping map[string]*model.Product
|
|
ProductClassMapping map[int64]*model.ProductClass
|
|
ProductClassMapping map[int64]*model.ProductClass
|
|
|
|
+
|
|
|
|
+ ActivityList []*model.ActivityClass //活动
|
|
|
|
+ ActivityCodeMapping map[string]*model.ActivityClass
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
ctx := gctx.New()
|
|
ctx := gctx.New()
|
|
- productManager, err := getInitJyProduct(ctx)
|
|
|
|
|
|
+ productManager, err := getInitJyProduct(ctx) //加载商品
|
|
if err != nil {
|
|
if err != nil {
|
|
g.Log().Panicf(ctx, "初始化剑鱼商品异常%s", err)
|
|
g.Log().Panicf(ctx, "初始化剑鱼商品异常%s", err)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if err := productManager.loadActivity(ctx); err != nil { //加载活动
|
|
|
|
+ g.Log().Panicf(ctx, "初始化剑鱼活动异常%s", err)
|
|
|
|
+ }
|
|
service.RegisterProductManager(productManager)
|
|
service.RegisterProductManager(productManager)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -37,7 +45,6 @@ func getInitJyProduct(ctx context.Context) (*sProductManager, error) {
|
|
productCLass []*model.ProductClass
|
|
productCLass []*model.ProductClass
|
|
productArray []*model.Product
|
|
productArray []*model.Product
|
|
)
|
|
)
|
|
- //查询产品类
|
|
|
|
classList, err := g.DB().Query(ctx, "SELECT * FROM jy_product_class WHERE state =1")
|
|
classList, err := g.DB().Query(ctx, "SELECT * FROM jy_product_class WHERE state =1")
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
@@ -54,7 +61,6 @@ func getInitJyProduct(ctx context.Context) (*sProductManager, error) {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- //for index, class := range productCLass {
|
|
|
|
for _, class := range productCLass {
|
|
for _, class := range productCLass {
|
|
productClassMapping[class.ClassId] = class
|
|
productClassMapping[class.ClassId] = class
|
|
var topRoot *model.ProductTop
|
|
var topRoot *model.ProductTop
|
|
@@ -89,8 +95,36 @@ func getInitJyProduct(ctx context.Context) (*sProductManager, error) {
|
|
}
|
|
}
|
|
|
|
|
|
// GetList 获取商品列表
|
|
// GetList 获取商品列表
|
|
-func (p *sProductManager) GetList() []*model.ProductTop {
|
|
|
|
- return p.ProductRoot
|
|
|
|
|
|
+func (p *sProductManager) GetList(buySet ...int) []*model.ProductTop {
|
|
|
|
+ var (
|
|
|
|
+ result []*model.ProductTop
|
|
|
|
+ set int = 3 //1个人 2企业 3个人和企业都支持
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ if len(buySet) > 0 {
|
|
|
|
+ set = common.If(buySet[0] > 0 && buySet[0] < 3, buySet[0], 3).(int)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if set == 3 {
|
|
|
|
+ return p.ProductRoot
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, top := range p.ProductRoot {
|
|
|
|
+ var t []*model.ProductClass
|
|
|
|
+ for _, ps := range top.ProductClassList {
|
|
|
|
+ if ps.BuySet == 1 && set != 2 {
|
|
|
|
+ t = append(t, ps)
|
|
|
|
+ }
|
|
|
|
+ if ps.BuySet == 2 && set != 1 {
|
|
|
|
+ t = append(t, ps)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if len(t) > 0 {
|
|
|
|
+ top.ProductClassList = t
|
|
|
|
+ result = append(result, top)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return result
|
|
}
|
|
}
|
|
|
|
|
|
// GetPriceConfig 根据产品code及请求参数获取价格
|
|
// GetPriceConfig 根据产品code及请求参数获取价格
|