feat:批发订单列表

master
howell 3 years ago
parent ba22baac2a
commit 8ddab53284

@ -23,6 +23,7 @@ type queryOrderListParam struct {
UserID uint `json:"userId"`
Page uint `json:"page"`
OrderType string `json:"orderType" validate:"omitempty,oneof=0 1"`
IsSale bool `json:"is_sale"`
}
type queryOrderListResponse struct {
@ -47,7 +48,7 @@ func QueryAllOrders(c *gin.Context) {
}
var orderInfoList []order.Information
SearchOrderList(p.OrderType, p.Page, p.UserID).Find(&orderInfoList, "user_id = ?", p.UserID)
SearchOrderList(p.OrderType, p.Page, p.UserID, p.IsSale).Find(&orderInfoList, "user_id = ?", p.UserID)
list := make([]queryOrderListResponse, 0, 0)
for i1, v1 := range orderInfoList {
@ -237,7 +238,7 @@ func QueryUnpaidOrders(c *gin.Context) {
}
var orderInfoList []order.Information
SearchOrderList(p.OrderType, p.Page, p.UserID).Find(&orderInfoList, "user_id = ? AND status = 0 AND expire_time > ?", p.UserID, time.Now())
SearchOrderList(p.OrderType, p.Page, p.UserID, p.IsSale).Find(&orderInfoList, "user_id = ? AND status = 0 AND expire_time > ?", p.UserID, time.Now())
list := make([]queryOrderListResponse, 0, 0)
for i1, v1 := range orderInfoList {
@ -271,7 +272,7 @@ func QueryUndeliveredOrders(c *gin.Context) {
//p.Page = 0
var orderInfoList []order.Information
SearchOrderList(p.OrderType, p.Page, p.UserID).Find(&orderInfoList, "user_id = ? AND status = 1 AND express_status = 0", p.UserID)
SearchOrderList(p.OrderType, p.Page, p.UserID, p.IsSale).Find(&orderInfoList, "user_id = ? AND status = 1 AND express_status = 0", p.UserID)
list := make([]queryOrderListResponse, 0, 0)
for i1, v1 := range orderInfoList {
@ -302,7 +303,7 @@ func QueryWaitingForReceiptOrders(c *gin.Context) {
}
var orderInfoList []order.Information
SearchOrderList(p.OrderType, p.Page, p.UserID).Find(&orderInfoList, "user_id = ? AND status=1 AND express_status = 1", p.UserID)
SearchOrderList(p.OrderType, p.Page, p.UserID, p.IsSale).Find(&orderInfoList, "user_id = ? AND status=1 AND express_status = 1", p.UserID)
list := make([]queryOrderListResponse, 0, 0)
for i1, v1 := range orderInfoList {
@ -341,7 +342,7 @@ func QueryUnEvaluateOrders(c *gin.Context) {
}
var orderInfoList []order.Information
SearchOrderList(p.OrderType, p.Page, p.UserID).Find(&orderInfoList, "user_id = ? AND status=4 AND evaluated_at IS NULL", p.UserID)
SearchOrderList(p.OrderType, p.Page, p.UserID, p.IsSale).Find(&orderInfoList, "user_id = ? AND status=4 AND evaluated_at IS NULL", p.UserID)
list := make([]queryOrderListResponse, 0, 0)
for i1, v1 := range orderInfoList {
@ -600,12 +601,15 @@ func QueryOrderDetail(c *gin.Context) {
}
// 搜索订单 条件
func SearchOrderList(OrderType string, Page, UserID uint) *gorm.DB {
func SearchOrderList(OrderType string, Page, UserID uint, isSale bool) *gorm.DB {
queryDB := dbc.DB
if len(OrderType) > 0 {
oType, _ := strconv.Atoi(OrderType)
queryDB = queryDB.Where("shipping_method = ?", oType)
}
if isSale {
queryDB = queryDB.Where("order_type = 2")
}
queryDB = queryDB.Where("is_split = 0").Order("id desc").Limit(10).Offset(10 * Page)
return queryDB
}

@ -1,482 +1,13 @@
package shop
import (
"github.com/golangkit/formatime"
orderPkg "recook/internal/api/mobile/order"
"recook/internal/back"
"recook/internal/dbc"
"recook/internal/model/aftersales"
"recook/internal/model/goods"
"recook/internal/model/order"
"recook/internal/model/user"
"recook/tools"
"github.com/gin-gonic/gin"
"github.com/shopspring/decimal"
)
type queryOrderListParam struct {
UserID uint `json:"userId"`
Page uint `json:"page"`
OrderType string `json:"orderType" validate:"omitempty,oneof=0 1"`
}
type queryOrderListResponse struct {
order.Information
TotalGoodsCount uint `json:"totalGoodsCount"`
GoodsList []order.GoodsDetail `json:"goodsList"`
}
//获取所有的伞下会员
func getUserSecondaryAll(rootId uint) []uint {
var trees []user.Tree
dbc.DB.Select("user_id").Where(user.Tree{
RootID: rootId,
}).Where("depth > ?", 0).Find(&trees)
var id []uint
for _, v := range trees {
id = append(id, v.UserID)
}
return id
}
func getUserSecondary(rootId uint) []uint {
var trees []user.Tree
dbc.DB.Select("user_id").Where(user.Tree{
RootID: rootId,
Depth: 1,
}).Find(&trees)
var id []uint
for _, v := range trees {
id = append(id, v.UserID)
}
return id
}
/*全部订单*/
func QuerySecondaryOrders(c *gin.Context) {
var p queryOrderListParam
if err := tools.ParseParams(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
var orderInfoList []order.Information
orderPkg.SearchOrderList(p.OrderType, p.Page, p.UserID).
Find(&orderInfoList, "user_id IN (?)", getUserSecondaryAll(p.UserID))
list := make([]queryOrderListResponse, 0, 0)
for i1, v1 := range orderInfoList {
var goodsList []order.GoodsDetail
dbc.DB.Find(&goodsList, "order_id = ?", v1.ID)
var totalGoodsCount uint = 0
for _, v2 := range goodsList {
totalGoodsCount += v2.Quantity
}
list = append(list, queryOrderListResponse{
Information: orderInfoList[i1],
TotalGoodsCount: totalGoodsCount,
GoodsList: goodsList,
})
}
back.Suc(c, "", list)
}
/*待发货 付款成功*/
func QuerySecondaryUndeliveredOrders(c *gin.Context) {
var p queryOrderListParam
if err := tools.ParseParams(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
var orderInfoList []order.Information
orderPkg.SearchOrderList(p.OrderType, p.Page, p.UserID).
Find(&orderInfoList, "user_id IN (?) and sharer_id = ? and user_id <> ? AND status = 1 AND express_status = 0", getUserSecondary(p.UserID), p.UserID, p.UserID)
list := make([]queryOrderListResponse, 0, 0)
for i1, v1 := range orderInfoList {
var goodsList []order.GoodsDetail
dbc.DB.Find(&goodsList, "order_id = ?", v1.ID)
list = append(list, queryOrderListResponse{
Information: orderInfoList[i1],
TotalGoodsCount: uint(len(goodsList)),
GoodsList: goodsList,
})
}
back.Suc(c, "", list)
}
/*待收货*/
func QuerySecondaryUnreceiveOrders(c *gin.Context) {
var p queryOrderListParam
if err := tools.ParseParams(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
var orderInfoList []order.Information
orderPkg.SearchOrderList(p.OrderType, p.Page, p.UserID).
Find(&orderInfoList, "user_id IN (?) and sharer_id = ? and user_id <> ? AND status=1 AND express_status = 1", getUserSecondary(p.UserID), p.UserID, p.UserID)
list := make([]queryOrderListResponse, 0, 0)
for i1, v1 := range orderInfoList {
var goodsList []order.GoodsDetail
dbc.DB.Find(&goodsList, "order_id = ?", v1.ID)
list = append(list, queryOrderListResponse{
Information: orderInfoList[i1],
TotalGoodsCount: uint(len(goodsList)),
GoodsList: goodsList,
})
}
back.Suc(c, "", list)
}
/*已收货*/
func QuerySecondaryReceiveOrders(c *gin.Context) {
var p queryOrderListParam
if err := tools.ParseParams(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
var orderInfoList []order.Information
orderPkg.SearchOrderList(p.OrderType, p.Page, p.UserID).
Find(&orderInfoList, "user_id IN (?) and sharer_id = ? and user_id <> ? AND status=4", getUserSecondary(p.UserID), p.UserID, p.UserID)
list := make([]queryOrderListResponse, 0, 0)
for i1, v1 := range orderInfoList {
var goodsList []order.GoodsDetail
dbc.DB.Find(&goodsList, "order_id = ?", v1.ID)
list = append(list, queryOrderListResponse{
Information: orderInfoList[i1],
TotalGoodsCount: uint(len(goodsList)),
GoodsList: goodsList,
})
}
back.Suc(c, "", list)
}
type afterSalesListParam struct {
UserID uint `json:"userId"`
Page uint `json:"page"`
Type uint `json:"type"`
ReturnStatus []uint
OrderType string `json:"orderType" validate:"omitempty,oneof=0 1"`
}
//type afterSalesListResp struct {
// ID uint `gorm:"column:id;primary_key" json:"asId"`
// OrderGoodsID uint `json:"orderGoodsId"`
// GoodsID uint `gorm:"column:goods_id" json:"goodsId"` // 商品ID
// GoodsName string `gorm:"column:goods_name" json:"goodsName"` // 商品名快照
// SkuName string `gorm:"column:sku_name" json:"skuName"` // SKU名字组合起来
// MainPhotoURL string `gorm:"column:main_photo_url" json:"mainPhotoUrl"` // 主图快照 先读sku 没有则读取主图
// RefundAmount decimal.Decimal `gorm:"column:refund_amount" json:"refundAmount"` // 退款金额
// AssType uint `gorm:"column:ass_type" json:"assType"`
// ReturnStatus uint `gorm:"column:return_status" json:"returnStatus"`
// RefundStatus uint `gorm:"column:refund_status" json:"refundStatus"`
// AsDesc string `json:"asDesc"`
// RefundDesc string `json:"refundDesc"`
//// 一对多
//type BrandManyGoods struct {
// BrandID uint `json:"brandId"`
// BrandName string `json:"brandName"`
// BrandLogoUrl string `json:"brandLogoUrl"`
// BrandExpressTotalAmount decimal.Decimal `json:"brandExpressTotalAmount"`
// BrandGoodsTotalAmount decimal.Decimal `json:"brandGoodsTotalAmount"`
// BrandGoodsTotalCount uint `json:"brandGoodsTotalCount"`
// Goods []order.GoodsDetail `json:"goods"`
// Coupon *order.CouponDetail `json:"coupon"` // 品牌优惠券
//}
type afterSalesListResp struct {
ID uint `gorm:"column:id;primary_key" json:"asId"`
OrderGoodsID uint `json:"orderGoodsId"`
GoodsID uint `gorm:"column:goods_id" json:"goodsId"` // 商品ID
GoodsName string `gorm:"column:goods_name" json:"goodsName"` // 商品名快照
SkuName string `gorm:"column:sku_name" json:"skuName"` // SKU名字组合起来
MainPhotoURL string `gorm:"column:main_photo_url" json:"mainPhotoUrl"` // 主图快照 先读sku 没有则读取主图
RefundAmount decimal.Decimal `gorm:"column:refund_amount" json:"refundAmount"` // 退款金额
RefundCoin decimal.Decimal `gorm:"column:refund_coin" json:"refundCoin"` // 退款瑞币
IsShip uint `gorm:"column:is_ship" json:"isShip"`
AssType uint `gorm:"column:ass_type" json:"assType"`
ReturnStatus uint `gorm:"column:return_status" json:"returnStatus"`
RefundStatus uint `gorm:"column:refund_status" json:"refundStatus"`
AsDesc string `json:"asDesc"`
RefundDesc string `json:"refundDesc"`
CreatedAt formatime.Second `json:"createdAt"`
Quantity uint `json:"quantity"`
Color int `json:"color"`
}
func QuerySecondaryAfterSalesGoodsList(c *gin.Context) {
var p afterSalesListParam
if err := tools.ParseParams(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
//p.Type=1未完结2已完成
//默认获取未完结的售后订单
if p.Type == 2 {
p.ReturnStatus = []uint{5}
} else if p.Type == 1 {
p.ReturnStatus = []uint{1, 2, 3, 4, 6}
} else {
p.ReturnStatus = []uint{1, 2, 3, 4, 5, 6}
}
asGoodsList := make([]aftersales.Goods, 0, 0)
orderPkg.SearchOrderList(p.OrderType, p.Page, p.UserID).Order("id desc").Find(&asGoodsList, "parent_id = ? and return_status in (?)", p.UserID, p.ReturnStatus)
list := make([]afterSalesListResp, 0, 0)
for _, v := range asGoodsList {
asDesc := ""
color := 0
//如果是已完成的订单
if v.ReturnStatus == 5 {
if v.IsClosed == 1 {
color = 3
if v.AssType == 2 {
asDesc = "退货已关闭"
} else {
asDesc = "退款已关闭"
}
} else {
color = 2
if v.AssType == 2 {
asDesc = "退货成功"
} else {
asDesc = "退款成功"
}
}
} else {
color = 1
if v.AssType == 2 {
asDesc = "退款退货"
} else {
asDesc = "仅退款"
}
}
//asDesc = asDesc + v.RefundAmount.Truncate(2).String() + "元"
refundDesc := ""
if v.ReturnStatus == 1 {
refundDesc = "商家审核中"
} else if v.ReturnStatus == 2 {
refundDesc = "申请被拒绝"
} else if v.ReturnStatus == 3 {
refundDesc = "审核成功:" + "请填写退货物流"
} else if v.ReturnStatus == 4 {
refundDesc = "等待商家确认收货"
} else if v.ReturnStatus == 5 {
refundDesc = "售后完成:" + v.RefundAmount.Truncate(2).String() + "元"
} else if v.ReturnStatus == 4 {
refundDesc = "退货商品被拒绝"
}
list = append(list, afterSalesListResp{
ID: v.ID, //售后编号
OrderGoodsID: v.OrderGoodsID,
GoodsID: v.GoodsID,
GoodsName: v.GoodsName, //商品名称
SkuName: v.SkuName, //sku名称
MainPhotoURL: v.MainPhotoURL, //主图的商品url
RefundAmount: v.RefundAmount, //退款金额
RefundCoin: v.RefundCoin, //退款瑞币
IsShip: v.IsShip,
AssType: v.AssType,
ReturnStatus: v.ReturnStatus,
RefundStatus: v.RefundStatus,
AsDesc: asDesc, //退款,退款退货,退货成功,退款成功 退货已关闭 退款已关闭
Color: color, //颜色 1售后中 2售后成功 3售后关闭
RefundDesc: refundDesc, //退款类型文字
CreatedAt: v.CreatedAt, //创建时间
Quantity: v.Quantity, //商品数量
})
}
back.Suc(c, "", &list)
}
type returnDetailParams struct {
OrderGoodsID uint `json:"orderGoodsId"`
}
type returnGoodsResp struct {
aftersales.Goods
Title string `json:"title"`
Subtitle string `json:"subtitle"`
}
func QuerySecondaryAfterSalesGoodsDetail(c *gin.Context) {
var p returnDetailParams
if err := tools.ParseParams(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
var asGoods aftersales.Goods
if err := dbc.DB.First(&asGoods, "order_goods_id = ?", p.OrderGoodsID).Error; err != nil {
back.Err(c, err.Error())
return
}
title := ""
subtitle := ""
if asGoods.ReturnStatus == 1 {
title = "商家审核中"
subtitle = "请耐心等待"
} else if asGoods.ReturnStatus == 2 {
title = "申请被拒绝"
subtitle = asGoods.RejectReason
} else if asGoods.ReturnStatus == 3 {
title = "审核成功"
subtitle = "请填写退货物流信息"
} else if asGoods.ReturnStatus == 4 {
title = "收货确认中"
subtitle = "请等待商家确认收货"
} else if asGoods.ReturnStatus == 5 {
title = "售后成功"
subtitle = "退款已原路退回,请查收"
} else if asGoods.ReturnStatus == 6 {
title = "退货被拒绝"
subtitle = "请与商家沟通"
}
if asGoods.IsClosed == 1 {
title = "已关闭"
subtitle = "退货退款申请已关闭"
}
back.Suc(c, "", &returnGoodsResp{
Goods: asGoods,
Title: title,
Subtitle: subtitle,
})
}
type queryOrderDetailParam struct {
UserID uint `json:"userId"`
OrderID uint `json:"orderId"`
}
type queryOrderDetailResponse struct {
order.Information
TotalGoodsCount uint `json:"totalGoodsCount"`
Coupon *order.CouponDetail `json:"coupon"`
Addr *order.Addr `json:"addr"`
Brands []BrandManyGoods `json:"brands"`
Invoice *order.Invoice `json:"invoice"`
}
// 一对多
type BrandManyGoods struct {
BrandID uint `json:"brandId"`
BrandName string `json:"brandName"`
BrandLogoUrl string `json:"brandLogoUrl"`
BrandExpressTotalAmount decimal.Decimal `json:"brandExpressTotalAmount"`
BrandGoodsTotalAmount decimal.Decimal `json:"brandGoodsTotalAmount"`
BrandGoodsTotalCount uint `json:"brandGoodsTotalCount"`
Goods []order.GoodsDetail `json:"goods"`
Coupon *order.CouponDetail `json:"coupon"` // 品牌优惠券
}
func QuerySecondaryOrderDetail(c *gin.Context) {
var p queryOrderDetailParam
if err := tools.ParseParams(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
var orderInfo order.Information
dbc.DB.First(&orderInfo, "id = ?", p.OrderID)
var invoice order.Invoice
dbc.DB.First(&invoice, "order_id = ?", p.OrderID)
var addr order.Addr
dbc.DB.First(&addr, "order_id = ?", p.OrderID)
var universeCoupon order.CouponDetail
dbc.DB.First(&universeCoupon, "order_id = ? AND scope = 0", p.OrderID)
// 获取到所有商品, 内存中进行分组操作
var goodsList []order.GoodsDetail
dbc.DB.Find(&goodsList, "order_id = ?", p.OrderID)
var totalGoodsCount uint = 0
brandMap := map[uint]uint{}
for _, v := range goodsList {
brandMap[v.BrandID] = 1
totalGoodsCount += v.Quantity
}
brandList := make([]BrandManyGoods, 0, 0)
for k := range brandMap {
var brandInfo goods.Brand
dbc.DB.Select("id, name, logo_url").First(&brandInfo, "id = ?", k)
var brandCoupon order.CouponDetail
dbc.DB.First(&brandCoupon, "order_id = ? AND brand_id = ?", p.OrderID, k)
internalGoodsList := make([]order.GoodsDetail, 0, 0)
brandExpressTotalFee := decimal.NewFromFloat(0.0)
brandGoodsTotalAmount := decimal.NewFromFloat(0.0)
brandGoodsTotalCount := 0
for i, v := range goodsList {
if v.BrandID == k {
internalGoodsList = append(internalGoodsList, goodsList[i])
brandExpressTotalFee = brandExpressTotalFee.Add(v.ExpressFee)
brandGoodsTotalAmount = brandGoodsTotalAmount.Add(v.GoodsAmount)
brandGoodsTotalCount += int(v.Quantity)
}
}
brandCouponPtr := &order.CouponDetail{}
if brandCoupon.ID == 0 {
brandCouponPtr = nil
} else {
brandCouponPtr = &brandCoupon
}
brandList = append(brandList, BrandManyGoods{
BrandID: brandInfo.ID,
BrandName: brandInfo.Name,
BrandLogoUrl: brandInfo.LogoURL,
BrandExpressTotalAmount: brandExpressTotalFee,
BrandGoodsTotalAmount: brandGoodsTotalAmount,
BrandGoodsTotalCount: uint(brandGoodsTotalCount),
Goods: internalGoodsList,
Coupon: brandCouponPtr,
})
}
universeCouponPtr := &order.CouponDetail{}
if universeCoupon.ID == 0 {
universeCouponPtr = nil
} else {
universeCouponPtr = &universeCoupon
}
invoicePtr := &order.Invoice{}
if invoice.ID == 0 {
invoicePtr = nil
} else {
invoicePtr = &invoice
}
back.Suc(c, "", queryOrderDetailResponse{
Information: orderInfo,
TotalGoodsCount: totalGoodsCount,
Coupon: universeCouponPtr,
Addr: &addr,
Brands: brandList,
Invoice: invoicePtr,
})
}

@ -35,8 +35,6 @@ import (
"recook/internal/api/mobile/pay/wxminipay"
"recook/internal/api/mobile/pay/wxpay"
"recook/internal/api/mobile/region"
"recook/internal/api/mobile/share_img"
"recook/internal/api/mobile/shop"
"recook/internal/api/mobile/shopping_trolley"
"recook/internal/api/mobile/show"
"recook/internal/api/mobile/users"
@ -195,21 +193,6 @@ func SetupRouter(v1 *gin.RouterGroup) {
walletR.POST("/balance/withdraw_detail", wallet.WithdrawDetail)
}
shopR := v1.Group("shop")
{
// 获取店铺分享图片
shopR.GET("/share_photo/:code", share_img.GetSharePhoto)
//shopR.POST("/summary", shop.QueryShopSummary)
shopR.POST("/secondary/order/list", shop.QuerySecondaryOrders)
shopR.POST("/secondary/order/undelivered/list", shop.QuerySecondaryUndeliveredOrders)
shopR.POST("/secondary/order/unreceive/list", shop.QuerySecondaryUnreceiveOrders)
shopR.POST("/secondary/order/receive/list", shop.QuerySecondaryReceiveOrders)
shopR.POST("/secondary/order/goods/after_sales/list", shop.QuerySecondaryAfterSalesGoodsList)
shopR.POST("/secondary/order/goods/after_sales/detail", shop.QuerySecondaryAfterSalesGoodsDetail)
shopR.POST("/secondary/order/detail", shop.QuerySecondaryOrderDetail)
}
applicationR := v1.Group("application")
{
applicationR.POST("/launch", application.LaunchApp)

Loading…
Cancel
Save