Browse Source

good stock

dev
Tooooommy 4 years ago
parent
commit
1b7b6da68a
  1. 11
      controllers/client/good.go
  2. 15
      controllers/client/order_entry.go
  3. 2
      go.mod
  4. 2
      go.sum
  5. 10
      models/customer_order_sub.go

11
controllers/client/good.go

@ -46,8 +46,13 @@ func (t *GoodCtl) ListGood() {
activityId := t.MustGetInt("activity_id")
areaId := t.MustGetInt("area_id")
activity := models.Activity{}
exist, err := models.Get(&activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
area := &models.AreaStore{}
exist, err := models.Get(area, areaId)
exist, err = models.Get(area, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
if area.IsMainArea != 1 && area.AreaGoodsRuleSwitch != 1 {
@ -71,7 +76,7 @@ func (t *GoodCtl) ListGood() {
for _, g := range goods {
goodIds = append(goodIds, g.Id)
}
res, err := models.GetSubOrderGoodNum(goodIds)
res, err := models.GetSubOrderGoodNum(goodIds, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
for index := range goods {
@ -192,7 +197,7 @@ func (t *GoodCtl) Order() {
t.ERROR("商品信息异常", code.MSG_DATA_NOT_EXIST)
}
orderGoodNum, err := models.GetSubOrderGoodNumBySession(s, goodIds)
orderGoodNum, err := models.GetSubOrderGoodNumBySession(s, goodIds, activity.RehearsalId, activity.ArchId)
if err != nil {
s.Rollback()
t.ERROR("商品信息异常", code.MSG_DATA_NOT_EXIST)

15
controllers/client/order_entry.go

@ -23,6 +23,11 @@ func (t *OrderEntryCtl) List() {
uid := t.GetAccountId()
activityId := t.MustGetInt("activity_id")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
areaId := 0
if _type == define.TYPE_ENTRYPEOPLE {
entryPerson := models.OrderEntryPerson{}
@ -35,7 +40,7 @@ func (t *OrderEntryCtl) List() {
}
area := &models.AreaStore{}
exist, err := models.Get(area, areaId)
exist, err = models.Get(area, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
if area.IsMainArea != 1 && area.AreaGoodsRuleSwitch != 1 {
@ -51,7 +56,7 @@ func (t *OrderEntryCtl) List() {
for _, g := range goods {
goodIds = append(goodIds, g.Id)
}
res, err := models.GetSubOrderGoodNum(goodIds)
res, err := models.GetSubOrderGoodNum(goodIds, activity.RehearsalId, activity.ArchId)
t.CheckErr(err)
for index := range goods {
@ -60,7 +65,7 @@ func (t *OrderEntryCtl) List() {
qrcode, err := utils.Qrcode2Base64(url)
t.CheckErr(err)
goods[index].Qrcode = qrcode
if goods[index].Stock == -1 {
if goods[index].Stock != -1 {
for _, v := range res {
if goods[index].Id == v.GoodsId {
goods[index].Stock -= v.GoodsNum
@ -134,7 +139,7 @@ func (t *OrderEntryCtl) Order() {
if good.Stock > -1 { // 库存
// 找出商品库存
ms, err := models.GetSubOrderGoodNumBySession(s, good.Id)
ms, err := models.GetSubOrderGoodNumBySession(s, good.Id, activity.RehearsalId, activity.ArchId)
if err != nil {
s.Rollback()
t.CheckErr(err)
@ -352,7 +357,7 @@ func (t *OrderEntryCtl) ManualOrder() {
// 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)
ms, err := models.GetSubOrderGoodNumBySession(s, goodIds, activity.RehearsalId, activity.ArchId)
if err != nil {
s.Rollback()
t.CheckErr(err)

2
go.mod

@ -9,7 +9,7 @@ require (
github.com/CloudyKit/jet v2.1.2+incompatible // indirect
github.com/agrison/go-tablib v0.0.0-20160310143025-4930582c22ee // indirect
github.com/agrison/mxj v0.0.0-20160310142625-1269f8afb3b4 // indirect
github.com/aws/aws-sdk-go v1.35.11 // indirect
github.com/aws/aws-sdk-go v1.35.12 // indirect
github.com/bndr/gotabulate v1.1.2 // indirect
github.com/chanxuehong/wechat v0.0.0-20200409104612-0a1fd76d7a3a
github.com/clbanning/mxj v1.8.4 // indirect

2
go.sum

@ -21,6 +21,8 @@ github.com/aws/aws-sdk-go v1.35.10 h1:FsJtrOS7P+Qmq1rPTGgS/+qC1Y9eGuAJHvAZpZlhmb
github.com/aws/aws-sdk-go v1.35.10/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
github.com/aws/aws-sdk-go v1.35.11 h1:LICFl2K+3Y5dMTW6PCV6ycK8fzIxs21HvDhI5A3Ee3Y=
github.com/aws/aws-sdk-go v1.35.11/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
github.com/aws/aws-sdk-go v1.35.12 h1:qpxQ/DXfgsTNSYn8mUaCgQiJkCjBP8iHKw5ju+wkucU=
github.com/aws/aws-sdk-go v1.35.12/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
github.com/bndr/gotabulate v1.1.2 h1:yC9izuZEphojb9r+KYL4W9IJKO/ceIO8HDwxMA24U4c=
github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U=
github.com/chanxuehong/rand v0.0.0-20180830053958-4b3aff17f488/go.mod h1:h13adSJmQ5tsaV9bR72eTp7ePXJ2WIWyK6heLeietxA=

10
models/customer_order_sub.go

@ -71,14 +71,14 @@ type OrderGoodNum struct {
GoodsNum int `json:"goods_num"`
}
func GetSubOrderGoodNum(goodIds interface{}) (res []*OrderGoodNum, err error) {
return GetSubOrderGoodNumBySession(core.GetXormAuto().NewSession(), goodIds)
func GetSubOrderGoodNum(goodIds, rehearsalId, archId interface{}) (res []*OrderGoodNum, err error) {
return GetSubOrderGoodNumBySession(core.GetXormAuto().NewSession(), goodIds, rehearsalId, archId)
}
func GetSubOrderGoodNumBySession(s *xorm.Session, goodIds interface{}) (res []*OrderGoodNum, err error) {
func GetSubOrderGoodNumBySession(s *xorm.Session, goodIds, rehearsalId, archId interface{}) (res []*OrderGoodNum, err error) {
err = s.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", "6", "8", "9").GroupBy("s.goods_id").Find(&res)
Where("o.is_delete=0 and s.is_delete=0 and s.rehearsal_id=? and arch_id=?", rehearsalId, archId).
In("s.goods_id", goodIds).NotIn("o.status", "0", "6", "8", "9").GroupBy("s.goods_id").Find(&res)
return
}
Loading…
Cancel
Save