|
|
@ -3,7 +3,9 @@ package client |
|
|
|
import ( |
|
|
|
"hudongzhuanjia/controllers" |
|
|
|
"hudongzhuanjia/models" |
|
|
|
pay_service "hudongzhuanjia/services/pay" |
|
|
|
"hudongzhuanjia/utils/code" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
type GoodCtl struct { |
|
|
@ -11,7 +13,7 @@ type GoodCtl struct { |
|
|
|
} |
|
|
|
|
|
|
|
// 商品列表
|
|
|
|
func (t *GoodCtl) List() { |
|
|
|
func (t *GoodCtl) ListGood() { |
|
|
|
activityId := t.MustGetInt64("activity_id") |
|
|
|
areaId := t.MustGetInt64("area_id") |
|
|
|
|
|
|
@ -21,8 +23,26 @@ func (t *GoodCtl) List() { |
|
|
|
t.JSON(goods) |
|
|
|
} |
|
|
|
|
|
|
|
func (t *GoodCtl) ListOrder() { |
|
|
|
activityId := t.MustGetInt64("activity_id") |
|
|
|
status := t.MustGetInt("status") |
|
|
|
areaId := t.MustGetInt64("area_id") |
|
|
|
|
|
|
|
activity := new(models.Activity) |
|
|
|
exist, err := models.GetById(activity, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
|
|
|
|
|
orders, err := models.GetCustomerOrdersByActivityId(activity.Id, activity.RehearsalId, areaId, status) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
t.JSON(orders) |
|
|
|
} |
|
|
|
|
|
|
|
// 下订单
|
|
|
|
func (t *GoodCtl) Order() { |
|
|
|
userId := t.MustGetUID() //
|
|
|
|
areaId := t.MustGetInt64("area_id") // 地区id
|
|
|
|
name := t.MustGet("name") // 收货人名字
|
|
|
|
phone := t.MustGet("phone") // 收货电话
|
|
|
|
address := t.MustGet("address") // 收货地址
|
|
|
@ -35,6 +55,52 @@ func (t *GoodCtl) Order() { |
|
|
|
t.ERROR("fee参数错误", code.MSG_ERR_Param) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
good := new(models.CustomerGoods) |
|
|
|
exist, err := models.GetById(good, goodId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "商品不存在") |
|
|
|
|
|
|
|
activity := new(models.Activity) |
|
|
|
exist, err = models.GetById(activity, good.ActivityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
|
|
|
|
|
area := new(models.AreaStore) |
|
|
|
exist, err = models.GetById(area, areaId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在") |
|
|
|
|
|
|
|
user := models.User{} |
|
|
|
exist, err = models.GetById(user, userId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") |
|
|
|
|
|
|
|
res, err := pay_service.UnifiedOrder("欧轩互动-直播商品", user.Openid, int64(int(good.Price*100)*num), 4, userId, activity.Id) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
order := models.CustomerOrder{} |
|
|
|
order.AreaId = areaId |
|
|
|
order.AreaName = area.Name |
|
|
|
order.RehearsalId = activity.RehearsalId |
|
|
|
order.BuyerId = userId |
|
|
|
order.GoodsId = goodId |
|
|
|
order.GoodsName = good.Name |
|
|
|
order.ActivityId = activity.Id |
|
|
|
order.TotalAmount = float64(num) * good.Price |
|
|
|
order.OutTradeNo = res["out_trade_no"].(string) |
|
|
|
order.GoodsNum = num |
|
|
|
order.Address = address |
|
|
|
order.Receiver = name |
|
|
|
order.Phone = phone |
|
|
|
order.Postage = fee |
|
|
|
order.Status = 0 |
|
|
|
order.IsDelete = false |
|
|
|
order.CreatedAt = time.Now() |
|
|
|
order.UpdatedAt = time.Now() |
|
|
|
_, err = order.Add() |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
res["order_id"] = order.Id |
|
|
|
t.JSON(res) |
|
|
|
} |