|
|
@ -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() |
|
|
|