添加下单接口

This commit is contained in:
邹宗楠
2022-06-27 15:36:47 +08:00
parent 1eb31e2b92
commit 1400845af3
6 changed files with 266 additions and 11 deletions

View File

@@ -2,26 +2,103 @@ package q_bida
import (
"errors"
"fmt"
bida "git.rosy.net.cn/baseapi/platformapi/q_bida"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals/api"
"time"
)
func QueryExpressPrice(param *bida.GetExpressPriceReq) ([]*bida.GetExpressPriceData, error) {
// QueryExpressPrice 查询配送价格,获取所有快递价格
func QueryExpressPrice(param *bida.GetExpressPriceReq) (map[string]*bida.GetExpressPriceRes, error) {
if param.Weight <= 0 {
return nil, errors.New("物品重量必须大于0")
}
fee, err := api.QBiDaAPI.GetExpressPrice(param)
if err != nil {
return nil, err
}
// 渠道费每公斤加价两毛
for _, v := range fee {
if v.ChannelFee != 0 {
addFee := v.ChannelFee + int64(param.Width*2)
v.ChannelFee = addFee
result := make(map[string]*bida.GetExpressPriceRes, 0)
if param.Type == 0 {
// 渠道费每公斤加价两毛
for i := 1; i <= 14; i++ {
param.Type = i
fee, err := api.QBiDaAPI.GetExpressPrice(param)
if err != nil {
return nil, err
}
if fee.Code != 0 {
result[fmt.Sprintf("%d", i)] = fee
continue
}
if fee.Data.ChannelFee != 0 {
addFee := fee.Data.ChannelFee + utils.Int2Float64(param.Width*2)
fee.Data.ChannelFee = addFee
result[fmt.Sprintf("%d", i)] = fee
}
}
} else {
fee, err := api.QBiDaAPI.GetExpressPrice(param)
if err != nil {
return nil, err
}
if fee.Code != 0 {
// result[fmt.Sprintf("%d", param.Type)] = fee
return nil, errors.New(fee.Msg)
}
if fee.Data.ChannelFee != 0 {
addFee := fee.Data.ChannelFee + utils.Int2Float64(param.Width*2)
fee.Data.ChannelFee = addFee
result[fmt.Sprintf("%d", param.Type)] = fee
}
}
return fee, nil
return result, nil
}
// CreateWayOrder 创建快递订单
func CreateWayOrder(ctx *jxcontext.Context, param *model.MakeOrderParamReq, userId string) error {
// 检查价格
if err := checkWayFeeIsTrue(param); err != nil {
return err
}
// 创建三方订单
otherId, err := createOtherOrder(param)
if err != nil {
return err
}
// 第三方数据创建成功,则创建本地数据
vendorOrder := &model.UserVendorOrder{
UserId: userId,
LocalWayBill: utils.Int64ToStr(time.Now().Unix()) + userId[:4], // 当前时间秒数加用户ID前四位
OtherWayBill: otherId,
PromiseTimeType: param.PromiseTimeType,
DeliveryType: param.DeliveryType,
Goods: param.Goods,
GuaranteeValueAmount: param.GuaranteeValueAmount,
Weight: param.Weight,
Length: param.Length,
Height: param.Height,
Width: param.Width,
OrderSendTime: param.OrderSendTime,
PackageNum: param.PackageNum,
ReceiveAddressID: param.ReceiveAddressId,
Remark: param.Remark,
SenderAddressID: param.SenderAddressID,
ThirdPlatform: param.ThirdPlatform,
Type: param.Type,
ChannelFee: param.ChannelFee,
ServiceCharge: param.ServiceCharge,
GuarantFee: param.GuarantFee,
OriginalFee: param.OriginalFee,
Bulk: param.Bulk,
Increment: param.Increment,
ChannelType: param.ChannelType,
OrderStatus: model.YES, // 创建
Img: param.Img,
}
dao.WrapAddIDCULEntity(vendorOrder, ctx.GetUserName())
return vendorOrder.CreateVendorOrder()
}

View File

@@ -0,0 +1,61 @@
package q_bida
import (
"errors"
"fmt"
bida "git.rosy.net.cn/baseapi/platformapi/q_bida"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/globals/api"
)
// 检查快递费是否正确
func checkWayFeeIsTrue(param *model.MakeOrderParamReq) error {
// 检查运费提交是否准确
orderWayFee, err := QueryExpressPrice(&bida.GetExpressPriceReq{
PromiseTimeType: param.PromiseTimeType,
DeliveryType: param.DeliveryType,
GoodsValue: param.GuaranteeValueAmount,
ReceiveAddress: param.ReceiveAddress,
SendAddress: param.SenderAddress,
Type: param.Type,
Weight: param.Weight,
Length: param.Length,
Height: param.Height,
Width: param.Width,
SendPhone: param.SenderPhone,
})
if err != nil {
return err
}
if fee, ok := orderWayFee[fmt.Sprintf("%d", param.Type)]; !ok || fee.Code != 0 || fee.Data.ChannelFee != param.ChannelFee {
return errors.New("价格核算错误,价格不匹配")
}
return nil
}
// 创建QBiDa订单
func createOtherOrder(param *model.MakeOrderParamReq) (string, error) {
// 创建三方订单
return api.QBiDaAPI.CreateOrder(&bida.MakeOrderReq{
PromiseTimeType: param.PromiseTimeType,
DeliveryType: param.DeliveryType,
Goods: param.Goods,
GuaranteeValueAmount: param.GuaranteeValueAmount,
Weight: param.Weight,
Length: param.Length,
Height: param.Height,
Width: param.Width,
OrderSendTime: param.OrderSendTime,
PackageNum: param.PackageNum,
ReceiveAddress: param.ReceiveAddress,
ReceiveName: param.ReceiveName,
ReceivePhone: param.ReceivePhone,
Remark: param.Remark,
SenderAddress: param.SenderAddress,
SenderName: param.SenderName,
SenderPhone: param.SenderPhone,
ThirdPlatform: param.ThirdPlatform,
Type: param.Type,
Img: param.Img,
})
}