From c0c9c249b8e68795777fc805d85c1ce9b47ff75e Mon Sep 17 00:00:00 2001 From: RIceWqy <1840169763@qq.com> Date: Mon, 25 Dec 2023 15:22:56 +0800 Subject: [PATCH] goods --- init/init.go | 2 + module/activity/Activity.go | 28 ++++++ module/activity/init.go | 12 +++ module/comment/Comment.go | 16 ++-- module/common/TimeRange.go | 6 -- module/coupon/Coupon.go | 54 +++++++---- module/goods/Goods.go | 96 +++++++++++++++---- module/itemGoodsSkuPrice/ItemGoodsSkuPrice.go | 17 ++++ module/itemGoodsSkuPrice/init.go | 12 +++ module/service/Service.go | 3 +- module/skuPrice/SKUPrice.go | 54 ++++++++--- 11 files changed, 233 insertions(+), 67 deletions(-) create mode 100644 module/activity/Activity.go create mode 100644 module/activity/init.go delete mode 100644 module/common/TimeRange.go create mode 100644 module/itemGoodsSkuPrice/ItemGoodsSkuPrice.go create mode 100644 module/itemGoodsSkuPrice/init.go diff --git a/init/init.go b/init/init.go index 79a2937..8d196c2 100644 --- a/init/init.go +++ b/init/init.go @@ -5,3 +5,5 @@ import _ "src/module/coupon" import _ "src/module/goods" import _ "src/module/service" import _ "src/module/skuPrice" +import _ "src/module/activity" +import _ "src/module/itemGoodsSkuPrice" diff --git a/module/activity/Activity.go b/module/activity/Activity.go new file mode 100644 index 0000000..5a3f5c5 --- /dev/null +++ b/module/activity/Activity.go @@ -0,0 +1,28 @@ +package activity + +func (Activity) TableName() string { + return "activity" +} + +type Activity struct { + ID int `json:"id"` // 活动ID + Title string `json:"title"` // 活动标题 + Type string `json:"type"` // 活动类型 + RichtextID int `json:"richtext_id"` // 富文本ID + RichtextTitle string `json:"richtext_title"` // 富文本标题 + StartTime int64 `json:"starttime"` // 活动开始时间 + EndTime int64 `json:"endtime"` // 活动结束时间 + Rules Rules `json:"rules" ` // 活动规则 + StatusCode string `json:"status_code"` // 活动状态码 +} +type Rules struct { + ActivityAutoClose string `json:"activity_auto_close"` // 活动自动关闭 + FictitiousNum string `json:"fictitious_num"` // 虚拟号码 + IsAlone string `json:"is_alone"` // 是否单独 + IsFictitious string `json:"is_fictitious"` // 是否虚拟 + LimitBuy string `json:"limit_buy"` // 限购 + OrderAutoClose string `json:"order_auto_close"` // 订单自动关闭 + TeamCard string `json:"team_card"` // 团购卡 + TeamNum string `json:"team_num"` // 团购人数 + ValidTime string `json:"valid_time"` // 有效时间 +} diff --git a/module/activity/init.go b/module/activity/init.go new file mode 100644 index 0000000..aa435a1 --- /dev/null +++ b/module/activity/init.go @@ -0,0 +1,12 @@ +package activity + +import ( + "github.com/towgo/towgo/dao/ormDriver/xormDriver" + "github.com/towgo/towgo/towgo" +) + +func init() { + xormDriver.Sync2(new(Activity)) + towgo.NewCRUDJsonrpcAPI("/activity", Activity{}, []Activity{}).RegAPI() + +} diff --git a/module/comment/Comment.go b/module/comment/Comment.go index 14d21b9..33a9efa 100644 --- a/module/comment/Comment.go +++ b/module/comment/Comment.go @@ -8,23 +8,23 @@ func (Comment) TableName() string { // Comment 用户评论结构体 type Comment struct { - ID int `json:"id"` // 评论ID - GoodsID int `json:"goods_id"` // 商品ID - OrderID int `json:"order_id"` // 订单ID - OrderItemID int `json:"order_item_id"` // 订单项ID - UserID int `json:"user_id"` // 用户ID - Level int `json:"level"` // 评级 + ID int64 `json:"id"` // 评论ID + GoodsID int64 `json:"goods_id"` // 商品ID + OrderID int64 `json:"order_id"` // 订单ID + OrderItemID int64 `json:"order_item_id"` // 订单项ID + UserID int64 `json:"user_id"` // 用户ID + Level int64 `json:"level"` // 评级 Content string `json:"content"` // 评论内容 Images []string `json:"images"` // 评论图片列表 Status string `json:"status"` // 评论状态 - AdminID int `json:"admin_id"` // 管理员ID + AdminID int64 `json:"admin_id"` // 管理员ID ReplyContent string `json:"reply_content"` // 回复内容 ReplyTime time.Time `json:"replytime"` // 回复时间 CreateTime int64 `json:"createtime"` // 创建时间 UpdateTime int64 `json:"updatetime"` // 更新时间 DeleteTime int64 `json:"deletetime"` // 删除时间 User struct { - ID int `json:"id"` // 用户ID + ID int64 `json:"id"` // 用户ID Nickname string `json:"nickname"` // 用户昵称 Avatar string `json:"avatar"` // 用户头像 } `json:"user" xorm:"-"` // 用户信息 diff --git a/module/common/TimeRange.go b/module/common/TimeRange.go deleted file mode 100644 index f249d57..0000000 --- a/module/common/TimeRange.go +++ /dev/null @@ -1,6 +0,0 @@ -package common - -type TimeRange struct { - Start int64 `json:"start"` // 开始时间 - End int64 `json:"end"` // 结束时间 -} diff --git a/module/coupon/Coupon.go b/module/coupon/Coupon.go index 64d2850..47145ea 100644 --- a/module/coupon/Coupon.go +++ b/module/coupon/Coupon.go @@ -1,27 +1,45 @@ package goods -import "src/module/common" - func (Coupon) TableName() string { return "coupon" } // Coupon 结构体表示优惠券信息 type Coupon struct { - ID int `json:"id"` // 优惠券ID - Name string `json:"name"` // 优惠券名称 - Type string `json:"type"` // 优惠券类型 - GoodsID string `json:"goods_ids"` // 商品ID - Amount string `json:"amount"` // 优惠券金额 - Enough string `json:"enough"` // 满足条件金额 - Stock int `json:"stock"` // 库存数量 - Limit int `json:"limit"` // 领取限制 - GetTime common.TimeRange `json:"gettime"` // 领取时间范围 - UseTime common.TimeRange `json:"usetime"` // 使用时间范围 - Description string `json:"description"` // 优惠券描述 - StartTime int64 `json:"gettimestart"` // 领取开始时间 - EndTime int64 `json:"gettimeend"` // 领取结束时间 - Status string `json:"status_code"` // 优惠券状态代码 - StatusName string `json:"status_name"` // 优惠券状态名称 - UserCoupons []string `json:"user_coupons"` // 用户优惠券列表 + ID int64 `json:"id"` // 优惠券ID + Name string `json:"name"` // 优惠券名称 + Type string `json:"type"` // 优惠券类型 + GoodsIds string `json:"goods_ids"` // 关联商品ID + Amount string `json:"amount"` // 优惠金额 + Enough string `json:"enough"` // 满足条件金额 + Stock int64 `json:"stock"` // 库存 + Limit int64 `json:"limit"` // 领取限制 + Usetimestart int64 `json:"usetimestart"` // 可使用时间段开始 + Usetimeend int64 `json:"usetimeend"` // 可使用时间段结束 + Gettimestart int64 `json:"gettimestart"` // 可领取时间段开始 + Gettimeend int64 `json:"gettimeend"` // 可领取时间段结束 + Description string `json:"description"` // 优惠券描述 + StatusCode string `json:"status_code"` // 优惠券状态代码 + StatusName string `json:"status_name"` // 优惠券状态名称 + GetTime TimeRange `json:"gettime" xorm:"-"` // 可领取时间段 + UseTime TimeRange `json:"usetime" xorm:"-"` // 可使用时间段 + UserCoupons []string `json:"user_coupons" xorm:"-"` // 用户优惠券列表 +} + +type TimeRange struct { + Start int64 `json:"start"` // 开始时间 + End int64 `json:"end"` // 结束时间 +} + +func (coupon *Coupon) AfterQuery() error { + coupon.GetTime = TimeRange{ + coupon.Gettimestart, + coupon.Gettimeend, + } + coupon.UseTime = TimeRange{ + coupon.Usetimestart, + coupon.Usetimeend, + } + + return nil } diff --git a/module/goods/Goods.go b/module/goods/Goods.go index c5d0ddf..c915fee 100644 --- a/module/goods/Goods.go +++ b/module/goods/Goods.go @@ -2,43 +2,46 @@ package goods import ( "github.com/towgo/towgo/dao/basedboperat" + "src/module/activity" + coupon "src/module/coupon" service "src/module/service" + skuPrice "src/module/skuPrice" + "strings" ) -import skuPrice "src/module/skuPrice" -import coupon "src/module/coupon" func (Goods) TableName() string { return "goods" } -// Product 结构体表示产品信息 +// Goods 结构体表示产品信息 type Goods struct { - ID int `json:"id"` // 产品ID + ID int64 `json:"id"` // 产品ID Type string `json:"type"` // 产品类型 Title string `json:"title"` // 产品标题 Subtitle string `json:"subtitle"` // 产品副标题 - Weigh int `json:"weigh"` // 产品权重 - CategoryIDs string `json:"category_ids"` // 类别ID + Weigh int64 `json:"weigh"` // 产品权重 + CategoryIds string `json:"category_ids"` // 类别ID Image string `json:"image"` // 产品图片 Images []string `json:"images"` // 产品图片数组 - Params []string `json:"params"` // 产品参数 + Params []Param `json:"params"` // 产品参数 Content string `json:"content"` // 产品内容 Price string `json:"price"` // 产品价格 OriginalPrice string `json:"original_price"` // 产品原价 - IsSKU int `json:"is_sku"` // 是否有SKU - Likes int `json:"likes"` // 喜欢数 - Views int `json:"views"` // 浏览数 - Sales int `json:"sales"` // 销售数 - ShowSales int `json:"show_sales"` // 展示销售数 - ServiceIDs string `json:"service_ids"` // 服务ID + 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 + DispatchIds string `json:"dispatch_ids"` // 派送ID DeleteTime interface{} `json:"deletetime"` // 删除时间 - Activity interface{} `json:"activity"` // 活动 - ActivityType interface{} `json:"activity_type"` // 活动类型 - Buyers []string `json:"buyers"` // 购买者列表 + 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 int `json:"stock"` // 库存 + Stock int64 `json:"stock"` // 库存 ActivityDiscounts []string `json:"activity_discounts"` // 活动折扣列表 ActivityDiscountsTypes string `json:"activity_discounts_types"` // 活动折扣类型 ActivityDiscountsTags []string `json:"activity_discounts_tags"` // 活动折扣标签 @@ -47,8 +50,63 @@ type Goods struct { 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 -func (good *Goods) AfterQuery(session basedboperat.DbTransactionSession) { + /* 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 } diff --git a/module/itemGoodsSkuPrice/ItemGoodsSkuPrice.go b/module/itemGoodsSkuPrice/ItemGoodsSkuPrice.go new file mode 100644 index 0000000..e312889 --- /dev/null +++ b/module/itemGoodsSkuPrice/ItemGoodsSkuPrice.go @@ -0,0 +1,17 @@ +package itemGoodsSkuPrice + +func (ItemGoodsSkuPrice) TableName() string { + return "item_goods_sku_price" +} + +// ItemGoodsSkuPrice 结构体表示商品 SKU 的价格信息中的具体项 +type ItemGoodsSkuPrice struct { + ID int64 `json:"id"` // 唯一标识 + ActivityID int64 `json:"activity_id"` // 活动的唯一标识 + SkuPriceID int64 `json:"sku_price_id"` // SKU 价格的唯一标识 + GoodsID int64 `json:"goods_id"` // 商品的唯一标识 + Stock int64 `json:"stock"` // 库存 + Sales int64 `json:"sales"` // 销量 + Price string `json:"price"` // 价格 + Status string `json:"status"` // 状态 +} diff --git a/module/itemGoodsSkuPrice/init.go b/module/itemGoodsSkuPrice/init.go new file mode 100644 index 0000000..9977b9f --- /dev/null +++ b/module/itemGoodsSkuPrice/init.go @@ -0,0 +1,12 @@ +package itemGoodsSkuPrice + +import ( + "github.com/towgo/towgo/dao/ormDriver/xormDriver" + "github.com/towgo/towgo/towgo" +) + +func init() { + xormDriver.Sync2(new(ItemGoodsSkuPrice)) + towgo.NewCRUDJsonrpcAPI("/itemGoodsSkuPrice", ItemGoodsSkuPrice{}, []ItemGoodsSkuPrice{}).RegAPI() + +} diff --git a/module/service/Service.go b/module/service/Service.go index 7445d3f..369ae81 100644 --- a/module/service/Service.go +++ b/module/service/Service.go @@ -6,9 +6,8 @@ func (Service) TableName() string { // Service 结构体表示服务信息 type Service struct { - ID int `json:"id"` // 服务ID + ID int64 `json:"id"` // 服务ID Name string `json:"name"` // 服务名称 Image string `json:"image"` // 服务图片 - GoodsID int `json:"goods_id"` // 商品ID Description string `json:"description"` // 服务描述 } diff --git a/module/skuPrice/SKUPrice.go b/module/skuPrice/SKUPrice.go index fb1645f..e1facde 100644 --- a/module/skuPrice/SKUPrice.go +++ b/module/skuPrice/SKUPrice.go @@ -1,22 +1,48 @@ package goods +import ( + "github.com/towgo/towgo/dao/basedboperat" + "src/module/itemGoodsSkuPrice" + "strconv" +) + func (SKUPrice) TableName() string { return "sku_price" } -// SKUPrice 结构体表示SKU价格信息 +// SKUPrice 结构体表示商品 SKU 的价格信息 type SKUPrice struct { - ID int `json:"id"` // SKU价格ID - GoodsID int `json:"goods_id"` // 商品ID - Weigh int `json:"weigh"` // 重量 - Image string `json:"image"` // 图片 - Stock int `json:"stock"` // 库存 - StockWarning string `json:"stock_warning"` // 库存警告 - Sales int `json:"sales"` // 销售数量 - SN string `json:"sn"` // 序列号 - Weight int `json:"weight"` // 重量 - Price string `json:"price"` // 价格 - GoodsSKUText string `json:"goods_sku_text"` // 商品SKU文本 - Status string `json:"status"` // 状态 - GoodsSKUIDArr []string `json:"goods_sku_id_arr"` // 商品SKU ID数组 + ID int64 `json:"id"` // SKU 价格的唯一标识 + GoodsSkuIds []int64 `json:"goods_sku_ids"` // 商品 SKU 的标识数组 + GoodsId int64 `json:"goods_id"` // 商品的唯一标识 + Weigh int64 `json:"weigh"` // 权重 + Image string `json:"image"` // 图片链接 + Stock int64 `json:"stock"` // 库存 + StockWarning interface{} `json:"stock_warning"` // 库存预警信息,根据实际情况调整数据类型 + Sales int64 `json:"sales"` // 销量 + SN string `json:"sn"` // 商品编号 + Weight int64 `json:"weight"` // 重量 + Price string `json:"price"` // 价格 + GoodsSkuText string `json:"goods_sku_text"` // 商品 SKU 文本描述 + Status string `json:"status"` // 状态 + GrouponPrice string `json:"groupon_price"` // 团购价格 + ActivityType string `json:"activity_type"` // 活动类型 + ActivityId int64 `json:"activity_id"` // 活动的唯一标识 + ItemGoodsSkuPrice itemGoodsSkuPrice.ItemGoodsSkuPrice `json:"item_goods_sku_price" xorm:"-"` // 商品 SKU 价格信息 + GoodsSkuIdArr []string `json:"goods_sku_id_arr" xorm:"-"` // 商品 SKU 标识数组 +} + +func (sku *SKUPrice) AfterQuery(session basedboperat.DbTransactionSession) error { + var item itemGoodsSkuPrice.ItemGoodsSkuPrice + err := session.Get(&item, nil, "sku_price_id = ?", sku.ID) + if err != nil { + return err + } + sku.ItemGoodsSkuPrice = item + for _, id := range sku.GoodsSkuIds { + sku.GoodsSkuIdArr = append(sku.GoodsSkuIdArr, strconv.FormatInt(id, 10)) + } + + return nil + }