支付回调以后更新订单状态

This commit is contained in:
2026-09-11 17:06:04 +08:00
parent a1c377489c
commit 4ff974eb8d
11 changed files with 235 additions and 99 deletions
+18 -27
View File
@@ -124,33 +124,6 @@ type OrderPay struct {
OutTradeNo string `gorm:"column:out_trade_no;type:varchar(50);comment:支付订单号;NOT NULL" json:"out_trade_no"`
}
type OrderDown struct {
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
StoreId int `gorm:"column:store_id;type:int(11);comment:美容院关联ID号" json:"store_id"`
StoreName string `gorm:"column:store_name;type:varchar(50);comment:门店名" json:"store_name"`
SaleName string `gorm:"column:sale_name;type:varchar(50);comment:销售姓名" json:"sale_name"`
SaleMobile string `gorm:"column:sale_mobile;type:char(60);comment:销售电话" json:"sale_mobile"`
SaleId int `gorm:"column:sale_id;type:int(11);comment:销售员ID号" json:"sale_id"`
Mobile string `gorm:"column:mobile;type:char(60);comment:收货人手机号;NOT NULL" json:"mobile"`
Address string `gorm:"column:address;type:varchar(255);comment:收货人地址;NOT NULL" json:"address"`
Addressee string `gorm:"column:addressee;type:varchar(50);comment:收货人姓名;NOT NULL" json:"addressee"`
DistrictIds string `gorm:"column:district_ids;type:varchar(255);comment:地区IDS;NOT NULL" json:"district_ids"`
TotalPrice float64 `gorm:"column:total_price;type:decimal(10,2);comment:总价;NOT NULL" json:"total_price"`
PayPrice float64 `gorm:"column:pay_price;type:decimal(10,2);comment:实际支付金额" json:"pay_price"`
PayType uint8 `gorm:"column:pay_type;type:tinyint(1);default:1;comment:支付类型,1为微信,2为支付宝,3为余额支付" json:"pay_type"`
Status uint8 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"`
ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"`
SignTime utils.CustomTime `gorm:"column:sign_time;type:datetime;comment:签收时间" json:"sign_time"`
CreateType uint8 `gorm:"column:create_type;type:tinyint(1);default:1;comment:下单人类型,1为销售,2为门店,3为个人;NOT NULL" json:"create_type"`
CreateTime utils.CustomTime `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP;comment:订单创建时间" json:"create_time"`
ProductName string `gorm:"-" json:"product_name"`
TypeName string `gorm:"-" json:"type_name"`
BankInfo string `gorm:"-" json:"bank_info"`
OriginalMobile string `gorm:"-" json:"original_mobile"`
OriginalSaleMobile string `gorm:"-" json:"original_sale_mobile"`
}
type OrderSaleItems struct {
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
@@ -274,6 +247,7 @@ type OrderInfoDetail struct {
DeliverStatus int32 `gorm:"column:deliver_status;type:tinyint(1);default:2;comment:发货状态,1为已签收,2为待发货,3为发货中,4为已发货" json:"deliver_status"`
Status int32 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"`
IsSupply int32 `gorm:"column:is_supply;type:tinyint(1);default:1;comment:是否补过货,1为没有,2为补过" json:"is_supply"`
RemitNo string `json:"remit_no" gorm:"remit_no"` // 线下汇款单号
Note string `gorm:"column:note;type:varchar(255);comment:备注" json:"note"`
ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"`
OutTradeNo string `gorm:"column:out_trade_no;type:varchar(50);comment:支付订单号" json:"out_trade_no"`
@@ -287,3 +261,20 @@ type Items struct {
Count int64 `json:"count" default:"0" type:"int"`
Items any `json:"items"`
}
type UpPayStatus struct {
Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
PayPrice float64 `gorm:"column:pay_price;type:decimal(10,2);comment:实际支付金额" json:"pay_price"`
PayType int32 `gorm:"column:pay_type;type:tinyint(1);default:1;comment:支付类型,1为微信,2为支付宝,3为余额支付" json:"pay_type"`
Status int32 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"`
RemitNo string `json:"remit_no" gorm:"remit_no"` // 线下汇款单号
OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"`
Mobile string `gorm:"column:mobile;type:char(60);comment:收货人手机号;NOT NULL" json:"mobile"`
Address string `gorm:"column:address;type:varchar(255);comment:收货人地址;NOT NULL" json:"address"`
Addressee string `gorm:"column:addressee;type:varchar(50);comment:收货人姓名;NOT NULL" json:"addressee"`
DistrictIds string `gorm:"column:district_ids;type:varchar(255);comment:地区IDS;NOT NULL" json:"district_ids"`
DeliverStatus uint8 `gorm:"column:deliver_status;type:tinyint(1);default:2;comment:发货状态,1为已签收,2为待发货,3为发货中,4为已发货" json:"deliver_status"`
DeliverType uint8 `json:"deliver_type" gorm:"deliver_type"` // 发货类型,1为需要发货,2为不需要发货
VerifyStatus uint8 `gorm:"column:verify_status;type:tinyint(1);default:0;comment:审核状态,1为通过,2为失败,3为待审核,0为正常订单不需要审核" json:"verify_status"`
ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"`
}
@@ -19,7 +19,6 @@ type GetOrderInfoLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewGetOrderInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderInfoLogic {
@@ -1,31 +0,0 @@
package logic
import (
"context"
"lone-services/rpc/order/pb"
"lone-services/services/order/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateOrderDPayStatusLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewUpdateOrderDPayStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrderDPayStatusLogic {
return &UpdateOrderDPayStatusLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateOrderDPayStatusLogic) UpdateOrderDPayStatus(in *order.UpdateOrderPayStatusRequest) (*order.UpdateOrderPayStatusResponse, error) {
// todo: add your logic here and delete this line
return &order.UpdateOrderPayStatusResponse{}, nil
}
@@ -4,11 +4,9 @@ import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/rpc/order/pb"
"lone-services/services/order/internal/dao"
"lone-services/services/order/internal/model"
"lone-services/services/order/validator"
"lone-services/rpc/order/pb"
"lone-services/services/order/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
@@ -32,11 +30,6 @@ func NewUpdateOrderDeliverStatusLogic(ctx context.Context, svcCtx *svc.ServiceCo
}
func (l *UpdateOrderDeliverStatusLogic) UpdateOrderDeliverStatus(in *order.UpdateOrderDeliverStatusRequest) (*order.UpdateOrderDeliverStatusResponse, error) {
var v validator.UpdateOrderDeliverStatusValidator
if fail := l.checkParams(in, &v); fail != nil {
return nil, status.Error(codes.InvalidArgument, fail.Msg)
}
data := dao.OrderDeliverGoodsStatus{
DeliverStatus: uint8(in.DeliverStatus),
}
@@ -0,0 +1,182 @@
package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
chore "lone-services/rpc/chore/pb"
express "lone-services/rpc/express/pb"
product "lone-services/rpc/product/pb"
"lone-services/services/order/internal/dao"
"lone-services/services/order/internal/model"
"strconv"
"strings"
"lone-services/rpc/order/pb"
"lone-services/services/order/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type UpdateOrderPayStatusLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateOrderPayStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrderPayStatusLogic {
return &UpdateOrderPayStatusLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateOrderPayStatusLogic) UpdateOrderPayStatus(in *order.UpdateOrderPayStatusRequest) (*order.UpdateOrderPayStatusResponse, error) {
var info dao.UpPayStatus
w := modelbase.Params{
Eq: map[string]string{"order_sn": in.OrderSn},
}
modelObj := model.OrderModel{}.Init()
err := modelObj.GetOne(w, &info)
if err != nil {
return nil, status.Error(codes.Internal, utils.Fail.Msg)
}
if info.Id < utils.NumberOne {
return nil, status.Error(codes.Internal, utils.ErrorNotFund.Msg)
}
info.PayPrice = utils.RoundMoney(in.PayPrice)
info.PayType = in.PayType
info.RemitNo = in.RemitNo
if in.Status == dao.OrderPayStatusOk {
info.Status = dao.OrderPayStatusOk
} else if in.Status == dao.OrderPayStatusFail {
info.Status = dao.OrderPayStatusFail
} else {
return nil, status.Error(codes.Internal, utils.ErrorParams.Msg)
}
deliverGoods, s := l.getDeliveryInfo(info)
if s != utils.Ok {
return nil, status.Error(codes.Internal, s.Msg)
}
_, err = modelObj.Edit(w, info)
if err != nil {
return nil, status.Error(codes.Internal, utils.Fail.Msg)
}
s = l.setDeliverGoods(deliverGoods)
if s != utils.Ok {
return nil, status.Error(codes.Internal, s.Msg)
}
return &order.UpdateOrderPayStatusResponse{Id: info.Id}, nil
}
func (l *UpdateOrderPayStatusLogic) setDeliverGoods(data express.DeliveryOrderCreateRequest) utils.Status {
cli, err := svc.GetRpcClient(l.svcCtx.ExpressSvcName)
if err != nil {
return utils.ErrorInternalServer
}
client := express.NewExpressClient(cli.Conn())
_, err = client.DeliveryOrderCreate(l.ctx, &data)
if err != nil {
logx.Errorf("set products err: %v", err)
return utils.ErrorInternalServer
}
return utils.Ok
}
func (l *UpdateOrderPayStatusLogic) getDeliveryInfo(info dao.UpPayStatus) (express.DeliveryOrderCreateRequest, utils.Status) {
deliverGoods := express.DeliveryOrderCreateRequest{
ObjId: strconv.FormatInt(info.Id, utils.NumberTen),
Mobile: info.Mobile,
Address: info.Address,
Addressee: info.Addressee,
ObjSn: info.OrderSn,
Type: dao.DeliverTypeOrder,
Status: dao.SendStatusWait,
}
if info.DeliverType == dao.OrderDeliverTypeSend {
deliverGoods.Status = dao.SendStatusOver
}
w := modelbase.Params{Eq: map[string]string{"order_sn": info.OrderSn}}
var orderProducts []dao.OrderProductInfo
err := model.OrderProductModel{}.Init().Items(w, &orderProducts)
if err != nil || len(orderProducts) < utils.NumberOne {
logx.Errorf("get products err: %v", err)
return deliverGoods, utils.ErrorNotFund
}
var productIds []int64
idsNumber := make(map[int64]int)
for _, item := range orderProducts {
productIds = append(productIds, item.ProductId)
idsNumber[item.ProductId] = item.Number
}
cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName)
if err != nil {
logx.Errorf("get products err: %v", err)
return deliverGoods, utils.ErrorInternalServer
}
productClient := product.NewProductClient(cli.Conn())
productItems, err := productClient.ItemsByIds(l.ctx, &product.ItemsByIdsReq{Ids: productIds})
if err != nil {
logx.Errorf("get products err: %v", err)
return deliverGoods, utils.ErrorInternalServer
}
for _, item := range productItems.Items {
number := utils.NumberZero
if _, ok := idsNumber[item.Id]; ok {
number = idsNumber[item.Id]
}
deliverGoods.ProductInfo = append(deliverGoods.ProductInfo, &express.DeliverOrderProductInfo{
ProductId: item.Id,
Number: int32(number),
Type: int32(item.Type),
ProductName: item.Name,
Price: item.Price,
})
}
clic, err := svc.GetRpcClient(l.svcCtx.ChoreSvcName)
if err != nil {
logx.Errorf("get region err: %v", err)
return deliverGoods, utils.ErrorInternalServer
}
var regionIds []int64
for _, item := range strings.Split(info.DistrictIds, utils.DecollatorComma) {
id, _ := strconv.Atoi(item)
regionIds = append(regionIds, int64(id))
}
clicClient := chore.NewChoreClient(clic.Conn())
regionItems, err := clicClient.RegionsByIds(l.ctx, &chore.RegionsByIdsReq{Ids: regionIds})
if err != nil {
logx.Errorf("get region err: %v", err)
return deliverGoods, utils.ErrorInternalServer
}
switch len(regionItems.Items) {
case utils.NumberOne:
deliverGoods.Province = regionItems.Items[utils.NumberZero].Name
case utils.NumberTwo:
deliverGoods.Province = regionItems.Items[utils.NumberZero].Name
deliverGoods.City = regionItems.Items[utils.NumberOne].Name
case utils.NumberThree:
deliverGoods.Province = regionItems.Items[utils.NumberZero].Name
deliverGoods.City = regionItems.Items[utils.NumberOne].Name
deliverGoods.County = regionItems.Items[utils.NumberTwo].Name
}
return deliverGoods, utils.Ok
}
@@ -123,7 +123,7 @@ func (s *OrderServer) GetOrderInfo(ctx context.Context, in *order.GetOrderInfoRe
return l.GetOrderInfo(in)
}
func (s *OrderServer) UpdateOrderDPayStatus(ctx context.Context, in *order.UpdateOrderPayStatusRequest) (*order.UpdateOrderPayStatusResponse, error) {
l := logic.NewUpdateOrderDPayStatusLogic(ctx, s.svcCtx)
return l.UpdateOrderDPayStatus(in)
func (s *OrderServer) UpdateOrderPayStatus(ctx context.Context, in *order.UpdateOrderPayStatusRequest) (*order.UpdateOrderPayStatusResponse, error) {
l := logic.NewUpdateOrderPayStatusLogic(ctx, s.svcCtx)
return l.UpdateOrderPayStatus(in)
}