feat: persist product claimed counts
This commit is contained in:
@@ -35,6 +35,7 @@ type ProductColumns struct {
|
|||||||
CoverUrl string // 封面URL
|
CoverUrl string // 封面URL
|
||||||
DetailHtml string // 商品详情
|
DetailHtml string // 商品详情
|
||||||
IsRecommended string // 是否推荐
|
IsRecommended string // 是否推荐
|
||||||
|
ClaimedCount string // 已领取展示数
|
||||||
PublishStatus string // 发布状态
|
PublishStatus string // 发布状态
|
||||||
StartAt string // 展示开始时间
|
StartAt string // 展示开始时间
|
||||||
EndAt string // 展示结束时间
|
EndAt string // 展示结束时间
|
||||||
@@ -65,6 +66,7 @@ var productColumns = ProductColumns{
|
|||||||
CoverUrl: "cover_url",
|
CoverUrl: "cover_url",
|
||||||
DetailHtml: "detail_html",
|
DetailHtml: "detail_html",
|
||||||
IsRecommended: "is_recommended",
|
IsRecommended: "is_recommended",
|
||||||
|
ClaimedCount: "claimed_count",
|
||||||
PublishStatus: "publish_status",
|
PublishStatus: "publish_status",
|
||||||
StartAt: "start_at",
|
StartAt: "start_at",
|
||||||
EndAt: "end_at",
|
EndAt: "end_at",
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ func (s *sSysProduct) Edit(ctx context.Context, in *sysin.ProductEditInp) (id ui
|
|||||||
id = in.Id
|
id = in.Id
|
||||||
} else {
|
} else {
|
||||||
in.ProductNo = "PD" + gtime.Now().Format("YmdHis") + grand.S(5)
|
in.ProductNo = "PD" + gtime.Now().Format("YmdHis") + grand.S(5)
|
||||||
result, e := s.Model(ctx).Fields(c.ProductNo, c.CategoryId, c.ProductType, c.PaymentType, c.Name, c.ShopName, c.PriceAmount, c.Currency, c.CoverAttachmentId, c.CoverUrl, c.DetailHtml, c.IsRecommended, c.PublishStatus, c.StartAt, c.EndAt, c.Sort, c.Remark, c.CreatedBy, c.UpdatedBy).Hook(hook.SaveTenant).Data(g.Map{c.ProductNo: in.ProductNo, c.CategoryId: in.CategoryId, c.ProductType: in.ProductType, c.PaymentType: in.PaymentType, c.Name: in.Name, c.ShopName: in.ShopName, c.PriceAmount: in.PriceAmount, c.Currency: in.Currency, c.CoverAttachmentId: in.CoverAttachmentId, c.CoverUrl: in.CoverUrl, c.DetailHtml: in.DetailHtml, c.IsRecommended: in.IsRecommended, c.PublishStatus: consts.BizPublishDraft, c.StartAt: in.StartAt, c.EndAt: in.EndAt, c.Sort: in.Sort, c.Remark: in.Remark, c.CreatedBy: uid, c.UpdatedBy: uid}).Insert()
|
result, e := s.Model(ctx).Fields(c.ProductNo, c.CategoryId, c.ProductType, c.PaymentType, c.Name, c.ShopName, c.PriceAmount, c.Currency, c.CoverAttachmentId, c.CoverUrl, c.DetailHtml, c.IsRecommended, c.ClaimedCount, c.PublishStatus, c.StartAt, c.EndAt, c.Sort, c.Remark, c.CreatedBy, c.UpdatedBy).Hook(hook.SaveTenant).Data(g.Map{c.ProductNo: in.ProductNo, c.CategoryId: in.CategoryId, c.ProductType: in.ProductType, c.PaymentType: in.PaymentType, c.Name: in.Name, c.ShopName: in.ShopName, c.PriceAmount: in.PriceAmount, c.Currency: in.Currency, c.CoverAttachmentId: in.CoverAttachmentId, c.CoverUrl: in.CoverUrl, c.DetailHtml: in.DetailHtml, c.IsRecommended: in.IsRecommended, c.ClaimedCount: grand.N(100, 500), c.PublishStatus: consts.BizPublishDraft, c.StartAt: in.StartAt, c.EndAt: in.EndAt, c.Sort: in.Sort, c.Remark: in.Remark, c.CreatedBy: uid, c.UpdatedBy: uid}).Insert()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return 0, gerror.Wrap(e, "创建商品失败")
|
return 0, gerror.Wrap(e, "创建商品失败")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ type Product struct {
|
|||||||
CoverUrl any // 封面URL
|
CoverUrl any // 封面URL
|
||||||
DetailHtml any // 商品详情
|
DetailHtml any // 商品详情
|
||||||
IsRecommended any // 是否推荐
|
IsRecommended any // 是否推荐
|
||||||
|
ClaimedCount any // 已领取展示数
|
||||||
PublishStatus any // 发布状态
|
PublishStatus any // 发布状态
|
||||||
StartAt *gtime.Time // 展示开始时间
|
StartAt *gtime.Time // 展示开始时间
|
||||||
EndAt *gtime.Time // 展示结束时间
|
EndAt *gtime.Time // 展示结束时间
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type Product struct {
|
|||||||
CoverUrl string `json:"coverUrl" orm:"cover_url" description:"封面URL"`
|
CoverUrl string `json:"coverUrl" orm:"cover_url" description:"封面URL"`
|
||||||
DetailHtml string `json:"detailHtml" orm:"detail_html" description:"商品详情"`
|
DetailHtml string `json:"detailHtml" orm:"detail_html" description:"商品详情"`
|
||||||
IsRecommended int `json:"isRecommended" orm:"is_recommended" description:"是否推荐"`
|
IsRecommended int `json:"isRecommended" orm:"is_recommended" description:"是否推荐"`
|
||||||
|
ClaimedCount uint `json:"claimedCount" orm:"claimed_count" description:"已领取展示数"`
|
||||||
PublishStatus int `json:"publishStatus" orm:"publish_status" description:"发布状态"`
|
PublishStatus int `json:"publishStatus" orm:"publish_status" description:"发布状态"`
|
||||||
StartAt *gtime.Time `json:"startAt" orm:"start_at" description:"展示开始时间"`
|
StartAt *gtime.Time `json:"startAt" orm:"start_at" description:"展示开始时间"`
|
||||||
EndAt *gtime.Time `json:"endAt" orm:"end_at" description:"展示结束时间"`
|
EndAt *gtime.Time `json:"endAt" orm:"end_at" description:"展示结束时间"`
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ type ProductUpdateFields struct {
|
|||||||
type ProductInsertFields struct {
|
type ProductInsertFields struct {
|
||||||
ProductUpdateFields
|
ProductUpdateFields
|
||||||
ProductNo string
|
ProductNo string
|
||||||
|
ClaimedCount uint
|
||||||
PublishStatus int
|
PublishStatus int
|
||||||
CreatedBy uint64
|
CreatedBy uint64
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
-- 手工商城领取数作为固定展示数据保存,页面和接口不再随机计算。
|
||||||
|
SET @product_claimed_count_exists = (
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = DATABASE()
|
||||||
|
AND TABLE_NAME = 'hg_product'
|
||||||
|
AND COLUMN_NAME = 'claimed_count'
|
||||||
|
);
|
||||||
|
SET @add_product_claimed_count = IF(
|
||||||
|
@product_claimed_count_exists = 0,
|
||||||
|
'ALTER TABLE `hg_product` ADD COLUMN `claimed_count` int unsigned NOT NULL DEFAULT 0 COMMENT ''已领取展示数'' AFTER `is_recommended`',
|
||||||
|
'SELECT 1'
|
||||||
|
);
|
||||||
|
PREPARE add_product_claimed_count_stmt FROM @add_product_claimed_count;
|
||||||
|
EXECUTE add_product_claimed_count_stmt;
|
||||||
|
DEALLOCATE PREPARE add_product_claimed_count_stmt;
|
||||||
|
|
||||||
|
-- 仅为尚未设置展示数的手工商品生成一次,后续只读取数据库中的值。
|
||||||
|
UPDATE `hg_product`
|
||||||
|
SET `claimed_count` = FLOOR(100 + RAND() * 401)
|
||||||
|
WHERE `product_type` = 2
|
||||||
|
AND `claimed_count` = 0
|
||||||
|
AND `deleted_at` IS NULL;
|
||||||
Reference in New Issue
Block a user