master
howell 4 years ago
parent cffc42ce44
commit a57b25c809

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

@ -6,6 +6,7 @@ import (
"recook/internal/back"
"recook/internal/cache"
"recook/internal/dbc"
"recook/internal/libs/snow"
"recook/internal/model/aftersales"
"recook/internal/model/goods"
"recook/internal/model/order"
@ -33,21 +34,18 @@ func GetAfterSalesReason(c *gin.Context) {
var orderReson []order.Reason
dbc.DB.Where("is_delete = 0").Find(&orderReson)
back.Suc(c, "获取成功", &orderReson)
}
/*
退
退
退
退退
退退
退
*/
// ApplyReturnOrder 退货 等待商家审核
//
//一个订单可能引发多次退货
//
//用户申请了一次退货后,
//如果退货还在审核,用户继续提价其他商品退货
//将这次退货补充到退货系统里区
//
//如果上次已经审核过了
//则创建退货记录
func ApplyReturnOrder(c *gin.Context) {
var p applyReturnParam
if err := tools.ParseParams(&p, c); err != nil {
@ -70,16 +68,6 @@ func ApplyReturnOrder(c *gin.Context) {
back.Fail(c, err.Error())
return
}
if one.StoreID > 0 {
//http.Fail(c, "门店订单不支持售后申请")
//return
}
if one.IsClosed == 1 {
//http.Fail(c, "该产品的售后已被关闭,无法再次申请,请联系客服")
//return
}
orderGoodsList = append(orderGoodsList, one)
}
@ -189,14 +177,14 @@ func ApplyReturnOrder(c *gin.Context) {
ReasonImg: p.ReasonImg,
RefundNo: fmt.Sprintf("%vA%d", orderInfo.TradeNo, v.ID),
}
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
}
one.ID = lastId
one.ID = uint(lastID)
if err := tx.Create(&one).Error; err != nil {
back.Err(c, err.Error())
@ -210,16 +198,16 @@ func ApplyReturnOrder(c *gin.Context) {
return
}
//这里插入日志
userlog, _ := common.GetManageUser(c)
aftersalesLog := aftersales.AftersalesLog{
AsId: lastId,
userLog, _ := common.GetManageUser(c)
Log := aftersales.AftersalesLog{
AsId: uint(lastID),
Title: "买家申请退货",
Content: "退货原因:" + p.ReasonContent + "|退款金额:" + one.RefundAmount.String() + "|退回瑞币:" + one.RefundCoin.Add(one.ExpressFree).String(),
Ctime: formatime.NewSecondNow(),
User: userlog.Name,
UserId: userlog.Id,
User: userLog.Name,
UserId: userLog.Id,
}
tx.Create(&aftersalesLog)
tx.Create(&Log)
}
}

@ -17,10 +17,7 @@ type cancelOrderParam struct {
OrderID uint `json:"orderId"`
}
// CancelOrder 取消订单
//标记订单取消
//优惠券退回
//瑞币退回
// CancelOrder 取消订单 标记订单取消
func CancelOrder(c *gin.Context) {
var p cancelOrderParam
err := tools.ParseParams(&p, c)

@ -85,6 +85,7 @@ func TaskMq() {
go orderCreate()
go OrderPay()
go OrderStockOut()
go OrderFinished()
go OrderCancel()
}
@ -208,8 +209,11 @@ func OrderFinished() {
log.Println(err.Error())
return err
}
order3.ConfirmOrderTradeSuc(&od)
od.JCookStatus = 1
if err = mysql.Db.Save(od).Error; err != nil {
log.Println(err.Error())
return err
}
return nil
})
}

@ -7,6 +7,7 @@ import (
)
var OrderWorker *Worker
var AfsWorker *Worker
var once sync.Once
func GetOrderWorker() *Worker {
@ -16,6 +17,13 @@ func GetOrderWorker() *Worker {
return OrderWorker
}
func GetAfsWorker() *Worker {
once.Do(func() {
AfsWorker = NewWorker(1, 2)
})
return AfsWorker
}
const (
workerIDBits = uint64(4)
businessIDBits = uint64(4)

@ -49,6 +49,7 @@ type Information struct {
JCookRootID uint `gorm:"column:jcook_root_id" json:"jcook_root_id"`
JCookParentID uint `gorm:"column:jcook_parent_id" json:"jcook_parent_id"`
Cost decimal.Decimal `json:"cost"`
JCookStatus int `gorm:"column:jcook_status" json:"jcook_status"`
}
const (

Loading…
Cancel
Save