|
|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"recook/internal/back"
|
|
|
|
|
"recook/internal/dbc"
|
|
|
|
|
"recook/internal/libs/snow"
|
|
|
|
|
"recook/internal/model/aftersales"
|
|
|
|
|
"recook/internal/model/goods"
|
|
|
|
|
"recook/internal/model/order"
|
|
|
|
@ -27,16 +28,14 @@ type applyRefundParam struct {
|
|
|
|
|
ReasonImg string `json:"reasonImg"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
退款
|
|
|
|
|
|
|
|
|
|
标记订单有售后痕迹
|
|
|
|
|
生成退款记录
|
|
|
|
|
|
|
|
|
|
钱包支付;退回商品用过的的余额
|
|
|
|
|
退回优惠券
|
|
|
|
|
退回运费
|
|
|
|
|
*/
|
|
|
|
|
// RefundOrder 退款
|
|
|
|
|
//
|
|
|
|
|
//标记订单有售后痕迹
|
|
|
|
|
//生成退款记录
|
|
|
|
|
//
|
|
|
|
|
//钱包支付;退回商品用过的的余额
|
|
|
|
|
//退回优惠券
|
|
|
|
|
//退回运费
|
|
|
|
|
func RefundOrder(c *gin.Context) {
|
|
|
|
|
var p applyRefundParam
|
|
|
|
|
err := tools.ParseParams(&p, c)
|
|
|
|
@ -45,11 +44,6 @@ func RefundOrder(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//p.UserID=4755
|
|
|
|
|
//p.OrderGoodsIDs=[]uint{872}
|
|
|
|
|
//p.Coin=decimal.NewFromInt(12)
|
|
|
|
|
//p.ReasonContent="测试理由"
|
|
|
|
|
|
|
|
|
|
if len(p.OrderGoodsIDs) == 0 {
|
|
|
|
|
back.Fail(c, "参数不完整")
|
|
|
|
|
return
|
|
|
|
@ -68,7 +62,7 @@ func RefundOrder(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if orderTemp.Kind == 1 || orderTemp.Kind == 2 {
|
|
|
|
|
if (orderTemp.Kind == 1 || orderTemp.Kind == 2) && orderTemp.JCookStatus == 0 {
|
|
|
|
|
var ogs []order.GoodsDetail
|
|
|
|
|
err = dbc.DB.Find(&ogs, "order_id = ?", orderTemp.ID).Error
|
|
|
|
|
if err != nil {
|
|
|
|
@ -91,16 +85,6 @@ func RefundOrder(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if one.StoreID > 0 {
|
|
|
|
|
//http.Fail(c, "门店订单不支持售后申请")
|
|
|
|
|
//return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if one.IsClosed == 1 {
|
|
|
|
|
//http.Fail(c, "该产品的售后已被关闭,无法再次申请,请联系客服")
|
|
|
|
|
//return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var count uint
|
|
|
|
|
dbc.DB.Table((&aftersales.Goods{}).TableName()).Where(aftersales.Goods{
|
|
|
|
|
OrderGoodsID: v,
|
|
|
|
@ -136,9 +120,6 @@ func RefundOrder(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//refundFee := decimal.NewFromFloat(0.0)
|
|
|
|
|
//由于业务的修改,其实这里的for只会循环一次
|
|
|
|
|
|
|
|
|
|
for _, v := range orderGoodsList {
|
|
|
|
|
|
|
|
|
|
if v.PayStatus == 0 {
|
|
|
|
@ -165,15 +146,8 @@ func RefundOrder(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//refundFee = refundFee.Add(v.ActualAmount)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if refundFee.GreaterThan(orderInfo.ActualTotalAmount) {
|
|
|
|
|
// http.Err(c, "计算错误!!! 退款金额大于总金额")
|
|
|
|
|
// return
|
|
|
|
|
//}
|
|
|
|
|
var goodsIds []uint
|
|
|
|
|
for _, detail := range orderGoodsList {
|
|
|
|
|
goodsIds = append(goodsIds, detail.GoodsID)
|
|
|
|
@ -184,9 +158,8 @@ func RefundOrder(c *gin.Context) {
|
|
|
|
|
for _, info := range goodsInfos {
|
|
|
|
|
goodsInfoMap[info.ID] = info
|
|
|
|
|
}
|
|
|
|
|
var idlist []uint
|
|
|
|
|
var ids []uint
|
|
|
|
|
for i, v := range orderGoodsList {
|
|
|
|
|
|
|
|
|
|
goodsDetail := orderGoodsList[i]
|
|
|
|
|
asGoods := aftersales.Goods{
|
|
|
|
|
AncestorID: v.AncestorID,
|
|
|
|
@ -242,14 +215,13 @@ func RefundOrder(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
tx := dbc.DB.Begin()
|
|
|
|
|
{
|
|
|
|
|
sql := `select max(id)+floor(1+rand()*50) from recook_after_sales_goods`
|
|
|
|
|
var lastId uint
|
|
|
|
|
if err = tx.Raw(sql).Count(&lastId).Error; err != nil {
|
|
|
|
|
back.Err(c, err.Error())
|
|
|
|
|
lastID, e := snow.GetAfsWorker().NextID()
|
|
|
|
|
if e != nil {
|
|
|
|
|
back.Err(c, "网络异常,请稍后重试")
|
|
|
|
|
tx.Rollback()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
asGoods.ID = lastId
|
|
|
|
|
asGoods.ID = uint(lastID)
|
|
|
|
|
if asGoods.IsShip == 1 {
|
|
|
|
|
tx.Model(&goodsDetail).Updates(order.GoodsDetail{
|
|
|
|
|
AssType: 3,
|
|
|
|
@ -265,7 +237,7 @@ func RefundOrder(c *gin.Context) {
|
|
|
|
|
tx.Rollback()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
idlist = append(idlist, asGoods.ID)
|
|
|
|
|
ids = append(ids, asGoods.ID)
|
|
|
|
|
if err := hook.AfterHook.Create(&goodsDetail, &asGoods); err != nil {
|
|
|
|
|
back.Err(c, err.Error())
|
|
|
|
|
tx.Rollback()
|
|
|
|
@ -273,47 +245,17 @@ func RefundOrder(c *gin.Context) {
|
|
|
|
|
}
|
|
|
|
|
//这里插入日志
|
|
|
|
|
user, _ := common.GetManageUser(c)
|
|
|
|
|
aftersalesLog := aftersales.AftersalesLog{
|
|
|
|
|
AsId: lastId,
|
|
|
|
|
Log := aftersales.AftersalesLog{
|
|
|
|
|
AsId: uint(lastID),
|
|
|
|
|
Title: "买家申请仅退款",
|
|
|
|
|
Content: "退款原因:" + p.ReasonContent + "|退款金额:" + (asGoods.RefundAmount).String() + "|退回瑞币:" + asGoods.RefundCoin.String(),
|
|
|
|
|
Ctime: formatime.NewSecondNow(),
|
|
|
|
|
User: user.Name,
|
|
|
|
|
UserId: user.Id,
|
|
|
|
|
}
|
|
|
|
|
tx.Create(&aftersalesLog)
|
|
|
|
|
|
|
|
|
|
// if orderInfo.PayMethod == 0 {
|
|
|
|
|
// err = recookpay.Refund(tx, &asGoods)
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// http.Err(c, err.Error())
|
|
|
|
|
// tx.Rollback()
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// } else if orderInfo.PayMethod == 1 {
|
|
|
|
|
// err = wxpay.Refund(&asGoods)
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// http.Err(c, err.Error())
|
|
|
|
|
// tx.Rollback()
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// } else if orderInfo.PayMethod == 2 {
|
|
|
|
|
// err = alipay.Refund(tx, &asGoods)
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// http.Err(c, err.Error())
|
|
|
|
|
// tx.Rollback()
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// } else if orderInfo.PayMethod == 4 {
|
|
|
|
|
// err = wxminipay.Refund(&asGoods)
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// http.Err(c, err.Error())
|
|
|
|
|
// tx.Rollback()
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (orderInfo.Kind == 1 || orderInfo.Kind == 2) && orderInfo.ApplyStatus != 11 && orderInfo.ApplyStatus != 12 {
|
|
|
|
|
tx.Create(&Log)
|
|
|
|
|
|
|
|
|
|
if (orderInfo.Kind == 1 || orderInfo.Kind == 2) && orderInfo.ApplyStatus != 11 && orderInfo.ApplyStatus != 12 && orderInfo.JCookStatus == 0 {
|
|
|
|
|
client := jcook.GetClient()
|
|
|
|
|
req := jcook.OrderCancelReq{
|
|
|
|
|
OrderID: orderInfo.JCookOrderID,
|
|
|
|
@ -337,7 +279,7 @@ func RefundOrder(c *gin.Context) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Set("status", "AfterApply")
|
|
|
|
|
c.Set("id", idlist)
|
|
|
|
|
c.Set("id", ids)
|
|
|
|
|
|
|
|
|
|
back.Suc(c, "申请成功,请等待商家审核", nil)
|
|
|
|
|
}
|
|
|
|
|