Browse Source

order no to sub

master
黄梓健 5 years ago
parent
commit
39712e48b6
  1. 8
      controllers/client/good.go
  2. 8
      models/customer_order_sub.go
  3. 5
      test/pay_test.go

8
controllers/client/good.go

@ -81,16 +81,16 @@ func (t *GoodCtl) ListOrder() {
orders, err := models.GetCustomerOrdersByActivityId(uid, activity.Id, activity.RehearsalId, orders, err := models.GetCustomerOrdersByActivityId(uid, activity.Id, activity.RehearsalId,
areaId, statusList, t.Page, t.PageSize) areaId, statusList, t.Page, t.PageSize)
t.CheckErr(err) t.CheckErr(err)
outTradeNos := make([]string, 0)
orderNos := make([]string, 0)
for _, order := range orders { for _, order := range orders {
outTradeNos = append(outTradeNos, order.OutTradeNo)
orderNos = append(orderNos, order.OrderNo)
} }
subs, err := models.GetCustomerOrderSubByOutTradeNos(outTradeNos...)
subs, err := models.GetCustomerOrderSubByOrderNos(orderNos...)
t.CheckErr(err) t.CheckErr(err)
for index, order := range orders { for index, order := range orders {
order.ServicePhone = option.MainServicePhone order.ServicePhone = option.MainServicePhone
for _, sub := range subs { for _, sub := range subs {
if order.OutTradeNo == sub["out_trade_no"] {
if order.OrderNo == sub["order_no"] {
orders[index].SubOrders = append(orders[index].SubOrders, sub) orders[index].SubOrders = append(orders[index].SubOrders, sub)
} }
} }

8
models/customer_order_sub.go

@ -32,11 +32,11 @@ func (t *CustomerOrderSub) Alias(n string) string {
return fmt.Sprintf("%s as %s", t.TableName(), n) return fmt.Sprintf("%s as %s", t.TableName(), n)
} }
func GetCustomerOrderSubByOutTradeNos(outTradeNos ...string) (subs []map[string]string, err error) {
func GetCustomerOrderSubByOrderNos(orderNos ...string) (subs []map[string]string, err error) {
err = core.GetXormAuto().Table(new(CustomerOrderSub)).Alias("s"). err = core.GetXormAuto().Table(new(CustomerOrderSub)).Alias("s").
Select("s.out_trade_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").In("s.out_trade_no", outTradeNos).
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").In("s.order_no", orderNos).
Desc("s.created_at").Find(&subs) Desc("s.created_at").Find(&subs)
return return
} }

5
test/pay_test.go

@ -26,10 +26,10 @@ func TestSendRedPack(t *testing.T) {
func TestQueryOrder(t *testing.T) { func TestQueryOrder(t *testing.T) {
//outTradeNo := "Dn13Gl6A6dB6aOae7syqtXSwUvCZ3mta" //outTradeNo := "Dn13Gl6A6dB6aOae7syqtXSwUvCZ3mta"
outTradeNo := "jGrqipGJdcxQz4uwSTQqrtnJ4rJE6Mx9"
outTradeNo := "6PM9n5WDSX47frNfQ9OxWEKe8u6ChBos"
res, err := pay_service.OrderQuery(outTradeNo) res, err := pay_service.OrderQuery(outTradeNo)
fmt.Println(err) fmt.Println(err)
fmt.Printf("%+v\n", res)
fmt.Printf("%+v\n", res.Query)
} }
func TestClose(t *testing.T) { func TestClose(t *testing.T) {
@ -91,4 +91,5 @@ func TestMy(t *testing.T) {
distance distance
LIMIT 100; LIMIT 100;
` `
fmt.Print(a)
} }
Loading…
Cancel
Save