From 10e96441854c7fbc46cc8282f635eda622503ecb Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Wed, 20 May 2020 12:16:55 +0800 Subject: [PATCH] sub order --- controllers/client/good.go | 4 ++-- controllers/common/im.go | 27 +++++++++++++++++++++++++++ models/customer_order.go | 15 +++++++-------- models/customer_order_sub.go | 11 ++++++++++- services/im/im.go | 1 + services/pay/handle.go | 34 +++++++++++++++++++++++++--------- 6 files changed, 72 insertions(+), 20 deletions(-) diff --git a/controllers/client/good.go b/controllers/client/good.go index 89fe656..fc58957 100644 --- a/controllers/client/good.go +++ b/controllers/client/good.go @@ -85,12 +85,12 @@ func (t *GoodCtl) ListOrder() { for _, order := range orders { orderNos = append(orderNos, order.OrderNo) } - subs, err := models.GetCustomerOrderSubByOrderNos(orderNos...) + subs, err := models.GetCustomerOrderSubsByOrderNos(orderNos...) t.CheckErr(err) for index, order := range orders { order.ServicePhone = option.MainServicePhone for _, sub := range subs { - if order.OrderNo == sub["order_no"] { + if order.OrderNo == sub.OrderNo { orders[index].SubOrders = append(orders[index].SubOrders, sub) } } diff --git a/controllers/common/im.go b/controllers/common/im.go index 189a332..4de1607 100644 --- a/controllers/common/im.go +++ b/controllers/common/im.go @@ -2,6 +2,8 @@ package common import ( "hudongzhuanjia/controllers" + "hudongzhuanjia/logger" + "hudongzhuanjia/models" im_service "hudongzhuanjia/services/im" "time" ) @@ -100,3 +102,28 @@ func (t *ImTestCtl) SendLottery() { t.SUCCESS("恭喜这B") } + +func (t *ImTestCtl) SendGood() { + userId := t.MustGetInt64("user_id") + orderNo := t.MustGet("order_no") + activityId := t.MustGetInt64("activity_id") + + subs, err := models.GetCustomerOrderSubsByOrderNos(orderNo) + if err != nil { + logger.Error("商品子订单查询异常", err) + } + for _, sub := range subs { + err = im_service.SendGroupCustomMessage(userId, activityId, im_service.NoticeLiveGoodBuy, + map[string]interface{}{ + "goods_pic_url": sub.GoodsPicUrl, + "goods_num": sub.GoodsNum, + "good_name": sub.GoodName, + "good_price": sub.GoodPrice, + "goods_id": sub.GoodsId, + "timestamp": time.Now().Unix(), + }) + if err != nil { + logger.Error("直播商品子订单信息发送异常异常", err) + } + } +} diff --git a/models/customer_order.go b/models/customer_order.go index 43acf67..cb1ebac 100644 --- a/models/customer_order.go +++ b/models/customer_order.go @@ -42,14 +42,13 @@ type CustomerOrder struct { AutoReceiveTime time.Time `json:"auto_receive_time" xorm:"comment('自动收货时间') DATETIME"` // 无关变量 - OrderTime string `json:"order_time,omitempty" xorm:"-"` - Good *CustomerGoods `json:"good,omitempty" xorm:"-"` - User *User `json:"user,omitempty" xorm:"-"` - OrderEntryPersonName string `json:"order_entry_person_name,omitempty" xorm:"-"` - ServicePhone string `json:"service_phone" xorm:"-"` - - // 无关变量 - SubOrders []map[string]string `json:"sub_orders,omitempty" xorm:"-"` + OrderTime string `json:"order_time,omitempty" xorm:"-"` + Good *CustomerGoods `json:"good,omitempty" xorm:"-"` + User *User `json:"user,omitempty" xorm:"-"` + OrderEntryPersonName string `json:"order_entry_person_name,omitempty" xorm:"-"` + ServicePhone string `json:"service_phone" xorm:"-"` + SubOrders []*CustomerOrderSub `json:"sub_orders" xorm:"-"` + //SubOrders []map[string]string `json:"sub_orders,omitempty" xorm:"-"` } func (t *CustomerOrder) TableName() string { diff --git a/models/customer_order_sub.go b/models/customer_order_sub.go index 9b57400..0fe4844 100644 --- a/models/customer_order_sub.go +++ b/models/customer_order_sub.go @@ -32,7 +32,7 @@ func (t *CustomerOrderSub) Alias(n string) string { return fmt.Sprintf("%s as %s", t.TableName(), n) } -func GetCustomerOrderSubByOrderNos(orderNos ...string) (subs []map[string]string, err error) { +func GetCustomerOrderSubsByOrderNos(orderNos ...string) (subs []*CustomerOrderSub, err error) { err = core.GetXormAuto().Table(new(CustomerOrderSub)).Alias("s"). Select("s.order_no, s.goods_id, s.goods_num, s.good_name, s.good_price, g.goods_pic_url"). Join("left", new(CustomerGoods).Alias("g"), "g.id=s.goods_id"). @@ -40,3 +40,12 @@ func GetCustomerOrderSubByOrderNos(orderNos ...string) (subs []map[string]string Desc("s.created_at").Find(&subs) return } + +//func GetCustomerOrderSubsByOutTradeNo(outTradeNo string) (subs []*CustomerOrderSub, err error) { +// err = core.GetXormAuto().Table(new(CustomerOrderSub)).Alias("s"). +// Select("s.order_no, s.goods_id, s.goods_num, s.good_name, s.good_price, g.goods_pic_url"). +// Join("left", new(CustomerGoods).Alias("g"), "g.id=s.goods_id"). +// Where("s.is_delete=0 and out_trade_no=?", outTradeNo). +// Desc("s.created_at").Find(&subs) +// return +//} diff --git a/services/im/im.go b/services/im/im.go index 4e37dd0..8d9ea45 100644 --- a/services/im/im.go +++ b/services/im/im.go @@ -24,6 +24,7 @@ const NoticeLotteryDrawStop = 263 // 抽奖结束 const NoticeLotteryDrawResult = 264 // 抽奖结果 const NoticeLotteryDrawRollStart = 265 // 开始滚动 const NoticeLotteryDrawRollStop = 266 // 停止滚动 +const NoticeLiveGoodBuy = 267 // 商品购买通知 func SendNoticeByActivityId(activityId int64, _type NoticeStatus, data map[string]interface{}, members ...string) error { live := new(models.LiveConfig) diff --git a/services/pay/handle.go b/services/pay/handle.go index 968823d..0ef1b61 100644 --- a/services/pay/handle.go +++ b/services/pay/handle.go @@ -25,6 +25,30 @@ func HandleSuccess(param *OrderDelayQueueParam) (err error) { if err != nil { return errors.New("更新状态发送错误") } + customerOrder.GetByOutTradeNO(param.Order.OutTradeNo) + if customerOrder.Status != 1 { + return errors.New("商品订单状态信息出现异常") + } + subs, err := models.GetCustomerOrderSubsByOrderNos(customerOrder.OrderNo) + if err != nil { + logger.Error("商品子订单查询异常", err) + return err + } + for _, sub := range subs { + err = im_service.SendGroupCustomMessage(customerOrder.BuyerId, param.Order.ActivityId, im_service.NoticeLiveGoodBuy, + map[string]interface{}{ + "goods_pic_url": sub.GoodsPicUrl, + "goods_num": sub.GoodsNum, + "good_name": sub.GoodName, + "good_price": sub.GoodPrice, + "goods_id": sub.GoodsId, + "timestamp": time.Now().Unix(), + }) + if err != nil { + logger.Error("直播商品子订单信息发送异常异常", err) + return err + } + } activity := new(models.Activity) exist, err = models.GetById(activity, param.Order.ActivityId) @@ -47,6 +71,7 @@ func HandleSuccess(param *OrderDelayQueueParam) (err error) { prize.PrizeImg = gift.GiftPicUrl prize.PrizeType = 4 prize.IsDelete = false + prize.Status = 1 prize.CreatedAt = time.Now() prize.UpdatedAt = time.Now() if exist { @@ -86,15 +111,6 @@ func HandleSuccess(param *OrderDelayQueueParam) (err error) { return } - user := new(models.User) - exist, err = models.GetById(user, info.UserId) - if err != nil || !exist { - err = fmt.Errorf("直播红包用户信息异常: err-> %v, exist->%v, status->%v, out_trade_no->%v", - err, exist, info.Status, param.Order.OutTradeNo) - logger.Error(err.Error()) - return - } - err = im_service.SendGroupCustomMessage(info.UserId, param.Order.ActivityId, im_service.NoticeLiveRedPackStart, map[string]interface{}{ "live_red_envelope_rule_id": info.Id,