fix:合并
This commit is contained in:
parent
e4343eb2d6
commit
ca7cf4c81e
85
constants/orders.go
Normal file
85
constants/orders.go
Normal file
|
@ -0,0 +1,85 @@
|
|||
package constants
|
||||
|
||||
// 货币
|
||||
type Currency string
|
||||
|
||||
const (
|
||||
Usd Currency = "usd"
|
||||
)
|
||||
|
||||
// 金额单位
|
||||
type AmountUnit string
|
||||
|
||||
// 交易方式
|
||||
type PayMethods string
|
||||
|
||||
const (
|
||||
Card PayMethods = "CARD"
|
||||
Visa PayMethods = "VISA"
|
||||
)
|
||||
|
||||
// 支付状态
|
||||
type PayStatusCode int64
|
||||
|
||||
const (
|
||||
PayStatusUnpaid PayStatusCode = 10 //10,未支付
|
||||
PayStatusPaid PayStatusCode = 20 //20,已支付
|
||||
PayStatusRefunded PayStatusCode = 30 //30,已退款
|
||||
)
|
||||
|
||||
// 订单状态
|
||||
type OrderStatusCode int64
|
||||
|
||||
const (
|
||||
ORDERSTATUSUNPAIDDEPOSIT OrderStatusCode = 0 // 0,未支付定金
|
||||
ORDERSTATUSDIRECTMAILORDERED OrderStatusCode = 10100 // 10100,直邮单--已下单
|
||||
ORDERSTATUSDIRECTMAILCANCEL OrderStatusCode = 10101 // 10101,直邮单--已取消
|
||||
ORDERSTATUSDIRECTMAILSTARTPRODUCTION OrderStatusCode = 10200 // 10200,直邮单--开始生产
|
||||
ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION OrderStatusCode = 10300 // 10300,直邮单--生产完成
|
||||
ORDERSTATUSDIRECTMAILSHIPPED OrderStatusCode = 10400 // 10400,直邮单--已发货
|
||||
ORDERSTATUSDIRECTMAILARRIVED OrderStatusCode = 10500 // 10500,直邮单--已到达
|
||||
ORDERSTATUSCLOUDSTOREORDERED OrderStatusCode = 20100 // 20100,云仓单--已下单
|
||||
ORDERSTATUSCLOUDSTORECANCEL OrderStatusCode = 20101 // 20101,云仓单--已取消
|
||||
ORDERSTATUSCLOUDSTORESTARTPRODUCTION OrderStatusCode = 20200 // 20200,云仓单--开始生产
|
||||
ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION OrderStatusCode = 20300 // 20300,云仓单--生产完成
|
||||
ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE OrderStatusCode = 20400 // 20400,云仓单--直达仓库
|
||||
)
|
||||
|
||||
// 订单状态名称
|
||||
var OrderStatusMessage map[OrderStatusCode]string
|
||||
|
||||
// 支付状态名称
|
||||
var PayStatusMessage map[PayStatusCode]string
|
||||
|
||||
// 订单状态--用户可见
|
||||
var OrderStatusUser []OrderStatusCode
|
||||
|
||||
func init() {
|
||||
// 订单状态名称
|
||||
PayStatusMessage = make(map[PayStatusCode]string)
|
||||
PayStatusMessage[PayStatusUnpaid] = "Paid"
|
||||
PayStatusMessage[PayStatusPaid] = "Unpaid"
|
||||
PayStatusMessage[PayStatusRefunded] = "Refunded"
|
||||
|
||||
// 订单状态名称
|
||||
OrderStatusMessage = make(map[OrderStatusCode]string)
|
||||
OrderStatusMessage[ORDERSTATUSUNPAIDDEPOSIT] = "未支付定金"
|
||||
|
||||
OrderStatusMessage[ORDERSTATUSDIRECTMAILORDERED] = "直邮单--已下单"
|
||||
OrderStatusMessage[ORDERSTATUSDIRECTMAILSTARTPRODUCTION] = "直邮单--开始生产"
|
||||
OrderStatusMessage[ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION] = "直邮单--生产完成"
|
||||
OrderStatusMessage[ORDERSTATUSDIRECTMAILSHIPPED] = "直邮单--已发货"
|
||||
OrderStatusMessage[ORDERSTATUSDIRECTMAILARRIVED] = "直邮单--已到达"
|
||||
|
||||
OrderStatusMessage[ORDERSTATUSCLOUDSTOREORDERED] = "云仓单--已下单"
|
||||
OrderStatusMessage[ORDERSTATUSCLOUDSTORESTARTPRODUCTION] = "云仓单--开始生产"
|
||||
OrderStatusMessage[ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION] = "云仓单--生产完成"
|
||||
OrderStatusMessage[ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE] = "云仓单--直达仓库"
|
||||
|
||||
// 订单状态--用户可见
|
||||
OrderStatusUser = []OrderStatusCode{
|
||||
ORDERSTATUSUNPAIDDEPOSIT,
|
||||
ORDERSTATUSDIRECTMAILORDERED, ORDERSTATUSDIRECTMAILSTARTPRODUCTION, ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION, ORDERSTATUSDIRECTMAILSHIPPED, ORDERSTATUSDIRECTMAILARRIVED,
|
||||
ORDERSTATUSCLOUDSTOREORDERED, ORDERSTATUSCLOUDSTORESTARTPRODUCTION, ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION, ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE,
|
||||
}
|
||||
}
|
25
model/gmodel/fs_cloud_storage_gen.go
Normal file
25
model/gmodel/fs_cloud_storage_gen.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// fs_cloud_storage 仓库的基本信息, 只做映射
|
||||
type FsCloudStorage struct {
|
||||
CloudStorageId *string `gorm:"unique_key;default:'';" json:"cloud_storage_id"` // 仓库id, 需要固定的命名规则, 能表达国外国内,区域等,简单明了
|
||||
Name *string `gorm:"default:'';" json:"name"` // 仓库的名字, 中文使用拼音,国外使用英文
|
||||
Address *string `gorm:"default:'';" json:"address"` // 仓库地址
|
||||
Contact *[]byte `gorm:"default:'';" json:"contact"` //
|
||||
Ownership *int64 `gorm:"default:0;" json:"ownership"` // 0为自有, 1为第三方, 后期可以自由定制
|
||||
Scope *[]byte `gorm:"default:'';" json:"scope"` //
|
||||
Capacity *[]byte `gorm:"default:'';" json:"capacity"` //
|
||||
Metadata *[]byte `gorm:"default:'';" json:"metadata"` //
|
||||
}
|
||||
type FsCloudStorageModel struct {
|
||||
db *gorm.DB
|
||||
name string
|
||||
}
|
||||
|
||||
func NewFsCloudStorageModel(db *gorm.DB) *FsCloudStorageModel {
|
||||
return &FsCloudStorageModel{db: db, name: "fs_cloud_storage"}
|
||||
}
|
2
model/gmodel/fs_cloud_storage_logic.go
Normal file
2
model/gmodel/fs_cloud_storage_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
|
@ -10,12 +10,13 @@ type FsOrder struct {
|
|||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 订单ID
|
||||
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID
|
||||
DeliveryMethod *int64 `gorm:"index;default:0;" json:"delivery_method"` // 物流类型
|
||||
OrderNo *string `gorm:"index;default:'';" json:"order_no"` //
|
||||
OrderSn *string `gorm:"index;default:'';" json:"order_sn"` //
|
||||
OrderSource *string `gorm:"default:'';" json:"order_source"` //
|
||||
Status *int64 `gorm:"index;default:0;" json:"status"` // 订单状态
|
||||
Metadata *[]byte `gorm:"default:'';" json:"metadata"` //
|
||||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
||||
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:0=否,1=是
|
||||
}
|
||||
type FsOrderModel struct {
|
||||
db *gorm.DB
|
||||
|
|
297
model/gmodel/fs_order_logic.go
Executable file → Normal file
297
model/gmodel/fs_order_logic.go
Executable file → Normal file
|
@ -1,192 +1,189 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fusenapi/constants"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"fusenapi/utils/handlers"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (o *FsOrderModel) FindOneBySn(ctx context.Context, userId int64, sn string) (resp *FsOrder, err error) {
|
||||
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where(" `user_id` = ? and `sn` = ? ", userId, sn).Take(&resp).Error
|
||||
return resp, err
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
type NewFsOrder struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 订单ID
|
||||
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID
|
||||
DeliveryMethod *int64 `gorm:"index;default:0;" json:"delivery_method"` // 物流类型
|
||||
OrderSn *string `gorm:"index;default:'';" json:"order_sn"` //
|
||||
OrderSource *string `gorm:"default:'';" json:"order_source"` //
|
||||
Status *int64 `gorm:"index;default:0;" json:"status"` // 订单状态
|
||||
Metadata *OrderDetail `gorm:"metadata,type:json" json:"metadata"` //
|
||||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
||||
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:0=否,1=是
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) FindOne(ctx context.Context, userId int64, OrderId int64) (order *FsOrder, err error) {
|
||||
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
// 订单详情
|
||||
type OrderDetail struct {
|
||||
DeliveryAddress *OrderAddress `json:"delivery_address"` // 收货地址
|
||||
OrderAmount OrderAmount `json:"order_amount"` // 订单金额
|
||||
OrderInfo OrderInfo `json:"order_info"` // 订单信息
|
||||
OrderProduct []OrderProduct `json:"order_product"` // 订单商品
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) Update(ctx context.Context, data *FsOrder) error {
|
||||
return o.db.WithContext(ctx).Model(&FsOrder{}).Where("`id` = ?", data.Id).Updates(&data).Error
|
||||
// 收货地址
|
||||
type OrderAddress struct {
|
||||
Address string `json:"address"` // 详细地址
|
||||
Mobile string `json:"mobile"` // 手机
|
||||
Name string `json:"name"` // 姓名
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) RBUpdate(ctx context.Context, data *FsOrder) error {
|
||||
return o.db.WithContext(ctx).Where("`id` = ?", data.Id).Updates(&data).Error
|
||||
// 订单金额
|
||||
type OrderAmount struct {
|
||||
Deposit PayInfo `json:"deposit"` // 定金
|
||||
RemainingBalance PayInfo `json:"remaining_balance"` // 尾款
|
||||
Discount AmountInfo `json:"discount"` // 折扣
|
||||
ShippingFee AmountInfo `json:"shipping_fee"` // 邮费
|
||||
Tax AmountInfo `json:"tax"` // 税费
|
||||
Subtotal AmountInfo `json:"subtotal"` // 商品总金额
|
||||
Total AmountInfo `json:"total"` // 订单总金额
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) Create(ctx context.Context, data *FsOrder) error {
|
||||
return o.db.WithContext(ctx).Model(&FsOrder{}).Create(&data).Error
|
||||
// 支付明细
|
||||
type PayInfo struct {
|
||||
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
||||
PayAmount AmountInfo `json:"pay_amount"` // 金额明细
|
||||
PayMethod string `json:"pay_method"` // 交易方式
|
||||
PayTime string `json:"pay_time"` // 支付时间
|
||||
Status PayStatus `json:"status"` // 当前状态
|
||||
StatusLink []PayStatus `json:"status_link"` // 状态链路
|
||||
TradeNo string `json:"trade_no"` // 支付交易号
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) FindOneAndCreateServiceContact(ctx context.Context, userId int64, OrderId int64, cs *FsContactService) (order *FsOrder, err error) {
|
||||
err = o.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
err = tx.Model(&FsOrder{}).Select("id").Limit(1).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctime := time.Now().UTC().Unix()
|
||||
cs.Ctime = &ctime
|
||||
if constants.ConcactService(*cs.Type) == constants.TYPE_DEFAULT {
|
||||
*cs.RelationId = 0
|
||||
}
|
||||
|
||||
return tx.Model(&FsContactService{}).Create(cs).Error
|
||||
})
|
||||
return order, err
|
||||
// 金额明细
|
||||
type AmountInfo struct {
|
||||
ExchangeRate string `json:"exchange_rate"` // 换算汇率
|
||||
Change constants.AmountUnit `json:"change,omitempty"` // 变动金额
|
||||
ChangeRemark string `json:"change_remark,omitempty"` // 变动备注状态编码
|
||||
Currency string `json:"currency"` // 货币
|
||||
Current constants.AmountUnit `json:"current"` // 当前金额
|
||||
Initiate constants.AmountUnit `json:"initiate"` // 初始金额
|
||||
Metadata map[string]interface{} `json:"metadata"` // 额外明细
|
||||
}
|
||||
|
||||
// 获取用户最近下单成功的订单
|
||||
func (o *FsOrderModel) FindLastSuccessOneOrder(ctx context.Context, userId int64, statusGt int64) (order *FsOrder, err error) {
|
||||
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where("`user_id` = ? and `status` > ?", userId, statusGt).Order("id DESC").Take(&order).Error
|
||||
return order, err
|
||||
// 金额货币
|
||||
type AmountCurrency struct {
|
||||
CurrentAmount constants.AmountUnit `json:"current_amount"` // 当前金额
|
||||
CurrentCurrency string `json:"current_currency"` // 当前货币
|
||||
ExchangeRate string `json:"exchange_rate"` // 换算汇率
|
||||
OriginalAmount constants.AmountUnit `json:"original_amount"` // 原始金额
|
||||
OriginalCurrency string `json:"original_currency"` // 原始货币
|
||||
}
|
||||
|
||||
// 分页查询的订单
|
||||
func (o *FsOrderModel) FindPageListByPage(ctx context.Context, rowBuilder *gorm.DB, page *int64, pageSize *int64, filterMap map[string]string, orderBy string) ([]*FsOrderRel, error) {
|
||||
var resp []*FsOrderRel
|
||||
// 过滤
|
||||
if filterMap != nil {
|
||||
rowBuilder = rowBuilder.Scopes(handlers.FilterData(filterMap))
|
||||
}
|
||||
|
||||
// 排序
|
||||
if orderBy != "" {
|
||||
var fieldsMap = make(map[string]struct{})
|
||||
s := reflect.TypeOf(&FsOrder{}).Elem() //通过反射获取type定义
|
||||
for i := 0; i < s.NumField(); i++ {
|
||||
fieldsMap[s.Field(i).Tag.Get("json")] = struct{}{}
|
||||
}
|
||||
rowBuilder = rowBuilder.Scopes(handlers.OrderCheck(orderBy, fieldsMap))
|
||||
}
|
||||
|
||||
// 分页
|
||||
rowBuilder = rowBuilder.Scopes(handlers.Paginate(page, pageSize))
|
||||
|
||||
// 结果
|
||||
result := rowBuilder.Debug().WithContext(ctx).Find(&resp)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
} else {
|
||||
return resp, nil
|
||||
}
|
||||
// 支付状态
|
||||
type PayStatus struct {
|
||||
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
||||
StatusCode int64 `json:"status_code"` // 状态编码
|
||||
StatusTitle string `json:"status_title"` // 状态名称
|
||||
}
|
||||
|
||||
type FsOrderRel struct {
|
||||
FsOrder
|
||||
FsOrderDetails []FsOrderDetails `gorm:"foreignKey:order_id;references:id"`
|
||||
FsOrderAffiliateInfo FsOrderAffiliate `gorm:"foreignKey:order_id;references:id"`
|
||||
// 订单信息
|
||||
type OrderInfo struct {
|
||||
Ctime string `json:"ctime"` // 创建日期
|
||||
DeliveryMethod int64 `json:"delivery_method"` // 物流类型
|
||||
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
||||
OrderSn string `json:"order_sn"` // 订单编号
|
||||
Status OrderStatus `json:"status"` // 当前状态
|
||||
StatusLink []OrderStatus `json:"status_link"` // 状态链路
|
||||
Utime string `json:"utime"` // 更新时间
|
||||
}
|
||||
|
||||
type FsOrderDetails struct {
|
||||
FsOrderDetail
|
||||
FsOrderDetailTemplateInfo FsOrderDetailTemplateInfo `gorm:"foreignKey:id;references:order_detail_template_id"`
|
||||
FsProductInfo FsProduct `gorm:"foreignKey:id;references:product_id"`
|
||||
// 订单状态--用户
|
||||
type OrderStatus struct {
|
||||
Children []*OrderStatus `json:"children"` // 子状态,管理人员的处理状态, 用户不可见
|
||||
Ctime string `json:"ctime"` // 创建时间
|
||||
ExpectedTime string `json:"expected_time"` // 预计时间
|
||||
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
||||
StatusCode constants.OrderStatusCode `json:"status_code"` // 状态编码
|
||||
StatusTitle string `json:"status_title"` // 状态名称
|
||||
Utime string `json:"utime"` // 更新时间
|
||||
}
|
||||
|
||||
type FsOrderDetailTemplateInfo struct {
|
||||
FsOrderDetailTemplate
|
||||
FsProductDesignInfo FsProductDesignInfo `gorm:"foreignKey:id;references:design_id"` //获取设计数据
|
||||
FsProductSizeInfo FsProductSize `gorm:"foreignKey:id;references:size_id"`
|
||||
// 订单商品
|
||||
type OrderProduct struct {
|
||||
Amount AmountCurrency `json:"amount"` // 商品总价
|
||||
ExpectedDeliveryTime string `json:"expected_delivery_time"` // 预计到货时间
|
||||
Number int64 `json:"number"` // 商品数量
|
||||
ProductID string `json:"product_id"` // 商品ID
|
||||
ProductLogo string `json:"product_logo"` // 商品logo
|
||||
ProductLogoResource *Resource `json:"product_logo_resource"` // 商品封面--资源详情
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
ProductPrice AmountCurrency `json:"product_price"` // 商品单价
|
||||
ProductSnapshot map[string]interface{} `json:"product_snapshot"` // 商品快照
|
||||
ShoppingCartSnapshot *ShoppingCartSnapshot `json:"shopping_cart_snapshot"` // 购物车快照
|
||||
Unit string `json:"unit"` // 商品单位
|
||||
}
|
||||
|
||||
type FsProductDesignInfo struct {
|
||||
FsProductDesign
|
||||
OptionData FsProduct `gorm:"foreignKey:id;references:optional_id"` //获取配件信息
|
||||
TemplateData FsProductTemplateV2 `gorm:"foreignKey:id;references:template_id"` //获取模板信息
|
||||
// 资源详情
|
||||
type Resource struct {
|
||||
Metadata map[string]interface{} `json:"metadata"` // 资源额外
|
||||
ResourceID string `json:"resource_id"` // 资源ID
|
||||
ResourceType string `json:"resource_type"` // 资源类型
|
||||
ResourceURL string `json:"resource_url"` // 资源地址
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) RowSelectBuilder(selectData []string) *gorm.DB {
|
||||
var rowBuilder = m.db.Table(m.name)
|
||||
|
||||
if selectData != nil {
|
||||
rowBuilder = rowBuilder.Select(selectData)
|
||||
} else {
|
||||
rowBuilder = rowBuilder.Select("*")
|
||||
}
|
||||
return rowBuilder
|
||||
// 购物车
|
||||
type ShoppingCartSnapshot struct {
|
||||
Ctime string `json:"ctime"` // 创建时间
|
||||
FittingID int64 `json:"fitting_id"` // 配件id
|
||||
ID int64 `json:"id"` // 购物车ID
|
||||
IsHighlyCustomized int64 `json:"is_highly_customized"` // 是否高度定制 0非 1是(针对客人高度定制只能后台增加如购物车)
|
||||
ModelID int64 `json:"model_id"` // 模型id
|
||||
ProductID int64 `json:"product_id"` // 产品id
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` // 购买数量
|
||||
SizeID int64 `json:"size_id"` // 尺寸id
|
||||
Snapshot Snapshot `json:"snapshot"` // 购物车快照数据
|
||||
TemplateID int64 `json:"template_id"` // 模板id
|
||||
UserID int64 `json:"user_id"` // 用户id
|
||||
Utime string `json:"utime"` // 更新时间
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) BuilderTrans(selectData []string) *gorm.DB {
|
||||
var rowBuilder = m.db
|
||||
|
||||
if selectData != nil {
|
||||
rowBuilder = rowBuilder.Select(selectData)
|
||||
} else {
|
||||
rowBuilder = rowBuilder.Select("*")
|
||||
}
|
||||
return rowBuilder
|
||||
// 购物车快照
|
||||
type Snapshot struct {
|
||||
CombineImage string `json:"combine_image"` // 刀版图地址
|
||||
FittingInfo FittingInfo `json:"fitting_info"`
|
||||
Logo string `json:"logo"` // logo地址
|
||||
ModelInfo ModelInfo `json:"model_info"`
|
||||
RenderImage string `json:"render_image"` // 模板数据
|
||||
SizeInfo SizeInfo `json:"size_info"`
|
||||
TemplateInfo TemplateInfo `json:"template_info"`
|
||||
UserDiyInformation UserDiyInformation `json:"user_diy_information"`
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) FindCount(ctx context.Context, countBuilder *gorm.DB, filterMap map[string]string) (int64, error) {
|
||||
var count int64
|
||||
|
||||
// 过滤
|
||||
if filterMap != nil {
|
||||
countBuilder = countBuilder.Scopes(handlers.FilterData(filterMap))
|
||||
}
|
||||
|
||||
result := countBuilder.WithContext(ctx).Limit(1).Count(&count)
|
||||
if result.Error != nil {
|
||||
return 0, result.Error
|
||||
} else {
|
||||
return count, nil
|
||||
}
|
||||
// 配件信息
|
||||
type FittingInfo struct {
|
||||
FittingJSON string `json:"fitting_json"`
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) FindOneByQuery(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string) (*FsOrderRel, error) {
|
||||
var resp FsOrderRel
|
||||
|
||||
if filterMap != nil {
|
||||
rowBuilder = rowBuilder.Scopes(handlers.FilterData(filterMap))
|
||||
}
|
||||
|
||||
result := rowBuilder.WithContext(ctx).Limit(1).Find(&resp)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
} else {
|
||||
return &resp, nil
|
||||
}
|
||||
// 模型数据
|
||||
type ModelInfo struct {
|
||||
ModelJSON string `json:"model_json"`
|
||||
}
|
||||
|
||||
// 事务
|
||||
func (m *FsOrderModel) Trans(ctx context.Context, fn func(ctx context.Context, connGorm *gorm.DB) error) error {
|
||||
tx := m.db.Table(m.name).WithContext(ctx).Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
if err := tx.Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := fn(ctx, tx); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit().Error
|
||||
// 尺寸信息
|
||||
type SizeInfo struct {
|
||||
CM string `json:"cm"`
|
||||
Inch string `json:"inch"`
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) TableName() string {
|
||||
return m.name
|
||||
// 模板数据
|
||||
type TemplateInfo struct {
|
||||
TemplateJSON string `json:"template_json"`
|
||||
TemplateTag string `json:"template_tag"`
|
||||
}
|
||||
|
||||
// DIY数据
|
||||
type UserDiyInformation struct {
|
||||
Address string `json:"address"` // 地址
|
||||
Phone string `json:"phone"` // 电话
|
||||
Qrcode string `json:"qrcode"` // 二维码
|
||||
Slogan string `json:"slogan"` // slogan
|
||||
Website string `json:"website"` // 网站
|
||||
}
|
||||
|
|
192
model/gmodel/fs_order_logic_1.go
Executable file
192
model/gmodel/fs_order_logic_1.go
Executable file
|
@ -0,0 +1,192 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fusenapi/constants"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"fusenapi/utils/handlers"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (o *FsOrderModel) FindOneBySn(ctx context.Context, userId int64, sn string) (resp *FsOrder, err error) {
|
||||
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where(" `user_id` = ? and `sn` = ? ", userId, sn).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) FindOne(ctx context.Context, userId int64, OrderId int64) (order *FsOrder, err error) {
|
||||
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) Update(ctx context.Context, data *FsOrder) error {
|
||||
return o.db.WithContext(ctx).Model(&FsOrder{}).Where("`id` = ?", data.Id).Updates(&data).Error
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) RBUpdate(ctx context.Context, data *FsOrder) error {
|
||||
return o.db.WithContext(ctx).Where("`id` = ?", data.Id).Updates(&data).Error
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) Create(ctx context.Context, data *FsOrder) error {
|
||||
return o.db.WithContext(ctx).Model(&FsOrder{}).Create(&data).Error
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) FindOneAndCreateServiceContact(ctx context.Context, userId int64, OrderId int64, cs *FsContactService) (order *FsOrder, err error) {
|
||||
err = o.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
err = tx.Model(&FsOrder{}).Select("id").Limit(1).Where("`user_id` = ? and `id` = ?", userId, OrderId).Take(&order).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctime := time.Now().UTC().Unix()
|
||||
cs.Ctime = &ctime
|
||||
if constants.ConcactService(*cs.Type) == constants.TYPE_DEFAULT {
|
||||
*cs.RelationId = 0
|
||||
}
|
||||
|
||||
return tx.Model(&FsContactService{}).Create(cs).Error
|
||||
})
|
||||
return order, err
|
||||
}
|
||||
|
||||
// 获取用户最近下单成功的订单
|
||||
func (o *FsOrderModel) FindLastSuccessOneOrder(ctx context.Context, userId int64, statusGt int64) (order *FsOrder, err error) {
|
||||
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where("`user_id` = ? and `status` > ?", userId, statusGt).Order("id DESC").Take(&order).Error
|
||||
return order, err
|
||||
}
|
||||
|
||||
// 分页查询的订单
|
||||
func (o *FsOrderModel) FindPageListByPage(ctx context.Context, rowBuilder *gorm.DB, page *int64, pageSize *int64, filterMap map[string]string, orderBy string) ([]*FsOrderRel, error) {
|
||||
var resp []*FsOrderRel
|
||||
// 过滤
|
||||
if filterMap != nil {
|
||||
rowBuilder = rowBuilder.Scopes(handlers.FilterData(filterMap))
|
||||
}
|
||||
|
||||
// 排序
|
||||
if orderBy != "" {
|
||||
var fieldsMap = make(map[string]struct{})
|
||||
s := reflect.TypeOf(&FsOrder{}).Elem() //通过反射获取type定义
|
||||
for i := 0; i < s.NumField(); i++ {
|
||||
fieldsMap[s.Field(i).Tag.Get("json")] = struct{}{}
|
||||
}
|
||||
rowBuilder = rowBuilder.Scopes(handlers.OrderCheck(orderBy, fieldsMap))
|
||||
}
|
||||
|
||||
// 分页
|
||||
rowBuilder = rowBuilder.Scopes(handlers.Paginate(page, pageSize))
|
||||
|
||||
// 结果
|
||||
result := rowBuilder.Debug().WithContext(ctx).Find(&resp)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
} else {
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
|
||||
type FsOrderRel struct {
|
||||
FsOrder
|
||||
FsOrderDetails []FsOrderDetails `gorm:"foreignKey:order_id;references:id"`
|
||||
FsOrderAffiliateInfo FsOrderAffiliate `gorm:"foreignKey:order_id;references:id"`
|
||||
}
|
||||
|
||||
type FsOrderDetails struct {
|
||||
FsOrderDetail
|
||||
FsOrderDetailTemplateInfo FsOrderDetailTemplateInfo `gorm:"foreignKey:id;references:order_detail_template_id"`
|
||||
FsProductInfo FsProduct `gorm:"foreignKey:id;references:product_id"`
|
||||
}
|
||||
|
||||
type FsOrderDetailTemplateInfo struct {
|
||||
FsOrderDetailTemplate
|
||||
FsProductDesignInfo FsProductDesignInfo `gorm:"foreignKey:id;references:design_id"` //获取设计数据
|
||||
FsProductSizeInfo FsProductSize `gorm:"foreignKey:id;references:size_id"`
|
||||
}
|
||||
|
||||
type FsProductDesignInfo struct {
|
||||
FsProductDesign
|
||||
OptionData FsProduct `gorm:"foreignKey:id;references:optional_id"` //获取配件信息
|
||||
TemplateData FsProductTemplateV2 `gorm:"foreignKey:id;references:template_id"` //获取模板信息
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) RowSelectBuilder(selectData []string) *gorm.DB {
|
||||
var rowBuilder = m.db.Table(m.name)
|
||||
|
||||
if selectData != nil {
|
||||
rowBuilder = rowBuilder.Select(selectData)
|
||||
} else {
|
||||
rowBuilder = rowBuilder.Select("*")
|
||||
}
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) BuilderTrans(selectData []string) *gorm.DB {
|
||||
var rowBuilder = m.db
|
||||
|
||||
if selectData != nil {
|
||||
rowBuilder = rowBuilder.Select(selectData)
|
||||
} else {
|
||||
rowBuilder = rowBuilder.Select("*")
|
||||
}
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) FindCount(ctx context.Context, countBuilder *gorm.DB, filterMap map[string]string) (int64, error) {
|
||||
var count int64
|
||||
|
||||
// 过滤
|
||||
if filterMap != nil {
|
||||
countBuilder = countBuilder.Scopes(handlers.FilterData(filterMap))
|
||||
}
|
||||
|
||||
result := countBuilder.WithContext(ctx).Limit(1).Count(&count)
|
||||
if result.Error != nil {
|
||||
return 0, result.Error
|
||||
} else {
|
||||
return count, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) FindOneByQuery(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string) (*FsOrderRel, error) {
|
||||
var resp FsOrderRel
|
||||
|
||||
if filterMap != nil {
|
||||
rowBuilder = rowBuilder.Scopes(handlers.FilterData(filterMap))
|
||||
}
|
||||
|
||||
result := rowBuilder.WithContext(ctx).Limit(1).Find(&resp)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
} else {
|
||||
return &resp, nil
|
||||
}
|
||||
}
|
||||
|
||||
// 事务
|
||||
func (m *FsOrderModel) Trans(ctx context.Context, fn func(ctx context.Context, connGorm *gorm.DB) error) error {
|
||||
tx := m.db.Table(m.name).WithContext(ctx).Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
if err := tx.Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := fn(ctx, tx); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) TableName() string {
|
||||
return m.name
|
||||
}
|
|
@ -1,6 +1,15 @@
|
|||
package gmodel
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type RelaFsShoppingCart struct {
|
||||
FsShoppingCart
|
||||
ShoppingCartProduct *FsProduct `json:"shopping_cart_product" gorm:"foreignkey:product_id;references:id"`
|
||||
ShoppingCartProductPriceList []*FsProductPrice `json:"shopping_cart_product_price_list" gorm:"foreignkey:product_id;references:product_id"`
|
||||
ShoppingCartProductModel3dList []*FsProductModel3d `json:"shopping_cart_product_model3d_list" gorm:"foreignkey:product_id;references:product_id"`
|
||||
}
|
||||
|
||||
// 获取单个
|
||||
func (s *FsShoppingCartModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsShoppingCart, err error) {
|
||||
|
|
|
@ -30,6 +30,7 @@ type AllModelsGen struct {
|
|||
FsCloudReceiveEveryOld *FsCloudReceiveEveryOldModel // fs_cloud_receive_every_old
|
||||
FsCloudReceiveOld *FsCloudReceiveOldModel // fs_cloud_receive_old 云仓接收工厂总单
|
||||
FsCloudRenderLogOld *FsCloudRenderLogOldModel // fs_cloud_render_log_old 云渲染日志表
|
||||
FsCloudStorage *FsCloudStorageModel // fs_cloud_storage 仓库的基本信息, 只做映射
|
||||
FsCloudUserApplyBackOld *FsCloudUserApplyBackOldModel // fs_cloud_user_apply_back_old 该表废弃
|
||||
FsContact *FsContactModel // fs_contact 该表暂未使用
|
||||
FsContactService *FsContactServiceModel // fs_contact_service
|
||||
|
@ -139,6 +140,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
|||
FsCloudReceiveEveryOld: NewFsCloudReceiveEveryOldModel(gdb),
|
||||
FsCloudReceiveOld: NewFsCloudReceiveOldModel(gdb),
|
||||
FsCloudRenderLogOld: NewFsCloudRenderLogOldModel(gdb),
|
||||
FsCloudStorage: NewFsCloudStorageModel(gdb),
|
||||
FsCloudUserApplyBackOld: NewFsCloudUserApplyBackOldModel(gdb),
|
||||
FsContact: NewFsContactModel(gdb),
|
||||
FsContactService: NewFsContactServiceModel(gdb),
|
||||
|
|
42
server_api/order.api
Normal file
42
server_api/order.api
Normal file
|
@ -0,0 +1,42 @@
|
|||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "订单模块"
|
||||
desc: "订单相关"
|
||||
author: ""
|
||||
email: ""
|
||||
)
|
||||
|
||||
import "basic.api"
|
||||
|
||||
service order {
|
||||
|
||||
@handler CreateOrderHandler
|
||||
post /api/order/create(CreateOrderReq) returns (response);
|
||||
|
||||
@handler CreatePrePaymentHandler
|
||||
post /api/order/create-prepayment(CreatePrePaymentReq) returns (response);
|
||||
|
||||
@handler OrderListHandler
|
||||
post /api/order/list(OrderListReq) returns (response);
|
||||
|
||||
}
|
||||
|
||||
type CreateOrderReq struct {
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
DeliveryMethod string `json:"delivery_method,options=[1,2]"`
|
||||
}
|
||||
|
||||
type CreatePrePaymentReq struct {
|
||||
OrderSn string `json:"order_sn"`
|
||||
DeliveryMethod int `json:"delivery_method"`
|
||||
DeliveryAddres struct {
|
||||
Address string `json:"address,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Mobile string `json:"mobile,optional"`
|
||||
} `json:"delivery_addres,optional"`
|
||||
}
|
||||
|
||||
type OrderListReq struct {
|
||||
|
||||
}
|
|
@ -1,217 +0,0 @@
|
|||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "订单模块"
|
||||
desc: "订单相关"
|
||||
author: ""
|
||||
email: ""
|
||||
)
|
||||
|
||||
import "basic.api"
|
||||
|
||||
service orders {
|
||||
|
||||
@handler CreateOrderHandler
|
||||
post /api/orders/create(CreateOrderReq) returns (response);
|
||||
|
||||
@handler CreatePrePaymentHandler
|
||||
post /api/orders/create-prepayment(OrderRefundReq) returns (response);
|
||||
|
||||
@handler OrderListHandler
|
||||
post /api/orders/list(OrderListReq) returns (response);
|
||||
|
||||
}
|
||||
|
||||
type CreateOrderReq struct {
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
DeliveryMethod string `json:"delivery_method"`
|
||||
}
|
||||
|
||||
type OrderRefundReq struct {
|
||||
OrderNo string `json:"order_no"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
DeliveryAddres DeliveryAddres `json:"delivery_addres"`
|
||||
}
|
||||
type DeliveryAddres struct {
|
||||
Address string `json:"address"`
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
||||
|
||||
type OrderDetail struct {
|
||||
OrderProduct []OrderProduct `json:"order_product"`
|
||||
OrderInfo OrderInfo `json:"order_info"`
|
||||
OrderAmount OrderAmount `json:"order_amount"`
|
||||
DeliveryAddres DeliveryAddres `json:"delivery_addres"`
|
||||
}
|
||||
|
||||
type ProductLogoResource struct {
|
||||
ResourceID string `json:"resource_id"`
|
||||
ResourceType string `json:"resource_type"`
|
||||
ResourceURL string `json:"resource_url"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
|
||||
type TemplateInfo struct {
|
||||
TemplateJSON string `json:"template_json"`
|
||||
TemplateTag string `json:"template_tag"`
|
||||
}
|
||||
type ModelInfo struct {
|
||||
ModelJSON string `json:"model_json"`
|
||||
}
|
||||
type FittingInfo struct {
|
||||
FittingJSON string `json:"fitting_json"`
|
||||
}
|
||||
type SizeInfo struct {
|
||||
Inch string `json:"inch"`
|
||||
Cm string `json:"cm"`
|
||||
}
|
||||
type UserDiyInformation struct {
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
Website string `json:"website"`
|
||||
Qrcode string `json:"qrcode"`
|
||||
Slogan string `json:"slogan"`
|
||||
}
|
||||
type Snapshot struct {
|
||||
Logo string `json:"logo"`
|
||||
CombineImage string `json:"combine_image"`
|
||||
RenderImage string `json:"render_image"`
|
||||
TemplateInfo TemplateInfo `json:"template_info"`
|
||||
ModelInfo ModelInfo `json:"model_info"`
|
||||
FittingInfo FittingInfo `json:"fitting_info"`
|
||||
SizeInfo SizeInfo `json:"size_info"`
|
||||
UserDiyInformation UserDiyInformation `json:"user_diy_information"`
|
||||
}
|
||||
type ShoppingCartSnapshot struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
ProductID int64 `json:"product_id"`
|
||||
TemplateID int64 `json:"template_id"`
|
||||
ModelID int64 `json:"model_id"`
|
||||
SizeID int64 `json:"size_id"`
|
||||
FittingID int64 `json:"fitting_id"`
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"`
|
||||
Snapshot Snapshot `json:"snapshot"`
|
||||
IsHighlyCustomized int64 `json:"is_highly_customized"`
|
||||
Ctime string `json:"ctime"`
|
||||
Utime string `json:"utime"`
|
||||
}
|
||||
type OrderProduct struct {
|
||||
ProductID string `json:"product_id"`
|
||||
ProductName string `json:"product_name"`
|
||||
ProductPrice string `json:"product_price"`
|
||||
ProductLogo string `json:"product_logo"`
|
||||
ProductLogoResource ProductLogoResource `json:"product_logo_resource"`
|
||||
ProductSnapshot map[string]interface{} `json:"product_snapshot"`
|
||||
Number int64 `json:"number"`
|
||||
Amount string `json:"amount"`
|
||||
Unit string `json:"unit"`
|
||||
ExpectedDeliveryTime string `json:"expected_delivery_time"`
|
||||
ShoppingCartSnapshot ShoppingCartSnapshot `json:"shopping_cart_snapshot"`
|
||||
}
|
||||
|
||||
type OrderStatus struct {
|
||||
StatusCode int64 `json:"status_code"`
|
||||
StatusTitle string `json:"status_title"`
|
||||
ExpectedTime string `json:"expected_time"`
|
||||
Ctime string `json:"ctime"`
|
||||
Utime string `json:"utime"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
Children []*OrderStatus `json:"children"`
|
||||
}
|
||||
type OrderInfo struct {
|
||||
OrderNo string `json:"order_no"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
Ctime string `json:"ctime"`
|
||||
Utime string `json:"utime"`
|
||||
Status OrderStatus `json:"status"`
|
||||
StatusLink []OrderStatus `json:"status_link"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
type Subtotal struct {
|
||||
Currency string `json:"currency"`
|
||||
Current string `json:"current"`
|
||||
Initiate string `json:"initiate"`
|
||||
Change string `json:"change"`
|
||||
ChangeRemark string `json:"change_remark"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
type ShippingFee struct {
|
||||
Currency string `json:"currency"`
|
||||
Current string `json:"current"`
|
||||
Initiate string `json:"initiate"`
|
||||
Change string `json:"change"`
|
||||
ChangeRemark string `json:"change_remark"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
type Tax struct {
|
||||
Currency string `json:"currency"`
|
||||
Current string `json:"current"`
|
||||
Initiate string `json:"initiate"`
|
||||
Change string `json:"change"`
|
||||
ChangeRemark string `json:"change_remark"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
type Discount struct {
|
||||
Currency string `json:"currency"`
|
||||
Current string `json:"current"`
|
||||
Initiate string `json:"initiate"`
|
||||
Change string `json:"change"`
|
||||
ChangeRemark string `json:"change_remark"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
type Total struct {
|
||||
Currency string `json:"currency"`
|
||||
Current string `json:"current"`
|
||||
Initiate string `json:"initiate"`
|
||||
Change string `json:"change"`
|
||||
ChangeRemark string `json:"change_remark"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
type PayStatus struct {
|
||||
StatusCode int64 `json:"status_code"`
|
||||
StatusTitle string `json:"status_title"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
|
||||
type PayAmount struct {
|
||||
Currency string `json:"currency"`
|
||||
Current string `json:"current"`
|
||||
Initiate string `json:"initiate"`
|
||||
Change string `json:"change"`
|
||||
ChangeRemark string `json:"change_remark"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
type Deposit struct {
|
||||
TradeNo string `json:"trade_no"`
|
||||
Status Status `json:"status"`
|
||||
StatusLink []PayStatus `json:"status_link"`
|
||||
PayTime string `json:"pay_time"`
|
||||
PayAmount PayAmount `json:"pay_amount"`
|
||||
PayMethod string `json:"pay_method"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
type RemainingBalance struct {
|
||||
TradeNo string `json:"trade_no"`
|
||||
Status PayStatus `json:"status"`
|
||||
StatusLink []PayStatus `json:"status_link"`
|
||||
PayTime string `json:"pay_time"`
|
||||
PayAmount PayAmount `json:"pay_amount"`
|
||||
PayMethod string `json:"pay_method"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
type OrderAmount struct {
|
||||
Subtotal Subtotal `json:"subtotal"`
|
||||
ShippingFee ShippingFee `json:"shipping_fee"`
|
||||
Tax Tax `json:"tax"`
|
||||
Discount Discount `json:"discount"`
|
||||
Total Total `json:"total"`
|
||||
Deposit Deposit `json:"deposit"`
|
||||
RemainingBalance RemainingBalance `json:"remaining_balance"`
|
||||
}
|
||||
type DeliveryAddres struct {
|
||||
Address string `json:"address"`
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
151
service/repositories/order.go
Normal file
151
service/repositories/order.go
Normal file
|
@ -0,0 +1,151 @@
|
|||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/shopping_cart"
|
||||
"math"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func NewOrder(gormDB *gorm.DB, bLMServiceUrl *string, awsSession *session.Session) Order {
|
||||
return &defaultOrder{
|
||||
MysqlConn: gormDB,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
defaultOrder struct {
|
||||
MysqlConn *gorm.DB
|
||||
}
|
||||
Order interface {
|
||||
// 下单
|
||||
// 预支付
|
||||
// 列表
|
||||
// 详情
|
||||
}
|
||||
|
||||
/* 下单 */
|
||||
CreateReq struct {
|
||||
CurrentCurrency string `json:"current_currency"` // 当前货币
|
||||
ExchangeRate string `json:"exchange_rate"` // 换算汇率
|
||||
OriginalCurrency string `json:"original_currency"` // 原始货币
|
||||
UserId int64 `json:"user_id"`
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
DeliveryMethod string `json:"delivery_method"`
|
||||
}
|
||||
CreateRes struct {
|
||||
ErrorCode basic.StatusResponse
|
||||
OrderSn string
|
||||
}
|
||||
/* 下单 */
|
||||
)
|
||||
|
||||
// 下单
|
||||
func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRes, err error) {
|
||||
var errorCode basic.StatusResponse
|
||||
err = d.MysqlConn.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
// 查询购物车
|
||||
var shoppingCartList []*gmodel.RelaFsShoppingCart
|
||||
resShoppingCartFind := tx.Preload("ShoppingCartProduct").Preload("ShoppingCartProductPriceList").Preload("ShoppingCartProductModel3dList").
|
||||
Where("id IN ?", in.CartIds).
|
||||
Where("user_id = ?", in.UserId).
|
||||
Find(&shoppingCartList)
|
||||
err = resShoppingCartFind.Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
shoppingCartListLen := len(shoppingCartList)
|
||||
if shoppingCartListLen == 0 {
|
||||
errorCode = *basic.CodeErrOrderCreatShoppingCartEmpty
|
||||
return errors.New(errorCode.Message)
|
||||
}
|
||||
if shoppingCartListLen != len(in.CartIds) {
|
||||
errorCode = *basic.CodeErrOrderCreatShoppingCartNotMatched
|
||||
return errors.New(errorCode.Message)
|
||||
}
|
||||
|
||||
var orderProductList []*gmodel.OrderProduct
|
||||
|
||||
for _, shoppingCart := range shoppingCartList {
|
||||
// 购物车快照
|
||||
var shoppingCartSnapshot shopping_cart.CartSnapshot
|
||||
// 购物车商品价格
|
||||
var shoppingCartProductPrice *gmodel.FsProductPrice
|
||||
// 购物车商品模型
|
||||
var shoppingCartProductModel3d *gmodel.FsProductModel3d
|
||||
if shoppingCart.Snapshot != nil {
|
||||
json.Unmarshal([]byte(*shoppingCart.Snapshot), &shoppingCartSnapshot)
|
||||
}
|
||||
// 商品异常
|
||||
if shoppingCart.ShoppingCartProduct == nil || (shoppingCart.ShoppingCartProduct != nil && *shoppingCart.ShoppingCartProduct.IsShelf == 0) {
|
||||
errorCode = *basic.CodeErrOrderCreatProductAbsent
|
||||
errorCode.Message = "create order failed, product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent。"
|
||||
return errors.New(errorCode.Message)
|
||||
}
|
||||
// 商品价格异常
|
||||
if len(shoppingCart.ShoppingCartProductPriceList) == 0 {
|
||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent。"
|
||||
return errors.New(errorCode.Message)
|
||||
} else {
|
||||
var isProductPrice bool
|
||||
for _, shoppingCartProductPriceInfo := range shoppingCart.ShoppingCartProductPriceList {
|
||||
if shoppingCart.SizeId == shoppingCartProductPriceInfo.SizeId {
|
||||
shoppingCartProductPrice = shoppingCartProductPriceInfo
|
||||
isProductPrice = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !isProductPrice {
|
||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent。"
|
||||
return errors.New(errorCode.Message)
|
||||
}
|
||||
shoppingCart.ShoppingCartProductPriceList = []*gmodel.FsProductPrice{shoppingCartProductPrice}
|
||||
}
|
||||
|
||||
// 商品模型异常
|
||||
if len(shoppingCart.ShoppingCartProductModel3dList) == 0 {
|
||||
errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent
|
||||
errorCode.Message = "create order failed, accessoryof product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent。"
|
||||
return errors.New(errorCode.Message)
|
||||
} else {
|
||||
var isProductModel bool
|
||||
for _, shoppingCartProductModel3dInfo := range shoppingCart.ShoppingCartProductModel3dList {
|
||||
if shoppingCart.SizeId == shoppingCartProductModel3dInfo.SizeId {
|
||||
shoppingCartProductModel3d = shoppingCartProductModel3dInfo
|
||||
isProductModel = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !isProductModel {
|
||||
errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent
|
||||
errorCode.Message = "create order failed, accessoryof product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent。"
|
||||
return errors.New(errorCode.Message)
|
||||
}
|
||||
shoppingCart.ShoppingCartProductModel3dList = []*gmodel.FsProductModel3d{shoppingCartProductModel3d}
|
||||
}
|
||||
|
||||
var purchaseQuantity float64 = float64(*shoppingCart.PurchaseQuantity)
|
||||
var eachBoxNum float64 = float64(*shoppingCartProductPrice.EachBoxNum)
|
||||
var boxNum int64 = math.Ceil(purchaseQuantity / eachBoxNum)
|
||||
|
||||
// 存储订单商品
|
||||
orderProductList = append(orderProductList, &gmodel.OrderProduct{})
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
return &CreateRes{
|
||||
ErrorCode: errorCode,
|
||||
}, nil
|
||||
}
|
|
@ -99,6 +99,13 @@ var (
|
|||
|
||||
CodeLogoCombineErr = &StatusResponse{5115, "logo combine fail"} // 合图失败
|
||||
CodeLogoCombineNoFoundErr = &StatusResponse{5116, "template record not found"} // 模版不存在
|
||||
|
||||
CodeErrOrder = &StatusResponse{5300, "ocreate order failed"} // 订单错误
|
||||
CodeErrOrderCreatShoppingCartEmpty = &StatusResponse{5301, "ocreate order failed, shopping cart is empty"} // 订单创建失败,购物车为空
|
||||
CodeErrOrderCreatShoppingCartNotMatched = &StatusResponse{5302, "ocreate order failed, shopping cart not matched"} // 订单创建失败,购物车不相符
|
||||
CodeErrOrderCreatProductAbsent = &StatusResponse{5303, "ocreate order failed, product is absent"} // 订单创建失败,商品不存在
|
||||
CodeErrOrderCreatProductPriceAbsent = &StatusResponse{5304, "ocreate order failed, price of product is absent"} // 订单创建失败,商品价格不存在
|
||||
CodeErrOrderCreatProductAccessoryAbsent = &StatusResponse{5305, "ocreate order failed, accessory of product is absent"} // 订单创建失败,商品配件不存在
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
|
|
|
@ -2,13 +2,7 @@ package configs
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"strconv"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
@ -27,49 +21,49 @@ type WebSetTimeInfoData struct {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
// 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
|
||||
}
|
||||
|
|
|
@ -1 +1,25 @@
|
|||
package order
|
||||
|
||||
import (
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetAmountCurrency(req *gmodel.AmountCurrency) (*float64, error) {
|
||||
if req.CurrentCurrency == req.OriginalCurrency {
|
||||
req.CurrentAmount = req.OriginalAmount
|
||||
} else {
|
||||
f1, err1 := strconv.ParseFloat(string(req.OriginalAmount), 64)
|
||||
if err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
f2, err2 := strconv.ParseFloat(string(req.OriginalAmount), 64)
|
||||
if err2 != nil {
|
||||
return nil, err2
|
||||
}
|
||||
result := f1 * f2
|
||||
req.CurrentAmount = constants.AmountUnit(strconv.FormatFloat(result, 'f', -1, 64))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user