From eb84567ecebe82eddabd93273865443f3fd3c37e Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Thu, 23 Apr 2020 13:09:45 +0800 Subject: [PATCH] good option --- controllers/client/good.go | 23 ++++++++++++++--------- go.mod | 1 + models/customer_goods.go | 8 ++++---- utils/utils_test.go | 17 ++++++++++++----- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/controllers/client/good.go b/controllers/client/good.go index 7eae796..8e3b026 100644 --- a/controllers/client/good.go +++ b/controllers/client/good.go @@ -13,6 +13,18 @@ type GoodCtl struct { controllers.AuthorCtl } +func (t *GoodCtl) GoodOption() { + activityId := t.MustGetInt64("activity_id") + //areaId := t.MustGetInt64("area_id") + + option := new(models.CustomerOrderOption) + exist, err := option.GetByActivityId(activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单活动不存在") + + t.JSON(option) +} + // 商品列表 func (t *GoodCtl) ListGood() { activityId := t.MustGetInt64("activity_id") @@ -22,18 +34,11 @@ func (t *GoodCtl) ListGood() { exist, err := option.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单活动不存在") - //if option.Status == 0 { - // t.ERROR("订单活动尚未开启", code.MSG_ORDER_RULE_NOT_EXIST) - // return - //} else { + goods, err := models.GetGoodsByActivityId(activityId, areaId) - for index := range goods { - goods[index].GoodType = option.PostFeeType - goods[index].Postage = option.PostFee - } + t.CheckErr(err) t.JSON(goods) - //} return } diff --git a/go.mod b/go.mod index a7132aa..4fbd78e 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( github.com/ouxuanserver/osmanthuswine v0.0.0-20190916032555-480efadf4941 github.com/panjf2000/ants v4.0.2+incompatible github.com/pkg/errors v0.9.1 + github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086 github.com/smartystreets/goconvey v1.6.4 github.com/swaggo/http-swagger v0.0.0-20190614090009-c2865af9083e // indirect diff --git a/models/customer_goods.go b/models/customer_goods.go index 26101c4..20367b2 100644 --- a/models/customer_goods.go +++ b/models/customer_goods.go @@ -23,10 +23,10 @@ type CustomerGoods struct { Price float64 `json:"price" xorm:"not null default '' comment('商品单价') DECIMAL(18)"` Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"` - // 无关变量 - GoodType int `json:"good_type" xorm:"-"` - Postage float64 `json:"postage" xorm:"-"` - Qrcode string `json:"qrcode,omitempty" xorm:"-"` + //// 无关变量 + //GoodType int `json:"good_type" xorm:"-"` + //Postage float64 `json:"postage" xorm:"-"` + Qrcode string `json:"qrcode,omitempty" xorm:"-"` } func (t *CustomerGoods) TableName() string { diff --git a/utils/utils_test.go b/utils/utils_test.go index 8a40cfd..1a2a5d6 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -1,6 +1,8 @@ package utils import ( + "fmt" + "github.com/shopspring/decimal" . "github.com/smartystreets/goconvey/convey" "testing" ) @@ -62,9 +64,14 @@ func TestPathExists(t *testing.T) { } func TestCountDownFormat(t *testing.T) { - Convey("测试倒计时格式", t, func() { - num := 12000 - str := CountDownFormat(num) - So(str, ShouldEqual, "3:20:0") - }) + //Convey("测试倒计时格式", t, func() { + // //num := 12000 + // //str := CountDownFormat(num) + // //So(str, ShouldEqual, "3:20:0") + //}) + d, _ := decimal.NewFromString("-123.45") + d2, _ := decimal.NewFromString(".0001") + a := d.Add(d2) + fmt.Println(a.Float64()) + }