123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- package logic
- import (
- "app.yhyue.com/moapp/jyMarketing/util"
- "app.yhyue.com/moapp/jybase/common"
- "context"
- "time"
- "app.yhyue.com/moapp/jyMarketing/rpc/activity"
- "app.yhyue.com/moapp/jyMarketing/rpc/internal/svc"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type GetAllActivityLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewGetAllActivityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllActivityLogic {
- return &GetAllActivityLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 商品下活动获取
- func (l *GetAllActivityLogic) GetAllActivity(in *activity.Request) (*activity.ActivityResp, error) {
- result := &activity.ActivityResp{}
- code, msg, activityData := activityServiceNew.GetAllActivity(in)
- var activityArr []*activity.ActivityJson
- for _, activityValue := range activityData {
- activityEntity := activity.ActivityJson{}
- timeBool := util.ActivityTime(activityValue.BeginDate) && !util.ActivityTimeOther(activityValue.EndDate) && util.ActivityTime(activityValue.PreheatingTime)
- var lotteryList []*activity.LotteryJson
- for _, value := range activityValue.LotteryData {
- lottery := activity.LotteryJson{}
- lottery.LotteryId = value.LotteryId
- lottery.LotteryName = value.Name
- lottery.IsReceive = false
- //IsReceive 是否可以领取true可以领取false不可领取
- //IsUser 是否使用 true 使用 false未使用
- if activityValue.ActivityType < 2 {
- //活动已开始 时间判断 剩余量判断
- if timeBool {
- if value.StockNumber == 0 {
- //库存不足
- lottery.IsReceive = false
- } else {
- //还有库存
- if value.IsLimitNumber == 0 {
- if value.Count > 0 {
- lottery.IsReceive = false
- } else {
- if value.AllUserCount >= common.Int64All(value.LimitNumber) {
- lottery.IsReceive = false
- } else {
- if value.UserCount >= common.Int64All(value.LimitNumber) {
- } else {
- lottery.IsReceive = true
- }
- }
- }
- } else {
- if value.Count > 0 {
- lottery.IsReceive = false
- } else {
- if value.UserCount == 0 {
- lottery.IsReceive = true
- }
- }
- }
- }
- } else {
- //活动未开始
- lottery.IsReceive = false
- }
- //奖券领取线坠
- lottery.IsUser = false
- if value.UserCount > 0 {
- lottery.IsUser = true
- }
- lottery.LotteryBeginDate = value.BeginDate.Format("2006-01-02 15:04:05")
- lottery.LotteryendDate = value.EndDate.Format("2006-01-02 15:04:05")
- } else {
- //其他奖券领取限制
- /*if timeBool {
- if value.StockNumber == 0 {
- //库存不足
- lottery.IsReceive = false
- } else {
- lottery.IsReceive = true
- }
- }*/
- lottery.IsReceive = false
- lottery.PromotionalPrice = value.PromotionalPrice
- lottery.GiftCode = value.GiftCode
- }
- lottery.LotteryType = value.LotteryType
- lottery.Instructions = value.Instructions
- lottery.StockNumber = value.StockNumber
- lottery.ReceiveNumber = value.ReceiveNumber
- lottery.Full = value.Full
- lottery.Reduce = value.Reduce
- lottery.Remark = value.Remark
- lottery.Discount = float32(value.Discount)
- lotteryList = append(lotteryList, &lottery)
- }
- activityEntity.LotteryJson = lotteryList
- endDate, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.EndDate, time.Local)
- activityEntity.ActivityendDate = endDate.Format("2006年01月02日 15时04分05秒")
- beginDate, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.BeginDate, time.Local)
- activityEntity.ActivityBeginDate = beginDate.Format("2006年01月02日 15时04分05秒")
- activityEntity.ActivityName = activityValue.Name
- activityEntity.ActivityDesc = activityValue.ActivityDesc
- activityEntity.ReceivingLocation = activityValue.ReceivingLocation
- switch activityValue.ActivityType {
- case 0:
- activityEntity.ActivityType = "满减券"
- case 1:
- activityEntity.ActivityType = "满折券"
- case 2:
- activityEntity.ActivityType = "满赠"
- case 3:
- activityEntity.ActivityType = "促销"
- case 4:
- activityEntity.ActivityType = "限时折扣"
- case 5:
- activityEntity.ActivityType = "限时减免"
- }
- if activityValue.PreheatingTime == "" {
- activityEntity.PreheatingTime = 0
- } else {
- PreheatingTime, _ := time.ParseInLocation("2006-01-02 15:04:05", activityValue.PreheatingTime, time.Local)
- activityEntity.PreheatingTime = PreheatingTime.Unix()
- }
- activityArr = append(activityArr, &activityEntity)
- }
- result.Code = code
- result.Message = msg
- result.ActivityJson = activityArr
- return result, nil
- }
|