You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.1 KiB
Go
100 lines
2.1 KiB
Go
package mall
|
|
|
|
import (
|
|
"joybuywork/internal/repository/model"
|
|
"joybuywork/internal/repository/mtype"
|
|
"joybuywork/internal/repository/withdefault"
|
|
"joybuywork/internal/service/provider/malls"
|
|
"joybuywork/internal/utils/logic"
|
|
"time"
|
|
|
|
pb "joybuywork/proto/go_proto/w_mall"
|
|
)
|
|
|
|
type ItemStore struct {
|
|
logic.Logic
|
|
|
|
Req *pb.ItemStoreReq
|
|
Res *pb.ItemStoreRes
|
|
}
|
|
|
|
func (s *ItemStore) Run() (err error) {
|
|
return logic.Run(s)
|
|
}
|
|
|
|
func (s *ItemStore) Exec() (err error) {
|
|
|
|
item, err := s.store()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return s.task(item)
|
|
}
|
|
|
|
func (s *ItemStore) store() (item *model.RedeemMallItem, err error) {
|
|
mall, err := malls.NewMall(s.Ctx, s.Req.GetMallId())
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
item = withdefault.RedeemMallItem(&model.RedeemMallItem{
|
|
MallID: mall.GetMall().ID,
|
|
RewardID: s.Req.GetRewardId(),
|
|
CoinNum: s.Req.GetCoinNum(),
|
|
Stock: s.Req.GetStock(),
|
|
UpType: int8(s.Req.GetUpType()),
|
|
DownType: int8(s.Req.GetDownType()),
|
|
DownCustom: s.Req.GetDownCustom(),
|
|
})
|
|
|
|
switch s.Req.GetUpType() {
|
|
case mtype.RedeemMallItemUpTypeNow:
|
|
item.UpAt = time.Now().Unix()
|
|
item.UpFrom = mtype.RedeemMallItemUpFromNow
|
|
case mtype.RedeemMallItemUpTypeCustom:
|
|
item.UpCustom = s.Req.GetUpCustom()
|
|
item.UpAt = s.Req.GetUpCustom()
|
|
item.UpFrom = mtype.RedeemMallItemUpFromTiming
|
|
}
|
|
|
|
list, err := mall.UpItems()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if len(list) > 0 {
|
|
item.Sort = list[0].Sort + 1
|
|
}
|
|
|
|
item.SetUpShow(s.Req.GetUpShow())
|
|
item.SetDownShow(s.Req.GetDownShow())
|
|
|
|
if err = s.GetDao().RedeemMallItem.WithContext(s.Ctx).Create(item); err != nil {
|
|
err = s.BE().MysqlError(err)
|
|
return
|
|
}
|
|
|
|
s.Res.Id = item.ID
|
|
|
|
return
|
|
}
|
|
|
|
func (s *ItemStore) task(item *model.RedeemMallItem) (err error) {
|
|
if item.DownType == mtype.RedeemMallItemDownTypeCustom {
|
|
|
|
task := withdefault.RedeemMallItemTask(&model.RedeemMallItemTask{
|
|
ItemID: item.ID,
|
|
DoAt: item.DownCustom,
|
|
Mark: mtype.RedeemMallItemTaskMarkDown,
|
|
})
|
|
|
|
if err = s.GetDao().RedeemMallItemTask.WithContext(s.Ctx).Create(task); err != nil {
|
|
err = s.BE().MysqlError(err)
|
|
return
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|