feat:新增订单发票,下单地址调整

This commit is contained in:
momo
2023-10-17 18:32:43 +08:00
parent 0310a6bd21
commit 6ae2cce870
23 changed files with 848 additions and 59 deletions

View File

@@ -19,4 +19,13 @@ type Config struct {
SuccessURL string
}
}
AWS struct {
S3 struct {
Credentials struct {
AccessKeyID string
Secret string
Token string
}
}
}
}

View File

@@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/order/internal/logic"
"fusenapi/server/order/internal/svc"
"fusenapi/server/order/internal/types"
)
func OrderInvoiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.OrderInvoiceReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewOrderInvoiceLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.OrderInvoice(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@@ -37,6 +37,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/order/close",
Handler: CloseOrderHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/order/invoice",
Handler: OrderInvoiceHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/order/list",

View File

@@ -43,16 +43,28 @@ func (l *CreatePrePaymentByDepositLogic) CreatePrePaymentByDeposit(req *types.Cr
if req.DeliveryAddress == nil {
return resp.SetStatus(basic.CodeErrOrderCreatePrePaymentParam)
} else {
if req.DeliveryAddress.Address == "" || req.DeliveryAddress.Mobile == "" || req.DeliveryAddress.Name == "" {
if req.DeliveryAddress.Street == "" ||
req.DeliveryAddress.City == "" ||
req.DeliveryAddress.Mobile == "" ||
req.DeliveryAddress.State == "" ||
req.DeliveryAddress.Suite == "" ||
req.DeliveryAddress.ZipCode == "" ||
req.DeliveryAddress.LastName == "" ||
req.DeliveryAddress.FirstName == "" {
return resp.SetStatus(basic.CodeErrOrderCreatePrePaymentParam)
}
}
}
var orderAddress repositories.OrderAddress
if req.DeliveryAddress != nil {
orderAddress.Address = req.DeliveryAddress.Address
orderAddress.Street = req.DeliveryAddress.Street
orderAddress.City = req.DeliveryAddress.City
orderAddress.FirstName = req.DeliveryAddress.FirstName
orderAddress.LastName = req.DeliveryAddress.LastName
orderAddress.Mobile = req.DeliveryAddress.Mobile
orderAddress.Name = req.DeliveryAddress.Name
orderAddress.State = req.DeliveryAddress.State
orderAddress.Suite = req.DeliveryAddress.Suite
orderAddress.ZipCode = req.DeliveryAddress.ZipCode
}
res, err := l.svcCtx.Repositories.NewOrder.CreatePrePaymentByDeposit(l.ctx, &repositories.CreatePrePaymentByDepositReq{
UserId: userinfo.UserId,

View File

@@ -0,0 +1,57 @@
package logic
import (
"fusenapi/service/repositories"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/order/internal/svc"
"fusenapi/server/order/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type OrderInvoiceLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewOrderInvoiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderInvoiceLogic {
return &OrderInvoiceLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *OrderInvoiceLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *OrderInvoiceLogic) OrderInvoice(req *types.OrderInvoiceReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if !userinfo.IsUser() {
// 如果是,返回未授权的错误码
return resp.SetStatus(basic.CodeUnAuth)
}
res, err := l.svcCtx.Repositories.NewOrder.Invoice(l.ctx, &repositories.InvoiceReq{
OrderSn: req.OrderSn,
UserId: userinfo.UserId,
})
if err != nil {
return resp.SetStatus(&res.ErrorCode)
}
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
"invoice_urls": res.InvoiceUrls,
})
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *OrderInvoiceLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@@ -7,6 +7,9 @@ import (
"fusenapi/initalize"
"fusenapi/model/gmodel"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"gorm.io/gorm"
)
@@ -20,10 +23,14 @@ type ServiceContext struct {
}
func NewServiceContext(c config.Config) *ServiceContext {
configAWS := aws.Config{
Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token),
}
conn := initalize.InitMysql(c.SourceMysql)
// delayQueue := initalize.InitDelayMessage()
repositories := initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: conn,
GormDB: conn,
AwsSession: session.Must(session.NewSession(&configAWS)),
// DelayQueue: delayQueue,
})

View File

@@ -5,6 +5,10 @@ import (
"fusenapi/utils/basic"
)
type OrderInvoiceReq struct {
OrderSn string `form:"order_sn"`
}
type CloseOrderReq struct {
OrderSn string `json:"order_sn"`
}
@@ -28,9 +32,14 @@ type CreatePrePaymentByDepositReq struct {
}
type DeliveryAddress struct {
Address string `json:"address,optional"`
Name string `json:"name,optional"`
Mobile string `json:"mobile,optional"`
Street string `json:"street,optional"` // 街道
City string `json:"city,optional"` // 城市
FirstName string `json:"first_name,optional"` // 姓
LastName string `json:"last_name,optional"` // 名
Mobile string `json:"mobile,optional"` // 手机
State string `json:"state,optional"` // 州
Suite string `json:"suite,optional"` // 房号
ZipCode string `json:"zip_code,optional"` // 邮编
}
type CreatePrePaymentByBalanceReq struct {

281
server/order/invoice.html Normal file
View File

@@ -0,0 +1,281 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Invoice</title>
<style>
@font-face {
font-family: "Montserrat-SemiBold";
src: url("https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/b808164b4f7ecc19f560d235db5b1f5b99fe8ab218b606f15debab2b9c4230e2");
}
@font-face {
font-family: "Montserrat-Medium";
src: url("https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/3d91bbd91ba6fac26b8460a078742b61bfd1e2976311c065f8ac9c5270be6901");
}
@font-face {
font-family: "Montserrat-Light";
src: url("https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/24e580a4a5afebf94596ec7b6c8d9c8d57f75a5429ee757217da552d5f03e5d1");
}
@font-face {
font-family: "Montserrat-Regular";
src: url("https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/78072d2cbce0a3f88c01ab2830ba3a453f0968b516388e45e9a6fb5e970450b8");
}
body {
margin: 0;
}
.header_warp {
background-color: #F8F8FA;
padding: 20px 5% 20px 6%;
}
.header_td {
width: 50%;
font-family: Montserrat-SemiBold;
}
.header_td.logo {
vertical-align: top;
}
.header_logo {
max-height: 15px;
max-width: 100%;
margin-top: 5px;
}
.header_td.title {
color: #212121;
font-weight: 600;
font-size: 36px;
}
.information_warp {
padding: 30px 5% 30px 6%;
}
.information_td {
width: 50%;
font-size: 13px;
line-height: 20px;
font-weight: 300;
font-family: Montserrat-Light;
}
.information_td.bill {
color: #212121;
font-weight: 500;
font-family: Montserrat-Medium;
}
.information_td.right {
color: #212121;
}
.information_td.info {
color: #666666;
line-height: 17px;
}
.bill_warp {
padding: 0 5% 0 6%;
}
.bill_td {
font-size: 13px;
}
.bill_td:first-child {
width: 47.59%;
}
.bill_td.title {
border-top: 2px solid #333;
padding: 13px 0 7px;
font-weight: 500;
color: #212121;
font-family: Montserrat-Medium;
}
.bill_td.info {
color: #666;
border-bottom: 1px solid #ccc;
padding: 8px 0;
font-weight: 400;
font-family: Montserrat-Light;
}
.bill_td.info:first-child {
font-family: Montserrat-Regular;
}
.bill_warp tr:last-child .bill_td.info {
border-bottom: none;
}
.total_warp {
padding: 14px 5% 24px 0;
}
.total_td {
color: #212121;
padding: 8px 0 7px;
font-size: 12px;
font-weight: 500;
font-family: Montserrat-Medium;
}
.total_td.info {
color: #666;
font-weight: 400;
font-family: Montserrat-Regular;
}
.total_td.border-dashed {
border-bottom: 1px dashed #ccc;
}
.total_td.border-solid {
border-bottom: 2px solid #333;
padding-bottom: 12px;
}
.total_td.total {
padding-top: 12px;
font-size: 13px;
font-weight: 600;
font-family: Montserrat-SemiBold;
}
.notes_warp {
padding: 0 5% 0 6%;
}
.notes_td {
font-size: 13px;
color: #666;
font-weight: 300;
width: 50%;
line-height: 21px;
font-family: Montserrat-Light;
}
.notes_td.title {
color: #212121;
font-weight: 500;
font-family: Montserrat-Medium;
}
.notes_td.notes {
vertical-align: top;
}
</style>
</head>
<body>
<!-- header -->
<table class="header_warp" border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="header_td logo" align="left">
<img class="header_logo" src="https://fusenapi.kayue.cn:8010/storage/email/logo.png" alt="logo">
</td>
<td class="header_td title" align="right">Invoice</td>
</tr>
</table>
<!-- information -->
<table class="information_warp" border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="information_td bill" align="left">Bill To:</td>
<td class="information_td right" align="right">Invoice No. #20220562040</td>
</tr>
<tr>
<td class="information_td info" align="left">Timmy Turner</td>
<td class="information_td right" align="right">Date: 2023/12/04</td>
</tr>
<tr>
<td class="information_td info" align="left">North Street</td>
<td class="information_td" align="right"></td>
</tr>
<tr>
<td class="information_td info" align="left">London, SE20 3JW</td>
<td class="information_td" align="right"></td>
</tr>
<tr>
<td class="information_td info" align="left">United Kingdom</td>
<td class="information_td" align="right"></td>
</tr>
</table>
<!-- bill -->
<table class="bill_warp" border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="bill_td title" align="left">Product Name</td>
<td class="bill_td title" align="right">Price</td>
<td class="bill_td title" align="right">Quantity</td>
<td class="bill_td title" align="right">Total</td>
</tr>
<tr>
<td class="bill_td info" align="left">Plastic bowl</td>
<td class="bill_td info" align="right">$01.00</td>
<td class="bill_td info" align="right">20,000 Units</td>
<td class="bill_td info" align="right">$99.00</td>
</tr>
<tr>
<td class="bill_td info" align="left">Paper bag with handlexxxxxxxxxxxxxxx second line</td>
<td class="bill_td info" align="right">$01.00</td>
<td class="bill_td info" align="right">20,000 Units</td>
<td class="bill_td info" align="right">$99.00</td>
</tr>
</table>
<!-- total -->
<table class="total_warp" border="0" align="right" cellpadding="0" cellspacing="0" width="50%">
<tr>
<td class="total_td" align="right">Subtotal</td>
<td class="total_td info" align="right">$198.00</td>
</tr>
<tr>
<td class="total_td" align="right">Shipping Fee</td>
<td class="total_td info" align="right">Free</td>
</tr>
<tr>
<td class="total_td border-dashed" align="right">Tax</td>
<td class="total_td info border-dashed" align="right">$0.00</td>
</tr>
<tr>
<td class="total_td" align="right">Total</td>
<td class="total_td info" align="right">$198.00</td>
</tr>
<tr>
<td class="total_td border-solid" align="right">Deposit Requested</td>
<td class="total_td info border-solid" align="right">$99.00</td>
</tr>
<tr>
<td class="total_td total" align="right">Deposit Due</td>
<td class="total_td total" align="right">$99.00</td>
</tr>
</table>
<!-- notes -->
<table class="notes_warp" border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="notes_td title" align="left">Payment Method:</td>
<td class="notes_td title" align="left">Notes:</td>
</tr>
<tr>
<td class="notes_td" align="left">ICBC</td>
<td class="notes_td notes" align="left" rowspan="2">Thank you for your business !</td>
</tr>
<tr>
<td class="notes_td" align="left">Account No. :20000000001</td>
</tr>
</table>
</body>
</html>