From 1b7b6da68a081faa31a9692e3ce26aa675a00de1 Mon Sep 17 00:00:00 2001 From: Tooooommy Date: Thu, 22 Oct 2020 11:41:46 +0800 Subject: [PATCH] good stock --- controllers/client/good.go | 11 ++++++++--- controllers/client/order_entry.go | 15 ++++++++++----- go.mod | 2 +- go.sum | 2 ++ models/customer_order_sub.go | 10 +++++----- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/controllers/client/good.go b/controllers/client/good.go index 7e744b1..241c873 100644 --- a/controllers/client/good.go +++ b/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) diff --git a/controllers/client/order_entry.go b/controllers/client/order_entry.go index 4fb12b3..4a3d418 100644 --- a/controllers/client/order_entry.go +++ b/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) diff --git a/go.mod b/go.mod index 874eb99..1884f3f 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index 509574f..76bbfe4 100644 --- a/go.sum +++ b/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= diff --git a/models/customer_order_sub.go b/models/customer_order_sub.go index c171c6e..c1832f5 100644 --- a/models/customer_order_sub.go +++ b/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 }