12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package productManager
- import (
- "context"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/os/gctx"
- "jyOrderManager/internal/model"
- "jyOrderManager/internal/service"
- )
- type (
- sProductManager struct {
- ProductRoot []*model.ProductTop
- ProductCodeMapping map[string]*model.Product
- }
- )
- func init() {
- ctx := gctx.New()
- productManager, err := getInitJyProduct(ctx)
- if err != nil {
- g.Log().Panicf(ctx, "初始化剑鱼商品异常%s", err)
- }
- service.RegisterProduct(productManager)
- }
- func getInitJyProduct(ctx context.Context) (*sProductManager, error) {
- var (
- productRoot []*model.ProductTop
- productCodeMapping = map[string]*model.Product{}
- productCLass []*model.ProductClass
- productArray []*model.Product
- )
- //查询产品类
- classList, err := g.DB().Query(ctx, "SELECT * FROM jy_product_class WHERE state =1")
- if err != nil {
- return nil, err
- }
- if err := classList.Structs(&productCLass); err != nil {
- return nil, err
- }
- //查询所有产品
- productList, err := g.DB().Query(ctx, "SELECT * FROM jy_product_item WHERE state =1")
- if err != nil {
- return nil, err
- }
- if err := productList.Structs(&productArray); err != nil {
- return nil, err
- }
- for _, class := range productCLass {
- var topRoot *model.ProductTop
- for _, top := range productRoot {
- if top.Name == class.TopClass {
- topRoot = top
- break
- }
- }
- if topRoot == nil {
- topRoot = &model.ProductTop{
- Name: class.TopClass,
- ProductClassList: []*model.ProductClass{},
- }
- productRoot = append(productRoot, topRoot)
- }
- for _, productItem := range productArray {
- productCodeMapping[productItem.Code] = productItem
- if class.ClassId == productItem.ProductClassId {
- class.ProductList = append(class.ProductList, productItem)
- }
- }
- topRoot.ProductClassList = append(topRoot.ProductClassList, class)
- }
- g.Dump(productRoot)
- return &sProductManager{
- ProductRoot: productRoot,
- ProductCodeMapping: productCodeMapping,
- }, nil
- }
- // GetList 获取商品列表
- func (p *sProductManager) GetList(classId int) map[string]interface{} {
- return nil
- }
- // GetPrice 根据产品code及请求参数获取价格
- func (p *sProductManager) GetPrice(productCode string, param interface{}) {
- }
|