feat: mall api
This commit is contained in:
parent
8575db059a
commit
8bdb3ee683
267
controller/mall.go
Normal file
267
controller/mall.go
Normal file
|
@ -0,0 +1,267 @@
|
||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/codinl/go-logger"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"mh-server/lib/auth"
|
||||||
|
"mh-server/lib/status"
|
||||||
|
"mh-server/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MallGoodsList(c *gin.Context) {
|
||||||
|
req := model.GoodsListReq{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
list, total, err := req.GoodsList()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := map[string]interface{}{
|
||||||
|
"list": list,
|
||||||
|
"cur_page": req.PageIdx,
|
||||||
|
"total_page": total,
|
||||||
|
}
|
||||||
|
|
||||||
|
RespOK(c, ret)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func MallGoodsDetail(c *gin.Context) {
|
||||||
|
req := model.GoodsDetailReq{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
detail, err := req.GoodsDetail()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
RespOK(c, detail)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func MallOrderCreate(c *gin.Context) {
|
||||||
|
req := struct {
|
||||||
|
GoodsId uint32 `json:"goods_id" binding:"required"` // 商品id
|
||||||
|
Quantity uint32 `json:"quantity" binding:"required"` // 购买数量
|
||||||
|
PayType uint32 `json:"pay_type" binding:"required"` // 支付方式
|
||||||
|
AddressId uint32 `json:"address_id" binding:"required"` // 收货地址
|
||||||
|
DeliveryExtraInfo string `json:"delivery_extra_info"` // 收货备注
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uc := auth.GetCurrentUser(c)
|
||||||
|
if uc == nil {
|
||||||
|
RespJson(c, status.Unauthorized, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 商品是否存在
|
||||||
|
var goods model.Goods
|
||||||
|
err := model.NewGoodsQuerySet(model.DB).GoodsIdEq(req.GoodsId).One(&goods)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 商品在售状态
|
||||||
|
if goods.SaleStatus != model.SaleStatusYes {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.GoodsNotSale, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 库存不足
|
||||||
|
if goods.Stock < req.Quantity {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.OrderUnpaidDeposit, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测收货地址是否正确
|
||||||
|
count, _ := model.NewUserAddressQuerySet(model.DB).UidEq(uc.Uid).IDEq(req.AddressId).Count()
|
||||||
|
if count != 1 {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.BadRequest, "收货地址错误")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算总金额
|
||||||
|
amount := uint32(0)
|
||||||
|
if req.PayType == model.PayTypeRm {
|
||||||
|
amount = req.Quantity * goods.PriceRm
|
||||||
|
} else if req.PayType == model.PayTypeVm {
|
||||||
|
amount = req.Quantity * goods.PriceVm
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开启事务
|
||||||
|
tx := model.TransactionBegin()
|
||||||
|
|
||||||
|
// 订单创建逻辑
|
||||||
|
order := model.GoodsOrder{
|
||||||
|
OrderId: model.CreateGoodsOrderId(),
|
||||||
|
SerialNo: model.CreateGoodsOrderSerialNo(),
|
||||||
|
Uid: uc.Uid,
|
||||||
|
GoodsId: req.GoodsId,
|
||||||
|
Amount: amount,
|
||||||
|
Quantity: req.Quantity,
|
||||||
|
PayType: req.PayType,
|
||||||
|
PayStatus: model.PayStatusInit,
|
||||||
|
AddressId: req.AddressId,
|
||||||
|
DeliveryExtraInfo: req.DeliveryExtraInfo,
|
||||||
|
DeliveryFee: goods.DeliveryFee,
|
||||||
|
}
|
||||||
|
err = order.Create(tx)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
tx.Rollback()
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO 减少库存
|
||||||
|
// TODO 确认下是在支付后减少,还是下单后?
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
|
||||||
|
RespOK(c, order)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 订单支付
|
||||||
|
// 暂时只支持积分支付, 以后再考虑人民币支付
|
||||||
|
func MallOrderPay(c *gin.Context) {
|
||||||
|
req := struct {
|
||||||
|
OrderId uint32 `json:"order_id" binding:"required"`
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uc := auth.GetCurrentUser(c)
|
||||||
|
if uc == nil {
|
||||||
|
RespJson(c, status.Unauthorized, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 订单是否存在
|
||||||
|
var order model.GoodsOrder
|
||||||
|
err := model.NewGoodsOrderQuerySet(model.DB).
|
||||||
|
OrderIdEq(req.OrderId).
|
||||||
|
UidEq(uc.Uid).
|
||||||
|
One(&order)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 订单状态不可以支付
|
||||||
|
if order.PayStatus != model.PayStatusInit {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tx := model.TransactionBegin()
|
||||||
|
|
||||||
|
// TODO 减少库存
|
||||||
|
// TODO 确认下是在支付后减少,还是下单后?
|
||||||
|
|
||||||
|
// TODO 减少用户积分
|
||||||
|
|
||||||
|
// 更新支付状态
|
||||||
|
err = model.NewGoodsOrderQuerySet(tx).
|
||||||
|
OrderIdEq(req.OrderId).
|
||||||
|
VersionIdEq(order.VersionId).
|
||||||
|
GetUpdater().
|
||||||
|
SetPayStatus(model.PayStatusOK).
|
||||||
|
SetVersionId(order.VersionId + 1).
|
||||||
|
Update()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
tx.Rollback()
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
|
||||||
|
RespOK(c, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func MallOrderList(c *gin.Context) {
|
||||||
|
req := model.GoodsOrderListReq{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uc := auth.GetCurrentUser(c)
|
||||||
|
if uc == nil {
|
||||||
|
RespJson(c, status.Unauthorized, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
list, total, err := req.OrderList(uc.Uid)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := map[string]interface{}{
|
||||||
|
"list": list,
|
||||||
|
"cur_page": req.PageIdx,
|
||||||
|
"total_page": total,
|
||||||
|
}
|
||||||
|
|
||||||
|
RespOK(c, ret)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func MallOrderDetail(c *gin.Context) {
|
||||||
|
req := model.GoodsOrderDetailReq{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uc := auth.GetCurrentUser(c)
|
||||||
|
if uc == nil {
|
||||||
|
RespJson(c, status.Unauthorized, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
detail, err := req.OrderDetail(uc.Uid)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
RespOK(c, detail)
|
||||||
|
return
|
||||||
|
}
|
|
@ -91,6 +91,8 @@ const (
|
||||||
|
|
||||||
RefundDepositSubmitted = 500507 // 已提交押金退款
|
RefundDepositSubmitted = 500507 // 已提交押金退款
|
||||||
|
|
||||||
|
GoodsNotSale = 500508 // 商品已下架
|
||||||
|
|
||||||
ToastErr = 600 // 报错
|
ToastErr = 600 // 报错
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -155,6 +157,8 @@ var statusDesc = map[int]string{
|
||||||
AwardOffShelves: "奖品已下架",
|
AwardOffShelves: "奖品已下架",
|
||||||
AwardExchangeOut: "奖品已兑完",
|
AwardExchangeOut: "奖品已兑完",
|
||||||
|
|
||||||
|
GoodsNotSale: "商品已下架",
|
||||||
|
|
||||||
NotMember: "非会员",
|
NotMember: "非会员",
|
||||||
HadReceiveReward: "已经领取过了",
|
HadReceiveReward: "已经领取过了",
|
||||||
}
|
}
|
||||||
|
@ -195,7 +199,6 @@ var statusMsg = map[int]string{
|
||||||
NotExists: "请求的资源不存在",
|
NotExists: "请求的资源不存在",
|
||||||
IsExists: "资源已经存在",
|
IsExists: "资源已经存在",
|
||||||
|
|
||||||
|
|
||||||
InternalServerError: "服务器开小差了,请稍后再试",
|
InternalServerError: "服务器开小差了,请稍后再试",
|
||||||
SmsFail: "短信发送失败",
|
SmsFail: "短信发送失败",
|
||||||
JsonParseError: "服务器开小差了,请稍后再试",
|
JsonParseError: "服务器开小差了,请稍后再试",
|
||||||
|
@ -218,6 +221,8 @@ var statusMsg = map[int]string{
|
||||||
AwardOffShelves: "奖品已下架",
|
AwardOffShelves: "奖品已下架",
|
||||||
AwardExchangeOut: "奖品已兑完",
|
AwardExchangeOut: "奖品已兑完",
|
||||||
|
|
||||||
|
GoodsNotSale: "商品已下架",
|
||||||
|
|
||||||
NotMember: "非会员",
|
NotMember: "非会员",
|
||||||
HadReceiveReward: "已经领取过了",
|
HadReceiveReward: "已经领取过了",
|
||||||
}
|
}
|
||||||
|
|
4315
model/autogenerated_mall.go
Normal file
4315
model/autogenerated_mall.go
Normal file
File diff suppressed because it is too large
Load Diff
24
model/invite.go
Normal file
24
model/invite.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
// 邀请关系
|
||||||
|
//go:generate goqueryset -in user_invite_level.go
|
||||||
|
// gen:qs
|
||||||
|
type UserInviteLevel struct {
|
||||||
|
Model
|
||||||
|
|
||||||
|
Uid uint32 `json:"uid" gorm:"column:uid;unique_index"`
|
||||||
|
|
||||||
|
Lv1 uint32 `json:"lv1"`
|
||||||
|
Lv2 uint32 `json:"lv2"`
|
||||||
|
Lv3 uint32 `json:"lv3"`
|
||||||
|
Lv4 uint32 `json:"lv4"`
|
||||||
|
Lv5 uint32 `json:"lv5"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// gen:qs
|
||||||
|
type UserInviteRecord struct {
|
||||||
|
Model
|
||||||
|
|
||||||
|
ToUid uint32 `json:"to_uid"` // 用户ID
|
||||||
|
FromUid uint32 `json:"from_uid"` // 邀请人ID
|
||||||
|
}
|
237
model/mall.go
Normal file
237
model/mall.go
Normal file
|
@ -0,0 +1,237 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/codinl/go-logger"
|
||||||
|
"mh-server/lib/utils"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
SaleStatusUnknown = iota
|
||||||
|
SaleStatusYes
|
||||||
|
SaleStatusNo
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PayTypeUnknown = iota
|
||||||
|
PayTypeRm // 人民币
|
||||||
|
PayTypeVm // 积分
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PayStatusUnknown = iota
|
||||||
|
PayStatusInit
|
||||||
|
PayStatusOK
|
||||||
|
PayStatusFail
|
||||||
|
)
|
||||||
|
|
||||||
|
// 商品
|
||||||
|
//go:generate goqueryset -in mall.go
|
||||||
|
// gen:qs
|
||||||
|
type Goods struct {
|
||||||
|
Model
|
||||||
|
|
||||||
|
GoodsId uint32 `json:"goods_id" gorm:"unique_index"`
|
||||||
|
SerialNo string `json:"serial_no" gorm:"unique_index"` // 序列号
|
||||||
|
CatId uint32 `json:"cat_id"` // 分类
|
||||||
|
Name string `json:"name"` // 名称
|
||||||
|
Title string `json:"title"` // 标题
|
||||||
|
MainImage string `json:"main_image"` // 主图
|
||||||
|
Images string `json:"images"` // 图片列表,用,隔开
|
||||||
|
Stock uint32 `json:"stock"` // 库存
|
||||||
|
Detail string `json:"detail" gorm:"type:text;"` // 详情, 富文本
|
||||||
|
|
||||||
|
SoldCount uint32 `json:"sold_count"` // 已销售数量
|
||||||
|
SaleStatus uint32 `json:"sale_status"` // 在售状态 1-在售 2-下架
|
||||||
|
|
||||||
|
PriceVm uint32 `json:"price_vm"` // 积分价格
|
||||||
|
PriceRm uint32 `json:"price_rm"` // 人民币价格
|
||||||
|
PriceOriginal uint32 `json:"price_original"` // 市场价
|
||||||
|
DeliveryFee uint32 `json:"delivery_fee"` // 邮费
|
||||||
|
|
||||||
|
VersionId uint64 `json:"version_id"` // 乐观锁
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateGoodsSerialNo() string {
|
||||||
|
for {
|
||||||
|
serialNo := utils.GenSerialNo()
|
||||||
|
if count, err := NewGoodsQuerySet(DB).SerialNoEq(serialNo).Count(); err == nil && count > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return serialNo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateGoodsId() uint32 {
|
||||||
|
for {
|
||||||
|
orderId := utils.GenUid()
|
||||||
|
if count, err := NewGoodsQuerySet(DB).GoodsIdEq(orderId).Count(); err == nil && count > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return orderId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodsListReq struct {
|
||||||
|
PageIdx int `json:"page_idx"`
|
||||||
|
PageSize int `json:"page_size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *GoodsListReq) GoodsList() ([]Goods, int, error) {
|
||||||
|
page := m.PageIdx - 1
|
||||||
|
if page < 0 {
|
||||||
|
page = 0
|
||||||
|
}
|
||||||
|
if m.PageSize == 0 {
|
||||||
|
m.PageSize = 10
|
||||||
|
}
|
||||||
|
var goodsList []Goods
|
||||||
|
qs := NewGoodsQuerySet(DB)
|
||||||
|
|
||||||
|
count, err := qs.Count()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
totalPage := count/m.PageSize + 1
|
||||||
|
|
||||||
|
err = qs.Offset(page * m.PageSize).Limit(m.PageSize).All(&goodsList)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return goodsList, totalPage, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodsDetailReq struct {
|
||||||
|
GoodsId uint32 `json:"goods_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *GoodsDetailReq) GoodsDetail() (*Goods, error) {
|
||||||
|
var goods Goods
|
||||||
|
err := NewGoodsQuerySet(DB).GoodsIdEq(m.GoodsId).One(&goods)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &goods, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 商品分类
|
||||||
|
// gen:qs
|
||||||
|
type GoodsCategory struct {
|
||||||
|
Model
|
||||||
|
|
||||||
|
CatId uint32 `json:"cat_id"`
|
||||||
|
ParentCatId uint32 `json:"parent_cat_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Sort uint32 `json:"sort"` // 排序
|
||||||
|
Level uint32 `json:"level"`
|
||||||
|
State uint32 `json:"state"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 商品订单
|
||||||
|
// gen:qs
|
||||||
|
type GoodsOrder struct {
|
||||||
|
Model
|
||||||
|
|
||||||
|
OrderId uint32 `json:"order_id" gorm:"unique_index"` // 订单 id
|
||||||
|
SerialNo string `json:"serial_no" gorm:"unique_index"` // 序列号
|
||||||
|
|
||||||
|
Uid uint32 `json:"uid" gorm:"index"`
|
||||||
|
GoodsId uint32 `json:"goods_id" gorm:"index"` // 商品id
|
||||||
|
Amount uint32 `json:"amount"` // 订单金额
|
||||||
|
Quantity uint32 `json:"quantity"` // 购买商品的数量
|
||||||
|
|
||||||
|
PayType uint32 `json:"pay_type"` // 支付方式 1-rm 2-vm
|
||||||
|
PayTime time.Time `json:"pay_time"` // 支付时间
|
||||||
|
PayStatus uint32 `json:"pay_status"` // 支付状态 1-待支付 2-已支付 3-失败
|
||||||
|
|
||||||
|
AddressId uint32 `json:"address_id"` // 收货地址
|
||||||
|
DeliveryExtraInfo string `json:"delivery_extra_info"` // 物流备注
|
||||||
|
DeliveryFee uint32 `json:"delivery_fee"` // 物流费用
|
||||||
|
DeliveryTrackingNo string `json:"delivery_tracking_no"` // 物流单号
|
||||||
|
DeliveryStatus uint32 `json:"delivery_status"` // 物流状态 1-待发货 2-已发货 3-已收货
|
||||||
|
|
||||||
|
VersionId uint64 `json:"version_id"` // 乐观锁
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateGoodsOrderSerialNo() string {
|
||||||
|
for {
|
||||||
|
serialNo := utils.GenSerialNo()
|
||||||
|
if count, err := NewGoodsOrderQuerySet(DB).SerialNoEq(serialNo).Count(); err == nil && count > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return serialNo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateGoodsOrderId() uint32 {
|
||||||
|
for {
|
||||||
|
orderId := utils.GenUid()
|
||||||
|
if count, err := NewGoodsOrderQuerySet(DB).OrderIdEq(orderId).Count(); err == nil && count > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return orderId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodsOrderListReq struct {
|
||||||
|
PageIdx int `json:"page_idx"`
|
||||||
|
PageSize int `json:"page_size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *GoodsOrderListReq) OrderList(uid uint32) ([]GoodsOrder, int, error) {
|
||||||
|
page := m.PageIdx - 1
|
||||||
|
if page < 0 {
|
||||||
|
page = 0
|
||||||
|
}
|
||||||
|
if m.PageSize == 0 {
|
||||||
|
m.PageSize = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []GoodsOrder
|
||||||
|
qs := NewGoodsOrderQuerySet(DB)
|
||||||
|
|
||||||
|
if uid != 0 {
|
||||||
|
qs = qs.UidEq(uid)
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err := qs.Count()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
totalPage := count/m.PageSize + 1
|
||||||
|
|
||||||
|
err = qs.Offset(page * m.PageSize).Limit(m.PageSize).All(&list)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, totalPage, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodsOrderDetailReq struct {
|
||||||
|
OrderId uint32 `json:"order_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *GoodsOrderDetailReq) OrderDetail(uid uint32) (*GoodsOrder, error) {
|
||||||
|
var order GoodsOrder
|
||||||
|
qs := NewGoodsOrderQuerySet(DB).
|
||||||
|
OrderIdEq(m.OrderId)
|
||||||
|
|
||||||
|
if uid != 0 {
|
||||||
|
qs = qs.UidEq(uid)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := qs.One(&order)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &order, nil
|
||||||
|
}
|
23
model/user_vm.go
Normal file
23
model/user_vm.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
// 用户积分
|
||||||
|
//go:generate goqueryset -in user_vm.go
|
||||||
|
// gen:qs
|
||||||
|
type UserVm struct {
|
||||||
|
Model
|
||||||
|
|
||||||
|
Uid uint32 `json:"uid" gorm:"column:uid;unique_index"`
|
||||||
|
Vm uint32 `json:"vm"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户积分-变动记录
|
||||||
|
// gen:qs
|
||||||
|
type UserVmRecord struct {
|
||||||
|
Model
|
||||||
|
|
||||||
|
Uid uint32 `json:"uid" gorm:"column:uid;unique_index"`
|
||||||
|
BeforeVm uint32 `json:"before_vm"` // 变动前
|
||||||
|
AfterVm uint32 `json:"after_vm"` // 变动后
|
||||||
|
Event string `json:"event" gorm:"type:varchar(100)"` // 事件
|
||||||
|
Describe string `json:"describe" gorm:"type:text"` // 描述
|
||||||
|
}
|
|
@ -152,11 +152,20 @@ func ConfigAppRouter(r gin.IRouter) {
|
||||||
}
|
}
|
||||||
activity := api.Group("activity")
|
activity := api.Group("activity")
|
||||||
{
|
{
|
||||||
|
|
||||||
activity.Use(auth.UserAccessAuth)
|
activity.Use(auth.UserAccessAuth)
|
||||||
activity.POST("redeem_code/user_redeem_code/list", controller.UserRedeemCodeList) // 详情
|
activity.POST("redeem_code/user_redeem_code/list", controller.UserRedeemCodeList) // 详情
|
||||||
activity.POST("redeem_code/user/convert", controller.UserConvertRedeemCode) // 会员兑换码
|
activity.POST("redeem_code/user/convert", controller.UserConvertRedeemCode) // 会员兑换码
|
||||||
|
}
|
||||||
|
|
||||||
|
mall := api.Group("mall")
|
||||||
|
{
|
||||||
|
mall.POST("goods/list", controller.MallGoodsList) // 商品-列表
|
||||||
|
mall.POST("goods/detail", controller.MallGoodsDetail) // 商品-详情
|
||||||
|
|
||||||
|
mall.POST("goods/order/create", controller.MallOrderCreate) // 订单-创建(下单)
|
||||||
|
mall.POST("goods/order/pay", controller.MallOrderPay) // 订单-支付
|
||||||
|
mall.POST("goods/order/list", controller.MallOrderList) // 订单-列表
|
||||||
|
mall.POST("goods/order/detail", controller.MallOrderDetail) // 订单-详情
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user