Browse Source

fix:bug

dev
Tooooommy 4 years ago
parent
commit
e3df412599
  1. 12
      controllers/client/good.go
  2. 25
      controllers/client/order_entry.go
  3. 13
      models/customer_order_sub.go

12
controllers/client/good.go

@ -64,12 +64,24 @@ func (t *GoodCtl) ListGood() {
return
}
// 库存
goods, err := models.GetGoodsByActivityId(activityId, area.Id)
t.CheckErr(err)
goodIds := make([]int, 0)
for _, g := range goods {
goodIds = append(goodIds, g.Id)
}
res, err := models.GetSubOrderGoodNumByGoodIds(goodIds)
t.CheckErr(err)
for index := range goods {
goods[index].GoodType = option.PostFeeType
goods[index].Postage = option.PostFee
for _, v := range res {
if goods[index].Id == v.GoodsId {
goods[index].Stock -= v.GoodsNum
}
}
}
t.JSON(goods)
return

25
controllers/client/order_entry.go

@ -44,15 +44,26 @@ func (t *OrderEntryCtl) List() {
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
}
// 库存
goods, err := models.GetGoodsByActivityId(activityId, area.Id)
t.CheckErr(err)
if _type == define.TYPE_USER {
for index := range goods {
url := fmt.Sprintf("%s/PcClient/Client/OrderEntryCtl/order?"+
"user_id=%d&activity_id=%d&good_id=%d", define.HOST, uid, activityId, goods[index].Id)
qrcode, err := utils.Qrcode2Base64(url)
t.CheckErr(err)
goods[index].Qrcode = qrcode
goodIds := make([]int, 0)
for _, g := range goods {
goodIds = append(goodIds, g.Id)
}
res, err := models.GetSubOrderGoodNumByGoodIds(goodIds)
t.CheckErr(err)
for index := range goods {
url := fmt.Sprintf("%s/PcClient/Client/OrderEntryCtl/order?"+
"user_id=%d&activity_id=%d&good_id=%d", define.HOST, uid, activityId, goods[index].Id)
qrcode, err := utils.Qrcode2Base64(url)
t.CheckErr(err)
goods[index].Qrcode = qrcode
for _, v := range res {
if goods[index].Id == v.GoodsId {
goods[index].Stock -= v.GoodsNum
}
}
}

13
models/customer_order_sub.go

@ -63,3 +63,16 @@ func GetSubOrdersByOrderId(orderId interface{}) ([]*CustomerOrderSub, error) {
err := core.GetXormAuto().Where("is_delete=0 and order_id=?", orderId).Find(&subs)
return subs, err
}
type OrderGoodNum struct {
GoodsId int `json:"goods_id"`
GoodsNum int `json:"goods_num"`
}
func GetSubOrderGoodNumByGoodIds(goodIds interface{}) (res []*OrderGoodNum, err error) {
err = core.GetXormAuto().Table(&CustomerOrderSub{}).Alias("s").Select("s.goods_id, SUM(s.goods_num) as goods_num").
Join("left", (&CustomerOrder{}).TableName()+" as o", "o.id=s.order_id").
Where("o.is_delete=0 and s.is_delete=0").In("s.goods_id", goodIds).
NotIn("o.status", "0", "8", "9").Find(&res)
return
}
Loading…
Cancel
Save