package goods import ( "github.com/towgo/towgo/dao/basedboperat" "log" "src/module/activity" coupon "src/module/coupon" "src/module/good_category_re" service "src/module/service" skuPrice "src/module/skuPrice" "strconv" "strings" ) func (Goods) TableName() string { return "goods" } // Goods 结构体表示产品信息 type Goods struct { ID int64 `json:"id"` // 产品ID Type string `json:"type"` // 产品类型 Title string `json:"title"` // 产品标题 Subtitle string `json:"subtitle"` // 产品副标题 Weigh int64 `json:"weigh"` // 产品权重 CategoryIds string `json:"category_ids" xorm:"-"` // 类别ID Image string `json:"image"` // 产品图片 Images []string `json:"images"` // 产品图片数组 Params []Param `json:"params"` // 产品参数 Content string `json:"content"` // 产品内容 Price string `json:"price"` // 产品价格 OriginalPrice string `json:"original_price"` // 产品原价 IsSKU int64 `json:"is_sku"` // 是否有SKU Likes int64 `json:"likes"` // 喜欢数 Views int64 `json:"views"` // 浏览数 Sales int64 `json:"sales"` // 销售数 ShowSales int64 `json:"show_sales"` // 展示销售数 TotalSales int64 `json:"total_sales"` // 总计销售额 ServiceIds string `json:"service_ids"` // 服务ID DispatchType string `json:"dispatch_type"` // 派送类型 DispatchIds string `json:"dispatch_ids"` // 派送ID DeleteTime interface{} `json:"deletetime"` // 删除时间 Activity activity.Activity `json:"activity" xorm:"-"` // 活动 ActivityType string `json:"activity_type"` // 活动类型 Buyers []string `json:"buyers" xorm:"-"` // 购买者列表 SKUPrice []skuPrice.SKUPrice `json:"sku_price" xorm:"-"` // SKU价格列表 Stock int64 `json:"stock"` // 库存 ActivityDiscounts []string `json:"activity_discounts"` // 活动折扣列表 ActivityDiscountsTypes string `json:"activity_discounts_types"` // 活动折扣类型 ActivityDiscountsTags []string `json:"activity_discounts_tags"` // 活动折扣标签 Favorite interface{} `json:"favorite"` // 收藏 DispatchTypeArr []string `json:"dispatch_type_arr"` // 派送类型数组 Service []service.Service `json:"service" xorm:"-"` // 服务列表 SKU []string `json:"sku"` // SKU列表 Coupons []coupon.Coupon `json:"coupons" xorm:"-"` // 优惠券列表 GrouponPrice string `json:"groupon_price"` // 团购价 } type Param struct { Title string `json:"title"` Content string `json:"content"` } func (good *Goods) AfterQuery(session basedboperat.DbTransactionSession) error { var skus []skuPrice.SKUPrice var sku skuPrice.SKUPrice var list basedboperat.List list.Limit = -1 list.Where = append(list.Where, basedboperat.Condition{ Field: "goods_id", Operator: "=", Value: good.ID, }) session.ListScan(&list, &sku, &skus) // 传递切片的指针 good.SKUPrice = skus if len(skus) > 0 { var a activity.Activity err := session.Get(&a, nil, "id = ?", skus[0].ActivityId) if err != nil { return err } good.Activity = a } var serverList []service.Service sIds := strings.Split(good.ServiceIds, ",") for _, sId := range sIds { var s service.Service err := session.Get(&s, nil, "id = ?", sId) if err != nil { return err } serverList = append(serverList, s) } good.Service = serverList var gcr good_category_re.GoodCategoryRe var gcrs []good_category_re.GoodCategoryRe var list2 basedboperat.List list2.Limit = -1 list2.Where = append(list.Where, basedboperat.Condition{ Field: "goods_id", Operator: "=", Value: good.ID, }) session.ListScan(&list2, &gcr, &gcrs) // 传递切片的指针 log.Println("goodid", good.ID) log.Println("gcrs", gcrs) var tempIds []string for _, v := range gcrs { tempIds = append(tempIds, strconv.FormatInt(v.CategoryId, 10)) } result := "" if len(tempIds) > 1 { result = strings.Join(tempIds, ",") } else if len(tempIds) == 1 { result = tempIds[0] } good.CategoryIds = result /* var cs []coupon.Coupon var c coupon.Coupon var list2 basedboperat.List list2.Limit = -1 list2.Where = append(list.Where, basedboperat.Condition{ Field: "goods_ids", Operator: "like", Value: "%" + strconv.FormatInt(good.ID, 10) + "%", }) list2.Or = append(list.Where, basedboperat.Condition{ Field: "goods_ids", Operator: "like", Value: "%" + strconv.FormatInt(good.ID, 10) + "%", }) session.ListScan(&list, &sku, &skus)*/ return nil }