|
|
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 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,
|
|
|
})
|
|
|
}
|