Browse Source

sub order

master
黄梓健 5 years ago
parent
commit
10e9644185
  1. 4
      controllers/client/good.go
  2. 27
      controllers/common/im.go
  3. 15
      models/customer_order.go
  4. 11
      models/customer_order_sub.go
  5. 1
      services/im/im.go
  6. 34
      services/pay/handle.go

4
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)
}
}

27
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)
}
}
}

15
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 {

11
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
//}

1
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)

34
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,

Loading…
Cancel
Save