更新合并
This commit is contained in:
parent
d64998c16d
commit
6c6066cea1
@ -20,6 +20,6 @@ func (o *FsOrderModel) FindOne(ctx context.Context, userId int64, OrderId int64)
|
|||||||
return order, err
|
return order, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *FsOrderModel) Update(ctx context.Context, id int64, data FsOrder) error {
|
func (o *FsOrderModel) Update(ctx context.Context, data *FsOrder) error {
|
||||||
return o.db.WithContext(ctx).Model(&FsOrder{}).Where("`id` = ?", id).Updates(data).Error
|
return o.db.WithContext(ctx).Model(data).Where("`id` = ?", data.Id).Updates(data).Error
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,9 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
||||||
|
|
||||||
|
func (fsRefundReason *FsRefundReasonModel) Update(cxt context.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/server/home-user-auth/internal/svc"
|
"fusenapi/server/home-user-auth/internal/svc"
|
||||||
@ -29,7 +30,7 @@ func NewUserFontsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserFon
|
|||||||
|
|
||||||
func (l *UserFontsLogic) UserFonts(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *UserFontsLogic) UserFonts(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
data, err := gmodel.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
|
data, err := gmodel.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
|
||||||
if err != gorm.ErrRecordNotFound && err != nil {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatus(basic.CodeOK)
|
return resp.SetStatus(basic.CodeOK)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
@ -34,7 +35,7 @@ func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *basic.Res
|
|||||||
|
|
||||||
// 在用户数据表中根据登录名(email)查找用户记录,并返回 UserModel 类型的结构体对象 userModel。
|
// 在用户数据表中根据登录名(email)查找用户记录,并返回 UserModel 类型的结构体对象 userModel。
|
||||||
user, err := m.FindUserByEmail(l.ctx, req.Name)
|
user, err := m.FindUserByEmail(l.ctx, req.Name)
|
||||||
if err == gorm.ErrRecordNotFound {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return resp.SetStatus(basic.CodeEmailNotFoundErr), ""
|
return resp.SetStatus(basic.CodeEmailNotFoundErr), ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"log"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
@ -35,8 +35,6 @@ func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo
|
|||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
// userinfo 传入值时, 一定不为null
|
// userinfo 传入值时, 一定不为null
|
||||||
|
|
||||||
log.Println(req)
|
|
||||||
|
|
||||||
if !userinfo.IsUser() {
|
if !userinfo.IsUser() {
|
||||||
return resp.SetStatus(basic.CodeUnAuth) // 如果不是用户信息, 返回未授权错误
|
return resp.SetStatus(basic.CodeUnAuth) // 如果不是用户信息, 返回未授权错误
|
||||||
}
|
}
|
||||||
@ -50,7 +48,7 @@ func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo
|
|||||||
m := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
m := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||||
order, err := m.FindOne(l.ctx, userinfo.UserId, orderId)
|
order, err := m.FindOne(l.ctx, userinfo.UserId, orderId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == gorm.ErrRecordNotFound {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return resp.SetStatus(basic.CodeOrderNotFoundErr)
|
return resp.SetStatus(basic.CodeOrderNotFoundErr)
|
||||||
}
|
}
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
@ -71,6 +69,63 @@ func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo
|
|||||||
return resp.SetStatus(basic.CodeOrderNotCancelledErr)
|
return resp.SetStatus(basic.CodeOrderNotCancelledErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//这里是将给定的PHP代码翻译成Golang代码:
|
||||||
|
|
||||||
|
uOrder := &gmodel.FsOrder{
|
||||||
|
Id: orderId,
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
isCancel int64 = 1
|
||||||
|
ustatus int64 = int64(constants.STATUS_NEW_CANCEL)
|
||||||
|
)
|
||||||
|
// 修改取消状态和取消原因
|
||||||
|
uOrder.Status = &ustatus
|
||||||
|
uOrder.IsCancel = &isCancel
|
||||||
|
uOrder.RefundReasonId = &req.RefundReasonId
|
||||||
|
uOrder.RefundReason = &req.RefundReason
|
||||||
|
|
||||||
|
err = m.Update(l.ctx, uOrder)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatus(basic.CodeDbUpdateErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
IsRefund int64 = 0
|
||||||
|
CreatedAt = time.Now().Unix()
|
||||||
|
)
|
||||||
|
|
||||||
|
refund := &gmodel.FsRefundReason{
|
||||||
|
IsRefund: &IsRefund,
|
||||||
|
RefundReasonId: &req.RefundReasonId,
|
||||||
|
RefundReason: &req.RefundReason,
|
||||||
|
OrderId: &order.Id,
|
||||||
|
CreatedAt: &CreatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
mFsRefund := gmodel.NewFsRefundReasonModel(l.svcCtx.MysqlConn)
|
||||||
|
|
||||||
|
err = refund.Save()
|
||||||
|
|
||||||
|
// 退款
|
||||||
|
// 调用第三方接口发起退款
|
||||||
|
config := GetStripeConfig()
|
||||||
|
|
||||||
|
// 查询支付信息
|
||||||
|
pays, err := Pay.Find(db.Where("order_number = ? AND is_refund = ? AND pay_status = ?", order.SN, 0, 1))
|
||||||
|
for _, pay := range pays {
|
||||||
|
stripe := stripe.New(config.SK)
|
||||||
|
_, err := stripe.Refunds.Create(stripe.RefundParams{
|
||||||
|
PaymentIntent: pay.TradeNo,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil && err == nil {
|
||||||
|
return ResponseSuccess(200, "Cancel successfully", order)
|
||||||
|
}
|
||||||
|
return ResponseError(500, "Cancellation failure")
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
return resp.SetStatus(basic.CodeOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,9 @@ type RequestAddAddress struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RequestOrderId struct {
|
type RequestOrderId struct {
|
||||||
OrderId int64 `json:"id"`
|
OrderId int64 `json:"id"` //订单id
|
||||||
|
RefundReasonId int64 `json:"refund_reason_id"` //取消原因id
|
||||||
|
RefundReason string `json:"refund_reason"` //取消原因
|
||||||
}
|
}
|
||||||
|
|
||||||
type DataUserLogin struct {
|
type DataUserLogin struct {
|
||||||
|
@ -50,7 +50,7 @@ func (l *ChangeOrderMethodLogic) ChangeOrderMethod(req *types.ChangeOrderMethodR
|
|||||||
if *orderInfo.PayedAmount > 0 {
|
if *orderInfo.PayedAmount > 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeApiErr, "the order`s address cannot be changed for it is paid")
|
return resp.SetStatusWithMessage(basic.CodeApiErr, "the order`s address cannot be changed for it is paid")
|
||||||
}
|
}
|
||||||
updData := gmodel.FsOrder{}
|
updData := &gmodel.FsOrder{Id: orderInfo.Id}
|
||||||
//地址
|
//地址
|
||||||
if req.AddressId > 0 {
|
if req.AddressId > 0 {
|
||||||
addressModel := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn)
|
addressModel := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||||
@ -69,7 +69,7 @@ func (l *ChangeOrderMethodLogic) ChangeOrderMethod(req *types.ChangeOrderMethodR
|
|||||||
updData.DeliveryMethod = &req.DeliveryMethod
|
updData.DeliveryMethod = &req.DeliveryMethod
|
||||||
updData.AddressId = &req.AddressId
|
updData.AddressId = &req.AddressId
|
||||||
updData.PayMethod = &req.PayMethod
|
updData.PayMethod = &req.PayMethod
|
||||||
if err = orderModel.Update(l.ctx, orderInfo.Id, updData); err != nil {
|
if err = orderModel.Update(l.ctx, updData); err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to save data")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to save data")
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,9 @@ type RequestAddAddress {
|
|||||||
|
|
||||||
// RequestOrderId 传入订单id的结构
|
// RequestOrderId 传入订单id的结构
|
||||||
type RequestOrderId {
|
type RequestOrderId {
|
||||||
OrderId int64 `json:"id"`
|
OrderId int64 `json:"id"` //订单id
|
||||||
|
RefundReasonId int64 `json:"refund_reason_id"` //取消原因id
|
||||||
|
RefundReason string `json:"refund_reason"` //取消原因
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserLoginHandler 用户登录请求结构
|
// UserLoginHandler 用户登录请求结构
|
||||||
|
Loading…
x
Reference in New Issue
Block a user