Browse Source

商品库存bug

dev
Tooooommy 4 years ago
parent
commit
04b64ceb53
  1. 6
      controllers/client/good.go
  2. 6
      controllers/client/order_entry.go
  3. 9
      models/customer_goods.go

6
controllers/client/good.go

@ -213,12 +213,6 @@ func (t *GoodCtl) Order() {
s.Rollback() s.Rollback()
t.ERROR("商品库存不足", code.MSG_DATA_NOT_EXIST) t.ERROR("商品库存不足", code.MSG_DATA_NOT_EXIST)
} else { } else {
// 需要减掉库存
//_, err = s.ID(good.Id).Decr("stock", g["num"]).Cols("stock").Update(good)
//if err != nil {
// s.Rollback()
// t.CheckErr(err)
//}
price += int(good.Price*100) * g["num"] price += int(good.Price*100) * g["num"]
subOrders = append(subOrders, &models.CustomerOrderSub{ subOrders = append(subOrders, &models.CustomerOrderSub{
IsDelete: false, IsDelete: false,

6
controllers/client/order_entry.go

@ -130,15 +130,13 @@ func (t *OrderEntryCtl) Order() {
return return
} }
// 找出商品库存 // 找出商品库存
ms := make([]map[string]int, 0)
err = s.Table(&models.CustomerOrderSub{}).Select("goods_id, sum(goods_num) as goods_num").
Where("goods_id=?", good.Id).GroupBy("goods_id").Find(&ms)
ms, err := models.GetSubOrderGoodNumBySession(s, good.Id)
if err != nil { if err != nil {
s.Rollback() s.Rollback()
t.CheckErr(err) t.CheckErr(err)
} }
for _, m := range ms { for _, m := range ms {
if m["goods_id"] == int(good.Id) && m["goods_num"] >= good.Stock {
if m.GoodsNum == good.Id && good.Stock-m.GoodsNum <= 0 {
s.Rollback() s.Rollback()
t.ERROR(good.Name+"商品库存不足", code.MSG_CUSTOMER_GOOD_NOT_ENOUGH) t.ERROR(good.Name+"商品库存不足", code.MSG_CUSTOMER_GOOD_NOT_ENOUGH)
return return

9
models/customer_goods.go

@ -1,18 +1,13 @@
package models package models
import ( import (
"time"
"git.ouxuan.net/tommy/osmanthuswine/src/core" "git.ouxuan.net/tommy/osmanthuswine/src/core"
) )
const CustomerGoodsTableName = TableNamePrefix + "customer_goods" const CustomerGoodsTableName = TableNamePrefix + "customer_goods"
type CustomerGoods struct { type CustomerGoods struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
IsDelete bool `json:"is_delete" xorm:"not null default 0 comment('是否删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"created comment('创建时间') TIMESTAMP"`
UpdatedAt time.Time `json:"updated_at" xorm:"updated comment('更新时间') TIMESTAMP"`
Model `xorm:"extends"`
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"` ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"` AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
@ -24,7 +19,7 @@ type CustomerGoods struct {
Price float64 `json:"price" xorm:"not null default 0.00 comment('商品单价') DECIMAL(18,2)"` Price float64 `json:"price" xorm:"not null default 0.00 comment('商品单价') DECIMAL(18,2)"`
Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"` Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"`
//// 无关变量
// 无关变量
GoodType int `json:"good_type" xorm:"-"` GoodType int `json:"good_type" xorm:"-"`
Postage float64 `json:"postage" xorm:"-"` Postage float64 `json:"postage" xorm:"-"`
Qrcode string `json:"qrcode,omitempty" xorm:"-"` Qrcode string `json:"qrcode,omitempty" xorm:"-"`

Loading…
Cancel
Save