105 lines
3.1 KiB
Go
105 lines
3.1 KiB
Go
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"
|
|
)
|
|
|
|
// QueryExpressPrice 查询配送价格,获取所有快递价格
|
|
func QueryExpressPrice(param *bida.GetExpressPriceReq) (map[string]*bida.GetExpressPriceRes, error) {
|
|
if param.Weight <= 0 {
|
|
return nil, errors.New("物品重量必须大于0")
|
|
}
|
|
|
|
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 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()
|
|
}
|