|
|
@ -60,12 +60,14 @@ func (t *OrderEntryCtl) List() { |
|
|
|
qrcode, err := utils.Qrcode2Base64(url) |
|
|
|
t.CheckErr(err) |
|
|
|
goods[index].Qrcode = qrcode |
|
|
|
if goods[index].Stock == -1 { |
|
|
|
for _, v := range res { |
|
|
|
if goods[index].Id == v.GoodsId { |
|
|
|
goods[index].Stock -= v.GoodsNum |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
t.JSON(map[string]interface{}{ |
|
|
|
"list": goods, |
|
|
@ -129,6 +131,8 @@ func (t *OrderEntryCtl) Order() { |
|
|
|
t.ERROR("商品信息异常", code.MSG_ERR_Param) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if good.Stock > -1 { // 库存
|
|
|
|
// 找出商品库存
|
|
|
|
ms, err := models.GetSubOrderGoodNumBySession(s, good.Id) |
|
|
|
if err != nil { |
|
|
@ -143,6 +147,7 @@ func (t *OrderEntryCtl) Order() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
order := models.CustomerOrder{} |
|
|
|
// 查询库存
|
|
|
|
total, err := s.Where("is_delete=0").Count(&order) // 订单总数
|
|
|
@ -342,11 +347,12 @@ func (t *OrderEntryCtl) ManualOrder() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ms := make([]map[string]int, 0) |
|
|
|
err = s.Table(&models.CustomerOrderSub{}).Alias("s").Select("s.goods_id, COALESCE(SUM(s.goods_num), 0) as goods_num"). |
|
|
|
Join("left", (&models.CustomerOrder{}).Alias("o"), "o.id=s.order_id"). |
|
|
|
Where("o.activity_id=? and o.rehearsal_id=? and o.arch_id=?", activity.Id, activity.RehearsalId, activity.ArchId). |
|
|
|
In("s.goods_id", goodIds).GroupBy("s.goods_id").Find(&ms) |
|
|
|
// ms := make([]map[string]int, 0)
|
|
|
|
// err = s.Table(&models.CustomerOrderSub{}).Alias("s").Select("s.goods_id, COALESCE(SUM(s.goods_num), 0) as goods_num").
|
|
|
|
// Join("left", (&models.CustomerOrder{}).Alias("o"), "o.id=s.order_id").
|
|
|
|
// Where("o.activity_id=? and o.rehearsal_id=? and o.arch_id=?", activity.Id, activity.RehearsalId, activity.ArchId).
|
|
|
|
// In("s.goods_id", goodIds).GroupBy("s.goods_id").Find(&ms)
|
|
|
|
ms, err := models.GetSubOrderGoodNumBySession(s, goodIds) |
|
|
|
if err != nil { |
|
|
|
s.Rollback() |
|
|
|
t.CheckErr(err) |
|
|
@ -356,7 +362,7 @@ func (t *OrderEntryCtl) ManualOrder() { |
|
|
|
if g.Stock == -1 { // 无上限
|
|
|
|
break |
|
|
|
} |
|
|
|
if m["goods_id"] == int(g.Id) && m["goods_num"] >= g.Stock { |
|
|
|
if m.GoodsId == g.Id && g.Stock-m.GoodsNum <= 0 { |
|
|
|
s.Rollback() |
|
|
|
t.ERROR(g.Name+"商品库存不足", code.MSG_CUSTOMER_GOOD_NOT_ENOUGH) |
|
|
|
return |
|
|
|