|
|
package aftersales
|
|
|
|
|
|
import (
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/golangkit/formatime"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"math"
|
|
|
"recook/internal/back"
|
|
|
"recook/internal/dbc"
|
|
|
"recook/internal/model/aftersales"
|
|
|
"recook/internal/model/official"
|
|
|
"recook/tools"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
type afterSalesListParam struct {
|
|
|
UserID uint `json:"userId"`
|
|
|
Page uint `json:"page"`
|
|
|
Type uint `json:"type"`
|
|
|
ReturnStatus []uint
|
|
|
}
|
|
|
|
|
|
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 QueryAfterSalesGoodsList(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 == 1 {
|
|
|
p.ReturnStatus = []uint{1, 3, 4}
|
|
|
} else if p.Type == 2 {
|
|
|
p.ReturnStatus = []uint{2, 5, 6}
|
|
|
} else {
|
|
|
p.ReturnStatus = []uint{1, 2, 3, 4, 5, 6}
|
|
|
}
|
|
|
|
|
|
asGoodsList := make([]aftersales.Goods, 0, 0)
|
|
|
dbc.DB.Limit(10).Offset(10*p.Page).Order("id desc").Find(&asGoodsList, "user_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 == 6 {
|
|
|
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"`
|
|
|
AfterSalesGoodsId uint `json:"afterSalesGoodsId"`
|
|
|
}
|
|
|
|
|
|
type afterLogPem struct {
|
|
|
AsGoodsId uint `json:"asGoodsId"`
|
|
|
}
|
|
|
|
|
|
type returnGoodsResp struct {
|
|
|
aftersales.Goods
|
|
|
Title string `json:"title"`
|
|
|
Subtitle string `json:"subtitle"`
|
|
|
RightTile string `json:"rightTile"`
|
|
|
StatusTile int `json:"statusTile"`
|
|
|
ResidueHour float64 `json:"residueHour"`
|
|
|
Status int `json:"status"`
|
|
|
Address string `json:"address"` //售后地址
|
|
|
}
|
|
|
|
|
|
func QueryAfterSalesLog(c *gin.Context) {
|
|
|
var p afterLogPem
|
|
|
if err := tools.ParseParams(&p, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
//p.AsGoodsId=511220
|
|
|
var afterLog []aftersales.AftersalesLog
|
|
|
dbc.DB.Order("id desc").Find(&afterLog, "as_id=?", p.AsGoodsId)
|
|
|
back.Suc(c, "", &afterLog)
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
func QueryAfterSalesGoodsDetail(c *gin.Context) {
|
|
|
var p returnDetailParams
|
|
|
if err := tools.ParseParams(&p, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
//p.OrderGoodsID=872
|
|
|
|
|
|
var asGoods aftersales.Goods
|
|
|
if p.AfterSalesGoodsId > 0 {
|
|
|
if err := dbc.DB.Order("id DESC").First(&asGoods, "order_goods_id = ? and id=? ", p.OrderGoodsID, p.AfterSalesGoodsId).Error; err != nil {
|
|
|
back.Err(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
|
if err := dbc.DB.Order("id DESC").First(&asGoods, "order_goods_id = ?", p.OrderGoodsID).Error; err != nil {
|
|
|
back.Err(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
title := "待审核" //左边的状态文字
|
|
|
rightTile := "退款成功" //右边的状态文字
|
|
|
subtitle := "" //状态详细说明
|
|
|
statusTile := 0 //0,左边打钩,1右边打钩,2两边打叉
|
|
|
totalHours := 24.0
|
|
|
status := 0 //售后的状态
|
|
|
if asGoods.ReturnStatus == 1 {
|
|
|
//这个里面其实还包含了是否发货
|
|
|
if asGoods.IsShip == 0 {
|
|
|
//未发货
|
|
|
title = "待审核"
|
|
|
subtitle = "等待平台审核"
|
|
|
statusTile = 0
|
|
|
|
|
|
} else {
|
|
|
//已发货
|
|
|
title = "待审核"
|
|
|
subtitle = "等待平台审核"
|
|
|
statusTile = 0
|
|
|
|
|
|
}
|
|
|
status = 1
|
|
|
|
|
|
} else if asGoods.ReturnStatus == 2 {
|
|
|
//这个里面其实还包含了是否发货
|
|
|
if asGoods.IsShip == 0 {
|
|
|
//未发货
|
|
|
title = "申请未通过"
|
|
|
subtitle = "申请未通过"
|
|
|
statusTile = 2
|
|
|
status = 6
|
|
|
} else {
|
|
|
//已发货
|
|
|
title = "申请未通过"
|
|
|
subtitle = "申请未通过"
|
|
|
statusTile = 2
|
|
|
status = 7
|
|
|
}
|
|
|
rightTile = "退款关闭"
|
|
|
|
|
|
//subtitle = asGoods.RejectReason
|
|
|
} else if asGoods.ReturnStatus == 3 {
|
|
|
//这边要判断是否有拒绝理由,如果有,就换个文字显示
|
|
|
//这边要判断是否有拒绝理由,如果有,就换个文字显示
|
|
|
if len(asGoods.RejectReason) > 0 {
|
|
|
//已发货
|
|
|
title = "待买家寄回"
|
|
|
subtitle = "等待买家重新寄回"
|
|
|
statusTile = 0
|
|
|
rightTile = "退货成功"
|
|
|
totalHours = 48 //给买家48小时的退货时间
|
|
|
status = 4
|
|
|
} else {
|
|
|
//已发货
|
|
|
title = "待买家寄回"
|
|
|
subtitle = "等待买家寄回"
|
|
|
statusTile = 0
|
|
|
rightTile = "退货成功"
|
|
|
totalHours = 48 //给买家48小时的退货时间
|
|
|
status = 2
|
|
|
}
|
|
|
|
|
|
} else if asGoods.ReturnStatus == 4 {
|
|
|
if len(asGoods.RejectReason) > 0 {
|
|
|
|
|
|
}
|
|
|
title = "待平台收货"
|
|
|
subtitle = "等待平台收货"
|
|
|
statusTile = 0
|
|
|
rightTile = "退货成功"
|
|
|
status = 3
|
|
|
} else if asGoods.ReturnStatus == 5 {
|
|
|
//这个里面其实还包含了是否发货
|
|
|
if asGoods.IsShip == 0 {
|
|
|
//未发货
|
|
|
title = "审核通过"
|
|
|
subtitle = "已办理退款"
|
|
|
statusTile = 1
|
|
|
} else {
|
|
|
//已发货
|
|
|
title = "审核通过"
|
|
|
subtitle = "已办理退款"
|
|
|
statusTile = 1
|
|
|
rightTile = "退货成功"
|
|
|
}
|
|
|
status = 5
|
|
|
|
|
|
} else if asGoods.ReturnStatus == 6 { //这个状态没有了
|
|
|
title = "退货被拒绝"
|
|
|
subtitle = "请与商家沟通"
|
|
|
}
|
|
|
|
|
|
if asGoods.IsClosed == 1 { //这个需要在加一个状态
|
|
|
if asGoods.IsShip == 0 {
|
|
|
//未发货
|
|
|
title = "申请未通过"
|
|
|
subtitle = "申请未通过"
|
|
|
statusTile = 2
|
|
|
status = 6
|
|
|
} else {
|
|
|
//已发货
|
|
|
title = "申请未通过"
|
|
|
subtitle = "申请未通过"
|
|
|
statusTile = 2
|
|
|
status = 7
|
|
|
}
|
|
|
rightTile = "退款关闭"
|
|
|
}
|
|
|
|
|
|
residueHour := totalHours - math.Ceil((float64(time.Now().Unix())-float64(asGoods.CreatedAt.Time.Unix()))/3600)
|
|
|
|
|
|
//获取寄回地址
|
|
|
var addr official.ReturnAddress
|
|
|
dbc.DB.Last(&addr)
|
|
|
|
|
|
back.Suc(c, "", &returnGoodsResp{
|
|
|
Goods: asGoods,
|
|
|
Title: title,
|
|
|
Subtitle: subtitle,
|
|
|
RightTile: rightTile,
|
|
|
StatusTile: statusTile,
|
|
|
ResidueHour: residueHour, //剩余时间
|
|
|
Status: status, //售后状态
|
|
|
Address: addr.Address + " " + addr.Name + " " + addr.Mobile, //售后地址
|
|
|
|
|
|
})
|
|
|
}
|