Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into feature/auth

This commit is contained in:
eson
2023-07-27 16:49:25 +08:00
63 changed files with 2319 additions and 142 deletions

View File

@@ -1,8 +1,75 @@
package configs
import (
"context"
"encoding/json"
"errors"
"fusenapi/constants"
"fusenapi/model/gmodel"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type WebSetTimeInfo struct {
ProductDay int64
FactoryDeliverDay int64
DeliverUpsDay int64
UpsTransDay int64
}
type WebSetTimeInfoData struct {
ProductDay string `json:"product_day"`
FactoryDeliverDay string `json:"factory_deliver_day"`
DeliverUpsDay string `json:"deliver_ups_day"`
UpsTransDay string `json:"ups_trans_day"`
}
func GetOrderTimeConfig(ctx context.Context, db *gorm.DB) (res WebSetTimeInfo, err error) {
resData, err := gmodel.NewFsWebSetModel(db).FindValueByKey(ctx, string(constants.WEBSET_TIME_INFO))
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
res.ProductDay = int64(constants.ORDER_PRODUCT_DAY)
res.FactoryDeliverDay = int64(constants.ORDER_FACTORY_DELIVER_DAY)
res.DeliverUpsDay = int64(constants.ORDER_DELIVER_UPS_DAY)
res.UpsTransDay = int64(constants.ORDER_UPS_TRANS_DAY)
return res, nil
}
logx.Error(err)
return res, err
} else {
var timeInfo WebSetTimeInfoData
err = json.Unmarshal([]byte(*resData.Value), &timeInfo)
if err != nil {
logx.Error(err)
return res, err
}
productDay, err := strconv.Atoi(timeInfo.ProductDay)
if err != nil {
logx.Error(err)
return res, err
}
factoryDeliverDay, err := strconv.Atoi(timeInfo.FactoryDeliverDay)
if err != nil {
logx.Error(err)
return res, err
}
deliverUpsDay, err := strconv.Atoi(timeInfo.DeliverUpsDay)
if err != nil {
logx.Error(err)
return res, err
}
upsTransDay, err := strconv.Atoi(timeInfo.UpsTransDay)
if err != nil {
logx.Error(err)
return res, err
}
res.ProductDay = int64(productDay)
res.FactoryDeliverDay = int64(factoryDeliverDay)
res.DeliverUpsDay = int64(deliverUpsDay)
res.UpsTransDay = int64(upsTransDay)
}
return res, nil
}

View File

@@ -0,0 +1,23 @@
package id_generator
import "sync"
type WebsocketId struct {
nodeId uint64
count uint64
mu sync.Mutex
}
func (wid *WebsocketId) Get() uint64 {
wid.mu.Lock()
defer wid.mu.Unlock()
wid.count++
return (wid.count << 8) | wid.nodeId
}
func NewWebsocketId(NodeId uint8) *WebsocketId {
return &WebsocketId{
nodeId: uint64(NodeId),
count: 0,
}
}

View File

@@ -37,6 +37,8 @@ type GetOrderStatusAndLogisticsReq struct {
OrderStatus constants.Order
DeliveryMethod constants.DeliveryMethod
IsPayCompleted int64
OrderCtime int64
SureTime int64
ProductTime int64
ProductEndtime int64
@@ -46,7 +48,6 @@ type GetOrderStatusAndLogisticsReq struct {
ArrivalTime int64
RecevieTime int64
OrderCtime int64
WebSetTimeInfo configs.WebSetTimeInfo
}
@@ -70,11 +71,11 @@ func GetOrderStatusAndLogistics(req GetOrderStatusAndLogisticsReq) (res GetOrder
times := make([]GetOrderStatusAndLogisticsResTimes, 5)
m := 1
for i := 0; i < 5; i++ {
m++
times[i] = GetOrderStatusAndLogisticsResTimes{
Key: m,
Time: "",
}
m++
}
switch req.OrderStatus {
@@ -160,6 +161,9 @@ func GetOrderStatusAndLogistics(req GetOrderStatusAndLogisticsReq) (res GetOrder
res.Times = times
} else {
timesData := times[0:3]
if logisticsStatus == constants.LOGISTICS_STATUS_DRAW {
timesData[1].Time = format.TimeIntToFormat(req.OrderCtime + req.WebSetTimeInfo.ProductDay*daySecond)
}
res.Times = timesData
}
return res

40
utils/pay/pay.go Normal file
View File

@@ -0,0 +1,40 @@
package pay
import "fusenapi/constants"
type Config struct {
// stripe支付
Stripe Stripe
}
// NewPayDriver 实例化方法
func NewPayDriver(PayMethod int64, config *Config) Pay {
switch PayMethod {
case int64(constants.PAYMETHOD_STRIPE):
return &Stripe{Key: config.Stripe.Key}
default:
return &Stripe{Key: config.Stripe.Key}
}
}
// Pay 支付集成接口
type Pay interface {
GeneratePrepayment(req *GeneratePrepaymentReq) (res *GeneratePrepaymentRes, err error)
}
type GeneratePrepaymentReq struct {
Amount int64 `json:"amount"` // 支付金额
Currency string `json:"currency"` // 支付货币
ProductName string `json:"product_name"` // 商品名称
ProductDescription string `json:"product_description"` // 商品描述
ProductImages []*string `json:"product_imageso"` // 商品照片
Quantity int64 `json:"quantity"` //数量
SuccessURL string `json:"success_url"` // 支付成功回调
CancelURL string `json:"cancel_url"` // 支付取消回调
}
type GeneratePrepaymentRes struct {
URL string `json:"url"` // 支付重定向地址
TradeNo string `json:"trade_no"` //交易ID
}

58
utils/pay/stripe.go Normal file
View File

@@ -0,0 +1,58 @@
package pay
import (
"github.com/stripe/stripe-go/v74"
"github.com/stripe/stripe-go/v74/checkout/session"
)
type Stripe struct {
Key string `json:"key"`
}
// 生成预付款
func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *GeneratePrepaymentRes, err error) {
var productData stripe.CheckoutSessionLineItemPriceDataProductDataParams
if req.ProductName != "" {
productData.Name = stripe.String(req.ProductName)
}
if req.ProductDescription != "" {
productData.Description = stripe.String(req.ProductDescription)
}
if len(req.ProductImages) > 0 {
productData.Images = req.ProductImages
}
// var images = make([]*string, 1)
// var image string = "https://img2.woyaogexing.com/2023/07/25/133132a32b9f79cfad84965a4bea57e0.jpg"
// images[0] = stripe.String(image)
// productData.Images = images
stripe.Key = stripePay.Key
params := &stripe.CheckoutSessionParams{
LineItems: []*stripe.CheckoutSessionLineItemParams{
{
PriceData: &stripe.CheckoutSessionLineItemPriceDataParams{
Currency: stripe.String(req.Currency),
ProductData: &productData,
UnitAmount: stripe.Int64(req.Amount),
},
Quantity: stripe.Int64(req.Quantity),
},
},
Mode: stripe.String(string(stripe.CheckoutSessionModePayment)),
SuccessURL: stripe.String(req.SuccessURL),
CancelURL: stripe.String(req.CancelURL),
}
result, err := session.New(params)
if err != nil {
return nil, err
}
return &GeneratePrepaymentRes{
URL: result.URL,
TradeNo: result.ID,
}, err
}