From 9e19dd93aa09f02acb210a13aa9a33f1f6877595 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Wed, 22 Apr 2020 17:41:42 +0800 Subject: [PATCH] post fee --- controllers/author.go | 2 +- controllers/client/good.go | 38 +++++++++++++++++++++++++++----------- models/customer_goods.go | 4 ++-- models/customer_order_option.go | 23 +++++++++++++++-------- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/controllers/author.go b/controllers/author.go index d3ea642..b45bc37 100644 --- a/controllers/author.go +++ b/controllers/author.go @@ -15,7 +15,7 @@ type AuthorCtl struct { func (t *AuthorCtl) Prepare() { t.BaseCtl.Prepare() - skip := t.MustGetInt("skip") + skip, _ := t.GetInt("skip") if skip == 1 { t.claims = &jwt.Claims{ AccountType: "customer", diff --git a/controllers/client/good.go b/controllers/client/good.go index b269524..1ba29e5 100644 --- a/controllers/client/good.go +++ b/controllers/client/good.go @@ -18,10 +18,22 @@ func (t *GoodCtl) ListGood() { 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, "订单活动不存在") + //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 + } t.CheckErr(err) - t.JSON(goods) + //} + return } func (t *GoodCtl) ListOrder() { @@ -50,13 +62,6 @@ func (t *GoodCtl) Order() { address := t.MustGet("address") // 收货地址 goodId := t.MustGetInt64("good_id") // 商品id num := t.MustGetInt("num") // 商品数量 - _type := t.MustGetInt("delivery") // 配送: 1 快递免邮 2 快递 xxx 3 自提 4 到付 - - fee, exist := t.GetDouble("fee") // 快递费用 - if _type == 2 && !exist || fee == 0 { - t.ERROR("fee参数错误", code.MSG_ERR_Param) - return - } activity := new(models.Activity) exist, err := models.GetById(activity, activityId) @@ -73,6 +78,15 @@ func (t *GoodCtl) Order() { t.CheckErr(err) t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") + option := new(models.CustomerOrderOption) + 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 + //} + // 注意库存 --> 开启事务 session := core.GetXormAuto().NewSession() defer session.Close() @@ -84,6 +98,7 @@ func (t *GoodCtl) Order() { session.Rollback() t.ERROR("商品信息异常", code.MSG_DATA_NOT_EXIST) } + if good.Stock == 0 { session.Rollback() t.ERROR("商品库存不足", code.MSG_DATA_NOT_EXIST) @@ -97,7 +112,8 @@ func (t *GoodCtl) Order() { } } - res, err := pay_service.UnifiedOrder("欧轩互动-直播商品", user.Openid, int64(int(good.Price*100)*num), 4, userId, activity.Id) + res, err := pay_service.UnifiedOrder("欧轩互动-直播商品", user.Openid, + int64(int(good.Price*100)*num+int(option.PostFee*100)), 4, userId, activity.Id) if err != nil { session.Rollback() t.CheckErr(err) @@ -111,14 +127,14 @@ func (t *GoodCtl) Order() { order.GoodsId = goodId order.GoodsName = good.Name order.ActivityId = activity.Id - order.TotalAmount = float64(num) * good.Price + order.TotalAmount = float64(num)*good.Price + option.PostFee order.PayAmount = order.TotalAmount order.OutTradeNo = res["out_trade_no"].(string) order.GoodsNum = num order.Address = address order.Receiver = name order.Phone = phone - order.Postage = fee + order.Postage = option.PostFee order.Status = 0 order.IsDelete = false order.CreatedAt = time.Now() diff --git a/models/customer_goods.go b/models/customer_goods.go index 3665f6d..4c036c5 100644 --- a/models/customer_goods.go +++ b/models/customer_goods.go @@ -17,7 +17,6 @@ type CustomerGoods struct { AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"` GoodsPicUrl string `json:"goods_pic_url" xorm:"not null default '' comment('商品图片') VARCHAR(255)"` IsForceAdded int `json:"is_force_added" xorm:"not null default 0 comment('是否强制上架0不强制1强制') TINYINT(1)"` - GoodType int `json:"good_type" xorm:"not null default 0 comment('商品类型0不需要邮寄1需要邮寄') TINYINT(1)"` FixedField string `json:"fixed_field" xorm:"not null default '' comment('固定不可改字段,|分隔') VARCHAR(255)"` Stock int `json:"stock" xorm:"not null default 0 comment('库存-1的时候无上限') INT(18)"` Name string `json:"name" xorm:"not null default '' comment('商品名称') VARCHAR(255)"` @@ -25,7 +24,8 @@ type CustomerGoods struct { Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"` // 无关变量 - Qrcode string `json:"qrcode,omitempty" xorm:"-"` + GoodType int `json:"good_type" xorm:"-"` + Qrcode string `json:"qrcode,omitempty" xorm:"-"` } func (t *CustomerGoods) TableName() string { diff --git a/models/customer_order_option.go b/models/customer_order_option.go index d7f02ef..23c38c8 100644 --- a/models/customer_order_option.go +++ b/models/customer_order_option.go @@ -1,6 +1,7 @@ package models import ( + "fmt" "github.com/ouxuanserver/osmanthuswine/src/core" "time" ) @@ -8,20 +9,26 @@ import ( const CustomerOrderOptionTableName = TableNamePrefix + "customer_order_option" type CustomerOrderOption struct { - Id int64 `json:"id" xorm:"not null pk INT(11)"` - ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"` - SettingBox string `json:"setting_box" xorm:"not null comment('json格式 选中的表单项') TEXT"` - SelfBox string `json:"self_box" xorm:"not null comment('json格式 邀请函选中的表单项') TEXT"` - Status int `json:"status" xorm:"not null default 0 comment('订单活动的开启1|关闭0') TINYINT(1)"` - IsDelete int `json:"-" xorm:"not null default 0 comment('删除') TINYINT(1)"` - CreatedAt time.Time `json:"-" xorm:"created"` - UpdatedAt time.Time `json:"-" xorm:"updated"` + Id int64 `json:"id" xorm:"not null pk INT(11)"` + ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"` + SettingBox string `json:"setting_box" xorm:"not null comment('json格式 选中的表单项') TEXT"` + SelfBox string `json:"self_box" xorm:"not null comment('json格式 邀请函选中的表单项') TEXT"` + Status int `json:"status" xorm:"not null default 0 comment('订单活动的开启1|关闭0') TINYINT(1)"` + PostFeeType int `json:"post_fee_type" xorm:"not null default 0 comment('直播订单运费设置0包邮1货到付款2收费') TINYINT(1)"` + PostFee float64 `json:"post_fee" xorm:"not null default 0.00 comment('直播订单运费') DECIMAL(18)"` + IsDelete int `json:"-" xorm:"not null default 0 comment('删除') TINYINT(1)"` + CreatedAt time.Time `json:"-" xorm:"created"` + UpdatedAt time.Time `json:"-" xorm:"updated"` } func (t *CustomerOrderOption) TableName() string { return CustomerOrderOptionTableName } +func (t *CustomerOrderOption) AliasName(n string) string { + return fmt.Sprintf("%s as %s", t.TableName(), n) +} + func (t *CustomerOrderOption) GetByActivityId(aid int64) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Get(t) }