diff --git a/.hz b/.hz index 2dea2ae..b12fff3 100644 --- a/.hz +++ b/.hz @@ -1,6 +1,6 @@ // Code generated by hz. DO NOT EDIT. -hz version: v0.9.0 +hz version: v0.9.1 handlerDir: "" modelDir: "" routerDir: "" diff --git a/biz/dal/mysql/voucher.go b/biz/dal/mysql/voucher.go index 23485fd..9bad67f 100644 --- a/biz/dal/mysql/voucher.go +++ b/biz/dal/mysql/voucher.go @@ -2,16 +2,41 @@ package mysql import ( "context" + "errors" + "gorm.io/gorm" "xzdp/biz/model/voucher" ) -func QueryVoucherByID(ctx context.Context, id int64) ([]*voucher.Voucher, error) { - var voucherList []*voucher.Voucher +func QueryShopVoucherByShopID(ctx context.Context, id int64) ([]*voucher.SeckillVoucher, error) { + var voucherList []*voucher.SeckillVoucher - err = DB.WithContext(ctx).Where("shop_id = ?", id).Find(&voucherList).Error + err = DB.WithContext(ctx).Raw("select v.*,s.stock,s.begin_time,s.end_time from tb_voucher v left join tb_seckill_voucher s on s.voucher_id = v.id where v.shop_id = ?", id). + Find(&voucherList).Error if err != nil { return nil, err } return voucherList, nil } + +func QueryVoucherByID(ctx context.Context, id int64) (*voucher.SeckillVoucher, error) { + var seckillVoucher voucher.SeckillVoucher + err = DB.WithContext(ctx).Where("voucher_id = ?", id).Order("create_time desc").Limit(1).Find(&seckillVoucher).Error + return &seckillVoucher, err +} + +func QueryVoucherOrderByVoucherID(ctx context.Context, userId int64, id int64) (*voucher.VoucherOrder, error) { + var voucherOrder voucher.VoucherOrder + if !errors.Is(DB.WithContext(ctx).Where("voucher_id = ? and user_id=?", id, userId).Limit(1).Find(&voucherOrder).Error, gorm.ErrRecordNotFound) { + return nil, errors.New("重复下单") + } + return &voucherOrder, nil +} + +func UpdateVoucherStock(ctx context.Context, id int64) error { + return DB.WithContext(ctx).Model(&voucher.SeckillVoucher{}).Where("voucher_id = ?", id).Update("stock", gorm.Expr("stock - ?", 1)).Error +} + +func CreateVoucherOrder(ctx context.Context, voucherOrder *voucher.VoucherOrder) error { + return DB.WithContext(ctx).Create(voucherOrder).Error +} diff --git a/biz/dal/redis/id_worker.go b/biz/dal/redis/id_worker.go index 7ed89d4..56593a9 100644 --- a/biz/dal/redis/id_worker.go +++ b/biz/dal/redis/id_worker.go @@ -7,12 +7,13 @@ import ( ) func NextId(ctx context.Context, prefix string) (int64, error) { + beginTimeStamp := int64(constants.BEGIN_TIMESTAMP) now := time.Now().Unix() - dateKey := time.Now().Format("2006-01-02") - - count, err := RedisClient.Incr(ctx, constants.ID_KEY+prefix+":"+dateKey).Result() + timeStamp := now - beginTimeStamp + dateKey := time.Unix(now, 0).Format("2006-01-02") + count, err := RedisClient.Incr(ctx, constants.ICRID_KEY+prefix+":"+dateKey).Result() if err != nil { return 0, err } - return (now << 32) | count, nil + return (timeStamp << constants.COUNT_BIT) | count, nil } diff --git a/biz/handler/voucher/voucher_service.go b/biz/handler/voucher/voucher_service.go index da9938a..8cd62f2 100644 --- a/biz/handler/voucher/voucher_service.go +++ b/biz/handler/voucher/voucher_service.go @@ -2,6 +2,7 @@ package voucher import ( "context" + "errors" "strconv" "github.com/cloudwego/hertz/pkg/app" @@ -36,3 +37,25 @@ func VoucherList(ctx context.Context, c *app.RequestContext) { utils.SendSuccessResponse(ctx, c, consts.StatusOK, resp) } + +// SeckillVoucher . +// @router /voucher-order/seckill/:id [POST] +func SeckillVoucher(ctx context.Context, c *app.RequestContext) { + var err error + voucherString := c.Param("id") + if voucherString == "" { + utils.SendErrResponse(ctx, c, consts.StatusOK, errors.New("参数错误")) + return + } + voucherID, err := strconv.ParseInt(voucherString, 10, 64) + if err != nil { + utils.SendErrResponse(ctx, c, consts.StatusOK, err) + return + } + resp, err := service.NewSeckillVoucherService(ctx, c).Run(&voucherID) + if err != nil { + utils.SendErrResponse(ctx, c, consts.StatusOK, err) + return + } + utils.SendSuccessResponse(ctx, c, consts.StatusOK, resp) +} diff --git a/biz/model/blog/blog.go b/biz/model/blog/blog.go index 7a2347b..3630a10 100644 --- a/biz/model/blog/blog.go +++ b/biz/model/blog/blog.go @@ -1,4 +1,4 @@ -// Code generated by thriftgo (0.3.14). DO NOT EDIT. +// Code generated by thriftgo (0.3.15). DO NOT EDIT. package blog diff --git a/biz/model/blog_comment/blog_comment.go b/biz/model/blog_comment/blog_comment.go index d183a20..e6b64ee 100644 --- a/biz/model/blog_comment/blog_comment.go +++ b/biz/model/blog_comment/blog_comment.go @@ -1,4 +1,4 @@ -// Code generated by thriftgo (0.3.14). DO NOT EDIT. +// Code generated by thriftgo (0.3.15). DO NOT EDIT. package blog_comment diff --git a/biz/model/follow/follow.go b/biz/model/follow/follow.go index 04ab2d0..df07e04 100644 --- a/biz/model/follow/follow.go +++ b/biz/model/follow/follow.go @@ -1,4 +1,4 @@ -// Code generated by thriftgo (0.3.14). DO NOT EDIT. +// Code generated by thriftgo (0.3.15). DO NOT EDIT. package follow diff --git a/biz/model/image/image.go b/biz/model/image/image.go index 6806328..6f75dc2 100644 --- a/biz/model/image/image.go +++ b/biz/model/image/image.go @@ -1,4 +1,4 @@ -// Code generated by thriftgo (0.3.14). DO NOT EDIT. +// Code generated by thriftgo (0.3.15). DO NOT EDIT. package image diff --git a/biz/model/message/message.go b/biz/model/message/message.go index 0e76066..08d62ef 100644 --- a/biz/model/message/message.go +++ b/biz/model/message/message.go @@ -1,4 +1,4 @@ -// Code generated by thriftgo (0.3.14). DO NOT EDIT. +// Code generated by thriftgo (0.3.15). DO NOT EDIT. package message diff --git a/biz/model/shop/shop.go b/biz/model/shop/shop.go index 288948c..01894a3 100644 --- a/biz/model/shop/shop.go +++ b/biz/model/shop/shop.go @@ -1,4 +1,4 @@ -// Code generated by thriftgo (0.3.14). DO NOT EDIT. +// Code generated by thriftgo (0.3.15). DO NOT EDIT. package shop diff --git a/biz/model/user/user.go b/biz/model/user/user.go index f385af2..5ddd2c5 100644 --- a/biz/model/user/user.go +++ b/biz/model/user/user.go @@ -1,4 +1,4 @@ -// Code generated by thriftgo (0.3.14). DO NOT EDIT. +// Code generated by thriftgo (0.3.15). DO NOT EDIT. package user diff --git a/biz/model/voucher/voucher.go b/biz/model/voucher/voucher.go index 508c347..24c931e 100644 --- a/biz/model/voucher/voucher.go +++ b/biz/model/voucher/voucher.go @@ -1,4 +1,4 @@ -// Code generated by thriftgo (0.3.14). DO NOT EDIT. +// Code generated by thriftgo (0.3.15). DO NOT EDIT. package voucher @@ -692,12 +692,21 @@ func (p *Voucher) String() string { } type SeckillVoucher struct { - VoucherId int64 `thrift:"voucherId,1" gorm:"voucher_id" form:"voucherId" json:"voucherId" query:"voucherId"` - Stock int32 `thrift:"stock,2" gorm:"stock" form:"stock" json:"stock" query:"stock"` - CreateTime string `thrift:"createTime,3" gorm:"create_time" form:"createTime" json:"createTime" query:"createTime"` - BeginTime string `thrift:"beginTime,4" gorm:"begin_time" form:"beginTime" json:"beginTime" query:"beginTime"` - EndTime string `thrift:"endTime,5" gorm:"end_time" form:"endTime" json:"endTime" query:"endTime"` - UpdateTime string `thrift:"updateTime,6" gorm:"update_time" form:"updateTime" json:"updateTime" query:"updateTime"` + ID int64 `thrift:"id,1" gorm:"id" form:"id" json:"id" query:"id"` + ShopId int64 `thrift:"shopId,2" gorm:"shop_id" form:"shopId" json:"shopId" query:"shopId"` + Title string `thrift:"title,3" gorm:"title" form:"title" json:"title" query:"title"` + SubTitle string `thrift:"subTitle,4" gorm:"sub_title" form:"subTitle" json:"subTitle" query:"subTitle"` + Rules string `thrift:"rules,5" gorm:"rules" form:"rules" json:"rules" query:"rules"` + PayValue int64 `thrift:"payValue,6" gorm:"pay_value" form:"payValue" json:"payValue" query:"payValue"` + ActualValue int64 `thrift:"actualValue,7" gorm:"actual_value" form:"actualValue" json:"actualValue" query:"actualValue"` + Type int8 `thrift:"type,8" gorm:"type" form:"type" json:"type" query:"type"` + Status int8 `thrift:"status,9" gorm:"status" form:"status" json:"status" query:"status"` + CreateTime string `thrift:"createTime,10" gorm:"create_time" form:"createTime" json:"createTime" query:"createTime"` + UpdateTime string `thrift:"updateTime,11" gorm:"update_time" form:"updateTime" json:"updateTime" query:"updateTime"` + VoucherId int64 `thrift:"voucherId,12" gorm:"voucher_id" form:"voucherId" json:"voucherId" query:"voucherId"` + Stock int32 `thrift:"stock,13" gorm:"stock" form:"stock" json:"stock" query:"stock"` + BeginTime string `thrift:"beginTime,15" gorm:"begin_time" form:"beginTime" json:"beginTime" query:"beginTime"` + EndTime string `thrift:"endTime,16" gorm:"end_time" form:"endTime" json:"endTime" query:"endTime"` } func NewSeckillVoucher() *SeckillVoucher { @@ -707,18 +716,58 @@ func NewSeckillVoucher() *SeckillVoucher { func (p *SeckillVoucher) InitDefault() { } -func (p *SeckillVoucher) GetVoucherId() (v int64) { - return p.VoucherId +func (p *SeckillVoucher) GetID() (v int64) { + return p.ID } -func (p *SeckillVoucher) GetStock() (v int32) { - return p.Stock +func (p *SeckillVoucher) GetShopId() (v int64) { + return p.ShopId +} + +func (p *SeckillVoucher) GetTitle() (v string) { + return p.Title +} + +func (p *SeckillVoucher) GetSubTitle() (v string) { + return p.SubTitle +} + +func (p *SeckillVoucher) GetRules() (v string) { + return p.Rules +} + +func (p *SeckillVoucher) GetPayValue() (v int64) { + return p.PayValue +} + +func (p *SeckillVoucher) GetActualValue() (v int64) { + return p.ActualValue +} + +func (p *SeckillVoucher) GetType() (v int8) { + return p.Type +} + +func (p *SeckillVoucher) GetStatus() (v int8) { + return p.Status } func (p *SeckillVoucher) GetCreateTime() (v string) { return p.CreateTime } +func (p *SeckillVoucher) GetUpdateTime() (v string) { + return p.UpdateTime +} + +func (p *SeckillVoucher) GetVoucherId() (v int64) { + return p.VoucherId +} + +func (p *SeckillVoucher) GetStock() (v int32) { + return p.Stock +} + func (p *SeckillVoucher) GetBeginTime() (v string) { return p.BeginTime } @@ -727,17 +776,22 @@ func (p *SeckillVoucher) GetEndTime() (v string) { return p.EndTime } -func (p *SeckillVoucher) GetUpdateTime() (v string) { - return p.UpdateTime -} - var fieldIDToName_SeckillVoucher = map[int16]string{ - 1: "voucherId", - 2: "stock", - 3: "createTime", - 4: "beginTime", - 5: "endTime", - 6: "updateTime", + 1: "id", + 2: "shopId", + 3: "title", + 4: "subTitle", + 5: "rules", + 6: "payValue", + 7: "actualValue", + 8: "type", + 9: "status", + 10: "createTime", + 11: "updateTime", + 12: "voucherId", + 13: "stock", + 15: "beginTime", + 16: "endTime", } func (p *SeckillVoucher) Read(iprot thrift.TProtocol) (err error) { @@ -768,7 +822,7 @@ func (p *SeckillVoucher) Read(iprot thrift.TProtocol) (err error) { goto SkipFieldError } case 2: - if fieldTypeId == thrift.I32 { + if fieldTypeId == thrift.I64 { if err = p.ReadField2(iprot); err != nil { goto ReadFieldError } @@ -800,13 +854,85 @@ func (p *SeckillVoucher) Read(iprot thrift.TProtocol) (err error) { goto SkipFieldError } case 6: - if fieldTypeId == thrift.STRING { + if fieldTypeId == thrift.I64 { if err = p.ReadField6(iprot); err != nil { goto ReadFieldError } } else if err = iprot.Skip(fieldTypeId); err != nil { goto SkipFieldError } + case 7: + if fieldTypeId == thrift.I64 { + if err = p.ReadField7(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 8: + if fieldTypeId == thrift.BYTE { + if err = p.ReadField8(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 9: + if fieldTypeId == thrift.BYTE { + if err = p.ReadField9(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 10: + if fieldTypeId == thrift.STRING { + if err = p.ReadField10(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 11: + if fieldTypeId == thrift.STRING { + if err = p.ReadField11(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 12: + if fieldTypeId == thrift.I64 { + if err = p.ReadField12(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 13: + if fieldTypeId == thrift.I32 { + if err = p.ReadField13(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 15: + if fieldTypeId == thrift.STRING { + if err = p.ReadField15(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 16: + if fieldTypeId == thrift.STRING { + if err = p.ReadField16(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } default: if err = iprot.Skip(fieldTypeId); err != nil { goto SkipFieldError @@ -844,18 +970,18 @@ func (p *SeckillVoucher) ReadField1(iprot thrift.TProtocol) error { } else { _field = v } - p.VoucherId = _field + p.ID = _field return nil } func (p *SeckillVoucher) ReadField2(iprot thrift.TProtocol) error { - var _field int32 - if v, err := iprot.ReadI32(); err != nil { + var _field int64 + if v, err := iprot.ReadI64(); err != nil { return err } else { _field = v } - p.Stock = _field + p.ShopId = _field return nil } func (p *SeckillVoucher) ReadField3(iprot thrift.TProtocol) error { @@ -866,7 +992,7 @@ func (p *SeckillVoucher) ReadField3(iprot thrift.TProtocol) error { } else { _field = v } - p.CreateTime = _field + p.Title = _field return nil } func (p *SeckillVoucher) ReadField4(iprot thrift.TProtocol) error { @@ -877,7 +1003,7 @@ func (p *SeckillVoucher) ReadField4(iprot thrift.TProtocol) error { } else { _field = v } - p.BeginTime = _field + p.SubTitle = _field return nil } func (p *SeckillVoucher) ReadField5(iprot thrift.TProtocol) error { @@ -888,11 +1014,66 @@ func (p *SeckillVoucher) ReadField5(iprot thrift.TProtocol) error { } else { _field = v } - p.EndTime = _field + p.Rules = _field return nil } func (p *SeckillVoucher) ReadField6(iprot thrift.TProtocol) error { + var _field int64 + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + _field = v + } + p.PayValue = _field + return nil +} +func (p *SeckillVoucher) ReadField7(iprot thrift.TProtocol) error { + + var _field int64 + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + _field = v + } + p.ActualValue = _field + return nil +} +func (p *SeckillVoucher) ReadField8(iprot thrift.TProtocol) error { + + var _field int8 + if v, err := iprot.ReadByte(); err != nil { + return err + } else { + _field = v + } + p.Type = _field + return nil +} +func (p *SeckillVoucher) ReadField9(iprot thrift.TProtocol) error { + + var _field int8 + if v, err := iprot.ReadByte(); err != nil { + return err + } else { + _field = v + } + p.Status = _field + return nil +} +func (p *SeckillVoucher) ReadField10(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.CreateTime = _field + return nil +} +func (p *SeckillVoucher) ReadField11(iprot thrift.TProtocol) error { + var _field string if v, err := iprot.ReadString(); err != nil { return err @@ -902,6 +1083,50 @@ func (p *SeckillVoucher) ReadField6(iprot thrift.TProtocol) error { p.UpdateTime = _field return nil } +func (p *SeckillVoucher) ReadField12(iprot thrift.TProtocol) error { + + var _field int64 + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + _field = v + } + p.VoucherId = _field + return nil +} +func (p *SeckillVoucher) ReadField13(iprot thrift.TProtocol) error { + + var _field int32 + if v, err := iprot.ReadI32(); err != nil { + return err + } else { + _field = v + } + p.Stock = _field + return nil +} +func (p *SeckillVoucher) ReadField15(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.BeginTime = _field + return nil +} +func (p *SeckillVoucher) ReadField16(iprot thrift.TProtocol) error { + + var _field string + if v, err := iprot.ReadString(); err != nil { + return err + } else { + _field = v + } + p.EndTime = _field + return nil +} func (p *SeckillVoucher) Write(oprot thrift.TProtocol) (err error) { var fieldId int16 @@ -933,6 +1158,42 @@ func (p *SeckillVoucher) Write(oprot thrift.TProtocol) (err error) { fieldId = 6 goto WriteFieldError } + if err = p.writeField7(oprot); err != nil { + fieldId = 7 + goto WriteFieldError + } + if err = p.writeField8(oprot); err != nil { + fieldId = 8 + goto WriteFieldError + } + if err = p.writeField9(oprot); err != nil { + fieldId = 9 + goto WriteFieldError + } + if err = p.writeField10(oprot); err != nil { + fieldId = 10 + goto WriteFieldError + } + if err = p.writeField11(oprot); err != nil { + fieldId = 11 + goto WriteFieldError + } + if err = p.writeField12(oprot); err != nil { + fieldId = 12 + goto WriteFieldError + } + if err = p.writeField13(oprot); err != nil { + fieldId = 13 + goto WriteFieldError + } + if err = p.writeField15(oprot); err != nil { + fieldId = 15 + goto WriteFieldError + } + if err = p.writeField16(oprot); err != nil { + fieldId = 16 + goto WriteFieldError + } } if err = oprot.WriteFieldStop(); err != nil { goto WriteFieldStopError @@ -952,10 +1213,10 @@ WriteStructEndError: } func (p *SeckillVoucher) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("voucherId", thrift.I64, 1); err != nil { + if err = oprot.WriteFieldBegin("id", thrift.I64, 1); err != nil { goto WriteFieldBeginError } - if err := oprot.WriteI64(p.VoucherId); err != nil { + if err := oprot.WriteI64(p.ID); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -969,10 +1230,10 @@ WriteFieldEndError: } func (p *SeckillVoucher) writeField2(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("stock", thrift.I32, 2); err != nil { + if err = oprot.WriteFieldBegin("shopId", thrift.I64, 2); err != nil { goto WriteFieldBeginError } - if err := oprot.WriteI32(p.Stock); err != nil { + if err := oprot.WriteI64(p.ShopId); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -986,10 +1247,10 @@ WriteFieldEndError: } func (p *SeckillVoucher) writeField3(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("createTime", thrift.STRING, 3); err != nil { + if err = oprot.WriteFieldBegin("title", thrift.STRING, 3); err != nil { goto WriteFieldBeginError } - if err := oprot.WriteString(p.CreateTime); err != nil { + if err := oprot.WriteString(p.Title); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -1003,10 +1264,10 @@ WriteFieldEndError: } func (p *SeckillVoucher) writeField4(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("beginTime", thrift.STRING, 4); err != nil { + if err = oprot.WriteFieldBegin("subTitle", thrift.STRING, 4); err != nil { goto WriteFieldBeginError } - if err := oprot.WriteString(p.BeginTime); err != nil { + if err := oprot.WriteString(p.SubTitle); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -1020,10 +1281,10 @@ WriteFieldEndError: } func (p *SeckillVoucher) writeField5(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("endTime", thrift.STRING, 5); err != nil { + if err = oprot.WriteFieldBegin("rules", thrift.STRING, 5); err != nil { goto WriteFieldBeginError } - if err := oprot.WriteString(p.EndTime); err != nil { + if err := oprot.WriteString(p.Rules); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -1037,10 +1298,10 @@ WriteFieldEndError: } func (p *SeckillVoucher) writeField6(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("updateTime", thrift.STRING, 6); err != nil { + if err = oprot.WriteFieldBegin("payValue", thrift.I64, 6); err != nil { goto WriteFieldBeginError } - if err := oprot.WriteString(p.UpdateTime); err != nil { + if err := oprot.WriteI64(p.PayValue); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -1053,6 +1314,159 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 6 end error: ", p), err) } +func (p *SeckillVoucher) writeField7(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("actualValue", thrift.I64, 7); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.ActualValue); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 7 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 7 end error: ", p), err) +} + +func (p *SeckillVoucher) writeField8(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("type", thrift.BYTE, 8); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteByte(p.Type); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 8 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 8 end error: ", p), err) +} + +func (p *SeckillVoucher) writeField9(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("status", thrift.BYTE, 9); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteByte(p.Status); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 9 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 9 end error: ", p), err) +} + +func (p *SeckillVoucher) writeField10(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("createTime", thrift.STRING, 10); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.CreateTime); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 10 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 10 end error: ", p), err) +} + +func (p *SeckillVoucher) writeField11(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("updateTime", thrift.STRING, 11); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.UpdateTime); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 11 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 11 end error: ", p), err) +} + +func (p *SeckillVoucher) writeField12(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("voucherId", thrift.I64, 12); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.VoucherId); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 12 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 12 end error: ", p), err) +} + +func (p *SeckillVoucher) writeField13(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("stock", thrift.I32, 13); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI32(p.Stock); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 13 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 13 end error: ", p), err) +} + +func (p *SeckillVoucher) writeField15(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("beginTime", thrift.STRING, 15); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.BeginTime); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 15 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 15 end error: ", p), err) +} + +func (p *SeckillVoucher) writeField16(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("endTime", thrift.STRING, 16); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.EndTime); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 16 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 16 end error: ", p), err) +} + func (p *SeckillVoucher) String() string { if p == nil { return "" @@ -1072,6 +1486,7 @@ type VoucherOrder struct { UseTime string `thrift:"useTime,8" gorm:"column:use_time" form:"useTime" json:"useTime" query:"useTime"` RefundTime string `thrift:"refundTime,9" gorm:"column:refund_time" form:"refundTime" json:"refundTime" query:"refundTime"` UpdateTime string `thrift:"updateTime,10" gorm:"column:update_time;default:CURRENT_TIMESTAMP;autoUpdateTime" form:"updateTime" json:"updateTime" query:"updateTime"` + OrderId int64 `thrift:"orderId,11" gorm:"column:order_id" form:"orderId" json:"orderId" query:"orderId"` } func NewVoucherOrder() *VoucherOrder { @@ -1121,6 +1536,10 @@ func (p *VoucherOrder) GetUpdateTime() (v string) { return p.UpdateTime } +func (p *VoucherOrder) GetOrderId() (v int64) { + return p.OrderId +} + var fieldIDToName_VoucherOrder = map[int16]string{ 1: "id", 2: "userId", @@ -1132,6 +1551,7 @@ var fieldIDToName_VoucherOrder = map[int16]string{ 8: "useTime", 9: "refundTime", 10: "updateTime", + 11: "orderId", } func (p *VoucherOrder) Read(iprot thrift.TProtocol) (err error) { @@ -1233,6 +1653,14 @@ func (p *VoucherOrder) Read(iprot thrift.TProtocol) (err error) { } else if err = iprot.Skip(fieldTypeId); err != nil { goto SkipFieldError } + case 11: + if fieldTypeId == thrift.I64 { + if err = p.ReadField11(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } default: if err = iprot.Skip(fieldTypeId); err != nil { goto SkipFieldError @@ -1372,6 +1800,17 @@ func (p *VoucherOrder) ReadField10(iprot thrift.TProtocol) error { p.UpdateTime = _field return nil } +func (p *VoucherOrder) ReadField11(iprot thrift.TProtocol) error { + + var _field int64 + if v, err := iprot.ReadI64(); err != nil { + return err + } else { + _field = v + } + p.OrderId = _field + return nil +} func (p *VoucherOrder) Write(oprot thrift.TProtocol) (err error) { var fieldId int16 @@ -1419,6 +1858,10 @@ func (p *VoucherOrder) Write(oprot thrift.TProtocol) (err error) { fieldId = 10 goto WriteFieldError } + if err = p.writeField11(oprot); err != nil { + fieldId = 11 + goto WriteFieldError + } } if err = oprot.WriteFieldStop(); err != nil { goto WriteFieldStopError @@ -1607,6 +2050,23 @@ WriteFieldEndError: return thrift.PrependError(fmt.Sprintf("%T write field 10 end error: ", p), err) } +func (p *VoucherOrder) writeField11(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("orderId", thrift.I64, 11); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteI64(p.OrderId); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 11 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 11 end error: ", p), err) +} + func (p *VoucherOrder) String() string { if p == nil { return "" @@ -1616,9 +2076,9 @@ func (p *VoucherOrder) String() string { } type VoucherService interface { - VoucherList(ctx context.Context, request *Empty) (r []*Voucher, err error) + VoucherList(ctx context.Context, request int64) (r []*SeckillVoucher, err error) - SeckillVoucher(ctx context.Context, request *Empty) (r int64, err error) + SeckillVoucher(ctx context.Context, request int64) (r int64, err error) } type VoucherServiceClient struct { @@ -1647,7 +2107,7 @@ func (p *VoucherServiceClient) Client_() thrift.TClient { return p.c } -func (p *VoucherServiceClient) VoucherList(ctx context.Context, request *Empty) (r []*Voucher, err error) { +func (p *VoucherServiceClient) VoucherList(ctx context.Context, request int64) (r []*SeckillVoucher, err error) { var _args VoucherServiceVoucherListArgs _args.Request = request var _result VoucherServiceVoucherListResult @@ -1656,7 +2116,7 @@ func (p *VoucherServiceClient) VoucherList(ctx context.Context, request *Empty) } return _result.GetSuccess(), nil } -func (p *VoucherServiceClient) SeckillVoucher(ctx context.Context, request *Empty) (r int64, err error) { +func (p *VoucherServiceClient) SeckillVoucher(ctx context.Context, request int64) (r int64, err error) { var _args VoucherServiceSeckillVoucherArgs _args.Request = request var _result VoucherServiceSeckillVoucherResult @@ -1727,7 +2187,7 @@ func (p *voucherServiceProcessorVoucherList) Process(ctx context.Context, seqId iprot.ReadMessageEnd() var err2 error result := VoucherServiceVoucherListResult{} - var retval []*Voucher + var retval []*SeckillVoucher if retval, err2 = p.handler.VoucherList(ctx, args.Request); err2 != nil { x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing VoucherList: "+err2.Error()) oprot.WriteMessageBegin("VoucherList", thrift.EXCEPTION, seqId) @@ -1805,7 +2265,7 @@ func (p *voucherServiceProcessorSeckillVoucher) Process(ctx context.Context, seq } type VoucherServiceVoucherListArgs struct { - Request *Empty `thrift:"request,1"` + Request int64 `thrift:"request,1"` } func NewVoucherServiceVoucherListArgs() *VoucherServiceVoucherListArgs { @@ -1815,12 +2275,7 @@ func NewVoucherServiceVoucherListArgs() *VoucherServiceVoucherListArgs { func (p *VoucherServiceVoucherListArgs) InitDefault() { } -var VoucherServiceVoucherListArgs_Request_DEFAULT *Empty - -func (p *VoucherServiceVoucherListArgs) GetRequest() (v *Empty) { - if !p.IsSetRequest() { - return VoucherServiceVoucherListArgs_Request_DEFAULT - } +func (p *VoucherServiceVoucherListArgs) GetRequest() (v int64) { return p.Request } @@ -1828,10 +2283,6 @@ var fieldIDToName_VoucherServiceVoucherListArgs = map[int16]string{ 1: "request", } -func (p *VoucherServiceVoucherListArgs) IsSetRequest() bool { - return p.Request != nil -} - func (p *VoucherServiceVoucherListArgs) Read(iprot thrift.TProtocol) (err error) { var fieldTypeId thrift.TType @@ -1852,7 +2303,7 @@ func (p *VoucherServiceVoucherListArgs) Read(iprot thrift.TProtocol) (err error) switch fieldId { case 1: - if fieldTypeId == thrift.STRUCT { + if fieldTypeId == thrift.I64 { if err = p.ReadField1(iprot); err != nil { goto ReadFieldError } @@ -1889,9 +2340,12 @@ ReadStructEndError: } func (p *VoucherServiceVoucherListArgs) ReadField1(iprot thrift.TProtocol) error { - _field := NewEmpty() - if err := _field.Read(iprot); err != nil { + + var _field int64 + if v, err := iprot.ReadI64(); err != nil { return err + } else { + _field = v } p.Request = _field return nil @@ -1926,10 +2380,10 @@ WriteStructEndError: } func (p *VoucherServiceVoucherListArgs) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("request", thrift.STRUCT, 1); err != nil { + if err = oprot.WriteFieldBegin("request", thrift.I64, 1); err != nil { goto WriteFieldBeginError } - if err := p.Request.Write(oprot); err != nil { + if err := oprot.WriteI64(p.Request); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { @@ -1951,7 +2405,7 @@ func (p *VoucherServiceVoucherListArgs) String() string { } type VoucherServiceVoucherListResult struct { - Success []*Voucher `thrift:"success,0,optional"` + Success []*SeckillVoucher `thrift:"success,0,optional"` } func NewVoucherServiceVoucherListResult() *VoucherServiceVoucherListResult { @@ -1961,9 +2415,9 @@ func NewVoucherServiceVoucherListResult() *VoucherServiceVoucherListResult { func (p *VoucherServiceVoucherListResult) InitDefault() { } -var VoucherServiceVoucherListResult_Success_DEFAULT []*Voucher +var VoucherServiceVoucherListResult_Success_DEFAULT []*SeckillVoucher -func (p *VoucherServiceVoucherListResult) GetSuccess() (v []*Voucher) { +func (p *VoucherServiceVoucherListResult) GetSuccess() (v []*SeckillVoucher) { if !p.IsSetSuccess() { return VoucherServiceVoucherListResult_Success_DEFAULT } @@ -2039,8 +2493,8 @@ func (p *VoucherServiceVoucherListResult) ReadField0(iprot thrift.TProtocol) err if err != nil { return err } - _field := make([]*Voucher, 0, size) - values := make([]Voucher, size) + _field := make([]*SeckillVoucher, 0, size) + values := make([]SeckillVoucher, size) for i := 0; i < size; i++ { _elem := &values[i] _elem.InitDefault() @@ -2122,7 +2576,7 @@ func (p *VoucherServiceVoucherListResult) String() string { } type VoucherServiceSeckillVoucherArgs struct { - Request *Empty `thrift:"request,1"` + Request int64 `thrift:"request,1"` } func NewVoucherServiceSeckillVoucherArgs() *VoucherServiceSeckillVoucherArgs { @@ -2132,12 +2586,7 @@ func NewVoucherServiceSeckillVoucherArgs() *VoucherServiceSeckillVoucherArgs { func (p *VoucherServiceSeckillVoucherArgs) InitDefault() { } -var VoucherServiceSeckillVoucherArgs_Request_DEFAULT *Empty - -func (p *VoucherServiceSeckillVoucherArgs) GetRequest() (v *Empty) { - if !p.IsSetRequest() { - return VoucherServiceSeckillVoucherArgs_Request_DEFAULT - } +func (p *VoucherServiceSeckillVoucherArgs) GetRequest() (v int64) { return p.Request } @@ -2145,10 +2594,6 @@ var fieldIDToName_VoucherServiceSeckillVoucherArgs = map[int16]string{ 1: "request", } -func (p *VoucherServiceSeckillVoucherArgs) IsSetRequest() bool { - return p.Request != nil -} - func (p *VoucherServiceSeckillVoucherArgs) Read(iprot thrift.TProtocol) (err error) { var fieldTypeId thrift.TType @@ -2169,7 +2614,7 @@ func (p *VoucherServiceSeckillVoucherArgs) Read(iprot thrift.TProtocol) (err err switch fieldId { case 1: - if fieldTypeId == thrift.STRUCT { + if fieldTypeId == thrift.I64 { if err = p.ReadField1(iprot); err != nil { goto ReadFieldError } @@ -2206,9 +2651,12 @@ ReadStructEndError: } func (p *VoucherServiceSeckillVoucherArgs) ReadField1(iprot thrift.TProtocol) error { - _field := NewEmpty() - if err := _field.Read(iprot); err != nil { + + var _field int64 + if v, err := iprot.ReadI64(); err != nil { return err + } else { + _field = v } p.Request = _field return nil @@ -2243,10 +2691,10 @@ WriteStructEndError: } func (p *VoucherServiceSeckillVoucherArgs) writeField1(oprot thrift.TProtocol) (err error) { - if err = oprot.WriteFieldBegin("request", thrift.STRUCT, 1); err != nil { + if err = oprot.WriteFieldBegin("request", thrift.I64, 1); err != nil { goto WriteFieldBeginError } - if err := p.Request.Write(oprot); err != nil { + if err := oprot.WriteI64(p.Request); err != nil { return err } if err = oprot.WriteFieldEnd(); err != nil { diff --git a/biz/model/xzdp/xzdp.go b/biz/model/xzdp/xzdp.go index 8676675..bfa5fcb 100644 --- a/biz/model/xzdp/xzdp.go +++ b/biz/model/xzdp/xzdp.go @@ -1,4 +1,4 @@ -// Code generated by thriftgo (0.3.14). DO NOT EDIT. +// Code generated by thriftgo (0.3.15). DO NOT EDIT. package xzdp diff --git a/biz/pkg/constants/constants.go b/biz/pkg/constants/constants.go index c24021e..32f5cc7 100644 --- a/biz/pkg/constants/constants.go +++ b/biz/pkg/constants/constants.go @@ -16,7 +16,6 @@ const ( LOCK_SHOP_KEY = "lock:shop:" LOCK_KEY = "lock:" LOGIN_CODE_EXPIRE = 300 - ID_KEY = "id:" USER_SIGN_KEY = "user:sign:" ) @@ -43,3 +42,10 @@ const ( STREAM_READ_GROUP = "stream.group:1" STREAM_CONSUMER = "stream.consume:" ) + +// voucher 相关 +const ( + BEGIN_TIMESTAMP = 1725120000 + ICRID_KEY = "id:" + COUNT_BIT = 32 +) diff --git a/biz/router/voucher/middleware.go b/biz/router/voucher/middleware.go index 58904e2..b6c6270 100644 --- a/biz/router/voucher/middleware.go +++ b/biz/router/voucher/middleware.go @@ -25,3 +25,18 @@ func _voucherlistMw() []app.HandlerFunc { // your code... return nil } + +func _voucher_orderMw() []app.HandlerFunc { + // your code... + return nil +} + +func _seckillMw() []app.HandlerFunc { + // your code... + return nil +} + +func _seckillvoucherMw() []app.HandlerFunc { + // your code... + return nil +} diff --git a/biz/router/voucher/voucher.go b/biz/router/voucher/voucher.go index 6319bde..25c053a 100644 --- a/biz/router/voucher/voucher.go +++ b/biz/router/voucher/voucher.go @@ -24,4 +24,11 @@ func Register(r *server.Hertz) { _list.GET("/:id", append(_voucherlistMw(), voucher.VoucherList)...) } } + { + _voucher_order := root.Group("/voucher-order", _voucher_orderMw()...) + { + _seckill := _voucher_order.Group("/seckill", _seckillMw()...) + _seckill.POST("/:id", append(_seckillvoucherMw(), voucher.SeckillVoucher)...) + } + } } diff --git a/biz/service/voucher/seckill_voucher.go b/biz/service/voucher/seckill_voucher.go new file mode 100644 index 0000000..d94b80c --- /dev/null +++ b/biz/service/voucher/seckill_voucher.go @@ -0,0 +1,78 @@ +package voucher + +import ( + "context" + "errors" + "github.com/cloudwego/hertz/pkg/app" + "time" + "xzdp/biz/dal/mysql" + "xzdp/biz/dal/redis" + voucherModel "xzdp/biz/model/voucher" + "xzdp/biz/utils" +) + +type SeckillVoucherService struct { + RequestContext *app.RequestContext + Context context.Context +} + +func NewSeckillVoucherService(Context context.Context, RequestContext *app.RequestContext) *SeckillVoucherService { + return &SeckillVoucherService{RequestContext: RequestContext, Context: Context} +} + +func (h *SeckillVoucherService) Run(req *int64) (resp *int64, err error) { + //defer func() { + // hlog.CtxInfof(h.Context, "req = %+v", req) + // hlog.CtxInfof(h.Context, "resp = %+v", resp) + //}() + // todo edit your code + //0.查询秒杀券 + voucher, err := mysql.QueryVoucherByID(h.Context, *req) + if err != nil { + return nil, err + } + now := time.Now() + //1.判断是否开始&&结束 + layout := "2006-01-02T15:04:05+08:00" + beginTime, _ := time.Parse(layout, voucher.GetBeginTime()) + endTime, _ := time.Parse(layout, voucher.GetEndTime()) + if beginTime.After(now) { + return nil, errors.New("秒杀还未开始") + } + if endTime.Before(now) { + return nil, errors.New("秒杀已经结束") + } + //2.判断库存是否充足 + if voucher.GetStock() <= 0 { + return nil, errors.New("已抢空") + } + //3.判断是否已经购买 + userId := utils.GetUser(h.Context).GetID() + order, err := mysql.QueryVoucherOrderByVoucherID(h.Context, userId, *req) + if order != nil { + return nil, err + } + //4.扣减库存 + err = mysql.UpdateVoucherStock(h.Context, *req) + if err != nil { + return nil, err + } + //5.创建订单 + orderId, err := redis.NextId(h.Context, "order") + if err != nil { + return nil, err + } + voucherOrder := &voucherModel.VoucherOrder{ + UserId: userId, + VoucherId: *req, + OrderId: orderId, + PayTime: time.Now().Format(layout), + UseTime: "0000-00-00 00:00:00", + RefundTime: "0000-00-00 00:00:00", + } + err = mysql.CreateVoucherOrder(h.Context, voucherOrder) + if err != nil { + return nil, err + } + return &orderId, nil +} diff --git a/biz/service/voucher/seckill_voucher_test.go b/biz/service/voucher/seckill_voucher_test.go new file mode 100644 index 0000000..e318e8e --- /dev/null +++ b/biz/service/voucher/seckill_voucher_test.go @@ -0,0 +1,22 @@ +package voucher + +import ( + "context" + "testing" + + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/common/test/assert" + voucher "xzdp/biz/model/voucher" +) + +func TestSeckillVoucherService_Run(t *testing.T) { + ctx := context.Background() + c := app.NewContext(1) + s := NewSeckillVoucherService(ctx, c) + // init req and assert value + req := &voucher.Empty{} + resp, err := s.Run(req) + assert.DeepEqual(t, nil, resp) + assert.DeepEqual(t, nil, err) + // todo edit your unit test. +} diff --git a/biz/service/voucher/voucher_list.go b/biz/service/voucher/voucher_list.go index 50aea20..b6e7de2 100644 --- a/biz/service/voucher/voucher_list.go +++ b/biz/service/voucher/voucher_list.go @@ -16,7 +16,7 @@ func NewVoucherListService(Context context.Context, RequestContext *app.RequestC return &VoucherListService{RequestContext: RequestContext, Context: Context} } -func (h *VoucherListService) Run(id int64) (resp *[]*voucher.Voucher, err error) { - result, err := mysql.QueryVoucherByID(h.Context, id) +func (h *VoucherListService) Run(id int64) (resp *[]*voucher.SeckillVoucher, err error) { + result, err := mysql.QueryShopVoucherByShopID(h.Context, id) return &result, nil } diff --git a/go.mod b/go.mod index 4af6aa6..d8f412d 100755 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/go-redis/redis/v8 v8.11.5 github.com/hertz-contrib/sse v0.0.5 github.com/jinzhu/copier v0.4.0 - github.com/kr/pretty v0.3.1 github.com/stretchr/testify v1.8.1 gopkg.in/validator.v2 v2.0.1 gopkg.in/yaml.v2 v2.4.0 @@ -37,10 +36,9 @@ require ( github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect - github.com/kr/text v0.2.0 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/nyaruka/phonenumbers v1.0.55 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rogpeppe/go-internal v1.9.0 // indirect github.com/stretchr/objx v0.5.0 // indirect github.com/tidwall/gjson v1.14.4 // indirect github.com/tidwall/match v1.1.1 // indirect diff --git a/idl/voucher.thrift b/idl/voucher.thrift index a2a024d..681ed70 100644 --- a/idl/voucher.thrift +++ b/idl/voucher.thrift @@ -17,12 +17,21 @@ struct Voucher { } struct SeckillVoucher { - 1: i64 voucherId (go.tag='gorm:"voucher_id"'); - 2: i32 stock (go.tag='gorm:"stock"'); - 3: string createTime (go.tag='gorm:"create_time"'); - 4: string beginTime (go.tag='gorm:"begin_time"'); - 5: string endTime (go.tag='gorm:"end_time"'); - 6: string updateTime (go.tag='gorm:"update_time"'); + 1: i64 id (go.tag='gorm:"id"'); + 2: i64 shopId (go.tag='gorm:"shop_id"'); + 3: string title (go.tag='gorm:"title"'); + 4: string subTitle (go.tag='gorm:"sub_title"'); + 5: string rules (go.tag='gorm:"rules"'); + 6: i64 payValue (go.tag='gorm:"pay_value"'); + 7: i64 actualValue (go.tag='gorm:"actual_value"'); + 8: i8 type (go.tag='gorm:"type"'); + 9: i8 status (go.tag='gorm:"status"'); + 10: string createTime (go.tag='gorm:"create_time"'); + 11: string updateTime (go.tag='gorm:"update_time"'); + 12: i64 voucherId (go.tag='gorm:"voucher_id"'); + 13: i32 stock (go.tag='gorm:"stock"'); + 15: string beginTime (go.tag='gorm:"begin_time"'); + 16: string endTime (go.tag='gorm:"end_time"'); } struct VoucherOrder { @@ -36,9 +45,10 @@ struct VoucherOrder { 8: string useTime (go.tag='gorm:"column:use_time"'); 9: string refundTime (go.tag='gorm:"column:refund_time"'); 10: string updateTime (go.tag='gorm:"column:update_time;default:CURRENT_TIMESTAMP;autoUpdateTime"'); + 11: i64 orderId (go.tag='gorm:"column:order_id"'); } service VoucherService { - list VoucherList(1: Empty request) (api.get="/voucher/list/:id"); - i64 SeckillVoucher(1: Empty request) (pi.post="/seckill/:id"); -} \ No newline at end of file + list VoucherList(1: i64 request) (api.get="/voucher/list/:id"); + i64 SeckillVoucher(1: i64 request) (api.post="/voucher-order/seckill/:id"); +}