fix:合并
This commit is contained in:
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),
|
||||
|
||||
Reference in New Issue
Block a user