diff --git a/constants/blm_service.go b/constants/blm_service.go new file mode 100644 index 00000000..2e6406e5 --- /dev/null +++ b/constants/blm_service.go @@ -0,0 +1,6 @@ +package constants + +const ( + BLMServiceUrlLogoCombine string = "/LogoCombine" + BLMServiceUrlLogoRemovebg string = "/removebg" +) diff --git a/constants/rabbitmq.go b/constants/rabbitmq.go index e9e06ef5..b8e374b3 100644 --- a/constants/rabbitmq.go +++ b/constants/rabbitmq.go @@ -4,17 +4,16 @@ type RABBIT_MQ string // 消息队列队列名 const ( - //组装渲染数据队列 - RABBIT_MQ_ASSEMBLE_RENDER_DATA RABBIT_MQ = "RABBIT_MQ_ASSEMBLE_RENDER_DATA" - //渲染结果数据队列 - RABBIT_MQ_RENDER_RESULT_DATA RABBIT_MQ = "RABBIT_MQ_RENDER_RESULT_DATA" - //原来发送到unity渲染的队列 - RABBIT_MQ_TO_UNITY RABBIT_MQ = "newTaskQueue" +//组装渲染数据队列 +/*RABBIT_MQ_ASSEMBLE_RENDER_DATA RABBIT_MQ = "RABBIT_MQ_ASSEMBLE_RENDER_DATA" +//渲染结果数据队列 +RABBIT_MQ_RENDER_RESULT_DATA RABBIT_MQ = "RABBIT_MQ_RENDER_RESULT_DATA"*/ ) // 队列列表 var MqQueueArr = []RABBIT_MQ{ - RABBIT_MQ_ASSEMBLE_RENDER_DATA, - RABBIT_MQ_RENDER_RESULT_DATA, - RABBIT_MQ_TO_UNITY, + /* + RABBIT_MQ_ASSEMBLE_RENDER_DATA, + RABBIT_MQ_RENDER_RESULT_DATA, + */ } diff --git a/constants/websocket.go b/constants/websocket.go index be28eb32..693e7802 100644 --- a/constants/websocket.go +++ b/constants/websocket.go @@ -8,8 +8,10 @@ const ( WEBSOCKET_UNAUTH = "WEBSOCKET_UNAUTH" //ws连接成功 WEBSOCKET_CONNECT_SUCCESS = "WEBSOCKET_CONNECT_SUCCESS" - //渲染前数据组装 - WEBSOCKET_RENDER_IMAGE_ASSEMBLE = "WEBSOCKET_RENDER_IMAGE_ASSEMBLE" + //请求恢复为上次连接的标识 + WEBSOCKET_REQUEST_REUSE_LAST_CONNECT = "WEBSOCKET_REQUEST_REUSE_LAST_CONNECT" + //请求恢复为上次连接的标识错误 + WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR = "WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR" //图片渲染 WEBSOCKET_RENDER_IMAGE = "WEBSOCKET_RENDER_IMAGE" //数据格式错误 diff --git a/initalize/service.go b/initalize/service.go new file mode 100644 index 00000000..7e486360 --- /dev/null +++ b/initalize/service.go @@ -0,0 +1,24 @@ +package initalize + +import ( + "fusenapi/service/repositories" + + "github.com/aws/aws-sdk-go/aws/session" + "gorm.io/gorm" +) + +type Repositories struct { + ImageHandle repositories.ImageHandle +} + +type NewAllRepositorieData struct { + GormDB *gorm.DB + BLMServiceUrl *string + AwsSession *session.Session +} + +func NewAllRepositories(newData *NewAllRepositorieData) *Repositories { + return &Repositories{ + ImageHandle: repositories.NewImageHandle(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession), + } +} diff --git a/model/gmodel/fs_auth_item_gen.go b/model/gmodel/fs_auth_item_gen.go index db2acb41..bca33e90 100644 --- a/model/gmodel/fs_auth_item_gen.go +++ b/model/gmodel/fs_auth_item_gen.go @@ -9,10 +9,10 @@ type FsAuthItem struct { Name string `gorm:"primary_key;default:'';" json:"name"` // 角色或权限名称 Type *int64 `gorm:"index;default:0;" json:"type"` // 权限类型:1 表示角色,2 表示权限 Description *string `gorm:"default:'';" json:"description"` // 角色或权限描述 - RuleName *string `gorm:"index;default:'';" json:"rule_name"` // + RuleName *string `gorm:"index;default:'';" json:"rule_name"` // 规则名称 Data *[]byte `gorm:"default:'';" json:"data"` // 角色或权限的额外数据 - CreatedAt *int64 `gorm:"default:0;" json:"created_at"` // - UpdatedAt *int64 `gorm:"default:0;" json:"updated_at"` // + CreatedAt *int64 `gorm:"default:0;" json:"created_at"` // 创建时间 + UpdatedAt *int64 `gorm:"default:0;" json:"updated_at"` // 更新时间 // FsAuthItemIbfk1 foreign `gorm:"" json:"fs_auth_item_ibfk_1"`// } type FsAuthItemModel struct { diff --git a/model/gmodel/fs_auth_rule_gen.go b/model/gmodel/fs_auth_rule_gen.go index c157140f..04808613 100644 --- a/model/gmodel/fs_auth_rule_gen.go +++ b/model/gmodel/fs_auth_rule_gen.go @@ -8,8 +8,8 @@ import ( type FsAuthRule struct { Name string `gorm:"primary_key;default:'';" json:"name"` // 规则名称 Data *[]byte `gorm:"default:'';" json:"data"` // 规则的额外数据 - CreatedAt *int64 `gorm:"default:0;" json:"created_at"` // - UpdatedAt *int64 `gorm:"default:0;" json:"updated_at"` // + CreatedAt *int64 `gorm:"default:0;" json:"created_at"` // 创建时间 + UpdatedAt *int64 `gorm:"default:0;" json:"updated_at"` // 更新时间 } type FsAuthRuleModel struct { db *gorm.DB diff --git a/model/gmodel/fs_canteen_product_gen.go b/model/gmodel/fs_canteen_product_gen.go index 7c43e5b9..a31bbc32 100644 --- a/model/gmodel/fs_canteen_product_gen.go +++ b/model/gmodel/fs_canteen_product_gen.go @@ -6,14 +6,16 @@ import ( // fs_canteen_product 餐厅类别产品对应表 type FsCanteenProduct struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID - CanteenType *int64 `gorm:"index;default:0;" json:"canteen_type"` // 餐厅类别id - ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id - SizeId *int64 `gorm:"default:0;" json:"size_id"` // 尺寸id - Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 - Status *int64 `gorm:"default:0;" json:"status"` // 状态位 1启用0停用 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 - Sid *string `gorm:"default:'';" json:"sid"` // 前端带入的id + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID + CanteenType *int64 `gorm:"index;default:0;" json:"canteen_type"` // 餐厅类别id + ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id + SizeId *int64 `gorm:"default:0;" json:"size_id"` // 尺寸id + Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 + Status *int64 `gorm:"default:0;" json:"status"` // 状态位 1启用0停用 + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 + Sid *string `gorm:"default:'';" json:"sid"` // 前端带入的id + ShowSizeTips *int64 `gorm:"default:0;" json:"show_size_tips"` // 是否显示提示 + ShowSizeList *int64 `gorm:"default:0;" json:"show_size_list"` // 是否显示规格列表 } type FsCanteenProductModel struct { db *gorm.DB diff --git a/model/gmodel/fs_cart_gen.go b/model/gmodel/fs_cart_gen.go index 915a837f..1fb12d84 100644 --- a/model/gmodel/fs_cart_gen.go +++ b/model/gmodel/fs_cart_gen.go @@ -8,7 +8,7 @@ import ( // fs_cart 购物车 type FsCart struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id - UserId *int64 `gorm:"index;default:0;" json:"user_id"` // + UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID TemplateId *int64 `gorm:"index;default:0;" json:"template_id"` // 模板ID PriceId *int64 `gorm:"index;default:0;" json:"price_id"` // 价格ID @@ -17,7 +17,7 @@ type FsCart struct { BuyNum *int64 `gorm:"default:0;" json:"buy_num"` // 购买数量 Cover *string `gorm:"default:'';" json:"cover"` // 截图 DesignId *int64 `gorm:"index;default:0;" json:"design_id"` // 设计ID - Ctime *int64 `gorm:"default:0;" json:"ctime"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 Status *int64 `gorm:"default:0;" json:"status"` // 状态位 OptionalId *int64 `gorm:"index;default:0;" json:"optional_id"` // 选项ID IsCheck *int64 `gorm:"default:0;" json:"is_check"` // 是否选中状态(0:未选中,1:选中) diff --git a/model/gmodel/fs_cart_logic.go b/model/gmodel/fs_cart_logic.go index d86b18be..e7ed91b1 100755 --- a/model/gmodel/fs_cart_logic.go +++ b/model/gmodel/fs_cart_logic.go @@ -4,6 +4,7 @@ package gmodel import ( "context" + "gorm.io/gorm" ) type FindOneCartByParamsReq struct { @@ -94,3 +95,22 @@ func (c *FsCartModel) DeleteCartsByIds(ctx context.Context, ids []int64) ( err e } return c.db.Table(c.name).WithContext(ctx).Model(&FsCart{}).Where("`id` in (?)", ids).Update("status", 0).Error } + +func (c *FsCartModel) RBDeleteCartsByIds(rowBuilder *gorm.DB,ids []int64) ( err error) { + if len(ids) == 0 { + return + } + return rowBuilder.Where("`id` in (?)", ids).Update("status", 0).Error +} + +func (c *FsCartModel) BuilderTrans(ctx context.Context,selectData []string) *gorm.DB { + var rowBuilder = c.db.WithContext(ctx) + + if selectData != nil { + rowBuilder = rowBuilder.Select(selectData) + } else { + rowBuilder = rowBuilder.Select("*") + } + return rowBuilder +} + diff --git a/model/gmodel/fs_cloud_render_log_gen.go b/model/gmodel/fs_cloud_render_log_gen.go index 2e851c6d..a1d8aeae 100644 --- a/model/gmodel/fs_cloud_render_log_gen.go +++ b/model/gmodel/fs_cloud_render_log_gen.go @@ -8,7 +8,6 @@ import ( type FsCloudRenderLog struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID UserId *int64 `gorm:"default:0;" json:"user_id"` // 用户id - GuestId *int64 `gorm:"default:0;" json:"guest_id"` // 游客id PostData *string `gorm:"default:'';" json:"post_data"` // PostUrl *string `gorm:"default:'';" json:"post_url"` // Title *string `gorm:"index;default:'';" json:"title"` // diff --git a/model/gmodel/fs_contact_gen.go b/model/gmodel/fs_contact_gen.go index 033c19a9..1e012861 100644 --- a/model/gmodel/fs_contact_gen.go +++ b/model/gmodel/fs_contact_gen.go @@ -11,8 +11,8 @@ type FsContact struct { Email *string `gorm:"index;default:'';" json:"email"` // 邮箱 Subject *int64 `gorm:"default:0;" json:"subject"` // 主题 Message *string `gorm:"default:'';" json:"message"` // 消息 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // - Status *int64 `gorm:"default:0;" json:"status"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 + Status *int64 `gorm:"default:0;" json:"status"` // 状态位 是否已处理 Mark *string `gorm:"default:'';" json:"mark"` // 后台订单备注 } type FsContactModel struct { diff --git a/model/gmodel/fs_contact_service_gen.go b/model/gmodel/fs_contact_service_gen.go index 578c1f7e..055ee183 100644 --- a/model/gmodel/fs_contact_service_gen.go +++ b/model/gmodel/fs_contact_service_gen.go @@ -12,10 +12,10 @@ type FsContactService struct { UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户id Name *string `gorm:"default:'';" json:"name"` // 联系人姓名 Email *string `gorm:"index;default:'';" json:"email"` // 联系人邮箱 - Phone *string `gorm:"default:'';" json:"phone"` // + Phone *string `gorm:"default:'';" json:"phone"` // 联系人电话 Remark *string `gorm:"default:'';" json:"remark"` // 备注内容 IsHandle *int64 `gorm:"default:0;" json:"is_handle"` // 是否被处理(0:未处理,1:已处理) - Ctime *int64 `gorm:"default:0;" json:"ctime"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 创建时间 HandleRemark *string `gorm:"default:'';" json:"handle_remark"` // 处理备注 HandleUid *int64 `gorm:"default:0;" json:"handle_uid"` // 处理人 HandleTime *int64 `gorm:"default:0;" json:"handle_time"` // 处理时间 diff --git a/model/gmodel/fs_email_template_gen.go b/model/gmodel/fs_email_template_gen.go index 520a8e02..c4a43101 100644 --- a/model/gmodel/fs_email_template_gen.go +++ b/model/gmodel/fs_email_template_gen.go @@ -10,10 +10,10 @@ type FsEmailTemplate struct { Type *int64 `gorm:"default:0;" json:"type"` // 模板类型 Name *string `gorm:"default:'';" json:"name"` // 模板名称 Title *string `gorm:"default:'';" json:"title"` // 模板标题 - ReplaceFields *string `gorm:"default:'';" json:"replace_fields"` // + ReplaceFields *string `gorm:"default:'';" json:"replace_fields"` // 需要替换的字段 Content *string `gorm:"default:'';" json:"content"` // 模板内容 Status *int64 `gorm:"default:0;" json:"status"` // 状态值(0:禁用,1:启用) - Ctime *int64 `gorm:"default:0;" json:"ctime"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 } type FsEmailTemplateModel struct { db *gorm.DB diff --git a/model/gmodel/fs_faq_gen.go b/model/gmodel/fs_faq_gen.go index f087a561..63fee257 100644 --- a/model/gmodel/fs_faq_gen.go +++ b/model/gmodel/fs_faq_gen.go @@ -13,7 +13,7 @@ type FsFaq struct { Content *string `gorm:"default:'';" json:"content"` // 内容 Status *int64 `gorm:"default:0;" json:"status"` // 状态(0:禁用,1:启用) Sort *int64 `gorm:"default:1;" json:"sort"` // 排序 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 } type FsFaqModel struct { db *gorm.DB diff --git a/model/gmodel/fs_gerent_gen.go b/model/gmodel/fs_gerent_gen.go index 0c6dfd2a..9aff318a 100644 --- a/model/gmodel/fs_gerent_gen.go +++ b/model/gmodel/fs_gerent_gen.go @@ -10,12 +10,12 @@ type FsGerent struct { Username *string `gorm:"unique_key;default:'';" json:"username"` // 用户名 AuthKey *string `gorm:"default:'';" json:"auth_key"` // token PasswordHash *string `gorm:"default:'';" json:"password_hash"` // 加密密码 - PasswordResetToken *string `gorm:"unique_key;default:'';" json:"password_reset_token"` // + PasswordResetToken *string `gorm:"unique_key;default:'';" json:"password_reset_token"` // 加密密码token Email *string `gorm:"unique_key;default:'';" json:"email"` // 邮箱 Status *int64 `gorm:"default:10;" json:"status"` // 状态 CreatedAt *int64 `gorm:"default:0;" json:"created_at"` // 创建时间 UpdatedAt *int64 `gorm:"default:0;" json:"updated_at"` // 更新时间 - Icon *string `gorm:"default:'';" json:"icon"` // + Icon *string `gorm:"default:'';" json:"icon"` // 标签图标 DepartmentId *int64 `gorm:"default:0;" json:"department_id"` // 部门id } type FsGerentModel struct { diff --git a/model/gmodel/fs_logo_cartoon_gen.go b/model/gmodel/fs_logo_cartoon_gen.go new file mode 100644 index 00000000..e4bac34b --- /dev/null +++ b/model/gmodel/fs_logo_cartoon_gen.go @@ -0,0 +1,29 @@ +package gmodel + +import ( + "gorm.io/gorm" + "time" +) + +// fs_logo_cartoon logo底图表 +type FsLogoCartoon struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID + CategoryId *int64 `gorm:"default:0;" json:"category_id"` // 分类 + Name *string `gorm:"default:'';" json:"name"` // + Url *string `gorm:"default:'';" json:"url"` // + IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 + CreateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"create_time"` // + UpdateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"update_time"` // + DeleteTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"delete_time"` // + CreateUid *int64 `gorm:"default:0;" json:"create_uid"` // 创建人 + UpdateUid *int64 `gorm:"default:0;" json:"update_uid"` // 更新人 + DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人 +} +type FsLogoCartoonModel struct { + db *gorm.DB + name string +} + +func NewFsLogoCartoonModel(db *gorm.DB) *FsLogoCartoonModel { + return &FsLogoCartoonModel{db: db, name: "fs_logo_cartoon"} +} diff --git a/model/gmodel/fs_logo_cartoon_logic.go b/model/gmodel/fs_logo_cartoon_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_logo_cartoon_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_merchant_category_gen.go b/model/gmodel/fs_merchant_category_gen.go new file mode 100644 index 00000000..732ec88b --- /dev/null +++ b/model/gmodel/fs_merchant_category_gen.go @@ -0,0 +1,25 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// fs_merchant_category 商户类型表 +type FsMerchantCategory struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // Id + ZnName *string `gorm:"default:'';" json:"zn_name"` // 中文名 + EnName *string `gorm:"default:'';" json:"en_name"` // 英文名 + Icon *string `gorm:"default:'';" json:"icon"` // 图标 + RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // 推荐商品 + Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 + Status *int64 `gorm:"default:0;" json:"status"` // 状态 + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 +} +type FsMerchantCategoryModel struct { + db *gorm.DB + name string +} + +func NewFsMerchantCategoryModel(db *gorm.DB) *FsMerchantCategoryModel { + return &FsMerchantCategoryModel{db: db, name: "fs_merchant_category"} +} diff --git a/model/gmodel/fs_merchant_category_logic.go b/model/gmodel/fs_merchant_category_logic.go new file mode 100644 index 00000000..cbf8c138 --- /dev/null +++ b/model/gmodel/fs_merchant_category_logic.go @@ -0,0 +1,54 @@ +package gmodel + +import ( + "context" + "fusenapi/utils/handlers" + "reflect" + + "gorm.io/gorm" +) + +// TODO: 使用model的属性做你想做的 + +func (m *FsMerchantCategoryModel) FindOne(ctx context.Context, id int64) (resp *FsMerchantCategory, err error) { + err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("id = ? and status = ?", id, 1).Take(&resp).Error + return resp, err +} +func (m *FsMerchantCategoryModel) FindRandOne(ctx context.Context) (resp *FsMerchantCategory, err error) { + err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("status = ?", 1).Order("RAND()").Take(&resp).Error + return resp, err +} + +func (m *FsMerchantCategoryModel) BuilderDB(ctx context.Context, selectData []string) *gorm.DB { + if selectData != nil { + return m.db.WithContext(ctx).Select(selectData) + } else { + return m.db.WithContext(ctx).Select("*") + } +} + +func (m *FsMerchantCategoryModel) FindAll(gormDB *gorm.DB, filterMap map[string]string, orderBy string) ([]*FsMerchantCategory, error) { + var resp []*FsMerchantCategory + + // 过滤 + if filterMap != nil { + gormDB = gormDB.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{}{} + } + gormDB = gormDB.Scopes(handlers.OrderCheck(orderBy, fieldsMap)) + } + + result := gormDB.Find(&resp) + if result.Error != nil { + return nil, result.Error + } else { + return resp, nil + } +} diff --git a/model/gmodel/fs_order_detail_gen.go b/model/gmodel/fs_order_detail_gen.go index 9a9ad151..01808b2a 100644 --- a/model/gmodel/fs_order_detail_gen.go +++ b/model/gmodel/fs_order_detail_gen.go @@ -9,7 +9,7 @@ type FsOrderDetail struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // Sn *string `gorm:"unique_key;default:'';" json:"sn"` // 唯一编码 OrderId *int64 `gorm:"index;default:0;" json:"order_id"` // 订单ID - UserId *int64 `gorm:"default:0;" json:"user_id"` // + UserId *int64 `gorm:"default:0;" json:"user_id"` // 用户ID FactoryId *int64 `gorm:"default:0;" json:"factory_id"` // 工厂ID OrderDetailTemplateId *int64 `gorm:"default:0;" json:"order_detail_template_id"` // 详情templateID ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品ID diff --git a/model/gmodel/fs_order_detail_template_gen.go b/model/gmodel/fs_order_detail_template_gen.go index 698b691c..376137fc 100644 --- a/model/gmodel/fs_order_detail_template_gen.go +++ b/model/gmodel/fs_order_detail_template_gen.go @@ -16,7 +16,7 @@ type FsOrderDetailTemplate struct { EachBoxNum *int64 `gorm:"default:0;" json:"each_box_num"` // 每一箱的个数 EachBoxWeight *float64 `gorm:"default:0.00;" json:"each_box_weight"` // 每一箱的重量 单位KG DesignId *int64 `gorm:"index;default:0;" json:"design_id"` // 设计ID - Ctime *int64 `gorm:"default:0;" json:"ctime"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 } type FsOrderDetailTemplateModel struct { db *gorm.DB diff --git a/model/gmodel/fs_order_detail_template_logic.go b/model/gmodel/fs_order_detail_template_logic.go index cbdcd360..c0cdf641 100755 --- a/model/gmodel/fs_order_detail_template_logic.go +++ b/model/gmodel/fs_order_detail_template_logic.go @@ -26,6 +26,10 @@ func (dt *FsOrderDetailTemplateModel) FindOne(ctx context.Context, id int64) (re return resp, err } +func (dt *FsOrderDetailTemplateModel) RBCreate(ctx context.Context, data *FsOrderDetailTemplate) error { + return dt.db.WithContext(ctx).Create(&data).Error +} + func (m *FsOrderDetailTemplateModel) TableName() string { return m.name } diff --git a/model/gmodel/fs_order_gen.go b/model/gmodel/fs_order_gen.go index 2ca004bf..ab34b331 100644 --- a/model/gmodel/fs_order_gen.go +++ b/model/gmodel/fs_order_gen.go @@ -9,17 +9,17 @@ import ( type FsOrder struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // Sn *string `gorm:"unique_key;default:'';" json:"sn"` // 订单编号 FS211224OL2XDKNP - UserId *int64 `gorm:"index;default:0;" json:"user_id"` // - SellerUserId *int64 `gorm:"default:0;" json:"seller_user_id"` // + UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID + SellerUserId *int64 `gorm:"default:0;" json:"seller_user_id"` // 销售员ID 0:自主下单 TotalAmount *int64 `gorm:"default:0;" json:"total_amount"` // 总价 PayedAmount *int64 `gorm:"default:0;" json:"payed_amount"` // 已支付金额 PayMethod *int64 `gorm:"default:0;" json:"pay_method"` // 支付方式 1paypal 2strip - Ctime *int64 `gorm:"default:0;" json:"ctime"` // - Utime *int64 `gorm:"default:0;" json:"utime"` // - Ptime *int64 `gorm:"default:0;" json:"ptime"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 + Utime *int64 `gorm:"default:0;" json:"utime"` // 更新时间 + Ptime *int64 `gorm:"default:0;" json:"ptime"` // 最后一次 支付时间(可能多次支付) AddressId *int64 `gorm:"index;default:0;" json:"address_id"` // 地址ID或者云仓ID DeliveryMethod *int64 `gorm:"default:0;" json:"delivery_method"` // 配送方式 1:直接发货到收获地址 2:云仓 - CustomerMark *string `gorm:"default:'';" json:"customer_mark"` // + CustomerMark *string `gorm:"default:'';" json:"customer_mark"` // 客户备注 Mark *string `gorm:"default:'';" json:"mark"` // 后台订单备注 AddressInfo *string `gorm:"default:'';" json:"address_info"` // 详细地址信息JSON IsSup *int64 `gorm:"default:0;" json:"is_sup"` // 0不是补货 1是补货 @@ -37,8 +37,8 @@ type FsOrder struct { IsRefunding *int64 `gorm:"default:0;" json:"is_refunding"` // 是否退款中(0:否,1:是) IsRefunded *int64 `gorm:"default:0;" json:"is_refunded"` // 是否退款完成(0:否,1:是) IsDeleted *int64 `gorm:"default:0;" json:"is_deleted"` // 是否删除(0:否,1:是) - RefundReasonId *int64 `gorm:"default:0;" json:"refund_reason_id"` // - RefundReason *string `gorm:"default:'';" json:"refund_reason"` // + RefundReasonId *int64 `gorm:"default:0;" json:"refund_reason_id"` // 取消订单原因ID + RefundReason *string `gorm:"default:'';" json:"refund_reason"` // 取消订单原因 TsTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ts_time"` // IsSure *int64 `gorm:"default:0;" json:"is_sure"` // 是否确认订单 1确认0未确认 DeliverSn *string `gorm:"default:'';" json:"deliver_sn"` // 发货单号 diff --git a/model/gmodel/fs_order_logic.go b/model/gmodel/fs_order_logic.go index 60ce74d8..c0d27763 100755 --- a/model/gmodel/fs_order_logic.go +++ b/model/gmodel/fs_order_logic.go @@ -28,6 +28,10 @@ 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 } @@ -120,6 +124,17 @@ func (m *FsOrderModel) RowSelectBuilder(selectData []string) *gorm.DB { 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 diff --git a/model/gmodel/fs_pay_logic.go b/model/gmodel/fs_pay_logic.go index c23f3b36..2ae4ebc9 100644 --- a/model/gmodel/fs_pay_logic.go +++ b/model/gmodel/fs_pay_logic.go @@ -29,6 +29,14 @@ func (p *FsPayModel) GetListByOrderNumberStage(ctx context.Context, sn string, s return resp, nil } +func (p *FsPayModel) RBGetListByOrderNumberStage(ctx context.Context, sn string, stage int64) (resp *FsPay, err error) { + err = p.db.WithContext(ctx).Where("`order_number` = ? ", sn).Where("`pay_stage` = ? ", stage).Take(&resp).Error + if err != nil { + return nil, err + } + return resp, nil +} + func (p *FsPayModel) CreateOrUpdate(ctx context.Context, req *FsPay) (resp *FsPay, err error) { rowBuilder := p.db.Table(p.name).WithContext(ctx) if req.Id > 0 { @@ -39,6 +47,16 @@ func (p *FsPayModel) CreateOrUpdate(ctx context.Context, req *FsPay) (resp *FsPa return req, err } +func (p *FsPayModel) RBCreateOrUpdate(ctx context.Context, req *FsPay) (resp *FsPay, err error) { + rowBuilder := p.db.WithContext(ctx) + if req.Id > 0 { + err = rowBuilder.Save(req).Error + } else { + err = rowBuilder.Create(req).Error + } + return req, err +} + func (m *FsPayModel) RowSelectBuilder(selectData []string) *gorm.DB { var rowBuilder = m.db.Table(m.name) @@ -50,6 +68,17 @@ func (m *FsPayModel) RowSelectBuilder(selectData []string) *gorm.DB { return rowBuilder } +func (m *FsPayModel) BuilderTrans(selectData []string) *gorm.DB { + var rowBuilder = m.db + + if selectData != nil { + rowBuilder = rowBuilder.Select(selectData) + } else { + rowBuilder = rowBuilder.Select("*") + } + return rowBuilder +} + func (m *FsPayModel) FindCount(ctx context.Context, countBuilder *gorm.DB, filterMap map[string]string) (int64, error) { var count int64 diff --git a/model/gmodel/fs_product_design_gather_gen.go b/model/gmodel/fs_product_design_gather_gen.go index 5e466861..6a434704 100644 --- a/model/gmodel/fs_product_design_gather_gen.go +++ b/model/gmodel/fs_product_design_gather_gen.go @@ -8,18 +8,19 @@ import ( type FsProductDesignGather struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // Sn *string `gorm:"index;default:'';" json:"sn"` // 唯一标识 - UserId *int64 `gorm:"index;default:0;" json:"user_id"` // + UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID TemplateId *int64 `gorm:"index;default:0;" json:"template_id"` // 模型ID MaterialId *int64 `gorm:"index;default:0;" json:"material_id"` // 材质ID SizeId *int64 `gorm:"index;default:0;" json:"size_id"` // 尺寸ID OptionalId *int64 `gorm:"index;default:0;" json:"optional_id"` // 选项ID - Cover *string `gorm:"default:'';" json:"cover"` // + Cover *string `gorm:"default:'';" json:"cover"` // 封面图 Info *string `gorm:"default:'';" json:"info"` // 保留的设计信息 - Utime *int64 `gorm:"default:0;" json:"utime"` // + Utime *int64 `gorm:"default:0;" json:"utime"` // 更新时间 Status *int64 `gorm:"default:1;" json:"status"` // 状态位(1:显示,0:删除) ClientIp *string `gorm:"default:'';" json:"client_ip"` // 客户端ip ClientNo *string `gorm:"default:'';" json:"client_no"` // 客户端唯一标识 + InfoNew *string `gorm:"default:'';" json:"info_new"` // 设计信息-改版 } type FsProductDesignGatherModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_design_gen.go b/model/gmodel/fs_product_design_gen.go index 978031f5..eee357fe 100644 --- a/model/gmodel/fs_product_design_gen.go +++ b/model/gmodel/fs_product_design_gen.go @@ -23,6 +23,7 @@ type FsProductDesign struct { IsPay *int64 `gorm:"default:0;" json:"is_pay"` // 是否已有支付 0 未 1 有 LogoColor *string `gorm:"default:'';" json:"logo_color"` // logo图片备选项 PageGuid *string `gorm:"default:'';" json:"page_guid"` // 页面识别id + InfoNew *string `gorm:"default:'';" json:"info_new"` // 设计信息-改版用 } type FsProductDesignModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_design_logic.go b/model/gmodel/fs_product_design_logic.go index 71f26d17..2dfe5dcc 100755 --- a/model/gmodel/fs_product_design_logic.go +++ b/model/gmodel/fs_product_design_logic.go @@ -2,6 +2,8 @@ package gmodel import ( "context" + + "gorm.io/gorm" ) func (d *FsProductDesignModel) FindOneBySn(ctx context.Context, sn string, userId int64) (resp *FsProductDesign, err error) { @@ -39,6 +41,21 @@ func (d *FsProductDesignModel) UpdateByIds(ctx context.Context, ids []int64, dat return d.db.Table(d.name).WithContext(ctx).Model(&FsProductDesign{}).Where("`id` in ?", ids).Updates(&data).Error } +func (d *FsProductDesignModel) RBUpdateByIds(rowBuilder *gorm.DB, ids []int64, data *FsProductDesign) error { + return rowBuilder.Where("`id` in ?", ids).Updates(&data).Error +} + +func (m *FsProductDesignModel) BuilderTrans(ctx context.Context, selectData []string) *gorm.DB { + var rowBuilder = m.db.WithContext(ctx) + + if selectData != nil { + rowBuilder = rowBuilder.Select(selectData) + } else { + rowBuilder = rowBuilder.Select("*") + } + return rowBuilder +} + func (m *FsProductDesignModel) TableName() string { return m.name } diff --git a/model/gmodel/fs_product_gen.go b/model/gmodel/fs_product_gen.go index 9eccb236..b888f9f2 100644 --- a/model/gmodel/fs_product_gen.go +++ b/model/gmodel/fs_product_gen.go @@ -17,11 +17,11 @@ type FsProduct struct { Intro *string `gorm:"default:'';" json:"intro"` // 简要描述 Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 SelledNum *int64 `gorm:"default:0;" json:"selled_num"` // 已卖数量 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 View *int64 `gorm:"default:0;" json:"view"` // 浏览量 - SizeIds *string `gorm:"default:'';" json:"size_ids"` // + SizeIds *string `gorm:"default:'';" json:"size_ids"` // 尺寸 1,2,3,4 MaterialIds *string `gorm:"default:'';" json:"material_ids"` // 材质 1,2,3 - TagIds *string `gorm:"default:'';" json:"tag_ids"` // + TagIds *string `gorm:"default:'';" json:"tag_ids"` // 标签 逗号间隔 Status *int64 `gorm:"default:0;" json:"status"` // 状态位 弃用 ProduceDays *int64 `gorm:"default:0;" json:"produce_days"` // 生产天数 DeliveryDays *int64 `gorm:"default:0;" json:"delivery_days"` // 运送天数 diff --git a/model/gmodel/fs_product_model3d_gen.go b/model/gmodel/fs_product_model3d_gen.go index 6842c3dc..7669602f 100644 --- a/model/gmodel/fs_product_model3d_gen.go +++ b/model/gmodel/fs_product_model3d_gen.go @@ -8,7 +8,6 @@ import ( type FsProductModel3d struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID - IsPopular *int64 `gorm:"default:0;" json:"is_popular"` // 是否热门 0否 1是 Tag *int64 `gorm:"default:1;" json:"tag"` // 类别(1:模型,2:配件,3:场景) Title *string `gorm:"default:'';" json:"title"` // 标题 Name *string `gorm:"default:'';" json:"name"` // 详情页展示名称 @@ -25,6 +24,7 @@ type FsProductModel3d struct { OptionTemplate *int64 `gorm:"default:0;" json:"option_template"` // 配件绑定的公共模板 Price *int64 `gorm:"default:0;" json:"price"` // 仅配件用,配件的价格, 单位:美分 Sku *string `gorm:"default:'';" json:"sku"` // sku + IsHot *int64 `gorm:"default:0;" json:"is_hot"` // 是否热门 } type FsProductModel3dModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_model3d_light_gen.go b/model/gmodel/fs_product_model3d_light_gen.go index aa93db60..723f62a3 100644 --- a/model/gmodel/fs_product_model3d_light_gen.go +++ b/model/gmodel/fs_product_model3d_light_gen.go @@ -10,7 +10,7 @@ type FsProductModel3dLight struct { Name *string `gorm:"default:'';" json:"name"` // 灯光名称 Info *string `gorm:"default:'';" json:"info"` // 灯光数据(json格式) Status *int64 `gorm:"default:1;" json:"status"` // 状态值(1:显示,0:删除) - Ctime *int64 `gorm:"default:0;" json:"ctime"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 创建时间 } type FsProductModel3dLightModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index 9cb2fe91..741fdac2 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -101,3 +101,14 @@ func (d *FsProductModel3dModel) FindOneJoinSize(ctx context.Context, productId i Order("s.sort ASC").Take(&resp).Error return resp, err } + +func (d *FsProductModel3dModel) GetOneBySizeIdTag(ctx context.Context, sizeId int64, tag int64, fields ...string) (resp *FsProductModel3d, err error) { + db := d.db.WithContext(ctx).Model(&FsProductModel3d{}). + Where("`size_id` = ? and `tag` = ? and `status` = ?", sizeId, tag, 1). + Order("sort DESC") + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_product_recommend_gen.go b/model/gmodel/fs_product_recommend_gen.go deleted file mode 100644 index 930a3da8..00000000 --- a/model/gmodel/fs_product_recommend_gen.go +++ /dev/null @@ -1,21 +0,0 @@ -package gmodel - -import ( - "gorm.io/gorm" -) - -// fs_product_recommend 推荐商品表 -type FsProductRecommend struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // - ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品ID - Status *int64 `gorm:"default:1;" json:"status"` // 状态 1正常 0不正常 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 -} -type FsProductRecommendModel struct { - db *gorm.DB - name string -} - -func NewFsProductRecommendModel(db *gorm.DB) *FsProductRecommendModel { - return &FsProductRecommendModel{db: db, name: "fs_product_recommend"} -} diff --git a/model/gmodel/fs_product_recommend_logic.go b/model/gmodel/fs_product_recommend_logic.go deleted file mode 100644 index 02e33584..00000000 --- a/model/gmodel/fs_product_recommend_logic.go +++ /dev/null @@ -1,39 +0,0 @@ -package gmodel - -import ( - "context" - "errors" - "gorm.io/gorm" -) - -type GetRecommendProductListReq struct { - Ctx context.Context - Page int - Limit int -} - -func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProductListReq) (resp []FsProduct, total int64, err error) { - db := r.db.WithContext(req.Ctx). - Table("fs_product_recommend as r"). - Joins("inner join fs_product as p on r.product_id = p.id"). - Where("r.status = ? ", 1). - Where("p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1) - if err = db.Limit(1).Count(&total).Error; err != nil { - return nil, 0, err - } - db = db.Select("p.*") - offset := (req.Page - 1) * req.Limit - err = db.Offset(offset).Limit(req.Limit).Find(&resp).Error - return resp, total, err -} -func (r *FsProductRecommendModel) CreateOrUpdate(ctx context.Context, productId int64, data *FsProductRecommend) error { - var info FsProductRecommend - err := r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ?", productId).Take(&info).Error - if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - return err - } - if info.Id == 0 { - return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Create(data).Error - } - return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ?", productId).Updates(data).Error -} diff --git a/model/gmodel/fs_product_render_design_gen.go b/model/gmodel/fs_product_render_design_gen.go index 460ec90f..16834189 100644 --- a/model/gmodel/fs_product_render_design_gen.go +++ b/model/gmodel/fs_product_render_design_gen.go @@ -8,19 +8,20 @@ import ( type FsProductRenderDesign struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // Sn *string `gorm:"index;default:'';" json:"sn"` // 唯一标识 - UserId *int64 `gorm:"index;default:0;" json:"user_id"` // + UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID TemplateId *int64 `gorm:"index;default:0;" json:"template_id"` // 模型ID MaterialId *int64 `gorm:"index;default:0;" json:"material_id"` // 材质ID SizeId *int64 `gorm:"index;default:0;" json:"size_id"` // 尺寸ID OptionalId *int64 `gorm:"index;default:0;" json:"optional_id"` // 选项ID - Cover *string `gorm:"default:'';" json:"cover"` // + Cover *string `gorm:"default:'';" json:"cover"` // 封面图 Info *string `gorm:"default:'';" json:"info"` // 保留的设计信息 - Utime *int64 `gorm:"default:0;" json:"utime"` // + Utime *int64 `gorm:"default:0;" json:"utime"` // 更新时间 Status *int64 `gorm:"default:1;" json:"status"` // 状态位(1:显示,0:删除) ClientIp *string `gorm:"default:'';" json:"client_ip"` // 客户端ip ClientNo *string `gorm:"default:'';" json:"client_no"` // 客户端唯一标识 LogoColor *string `gorm:"default:'';" json:"logo_color"` // logo图片备选颜色 + InfoNew *string `gorm:"default:'';" json:"info_new"` // 设计信息-改版用 } type FsProductRenderDesignModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_size_gen.go b/model/gmodel/fs_product_size_gen.go index 0c3560e3..24cedf8c 100644 --- a/model/gmodel/fs_product_size_gen.go +++ b/model/gmodel/fs_product_size_gen.go @@ -8,15 +8,15 @@ import ( type FsProductSize struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID - IsPopular *int64 `gorm:"default:0;" json:"is_popular"` // 是否受欢迎 0否1是 Title *string `gorm:"default:'';" json:"title"` // 标题 10*10*20 - Cover *string `gorm:"default:'';" json:"cover"` // - CoverImg *string `gorm:"default:'';" json:"cover_img"` // + Cover *string `gorm:"default:'';" json:"cover"` // 封面图 + CoverImg *string `gorm:"default:'';" json:"cover_img"` // 背景图 Capacity *string `gorm:"default:'';" json:"capacity"` // 自己填的尺寸名称 Status *int64 `gorm:"default:0;" json:"status"` // 状态位 显示 删除 Sort *int64 `gorm:"default:50;" json:"sort"` // 排序 - Remark *string `gorm:"default:'';" json:"remark"` // + Remark *string `gorm:"default:'';" json:"remark"` // 备注信息 PartsCanDeleted *int64 `gorm:"default:1;" json:"parts_can_deleted"` // 配件是否可移除 1是0否 + IsHot *int64 `gorm:"default:0;" json:"is_hot"` // 是否热门 } type FsProductSizeModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_tag_prop_logic.go b/model/gmodel/fs_product_tag_prop_logic.go index 6612e196..338a61d1 100644 --- a/model/gmodel/fs_product_tag_prop_logic.go +++ b/model/gmodel/fs_product_tag_prop_logic.go @@ -5,7 +5,7 @@ import "context" // TODO: 使用model的属性做你想做的 type GetTagPropByProductIdsWithProductTagRsp struct { FsProductTagProp - Title string `json:"title"` + TemplateTag string `json:"template_tag"` } func (p *FsProductTagPropModel) GetTagPropByProductIdsWithProductTag(ctx context.Context, productIds []int64) (resp []GetTagPropByProductIdsWithProductTagRsp, err error) { @@ -14,7 +14,7 @@ func (p *FsProductTagPropModel) GetTagPropByProductIdsWithProductTag(ctx context } err = p.db.WithContext(ctx).Table(p.name+" as p "). Joins("left join fs_product_template_tags as t on p.template_tag_id = t.id"). - Select("p.*,t.title as title"). + Select("p.*,t.template_tag as template_tag"). Where("p.product_id in (?) and p.status = ? and t.status = ?", productIds, 1, 1). Find(&resp).Error return resp, err diff --git a/model/gmodel/fs_product_template_element_0826_gen.go b/model/gmodel/fs_product_template_element_0826_gen.go new file mode 100644 index 00000000..03b30c20 --- /dev/null +++ b/model/gmodel/fs_product_template_element_0826_gen.go @@ -0,0 +1,35 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// fs_product_template_element_0826 +type FsProductTemplateElement0826 struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // + Title *string `gorm:"default:'';" json:"title"` // 产品模板名称 + ProductTemplateId *int64 `gorm:"index;default:0;" json:"product_template_id"` // 产品模板id + Main *string `gorm:"default:'';" json:"main"` // + Second *string `gorm:"default:'';" json:"second"` // + Base *string `gorm:"default:'';" json:"base"` // + Paper *string `gorm:"default:'';" json:"paper"` // + Spoon *string `gorm:"default:'';" json:"spoon"` // + Fork *string `gorm:"default:'';" json:"fork"` // + Toothpick *string `gorm:"default:'';" json:"toothpick"` // + Chopsticks *string `gorm:"default:'';" json:"chopsticks"` // + Shadow *string `gorm:"default:'';" json:"shadow"` // + Cover *string `gorm:"default:'';" json:"cover"` // + Cover1 *string `gorm:"default:'';" json:"cover1"` // + Mode *string `gorm:"default:'';" json:"mode"` // + Light *int64 `gorm:"default:0;" json:"light"` // + Rotation *string `gorm:"default:'';" json:"rotation"` // + Scale *string `gorm:"default:'';" json:"scale"` // +} +type FsProductTemplateElement0826Model struct { + db *gorm.DB + name string +} + +func NewFsProductTemplateElement0826Model(db *gorm.DB) *FsProductTemplateElement0826Model { + return &FsProductTemplateElement0826Model{db: db, name: "fs_product_template_element_0826"} +} diff --git a/model/gmodel/fs_product_template_element_0826_logic.go b/model/gmodel/fs_product_template_element_0826_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_product_template_element_0826_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_product_template_element_22_gen.go b/model/gmodel/fs_product_template_element_22_gen.go new file mode 100644 index 00000000..3c4665b1 --- /dev/null +++ b/model/gmodel/fs_product_template_element_22_gen.go @@ -0,0 +1,25 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// fs_product_template_element_22 +type FsProductTemplateElement22 struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // + Title *string `gorm:"default:'';" json:"title"` // 产品模板名称 + ProductTemplateId *int64 `gorm:"index;default:0;" json:"product_template_id"` // 产品模板id + Model *string `gorm:"default:'';" json:"model"` // + Mode *string `gorm:"default:'';" json:"mode"` // + Light *int64 `gorm:"default:0;" json:"light"` // + Rotation *string `gorm:"default:'';" json:"rotation"` // + Scale *string `gorm:"default:'';" json:"scale"` // +} +type FsProductTemplateElement22Model struct { + db *gorm.DB + name string +} + +func NewFsProductTemplateElement22Model(db *gorm.DB) *FsProductTemplateElement22Model { + return &FsProductTemplateElement22Model{db: db, name: "fs_product_template_element_22"} +} diff --git a/model/gmodel/fs_product_template_element_22_logic.go b/model/gmodel/fs_product_template_element_22_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_product_template_element_22_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_product_template_element_backup1018_gen.go b/model/gmodel/fs_product_template_element_backup1018_gen.go new file mode 100644 index 00000000..3c62068a --- /dev/null +++ b/model/gmodel/fs_product_template_element_backup1018_gen.go @@ -0,0 +1,37 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// fs_product_template_element_backup1018 +type FsProductTemplateElementBackup1018 struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // + Title *string `gorm:"default:'';" json:"title"` // 产品模板名称 + ProductTemplateId *int64 `gorm:"index;default:0;" json:"product_template_id"` // 产品模板id + Main *string `gorm:"default:'';" json:"main"` // + Second *string `gorm:"default:'';" json:"second"` // + Base *string `gorm:"default:'';" json:"base"` // + Paper *string `gorm:"default:'';" json:"paper"` // + Spoon *string `gorm:"default:'';" json:"spoon"` // + Fork *string `gorm:"default:'';" json:"fork"` // + Toothpick *string `gorm:"default:'';" json:"toothpick"` // + Chopsticks *string `gorm:"default:'';" json:"chopsticks"` // + Shadow *string `gorm:"default:'';" json:"shadow"` // + Cover *string `gorm:"default:'';" json:"cover"` // + Cover1 *string `gorm:"default:'';" json:"cover1"` // + Mode *string `gorm:"default:'';" json:"mode"` // + Light *int64 `gorm:"default:0;" json:"light"` // + Rotation *string `gorm:"default:'';" json:"rotation"` // + Scale *string `gorm:"default:'';" json:"scale"` // + ModelP *string `gorm:"default:'';" json:"model_p"` // 配件对应的云渲染贴图数据 + Refletion *int64 `gorm:"default:0;" json:"refletion"` // 反射探头 +} +type FsProductTemplateElementBackup1018Model struct { + db *gorm.DB + name string +} + +func NewFsProductTemplateElementBackup1018Model(db *gorm.DB) *FsProductTemplateElementBackup1018Model { + return &FsProductTemplateElementBackup1018Model{db: db, name: "fs_product_template_element_backup1018"} +} diff --git a/model/gmodel/fs_product_template_element_backup1018_logic.go b/model/gmodel/fs_product_template_element_backup1018_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_product_template_element_backup1018_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_product_template_element_gen.go b/model/gmodel/fs_product_template_element_gen.go index 7dd21864..5da26874 100644 --- a/model/gmodel/fs_product_template_element_gen.go +++ b/model/gmodel/fs_product_template_element_gen.go @@ -8,22 +8,22 @@ import ( type FsProductTemplateElement struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id Title *string `gorm:"default:'';" json:"title"` // 产品模板名称 - ProductTemplateId *int64 `gorm:"index;default:0;" json:"product_template_id"` // 产品模板id - Main *string `gorm:"default:'';" json:"main"` // - Second *string `gorm:"default:'';" json:"second"` // - Base *string `gorm:"default:'';" json:"base"` // - Paper *string `gorm:"default:'';" json:"paper"` // - Spoon *string `gorm:"default:'';" json:"spoon"` // - Fork *string `gorm:"default:'';" json:"fork"` // - Toothpick *string `gorm:"default:'';" json:"toothpick"` // - Chopsticks *string `gorm:"default:'';" json:"chopsticks"` // - Shadow *string `gorm:"default:'';" json:"shadow"` // - Cover *string `gorm:"default:'';" json:"cover"` // - Cover1 *string `gorm:"default:'';" json:"cover1"` // - Mode *string `gorm:"default:'';" json:"mode"` // - Light *int64 `gorm:"default:0;" json:"light"` // - Rotation *string `gorm:"default:'';" json:"rotation"` // - Scale *string `gorm:"default:'';" json:"scale"` // + ProductTemplateId *int64 `gorm:"index;default:0;" json:"product_template_id"` // 产品模型id + Main *string `gorm:"default:'';" json:"main"` // 废弃 + Second *string `gorm:"default:'';" json:"second"` // 废弃 + Base *string `gorm:"default:'';" json:"base"` // base + Paper *string `gorm:"default:'';" json:"paper"` // 废弃 + Spoon *string `gorm:"default:'';" json:"spoon"` // 废弃 + Fork *string `gorm:"default:'';" json:"fork"` // 废弃 + Toothpick *string `gorm:"default:'';" json:"toothpick"` // 废弃 + Chopsticks *string `gorm:"default:'';" json:"chopsticks"` // 废弃 + Shadow *string `gorm:"default:'';" json:"shadow"` // shadow + Cover *string `gorm:"default:'';" json:"cover"` // 废弃 + Cover1 *string `gorm:"default:'';" json:"cover1"` // 废弃 + Mode *string `gorm:"default:'';" json:"mode"` // 材质类型 + Light *int64 `gorm:"default:0;" json:"light"` // 灯光组 + Rotation *string `gorm:"default:'';" json:"rotation"` // 旋转 + Scale *string `gorm:"default:'';" json:"scale"` // 缩放 ModelP *string `gorm:"default:'';" json:"model_p"` // 配件对应的云渲染贴图数据 Refletion *string `gorm:"default:'';" json:"refletion"` // 反射探头组 } diff --git a/model/gmodel/fs_product_template_element_kongde_gen.go b/model/gmodel/fs_product_template_element_kongde_gen.go new file mode 100644 index 00000000..a7d72cb8 --- /dev/null +++ b/model/gmodel/fs_product_template_element_kongde_gen.go @@ -0,0 +1,35 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// fs_product_template_element_kongde +type FsProductTemplateElementKongde struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // + Title *string `gorm:"default:'';" json:"title"` // 产品模板名称 + ProductTemplateId *int64 `gorm:"index;default:0;" json:"product_template_id"` // 产品模板id + Main *string `gorm:"default:'';" json:"main"` // + Second *string `gorm:"default:'';" json:"second"` // + Base *string `gorm:"default:'';" json:"base"` // + Paper *string `gorm:"default:'';" json:"paper"` // + Spoon *string `gorm:"default:'';" json:"spoon"` // + Fork *string `gorm:"default:'';" json:"fork"` // + Toothpick *string `gorm:"default:'';" json:"toothpick"` // + Chopsticks *string `gorm:"default:'';" json:"chopsticks"` // + Shadow *string `gorm:"default:'';" json:"shadow"` // + Cover *string `gorm:"default:'';" json:"cover"` // + Cover1 *string `gorm:"default:'';" json:"cover1"` // + Mode *string `gorm:"default:'';" json:"mode"` // + Light *int64 `gorm:"default:0;" json:"light"` // + Rotation *string `gorm:"default:'';" json:"rotation"` // + Scale *string `gorm:"default:'';" json:"scale"` // +} +type FsProductTemplateElementKongdeModel struct { + db *gorm.DB + name string +} + +func NewFsProductTemplateElementKongdeModel(db *gorm.DB) *FsProductTemplateElementKongdeModel { + return &FsProductTemplateElementKongdeModel{db: db, name: "fs_product_template_element_kongde"} +} diff --git a/model/gmodel/fs_product_template_element_kongde_logic.go b/model/gmodel/fs_product_template_element_kongde_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_product_template_element_kongde_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_product_template_element_logic.go b/model/gmodel/fs_product_template_element_logic.go index 783f5480..5ace306f 100644 --- a/model/gmodel/fs_product_template_element_logic.go +++ b/model/gmodel/fs_product_template_element_logic.go @@ -7,7 +7,7 @@ import "context" func (e *FsProductTemplateElementModel) FindOneByModelId(ctx context.Context, modelId int64) (resp *FsProductTemplateElement, err error) { err = e.db.WithContext(ctx).Model(&FsProductTemplateElement{}). //以前的神仙员工把表model_id变成product_template_id - Where("`product_template_id` = ?", modelId). + Where("`model_id` = ?", modelId). Take(&resp).Error return resp, err } diff --git a/model/gmodel/fs_product_template_tags_gen.go b/model/gmodel/fs_product_template_tags_gen.go index 227af16d..4cc602cc 100644 --- a/model/gmodel/fs_product_template_tags_gen.go +++ b/model/gmodel/fs_product_template_tags_gen.go @@ -6,11 +6,12 @@ import ( // fs_product_template_tags 模板标签表 type FsProductTemplateTags struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID - Title *string `gorm:"default:'';" json:"title"` // 标题 - CoverImg *string `gorm:"default:'';" json:"cover_img"` // 封面图 - Status *int64 `gorm:"default:0;" json:"status"` // 状态 1:可用 - CreateAt *int64 `gorm:"default:0;" json:"create_at"` // 创建时间 + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID + TemplateTag *string `gorm:"unique_key;default:'';" json:"template_tag"` // 标题 + Cover *string `gorm:"default:'';" json:"cover"` // 缩略图 + Status *int64 `gorm:"default:0;" json:"status"` // 状态 1:可用 + CreateAt *int64 `gorm:"default:0;" json:"create_at"` // 创建时间 + Groups *string `gorm:"default:'';" json:"groups"` // 分组信息 } type FsProductTemplateTagsModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_template_tags_logic.go b/model/gmodel/fs_product_template_tags_logic.go index 4c26d2fb..53e76130 100755 --- a/model/gmodel/fs_product_template_tags_logic.go +++ b/model/gmodel/fs_product_template_tags_logic.go @@ -32,3 +32,22 @@ func (pt *FsProductTemplateTagsModel) GetList(ctx context.Context, page, limit i err = db.Offset(offset).Limit(limit).Find(&resp).Error return resp, err } +func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tagNames []string, limit int, orderBy string) (resp []FsProductTemplateTags, err error) { + if len(tagNames) == 0 { + return nil, nil + } + db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` in (?) and `status` = ?", tagNames, 1) + if orderBy != "" { + db = db.Order(orderBy) + } + err = db.Limit(limit).Find(&resp).Error + return resp, err +} +func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, tagName string, fields ...string) (resp *FsProductTemplateTags, err error) { + db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", tagName, 1) + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_product_template_v2_gen.go b/model/gmodel/fs_product_template_v2_gen.go index 5e14427f..febe3f7c 100644 --- a/model/gmodel/fs_product_template_v2_gen.go +++ b/model/gmodel/fs_product_template_v2_gen.go @@ -20,10 +20,10 @@ type FsProductTemplateV2 struct { IsPublic *int64 `gorm:"default:0;" json:"is_public"` // 是否可公用(1:可以,0:不可以) Status *int64 `gorm:"default:0;" json:"status"` // 状态1正常 2异常 Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 - Tag *string `gorm:"default:'';" json:"tag"` // 标签(用户自填) + TemplateTag *string `gorm:"default:'';" json:"template_tag"` // 标签(用户自填) IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 1删除 - GroupOptions *string `gorm:"default:'';" json:"group_options"` // 颜色分组 - Version *int64 `gorm:"default:0;" json:"version"` // + SwitchInfo *string `gorm:"default:'';" json:"switch_info"` // 开关信息 + Version *int64 `gorm:"default:0;" json:"version"` // 默认1 } type FsProductTemplateV2Model struct { db *gorm.DB diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index d760f398..d5364778 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -4,11 +4,14 @@ import ( "context" ) -func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64, fields ...string) (resp []FsProductTemplateV2, err error) { +func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64, sort string, fields ...string) (resp []FsProductTemplateV2, err error) { if len(productIds) == 0 { return } db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?) and `is_del` = ? and `status` = ?", productIds, 0, 1) + if sort != "" { + db = db.Order(sort) + } if len(fields) != 0 { db = db.Select(fields[0]) } @@ -38,7 +41,7 @@ func (t *FsProductTemplateV2Model) FindAllByIdsWithoutStatus(ctx context.Context } func (t *FsProductTemplateV2Model) FindOne(ctx context.Context, id int64) (resp *FsProductTemplateV2, err error) { - err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? ", id).Find(&resp).Error + err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? ", id).Take(&resp).Error return resp, err } func (t *FsProductTemplateV2Model) FindByParam(ctx context.Context, id int64, modelId int64, fields ...string) (resp *FsProductTemplateV2, err error) { @@ -111,14 +114,14 @@ func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Co } // 获取第一个尺寸下的模板 -func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx context.Context, productId int64, tagId string) (resp *FsProductTemplateV2, err error) { +func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx context.Context, productId int64, templateTag string) (resp *FsProductTemplateV2, err error) { err = t.db.WithContext(ctx).Table(t.name+" as t"). - Joins("left join fs_product_size as s on t.product_id = s.product_id"). + Joins("inner join fs_product_size as s on t.product_id = s.product_id"). Select("t.*"). - Where("t.product_id = ? and t.tag = ? ", productId, tagId). + Where("t.product_id = ? and t.template_tag = ? ", productId, templateTag). Where("t.status = ? and t.is_del = ?", 1, 0). Where("s.status = ?", 1). - Order("s.sort ASC"). + Order("t.sort ASC,s.sort ASC"). Take(&resp).Error return resp, err } @@ -126,7 +129,7 @@ func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Cont if len(modelIds) == 0 { return } - db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `tag` = ? and `is_del` = ? and `status` = ?", modelIds, templateTag, 0, 1) + db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `template_tag` = ? and `is_del` = ? and `status` = ?", modelIds, templateTag, 0, 1) if len(fields) != 0 { db = db.Select(fields[0]) } @@ -139,3 +142,14 @@ func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Cont err = db.Find(&resp).Error return resp, err } + +// 获取产品在指定模板标签下的所有模板 +func (t *FsProductTemplateV2Model) GetListByProductAndTemplateTag(ctx context.Context, templateTagId string, productId int64, fields ...string) (resp []FsProductTemplateV2, err error) { + db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}). + Where("template_tag = ? and product_id = ? and status = ? and is_del = ?", templateTagId, productId, 1, 0) + if len(fields) > 0 { + db = db.Select(fields[0]) + } + err = db.Find(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_qrcode_log_gen.go b/model/gmodel/fs_qrcode_log_gen.go index 45b3477d..8d61dac8 100644 --- a/model/gmodel/fs_qrcode_log_gen.go +++ b/model/gmodel/fs_qrcode_log_gen.go @@ -11,8 +11,8 @@ type FsQrcodeLog struct { QrcodeId *int64 `gorm:"default:0;" json:"qrcode_id"` // 二维码ID TagId *int64 `gorm:"default:0;" json:"tag_id"` // 分组ID CreateAt *int64 `gorm:"default:0;" json:"create_at"` // 创建时间 - Platform *string `gorm:"default:'';" json:"platform"` // - UserAgent *string `gorm:"default:'';" json:"user_agent"` // + Platform *string `gorm:"default:'';" json:"platform"` // 系统信息 + UserAgent *string `gorm:"default:'';" json:"user_agent"` // 浏览器 } type FsQrcodeLogModel struct { db *gorm.DB diff --git a/model/gmodel/fs_quotation_gen.go b/model/gmodel/fs_quotation_gen.go index 08b6885f..041bbb84 100644 --- a/model/gmodel/fs_quotation_gen.go +++ b/model/gmodel/fs_quotation_gen.go @@ -19,7 +19,6 @@ type FsQuotation struct { DesignId *int64 `gorm:"default:0;" json:"design_id"` // 设计人员 QuotationId *int64 `gorm:"default:0;" json:"quotation_id"` // 报价人员 IsMark *int64 `gorm:"default:0;" json:"is_mark"` // 星标 - Qid *int64 `gorm:"default:0;" json:"qid"` // } type FsQuotationModel struct { db *gorm.DB diff --git a/model/gmodel/fs_quotation_price_gen.go b/model/gmodel/fs_quotation_price_gen.go new file mode 100644 index 00000000..6f4b8b52 --- /dev/null +++ b/model/gmodel/fs_quotation_price_gen.go @@ -0,0 +1,23 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// fs_quotation_price 报价单价格表 +type FsQuotationPrice struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // Id + ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id + SizeId *int64 `gorm:"default:0;" json:"size_id"` // 尺寸id + PriceInfo *string `gorm:"default:'';" json:"price_info"` // 价格数据 + Status *int64 `gorm:"default:1;" json:"status"` // 状态 1启用0废弃 + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 +} +type FsQuotationPriceModel struct { + db *gorm.DB + name string +} + +func NewFsQuotationPriceModel(db *gorm.DB) *FsQuotationPriceModel { + return &FsQuotationPriceModel{db: db, name: "fs_quotation_price"} +} diff --git a/model/gmodel/fs_quotation_price_logic.go b/model/gmodel/fs_quotation_price_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_quotation_price_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_quotation_product_gen.go b/model/gmodel/fs_quotation_product_gen.go index 9f417951..498c311c 100644 --- a/model/gmodel/fs_quotation_product_gen.go +++ b/model/gmodel/fs_quotation_product_gen.go @@ -6,20 +6,23 @@ import ( // fs_quotation_product 报价单产品表 type FsQuotationProduct struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID - QuotationId *int64 `gorm:"index;default:0;" json:"quotation_id"` // 报价单id - Name *string `gorm:"default:'';" json:"name"` // 产品名 - Size *string `gorm:"default:'';" json:"size"` // 产品规格 - Cycle *int64 `gorm:"default:0;" json:"cycle"` // 交付周期 - IsGift *int64 `gorm:"default:0;" json:"is_gift"` // 是否赠品 - Img *string `gorm:"default:'';" json:"img"` // 效果图 - Status *int64 `gorm:"default:0;" json:"status"` // 状态位 1启用0停用 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 - Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 - Sid *string `gorm:"default:'';" json:"sid"` // 前端sid - PriceInfo *string `gorm:"default:'';" json:"price_info"` // 价格信息 - Remark *string `gorm:"default:'';" json:"remark"` // 备注 - Num *int64 `gorm:"default:0;" json:"num"` // 产品数量 + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID + QuotationId *int64 `gorm:"index;default:0;" json:"quotation_id"` // 报价单id + Name *string `gorm:"default:'';" json:"name"` // 产品名 + Size *string `gorm:"default:'';" json:"size"` // 产品规格 + Cycle *int64 `gorm:"default:0;" json:"cycle"` // 交付周期 + IsGift *int64 `gorm:"default:0;" json:"is_gift"` // 是否赠品 + Img *string `gorm:"default:'';" json:"img"` // 效果图 + Status *int64 `gorm:"default:0;" json:"status"` // 状态位 1启用0停用 + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 + Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 + Sid *string `gorm:"default:'';" json:"sid"` // 前端sid + PriceInfo *string `gorm:"default:'';" json:"price_info"` // 价格信息 + Remark *string `gorm:"default:'';" json:"remark"` // 备注 + Num *int64 `gorm:"default:0;" json:"num"` // 产品数量 + ShowSizeTips *int64 `gorm:"default:0;" json:"show_size_tips"` // 是否显示提示 + ShowSizeList *int64 `gorm:"default:0;" json:"show_size_list"` // 是否显示规格列表 + ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id } type FsQuotationProductModel struct { db *gorm.DB diff --git a/model/gmodel/fs_quotation_size_layout_gen.go b/model/gmodel/fs_quotation_size_layout_gen.go new file mode 100644 index 00000000..67d73ac6 --- /dev/null +++ b/model/gmodel/fs_quotation_size_layout_gen.go @@ -0,0 +1,22 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// fs_quotation_size_layout 产品尺寸排版表 +type FsQuotationSizeLayout struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // + ProductId *int64 `gorm:"unique_key;default:0;" json:"product_id"` // 产品id + SizeHtml *string `gorm:"default:'';" json:"size_html"` // 尺寸排版html + Status *int64 `gorm:"default:1;" json:"status"` // 状态 + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 +} +type FsQuotationSizeLayoutModel struct { + db *gorm.DB + name string +} + +func NewFsQuotationSizeLayoutModel(db *gorm.DB) *FsQuotationSizeLayoutModel { + return &FsQuotationSizeLayoutModel{db: db, name: "fs_quotation_size_layout"} +} diff --git a/model/gmodel/fs_quotation_size_layout_logic.go b/model/gmodel/fs_quotation_size_layout_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_quotation_size_layout_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_refund_reason_logic.go b/model/gmodel/fs_refund_reason_logic.go index 14acda7a..5a6fce1b 100644 --- a/model/gmodel/fs_refund_reason_logic.go +++ b/model/gmodel/fs_refund_reason_logic.go @@ -36,6 +36,16 @@ func (m *FsRefundReasonModel) CreateOrUpdate(ctx context.Context, req *FsRefundR return req, err } +func (m *FsRefundReasonModel) RBCreateOrUpdate(ctx context.Context, req *FsRefundReason) (resp *FsRefundReason, err error) { + rowBuilder := m.db.WithContext(ctx) + if req.Id > 0 { + err = rowBuilder.Save(req).Error + } else { + err = rowBuilder.Create(req).Error + } + return req, err +} + func (m *FsRefundReasonModel) FindOneByQuery(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string) (*FsRefundReason, error) { var resp FsRefundReason @@ -62,6 +72,16 @@ func (m *FsRefundReasonModel) RowSelectBuilder(selectData []string) *gorm.DB { return rowBuilder } +func (m *FsRefundReasonModel) BuilderTrans(selectData []string) *gorm.DB { + var rowBuilder = m.db + if selectData != nil { + rowBuilder = rowBuilder.Select(selectData) + } else { + rowBuilder = rowBuilder.Select("*") + } + return rowBuilder +} + func (m *FsRefundReasonModel) TableName() string { return m.name } diff --git a/model/gmodel/fs_resource_gen.go b/model/gmodel/fs_resource_gen.go index 400dd9e4..a85dc617 100644 --- a/model/gmodel/fs_resource_gen.go +++ b/model/gmodel/fs_resource_gen.go @@ -13,11 +13,12 @@ type FsResource struct { ResourceType *string `gorm:"index;default:'';" json:"resource_type"` // 资源类型 ResourceUrl *string `gorm:"default:'';" json:"resource_url"` // 资源 URL Version *string `gorm:"index;default:'0';" json:"version"` // 版本信息 - UploadedAt *time.Time `gorm:"index;default:'0000-00-00 00:00:00';" json:"uploaded_at"` // 上传时间 + UploadedAt *time.Time `gorm:"index;default:'0000-00-00 00:00:00';" json:"uploaded_at"` // Metadata *string `gorm:"default:'';" json:"metadata"` // 元数据,json格式,存储图像分率 MetaKey1 *string `gorm:"index;default:'';" json:"meta_key1"` // 需要关键信息查询的自定义属性1,可以动态增加 ApiType *int64 `gorm:"default:1;" json:"api_type"` // 调用类型:1=对外,2=对内 BucketName *string `gorm:"default:'';" json:"bucket_name"` // 存储桶名: 1=持久 2=缓存 + Source *string `gorm:"default:'';" json:"source"` // 来源 } type FsResourceModel struct { db *gorm.DB diff --git a/model/gmodel/fs_resource_logic.go b/model/gmodel/fs_resource_logic.go index 19e095db..31212da2 100644 --- a/model/gmodel/fs_resource_logic.go +++ b/model/gmodel/fs_resource_logic.go @@ -24,6 +24,16 @@ func (p *FsResourceModel) Update(ctx context.Context, req *FsResource) (resp *Fs return req, err } +func (p *FsResourceModel) BuilderCreate(ctx context.Context, rowBuilder *gorm.DB, req *FsResource) (resp *FsResource, err error) { + err = rowBuilder.WithContext(ctx).Create(req).Error + return req, err +} + +func (p *FsResourceModel) BuilderUpdate(ctx context.Context, rowBuilder *gorm.DB, req *FsResource) (resp *FsResource, err error) { + err = rowBuilder.WithContext(ctx).Where("resource_id =?", req.ResourceId).Save(req).Error + return req, err +} + func (m *FsResourceModel) FindOneByQuery(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string) (*FsResource, error) { var resp FsResource @@ -50,6 +60,17 @@ func (m *FsResourceModel) RowSelectBuilder(selectData []string) *gorm.DB { return rowBuilder } +func (m *FsResourceModel) BuilderTrans(selectData []string) *gorm.DB { + var rowBuilder = m.db + + if selectData != nil { + rowBuilder = rowBuilder.Select(selectData) + } else { + rowBuilder = rowBuilder.Select("*") + } + return rowBuilder +} + // 事务 func (m *FsResourceModel) Trans(ctx context.Context, fn func(ctx context.Context, connGorm *gorm.DB) error) error { diff --git a/model/gmodel/fs_tags_gen.go b/model/gmodel/fs_tags_gen.go index 5f27544b..1a7d89c9 100644 --- a/model/gmodel/fs_tags_gen.go +++ b/model/gmodel/fs_tags_gen.go @@ -16,8 +16,8 @@ type FsTags struct { Icon *string `gorm:"default:'';" json:"icon"` // 标签图标 Status *int64 `gorm:"default:1;" json:"status"` // 状态 1:可用 Description *string `gorm:"default:'';" json:"description"` // 介绍 Seo - RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // - RecommendProductSort *string `gorm:"default:'';" json:"recommend_product_sort"` // + RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // 推荐产品id例如: 1,3,4,5 + RecommendProductSort *string `gorm:"default:'';" json:"recommend_product_sort"` // 推荐排序例如:1324 Category *int64 `gorm:"default:1;" json:"category"` // 分类:1前台用的 2后台用的 } type FsTagsModel struct { diff --git a/model/gmodel/fs_trade_gen.go b/model/gmodel/fs_trade_gen.go index 740f1300..41514e47 100644 --- a/model/gmodel/fs_trade_gen.go +++ b/model/gmodel/fs_trade_gen.go @@ -13,10 +13,10 @@ type FsTrade struct { TradeSn *string `gorm:"unique_key;default:'';" json:"trade_sn"` // 三方交易号 OrderId *int64 `gorm:"index;default:0;" json:"order_id"` // 订单ID Amount *int64 `gorm:"default:0;" json:"amount"` // 支付金额 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // - Utime *int64 `gorm:"default:0;" json:"utime"` // - Desc *string `gorm:"default:'';" json:"desc"` // - Status *int64 `gorm:"default:0;" json:"status"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 + Utime *int64 `gorm:"default:0;" json:"utime"` // 更新时间 + Desc *string `gorm:"default:'';" json:"desc"` // 简要描述 + Status *int64 `gorm:"default:0;" json:"status"` // 状态位 是否支付成功 } type FsTradeModel struct { db *gorm.DB diff --git a/model/gmodel/fs_user_design_gen.go b/model/gmodel/fs_user_design_gen.go index 08d76923..8b6abf07 100644 --- a/model/gmodel/fs_user_design_gen.go +++ b/model/gmodel/fs_user_design_gen.go @@ -7,13 +7,13 @@ import ( // fs_user_design 废弃表 type FsUserDesign struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // - UserId *int64 `gorm:"index;default:0;" json:"user_id"` // + UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID TemplateId *int64 `gorm:"index;default:0;" json:"template_id"` // 模型ID MaterialId *int64 `gorm:"index;default:0;" json:"material_id"` // 材质ID SizeId *int64 `gorm:"index;default:0;" json:"size_id"` // 尺寸ID Info *string `gorm:"default:'';" json:"info"` // 其他设计信息 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 } type FsUserDesignModel struct { db *gorm.DB diff --git a/model/gmodel/fs_user_gen.go b/model/gmodel/fs_user_gen.go index 81d0f008..6c56d10a 100644 --- a/model/gmodel/fs_user_gen.go +++ b/model/gmodel/fs_user_gen.go @@ -9,11 +9,11 @@ type FsUser struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID FaceId *int64 `gorm:"default:0;" json:"face_id"` // facebook的userid GoogleId *int64 `gorm:"default:0;" json:"google_id"` // google的sub - FirstName *string `gorm:"default:'';" json:"first_name"` // - LastName *string `gorm:"default:'';" json:"last_name"` // + FirstName *string `gorm:"default:'';" json:"first_name"` // FirstName + LastName *string `gorm:"default:'';" json:"last_name"` // LastName Username *string `gorm:"unique_key;default:'';" json:"username"` // - Company *string `gorm:"default:'';" json:"company"` // - Mobile *string `gorm:"default:'';" json:"mobile"` // + Company *string `gorm:"default:'';" json:"company"` // 公司名称 + Mobile *string `gorm:"default:'';" json:"mobile"` // 手机号码 AuthKey *string `gorm:"default:'';" json:"auth_key"` // PasswordHash *string `gorm:"default:'';" json:"password_hash"` // VerificationToken *string `gorm:"default:'';" json:"verification_token"` // @@ -30,7 +30,7 @@ type FsUser struct { IsPhoneAdvertisement *int64 `gorm:"default:0;" json:"is_phone_advertisement"` // 是否接收短信广告 IsOpenRender *int64 `gorm:"default:0;" json:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭) IsThousandFace *int64 `gorm:"default:0;" json:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在) - IsLowRendering *int64 `gorm:"default:0;" json:"is_low_rendering"` // 是否开启低渲染模型渲染 + IsLowRendering *int64 `gorm:"default:0;" json:"is_low_rendering"` // IsRemoveBg *int64 `gorm:"default:1;" json:"is_remove_bg"` // 用户上传logo是否去除背景 } type FsUserModel struct { diff --git a/model/gmodel/fs_user_info_gen.go b/model/gmodel/fs_user_info_gen.go new file mode 100644 index 00000000..71b1bd7a --- /dev/null +++ b/model/gmodel/fs_user_info_gen.go @@ -0,0 +1,25 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// fs_user_info 用户信息表 +type FsUserInfo struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID + Module *string `gorm:"default:'';" json:"module"` // 所属模块 + UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户 ID + GuestId *int64 `gorm:"index;default:0;" json:"guest_id"` // 访客 ID + Metadata *string `gorm:"default:'';" json:"metadata"` // 元数据,json格式 + MetaKey1 *string `gorm:"default:'';" json:"meta_key1"` // 需要关键信息查询的自定义属性1,可以动态增加 + Ctime *int64 `gorm:"default:0;" json:"ctime"` // + Utime *int64 `gorm:"default:0;" json:"utime"` // +} +type FsUserInfoModel struct { + db *gorm.DB + name string +} + +func NewFsUserInfoModel(db *gorm.DB) *FsUserInfoModel { + return &FsUserInfoModel{db: db, name: "fs_user_info"} +} diff --git a/model/gmodel/fs_user_info_logic.go b/model/gmodel/fs_user_info_logic.go new file mode 100644 index 00000000..ad7ae9d6 --- /dev/null +++ b/model/gmodel/fs_user_info_logic.go @@ -0,0 +1,44 @@ +package gmodel + +// TODO: 使用model的属性做你想做的 + +import ( + "context" + "fusenapi/utils/handlers" + + "gorm.io/gorm" +) + +// TODO: 使用model的属性做你想做的 + +func (m *FsUserInfoModel) BuilderDB(ctx context.Context, selectData []string) *gorm.DB { + if selectData != nil { + return m.db.WithContext(ctx).Select(selectData) + } else { + return m.db.WithContext(ctx).Select("*") + } +} + +func (m *FsUserInfoModel) FindOne(gormDB *gorm.DB, filterMap map[string]string) (*FsUserInfo, error) { + var resp FsUserInfo + + if filterMap != nil { + gormDB = gormDB.Scopes(handlers.FilterData(filterMap)) + } + + result := gormDB.Limit(1).Find(&resp) + if result.Error != nil { + return nil, result.Error + } else { + return &resp, nil + } +} + +func (p *FsUserInfoModel) CreateOrUpdate(gormDB *gorm.DB, req *FsUserInfo) (resp *FsUserInfo, err error) { + if req.Id > 0 { + err = gormDB.Save(req).Error + } else { + err = gormDB.Create(req).Error + } + return req, err +} diff --git a/model/gmodel/fs_user_material_logic.go b/model/gmodel/fs_user_material_logic.go index 98c0bb08..842a458e 100644 --- a/model/gmodel/fs_user_material_logic.go +++ b/model/gmodel/fs_user_material_logic.go @@ -58,15 +58,9 @@ func (m *FsUserMaterialModel) RowSelectBuilder(selectData []string) *gorm.DB { // 获取最新记录 func (m *FsUserMaterialModel) FindLatestOne(ctx context.Context, userId int64, guestId int64) (resp FsUserMaterial, err error) { - if userId == 0 && guestId == 0 { - return FsUserMaterial{}, nil - } - db := m.db.WithContext(ctx).Model(&FsUserMaterial{}).Order("id DESC") - if userId != 0 { - db = db.Where("`user_id` = ?", userId) - } else { - db = db.Where("`guest_id` = ?", guestId) - } + db := m.db.WithContext(ctx).Model(&FsUserMaterial{}). + Where("`user_id` = ? and `guest_id` = ?", userId, guestId). + Order("id DESC") err = db.Take(&resp).Error return resp, err } @@ -75,3 +69,8 @@ func (m *FsUserMaterialModel) FindOneById(ctx context.Context, id int64) (resp * err = m.db.WithContext(ctx).Model(&FsUserMaterial{}).Where("id = ?", id).Take(&resp).Error return resp, err } +func (m *FsUserMaterialModel) GetListByUser(ctx context.Context, userId, guestId int64, limit int) (resp *FsUserMaterial, err error) { + err = m.db.WithContext(ctx).Model(&FsUserMaterial{}). + Where("`user_id` = ? and `guest_id` = ?", userId, guestId).Order("id DESC").Limit(limit).Find(&resp).Error + return resp, err +} diff --git a/model/gmodel/var_gen.go b/model/gmodel/var_gen.go index 46818f31..57ed36d2 100644 --- a/model/gmodel/var_gen.go +++ b/model/gmodel/var_gen.go @@ -4,191 +4,207 @@ import "gorm.io/gorm" // AllModelsGen 所有Model集合,修改单行,只要不改字段名,不会根据新的内容修改,需要修改的话手动删除 type AllModelsGen struct { - FsAddress *FsAddressModel // fs_address 用户地址表 - FsAuthAssignment *FsAuthAssignmentModel // fs_auth_assignment 用户角色和权限信息 - FsAuthItem *FsAuthItemModel // fs_auth_item 用户角色和权限信息 - FsAuthItemChild *FsAuthItemChildModel // fs_auth_item_child 角色和权限关系表 - FsAuthRule *FsAuthRuleModel // fs_auth_rule 规则表 - FsBackendUser *FsBackendUserModel // fs_backend_user 管理员表 - FsCanteenProduct *FsCanteenProductModel // fs_canteen_product 餐厅类别产品对应表 - FsCanteenType *FsCanteenTypeModel // fs_canteen_type 餐厅类型表 - FsCard *FsCardModel // fs_card 卡号表 - FsCardGroup *FsCardGroupModel // fs_card_group 卡号分组表 - FsCart *FsCartModel // fs_cart 购物车 - FsChangeCode *FsChangeCodeModel // fs_change_code 忘记密码code表 - FsCloud *FsCloudModel // fs_cloud 云仓表 - FsCloudDeliverEveryTmp *FsCloudDeliverEveryTmpModel // fs_cloud_deliver_every_tmp - FsCloudDeliverTmp *FsCloudDeliverTmpModel // fs_cloud_deliver_tmp - FsCloudPickUp *FsCloudPickUpModel // fs_cloud_pick_up 云仓提货单 - FsCloudPickUpDetail *FsCloudPickUpDetailModel // fs_cloud_pick_up_detail 云仓提货单-详情 - FsCloudReceive *FsCloudReceiveModel // fs_cloud_receive 云仓接收工厂总单 - FsCloudReceiveEvery *FsCloudReceiveEveryModel // fs_cloud_receive_every - FsCloudRenderLog *FsCloudRenderLogModel // fs_cloud_render_log 云渲染日志表 - FsCloudUserApplyBack *FsCloudUserApplyBackModel // fs_cloud_user_apply_back 该表废弃 - FsContact *FsContactModel // fs_contact 该表暂未使用 - FsContactService *FsContactServiceModel // fs_contact_service - FsCoupon *FsCouponModel // fs_coupon 代金券(暂未使用) - FsDeliver *FsDeliverModel // fs_deliver 发货表 云仓 直发 通用(已废弃) - FsDeliverEvery *FsDeliverEveryModel // fs_deliver_every 发货详细表(已废弃) - FsDepartment *FsDepartmentModel // fs_department 部门表 - FsEmailLogs *FsEmailLogsModel // fs_email_logs 邮件日志表 - FsEmailTemplate *FsEmailTemplateModel // fs_email_template 邮件模板表(暂未使用) - FsFactory *FsFactoryModel // fs_factory 该表废弃 - FsFactoryDeliver *FsFactoryDeliverModel // fs_factory_deliver 工厂发货主表(废弃) - FsFactoryDeliverEvery *FsFactoryDeliverEveryModel // fs_factory_deliver_every 该表废弃 - FsFactoryProduct *FsFactoryProductModel // fs_factory_product 工厂生产表(废弃) - FsFactoryShipTmp *FsFactoryShipTmpModel // fs_factory_ship_tmp - FsFaq *FsFaqModel // fs_faq 常见问题 - FsFont *FsFontModel // fs_font 字体配置 - FsGerent *FsGerentModel // fs_gerent 管理员表 - FsGuest *FsGuestModel // fs_guest 游客表 - FsLog *FsLogModel // fs_log 日志表 - FsMapLibrary *FsMapLibraryModel // fs_map_library 贴图库 - FsMenu *FsMenuModel // fs_menu 后台菜单 - FsMigration *FsMigrationModel // fs_migration 版本库 - FsOrder *FsOrderModel // fs_order - FsOrderAffiliate *FsOrderAffiliateModel // fs_order_affiliate 订单附属表-流程控制时间等 - FsOrderDetail *FsOrderDetailModel // fs_order_detail 订单详细表 - FsOrderDetailTemplate *FsOrderDetailTemplateModel // fs_order_detail_template 订单模板详细表 - FsOrderRemark *FsOrderRemarkModel // fs_order_remark 订单备注表 - FsPay *FsPayModel // fs_pay 支付记录 - FsPayEvent *FsPayEventModel // fs_pay_event 支付回调事件日志 - FsProduct *FsProductModel // fs_product 产品表 - FsProductCopy1 *FsProductCopy1Model // fs_product_copy1 产品表 - FsProductDesign *FsProductDesignModel // fs_product_design 产品设计表 - FsProductDesignGather *FsProductDesignGatherModel // fs_product_design_gather - FsProductModel3d *FsProductModel3dModel // fs_product_model3d 产品模型表 - FsProductModel3dLight *FsProductModel3dLightModel // fs_product_model3d_light 模型-灯光组表 - FsProductOption *FsProductOptionModel // fs_product_option 产品选项表(已废弃) - FsProductPrice *FsProductPriceModel // fs_product_price 阶梯价格表 - FsProductRecommend *FsProductRecommendModel // fs_product_recommend 推荐商品表 - FsProductRenderDesign *FsProductRenderDesignModel // fs_product_render_design - FsProductScene *FsProductSceneModel // fs_product_scene 产品场景表 - FsProductSize *FsProductSizeModel // fs_product_size 产品尺寸表 - FsProductTagProp *FsProductTagPropModel // fs_product_tag_prop 产品标签相关属性表 - FsProductTemplate *FsProductTemplateModel // fs_product_template 产品模板表(已废弃) - FsProductTemplateBasemap *FsProductTemplateBasemapModel // fs_product_template_basemap 模板底图表 - FsProductTemplateElement *FsProductTemplateElementModel // fs_product_template_element 云渲染配置表 - FsProductTemplateTags *FsProductTemplateTagsModel // fs_product_template_tags 模板标签表 - FsProductTemplateV2 *FsProductTemplateV2Model // fs_product_template_v2 产品-模型-模板表 - FsProductV2Tmp *FsProductV2TmpModel // fs_product_v2_tmp 产品表 - FsQrcode *FsQrcodeModel // fs_qrcode - FsQrcodeLog *FsQrcodeLogModel // fs_qrcode_log 二维码扫描日志 - FsQrcodeSet *FsQrcodeSetModel // fs_qrcode_set 二维码边框配置表 - FsQrcodeUser *FsQrcodeUserModel // fs_qrcode_user 二维码-用户名表 - FsQuotation *FsQuotationModel // fs_quotation 报价单信息表 - FsQuotationProduct *FsQuotationProductModel // fs_quotation_product 报价单产品表 - FsQuotationRemarkTemplate *FsQuotationRemarkTemplateModel // fs_quotation_remark_template 报价单备注模板 - FsQuotationSaler *FsQuotationSalerModel // fs_quotation_saler 报价单业务员表 - FsRefundReason *FsRefundReasonModel // fs_refund_reason - FsResource *FsResourceModel // fs_resource 资源表 - FsResources *FsResourcesModel // fs_resources 资源表 - FsStandardLogo *FsStandardLogoModel // fs_standard_logo 标准logo - FsTags *FsTagsModel // fs_tags 产品分类表 - FsToolLogs *FsToolLogsModel // fs_tool_logs 3d设计工具日志表 - FsToolTemplate *FsToolTemplateModel // fs_tool_template 设计工具模板(废弃) - FsToolUser *FsToolUserModel // fs_tool_user 3d设计工具用户表 - FsTrade *FsTradeModel // fs_trade - FsUser *FsUserModel // fs_user 用户表 - FsUserDesign *FsUserDesignModel // fs_user_design 废弃表 - FsUserMaterial *FsUserMaterialModel // fs_user_material 用户素材表 - FsUserStock *FsUserStockModel // fs_user_stock 用户云仓库存 - FsWebSet *FsWebSetModel // fs_web_set 网站配置表 + FsAddress *FsAddressModel // fs_address 用户地址表 + FsAuthAssignment *FsAuthAssignmentModel // fs_auth_assignment 用户角色和权限信息 + FsAuthItem *FsAuthItemModel // fs_auth_item 用户角色和权限信息 + FsAuthItemChild *FsAuthItemChildModel // fs_auth_item_child 角色和权限关系表 + FsAuthRule *FsAuthRuleModel // fs_auth_rule 规则表 + FsBackendUser *FsBackendUserModel // fs_backend_user 管理员表 + FsCanteenProduct *FsCanteenProductModel // fs_canteen_product 餐厅类别产品对应表 + FsCanteenType *FsCanteenTypeModel // fs_canteen_type 餐厅类型表 + FsCard *FsCardModel // fs_card 卡号表 + FsCardGroup *FsCardGroupModel // fs_card_group 卡号分组表 + FsCart *FsCartModel // fs_cart 购物车 + FsChangeCode *FsChangeCodeModel // fs_change_code 忘记密码code表 + FsCloud *FsCloudModel // fs_cloud 云仓表 + FsCloudDeliverEveryTmp *FsCloudDeliverEveryTmpModel // fs_cloud_deliver_every_tmp + FsCloudDeliverTmp *FsCloudDeliverTmpModel // fs_cloud_deliver_tmp + FsCloudPickUp *FsCloudPickUpModel // fs_cloud_pick_up 云仓提货单 + FsCloudPickUpDetail *FsCloudPickUpDetailModel // fs_cloud_pick_up_detail 云仓提货单-详情 + FsCloudReceive *FsCloudReceiveModel // fs_cloud_receive 云仓接收工厂总单 + FsCloudReceiveEvery *FsCloudReceiveEveryModel // fs_cloud_receive_every + FsCloudRenderLog *FsCloudRenderLogModel // fs_cloud_render_log 云渲染日志表 + FsCloudUserApplyBack *FsCloudUserApplyBackModel // fs_cloud_user_apply_back 该表废弃 + FsContact *FsContactModel // fs_contact 该表暂未使用 + FsContactService *FsContactServiceModel // fs_contact_service + FsCoupon *FsCouponModel // fs_coupon 代金券(暂未使用) + FsDeliver *FsDeliverModel // fs_deliver 发货表 云仓 直发 通用(已废弃) + FsDeliverEvery *FsDeliverEveryModel // fs_deliver_every 发货详细表(已废弃) + FsDepartment *FsDepartmentModel // fs_department 部门表 + FsEmailLogs *FsEmailLogsModel // fs_email_logs 邮件日志表 + FsEmailTemplate *FsEmailTemplateModel // fs_email_template 邮件模板表(暂未使用) + FsFactory *FsFactoryModel // fs_factory 该表废弃 + FsFactoryDeliver *FsFactoryDeliverModel // fs_factory_deliver 工厂发货主表(废弃) + FsFactoryDeliverEvery *FsFactoryDeliverEveryModel // fs_factory_deliver_every 该表废弃 + FsFactoryProduct *FsFactoryProductModel // fs_factory_product 工厂生产表(废弃) + FsFactoryShipTmp *FsFactoryShipTmpModel // fs_factory_ship_tmp + FsFaq *FsFaqModel // fs_faq 常见问题 + FsFont *FsFontModel // fs_font 字体配置 + FsGerent *FsGerentModel // fs_gerent 管理员表 + FsGuest *FsGuestModel // fs_guest 游客表 + FsLog *FsLogModel // fs_log 日志表 + FsLogoCartoon *FsLogoCartoonModel // fs_logo_cartoon logo底图表 + FsMapLibrary *FsMapLibraryModel // fs_map_library 贴图库 + FsMenu *FsMenuModel // fs_menu 后台菜单 + FsMerchantCategory *FsMerchantCategoryModel // fs_merchant_category 商户类型表 + FsMigration *FsMigrationModel // fs_migration 版本库 + FsOrder *FsOrderModel // fs_order + FsOrderAffiliate *FsOrderAffiliateModel // fs_order_affiliate 订单附属表-流程控制时间等 + FsOrderDetail *FsOrderDetailModel // fs_order_detail 订单详细表 + FsOrderDetailTemplate *FsOrderDetailTemplateModel // fs_order_detail_template 订单模板详细表 + FsOrderRemark *FsOrderRemarkModel // fs_order_remark 订单备注表 + FsPay *FsPayModel // fs_pay 支付记录 + FsPayEvent *FsPayEventModel // fs_pay_event 支付回调事件日志 + FsProduct *FsProductModel // fs_product 产品表 + FsProductCopy1 *FsProductCopy1Model // fs_product_copy1 产品表 + FsProductDesign *FsProductDesignModel // fs_product_design 产品设计表 + FsProductDesignGather *FsProductDesignGatherModel // fs_product_design_gather + FsProductModel3d *FsProductModel3dModel // fs_product_model3d 产品模型表 + FsProductModel3dLight *FsProductModel3dLightModel // fs_product_model3d_light 模型-灯光组表 + FsProductOption *FsProductOptionModel // fs_product_option 产品选项表(已废弃) + FsProductPrice *FsProductPriceModel // fs_product_price 阶梯价格表 + FsProductRenderDesign *FsProductRenderDesignModel // fs_product_render_design + FsProductScene *FsProductSceneModel // fs_product_scene 产品场景表 + FsProductSize *FsProductSizeModel // fs_product_size 产品尺寸表 + FsProductTagProp *FsProductTagPropModel // fs_product_tag_prop 产品标签相关属性表 + FsProductTemplate *FsProductTemplateModel // fs_product_template 产品模板表(已废弃) + FsProductTemplateBasemap *FsProductTemplateBasemapModel // fs_product_template_basemap 模板底图表 + FsProductTemplateElement *FsProductTemplateElementModel // fs_product_template_element 云渲染配置表 + FsProductTemplateElement0826 *FsProductTemplateElement0826Model // fs_product_template_element_0826 + FsProductTemplateElement22 *FsProductTemplateElement22Model // fs_product_template_element_22 + FsProductTemplateElementBackup1018 *FsProductTemplateElementBackup1018Model // fs_product_template_element_backup1018 + FsProductTemplateElementKongde *FsProductTemplateElementKongdeModel // fs_product_template_element_kongde + FsProductTemplateTags *FsProductTemplateTagsModel // fs_product_template_tags 模板标签表 + FsProductTemplateV2 *FsProductTemplateV2Model // fs_product_template_v2 产品-模型-模板表 + FsProductV2Tmp *FsProductV2TmpModel // fs_product_v2_tmp 产品表 + FsQrcode *FsQrcodeModel // fs_qrcode + FsQrcodeLog *FsQrcodeLogModel // fs_qrcode_log 二维码扫描日志 + FsQrcodeSet *FsQrcodeSetModel // fs_qrcode_set 二维码边框配置表 + FsQrcodeUser *FsQrcodeUserModel // fs_qrcode_user 二维码-用户名表 + FsQuotation *FsQuotationModel // fs_quotation 报价单信息表 + FsQuotationPrice *FsQuotationPriceModel // fs_quotation_price 报价单价格表 + FsQuotationProduct *FsQuotationProductModel // fs_quotation_product 报价单产品表 + FsQuotationRemarkTemplate *FsQuotationRemarkTemplateModel // fs_quotation_remark_template 报价单备注模板 + FsQuotationSaler *FsQuotationSalerModel // fs_quotation_saler 报价单业务员表 + FsQuotationSizeLayout *FsQuotationSizeLayoutModel // fs_quotation_size_layout 产品尺寸排版表 + FsRefundReason *FsRefundReasonModel // fs_refund_reason + FsResource *FsResourceModel // fs_resource 资源表 + FsResources *FsResourcesModel // fs_resources 资源表 + FsStandardLogo *FsStandardLogoModel // fs_standard_logo 标准logo + FsTags *FsTagsModel // fs_tags 产品分类表 + FsToolLogs *FsToolLogsModel // fs_tool_logs 3d设计工具日志表 + FsToolTemplate *FsToolTemplateModel // fs_tool_template 设计工具模板(废弃) + FsToolUser *FsToolUserModel // fs_tool_user 3d设计工具用户表 + FsTrade *FsTradeModel // fs_trade + FsUser *FsUserModel // fs_user 用户表 + FsUserDesign *FsUserDesignModel // fs_user_design 废弃表 + FsUserInfo *FsUserInfoModel // fs_user_info 用户信息表 + FsUserMaterial *FsUserMaterialModel // fs_user_material 用户素材表 + FsUserStock *FsUserStockModel // fs_user_stock 用户云仓库存 + FsWebSet *FsWebSetModel // fs_web_set 网站配置表 } func NewAllModels(gdb *gorm.DB) *AllModelsGen { models := &AllModelsGen{ - FsAddress: NewFsAddressModel(gdb), - FsAuthAssignment: NewFsAuthAssignmentModel(gdb), - FsAuthItem: NewFsAuthItemModel(gdb), - FsAuthItemChild: NewFsAuthItemChildModel(gdb), - FsAuthRule: NewFsAuthRuleModel(gdb), - FsBackendUser: NewFsBackendUserModel(gdb), - FsCanteenProduct: NewFsCanteenProductModel(gdb), - FsCanteenType: NewFsCanteenTypeModel(gdb), - FsCard: NewFsCardModel(gdb), - FsCardGroup: NewFsCardGroupModel(gdb), - FsCart: NewFsCartModel(gdb), - FsChangeCode: NewFsChangeCodeModel(gdb), - FsCloud: NewFsCloudModel(gdb), - FsCloudDeliverEveryTmp: NewFsCloudDeliverEveryTmpModel(gdb), - FsCloudDeliverTmp: NewFsCloudDeliverTmpModel(gdb), - FsCloudPickUp: NewFsCloudPickUpModel(gdb), - FsCloudPickUpDetail: NewFsCloudPickUpDetailModel(gdb), - FsCloudReceive: NewFsCloudReceiveModel(gdb), - FsCloudReceiveEvery: NewFsCloudReceiveEveryModel(gdb), - FsCloudRenderLog: NewFsCloudRenderLogModel(gdb), - FsCloudUserApplyBack: NewFsCloudUserApplyBackModel(gdb), - FsContact: NewFsContactModel(gdb), - FsContactService: NewFsContactServiceModel(gdb), - FsCoupon: NewFsCouponModel(gdb), - FsDeliver: NewFsDeliverModel(gdb), - FsDeliverEvery: NewFsDeliverEveryModel(gdb), - FsDepartment: NewFsDepartmentModel(gdb), - FsEmailLogs: NewFsEmailLogsModel(gdb), - FsEmailTemplate: NewFsEmailTemplateModel(gdb), - FsFactory: NewFsFactoryModel(gdb), - FsFactoryDeliver: NewFsFactoryDeliverModel(gdb), - FsFactoryDeliverEvery: NewFsFactoryDeliverEveryModel(gdb), - FsFactoryProduct: NewFsFactoryProductModel(gdb), - FsFactoryShipTmp: NewFsFactoryShipTmpModel(gdb), - FsFaq: NewFsFaqModel(gdb), - FsFont: NewFsFontModel(gdb), - FsGerent: NewFsGerentModel(gdb), - FsGuest: NewFsGuestModel(gdb), - FsLog: NewFsLogModel(gdb), - FsMapLibrary: NewFsMapLibraryModel(gdb), - FsMenu: NewFsMenuModel(gdb), - FsMigration: NewFsMigrationModel(gdb), - FsOrder: NewFsOrderModel(gdb), - FsOrderAffiliate: NewFsOrderAffiliateModel(gdb), - FsOrderDetail: NewFsOrderDetailModel(gdb), - FsOrderDetailTemplate: NewFsOrderDetailTemplateModel(gdb), - FsOrderRemark: NewFsOrderRemarkModel(gdb), - FsPay: NewFsPayModel(gdb), - FsPayEvent: NewFsPayEventModel(gdb), - FsProduct: NewFsProductModel(gdb), - FsProductCopy1: NewFsProductCopy1Model(gdb), - FsProductDesign: NewFsProductDesignModel(gdb), - FsProductDesignGather: NewFsProductDesignGatherModel(gdb), - FsProductModel3d: NewFsProductModel3dModel(gdb), - FsProductModel3dLight: NewFsProductModel3dLightModel(gdb), - FsProductOption: NewFsProductOptionModel(gdb), - FsProductPrice: NewFsProductPriceModel(gdb), - FsProductRecommend: NewFsProductRecommendModel(gdb), - FsProductRenderDesign: NewFsProductRenderDesignModel(gdb), - FsProductScene: NewFsProductSceneModel(gdb), - FsProductSize: NewFsProductSizeModel(gdb), - FsProductTagProp: NewFsProductTagPropModel(gdb), - FsProductTemplate: NewFsProductTemplateModel(gdb), - FsProductTemplateBasemap: NewFsProductTemplateBasemapModel(gdb), - FsProductTemplateElement: NewFsProductTemplateElementModel(gdb), - FsProductTemplateTags: NewFsProductTemplateTagsModel(gdb), - FsProductTemplateV2: NewFsProductTemplateV2Model(gdb), - FsProductV2Tmp: NewFsProductV2TmpModel(gdb), - FsQrcode: NewFsQrcodeModel(gdb), - FsQrcodeLog: NewFsQrcodeLogModel(gdb), - FsQrcodeSet: NewFsQrcodeSetModel(gdb), - FsQrcodeUser: NewFsQrcodeUserModel(gdb), - FsQuotation: NewFsQuotationModel(gdb), - FsQuotationProduct: NewFsQuotationProductModel(gdb), - FsQuotationRemarkTemplate: NewFsQuotationRemarkTemplateModel(gdb), - FsQuotationSaler: NewFsQuotationSalerModel(gdb), - FsRefundReason: NewFsRefundReasonModel(gdb), - FsResource: NewFsResourceModel(gdb), - FsResources: NewFsResourcesModel(gdb), - FsStandardLogo: NewFsStandardLogoModel(gdb), - FsTags: NewFsTagsModel(gdb), - FsToolLogs: NewFsToolLogsModel(gdb), - FsToolTemplate: NewFsToolTemplateModel(gdb), - FsToolUser: NewFsToolUserModel(gdb), - FsTrade: NewFsTradeModel(gdb), - FsUser: NewFsUserModel(gdb), - FsUserDesign: NewFsUserDesignModel(gdb), - FsUserMaterial: NewFsUserMaterialModel(gdb), - FsUserStock: NewFsUserStockModel(gdb), - FsWebSet: NewFsWebSetModel(gdb), + FsAddress: NewFsAddressModel(gdb), + FsAuthAssignment: NewFsAuthAssignmentModel(gdb), + FsAuthItem: NewFsAuthItemModel(gdb), + FsAuthItemChild: NewFsAuthItemChildModel(gdb), + FsAuthRule: NewFsAuthRuleModel(gdb), + FsBackendUser: NewFsBackendUserModel(gdb), + FsCanteenProduct: NewFsCanteenProductModel(gdb), + FsCanteenType: NewFsCanteenTypeModel(gdb), + FsCard: NewFsCardModel(gdb), + FsCardGroup: NewFsCardGroupModel(gdb), + FsCart: NewFsCartModel(gdb), + FsChangeCode: NewFsChangeCodeModel(gdb), + FsCloud: NewFsCloudModel(gdb), + FsCloudDeliverEveryTmp: NewFsCloudDeliverEveryTmpModel(gdb), + FsCloudDeliverTmp: NewFsCloudDeliverTmpModel(gdb), + FsCloudPickUp: NewFsCloudPickUpModel(gdb), + FsCloudPickUpDetail: NewFsCloudPickUpDetailModel(gdb), + FsCloudReceive: NewFsCloudReceiveModel(gdb), + FsCloudReceiveEvery: NewFsCloudReceiveEveryModel(gdb), + FsCloudRenderLog: NewFsCloudRenderLogModel(gdb), + FsCloudUserApplyBack: NewFsCloudUserApplyBackModel(gdb), + FsContact: NewFsContactModel(gdb), + FsContactService: NewFsContactServiceModel(gdb), + FsCoupon: NewFsCouponModel(gdb), + FsDeliver: NewFsDeliverModel(gdb), + FsDeliverEvery: NewFsDeliverEveryModel(gdb), + FsDepartment: NewFsDepartmentModel(gdb), + FsEmailLogs: NewFsEmailLogsModel(gdb), + FsEmailTemplate: NewFsEmailTemplateModel(gdb), + FsFactory: NewFsFactoryModel(gdb), + FsFactoryDeliver: NewFsFactoryDeliverModel(gdb), + FsFactoryDeliverEvery: NewFsFactoryDeliverEveryModel(gdb), + FsFactoryProduct: NewFsFactoryProductModel(gdb), + FsFactoryShipTmp: NewFsFactoryShipTmpModel(gdb), + FsFaq: NewFsFaqModel(gdb), + FsFont: NewFsFontModel(gdb), + FsGerent: NewFsGerentModel(gdb), + FsGuest: NewFsGuestModel(gdb), + FsLog: NewFsLogModel(gdb), + FsLogoCartoon: NewFsLogoCartoonModel(gdb), + FsMapLibrary: NewFsMapLibraryModel(gdb), + FsMenu: NewFsMenuModel(gdb), + FsMerchantCategory: NewFsMerchantCategoryModel(gdb), + FsMigration: NewFsMigrationModel(gdb), + FsOrder: NewFsOrderModel(gdb), + FsOrderAffiliate: NewFsOrderAffiliateModel(gdb), + FsOrderDetail: NewFsOrderDetailModel(gdb), + FsOrderDetailTemplate: NewFsOrderDetailTemplateModel(gdb), + FsOrderRemark: NewFsOrderRemarkModel(gdb), + FsPay: NewFsPayModel(gdb), + FsPayEvent: NewFsPayEventModel(gdb), + FsProduct: NewFsProductModel(gdb), + FsProductCopy1: NewFsProductCopy1Model(gdb), + FsProductDesign: NewFsProductDesignModel(gdb), + FsProductDesignGather: NewFsProductDesignGatherModel(gdb), + FsProductModel3d: NewFsProductModel3dModel(gdb), + FsProductModel3dLight: NewFsProductModel3dLightModel(gdb), + FsProductOption: NewFsProductOptionModel(gdb), + FsProductPrice: NewFsProductPriceModel(gdb), + FsProductRenderDesign: NewFsProductRenderDesignModel(gdb), + FsProductScene: NewFsProductSceneModel(gdb), + FsProductSize: NewFsProductSizeModel(gdb), + FsProductTagProp: NewFsProductTagPropModel(gdb), + FsProductTemplate: NewFsProductTemplateModel(gdb), + FsProductTemplateBasemap: NewFsProductTemplateBasemapModel(gdb), + FsProductTemplateElement: NewFsProductTemplateElementModel(gdb), + FsProductTemplateElement0826: NewFsProductTemplateElement0826Model(gdb), + FsProductTemplateElement22: NewFsProductTemplateElement22Model(gdb), + FsProductTemplateElementBackup1018: NewFsProductTemplateElementBackup1018Model(gdb), + FsProductTemplateElementKongde: NewFsProductTemplateElementKongdeModel(gdb), + FsProductTemplateTags: NewFsProductTemplateTagsModel(gdb), + FsProductTemplateV2: NewFsProductTemplateV2Model(gdb), + FsProductV2Tmp: NewFsProductV2TmpModel(gdb), + FsQrcode: NewFsQrcodeModel(gdb), + FsQrcodeLog: NewFsQrcodeLogModel(gdb), + FsQrcodeSet: NewFsQrcodeSetModel(gdb), + FsQrcodeUser: NewFsQrcodeUserModel(gdb), + FsQuotation: NewFsQuotationModel(gdb), + FsQuotationPrice: NewFsQuotationPriceModel(gdb), + FsQuotationProduct: NewFsQuotationProductModel(gdb), + FsQuotationRemarkTemplate: NewFsQuotationRemarkTemplateModel(gdb), + FsQuotationSaler: NewFsQuotationSalerModel(gdb), + FsQuotationSizeLayout: NewFsQuotationSizeLayoutModel(gdb), + FsRefundReason: NewFsRefundReasonModel(gdb), + FsResource: NewFsResourceModel(gdb), + FsResources: NewFsResourcesModel(gdb), + FsStandardLogo: NewFsStandardLogoModel(gdb), + FsTags: NewFsTagsModel(gdb), + FsToolLogs: NewFsToolLogsModel(gdb), + FsToolTemplate: NewFsToolTemplateModel(gdb), + FsToolUser: NewFsToolUserModel(gdb), + FsTrade: NewFsTradeModel(gdb), + FsUser: NewFsUserModel(gdb), + FsUserDesign: NewFsUserDesignModel(gdb), + FsUserInfo: NewFsUserInfoModel(gdb), + FsUserMaterial: NewFsUserMaterialModel(gdb), + FsUserStock: NewFsUserStockModel(gdb), + FsWebSet: NewFsWebSetModel(gdb), } return models } diff --git a/server/assistant/assistant.go b/server/assistant/assistant.go index 8ae0cf8e..2d1ab230 100644 --- a/server/assistant/assistant.go +++ b/server/assistant/assistant.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/utils/auth" @@ -23,7 +22,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() diff --git a/server/assistant/etc/assistant.yaml b/server/assistant/etc/assistant.yaml index 3804fea1..f65d63af 100644 --- a/server/assistant/etc/assistant.yaml +++ b/server/assistant/etc/assistant.yaml @@ -1,6 +1,7 @@ Name: assistant Host: 0.0.0.0 Port: 9950 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/backend/backend.go b/server/backend/backend.go index 83ae4af9..099cb974 100644 --- a/server/backend/backend.go +++ b/server/backend/backend.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/backend/internal/config" "fusenapi/server/backend/internal/handler" @@ -22,7 +21,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/backend/etc/backend.yaml b/server/backend/etc/backend.yaml index 18f08394..f0cdc6c8 100644 --- a/server/backend/etc/backend.yaml +++ b/server/backend/etc/backend.yaml @@ -1,6 +1,7 @@ Name: backend Host: 0.0.0.0 Port: 9901 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen_backend_2023 diff --git a/server/base/base.go b/server/base/base.go new file mode 100644 index 00000000..1d3f1af1 --- /dev/null +++ b/server/base/base.go @@ -0,0 +1,35 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + + "fusenapi/utils/auth" + + "fusenapi/server/base/internal/config" + "fusenapi/server/base/internal/handler" + "fusenapi/server/base/internal/svc" + + "github.com/zeromicro/go-zero/core/conf" + "github.com/zeromicro/go-zero/rest" +) + +var configFile = flag.String("f", "etc/base.yaml", "the config file") + +func main() { + flag.Parse() + + var c config.Config + conf.MustLoad(*configFile, &c) + + server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { + })) + defer server.Stop() + + ctx := svc.NewServiceContext(c) + handler.RegisterHandlers(server, ctx) + + fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) + server.Start() +} diff --git a/server/base/base_test.go b/server/base/base_test.go new file mode 100644 index 00000000..80820ef2 --- /dev/null +++ b/server/base/base_test.go @@ -0,0 +1,9 @@ +package main + +import ( + "testing" +) + +func TestMain(t *testing.T) { + main() +} diff --git a/server/base/etc/base.yaml b/server/base/etc/base.yaml new file mode 100644 index 00000000..e201a85b --- /dev/null +++ b/server/base/etc/base.yaml @@ -0,0 +1,10 @@ +Name: base +Host: 0.0.0.0 +Port: 9920 +Timeout: 15000 #服务超时时间(毫秒) +SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest +Auth: + AccessSecret: fusen2023 + AccessExpire: 2592000 + RefreshAfter: 1592000 +SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672 \ No newline at end of file diff --git a/server/base/internal/config/config.go b/server/base/internal/config/config.go new file mode 100644 index 00000000..be42afd5 --- /dev/null +++ b/server/base/internal/config/config.go @@ -0,0 +1,14 @@ +package config + +import ( + "fusenapi/server/base/internal/types" + + "github.com/zeromicro/go-zero/rest" +) + +type Config struct { + rest.RestConf + SourceMysql string + Auth types.Auth + SourceRabbitMq string +} diff --git a/server/base/internal/handler/merchantcategorylisthandler.go b/server/base/internal/handler/merchantcategorylisthandler.go new file mode 100644 index 00000000..c7b4484a --- /dev/null +++ b/server/base/internal/handler/merchantcategorylisthandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/base/internal/logic" + "fusenapi/server/base/internal/svc" + "fusenapi/server/base/internal/types" +) + +func MerchantCategoryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.MerchantCategoryListReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewMerchantCategoryListLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.MerchantCategoryList(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/base/internal/handler/routes.go b/server/base/internal/handler/routes.go new file mode 100644 index 00000000..4f4764c0 --- /dev/null +++ b/server/base/internal/handler/routes.go @@ -0,0 +1,22 @@ +// Code generated by goctl. DO NOT EDIT. +package handler + +import ( + "net/http" + + "fusenapi/server/base/internal/svc" + + "github.com/zeromicro/go-zero/rest" +) + +func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/api/base/merchant_category_list", + Handler: MerchantCategoryListHandler(serverCtx), + }, + }, + ) +} diff --git a/server/base/internal/logic/merchantcategorylistlogic.go b/server/base/internal/logic/merchantcategorylistlogic.go new file mode 100644 index 00000000..eb9dd3ae --- /dev/null +++ b/server/base/internal/logic/merchantcategorylistlogic.go @@ -0,0 +1,53 @@ +package logic + +import ( + "fusenapi/model/gmodel" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/base/internal/svc" + "fusenapi/server/base/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type MerchantCategoryListLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewMerchantCategoryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MerchantCategoryListLogic { + return &MerchantCategoryListLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *MerchantCategoryListLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *MerchantCategoryListLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } + +func (l *MerchantCategoryListLogic) MerchantCategoryList(req *types.MerchantCategoryListReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + fsMerchantCategoryModel := gmodel.NewFsMerchantCategoryModel(l.svcCtx.MysqlConn) + BuilderDB := fsMerchantCategoryModel.BuilderDB(l.ctx, nil).Model(&gmodel.FsMerchantCategory{}) + resourceInfo, err := fsMerchantCategoryModel.FindAll(BuilderDB, nil, "sort desc") + if err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeDbSqlErr, "MerchantCategoryList error system failed") + } + // 返回成功 + return resp.SetStatus(basic.CodeOK, map[string]interface{}{ + "list": resourceInfo, + }) +} diff --git a/server/base/internal/svc/servicecontext.go b/server/base/internal/svc/servicecontext.go new file mode 100644 index 00000000..335cab29 --- /dev/null +++ b/server/base/internal/svc/servicecontext.go @@ -0,0 +1,62 @@ +package svc + +import ( + "errors" + "fmt" + "fusenapi/server/base/internal/config" + "net/http" + + "fusenapi/initalize" + "fusenapi/model/gmodel" + + "github.com/golang-jwt/jwt" + "gorm.io/gorm" +) + +type ServiceContext struct { + Config config.Config + + MysqlConn *gorm.DB + AllModels *gmodel.AllModelsGen + RabbitMq *initalize.RabbitMqHandle +} + +func NewServiceContext(c config.Config) *ServiceContext { + return &ServiceContext{ + Config: c, + MysqlConn: initalize.InitMysql(c.SourceMysql), + AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), + RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), + } +} + +func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { + AuthKey := r.Header.Get("Authorization") + if AuthKey == "" { + return nil, nil + } + AuthKey = AuthKey[7:] + + if len(AuthKey) <= 50 { + return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) + } + + token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) { + // 检查签名方法是否为 HS256 + if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { + return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) + } + // 返回用于验证签名的密钥 + return []byte(svcCtx.Config.Auth.AccessSecret), nil + }) + if err != nil { + return nil, errors.New(fmt.Sprint("Error parsing token:", err)) + } + + // 验证成功返回 + if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid { + return claims, nil + } + + return nil, errors.New(fmt.Sprint("Invalid token", err)) +} diff --git a/server/base/internal/types/types.go b/server/base/internal/types/types.go new file mode 100644 index 00000000..afa558e9 --- /dev/null +++ b/server/base/internal/types/types.go @@ -0,0 +1,78 @@ +// Code generated by goctl. DO NOT EDIT. +package types + +import ( + "fusenapi/utils/basic" +) + +type MerchantCategoryListReq struct { +} + +type Request struct { +} + +type Response struct { + Code int `json:"code"` + Message string `json:"msg"` + Data interface{} `json:"data"` +} + +type Auth struct { + AccessSecret string `json:"accessSecret"` + AccessExpire int64 `json:"accessExpire"` + RefreshAfter int64 `json:"refreshAfter"` +} + +type File struct { + Filename string `fsfile:"filename"` + Header map[string][]string `fsfile:"header"` + Size int64 `fsfile:"size"` + Data []byte `fsfile:"data"` +} + +type Meta struct { + TotalCount int64 `json:"totalCount"` + PageCount int64 `json:"pageCount"` + CurrentPage int `json:"currentPage"` + PerPage int `json:"perPage"` +} + +// Set 设置Response的Code和Message值 +func (resp *Response) Set(Code int, Message string) *Response { + return &Response{ + Code: Code, + Message: Message, + } +} + +// Set 设置整个Response +func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response { + return &Response{ + Code: Code, + Message: Message, + Data: Data, + } +} + +// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数 +func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response { + newResp := &Response{ + Code: sr.Code, + } + if len(data) == 1 { + newResp.Data = data[0] + } + return newResp +} + +// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数 +func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response { + newResp := &Response{ + Code: sr.Code, + Message: msg, + } + if len(data) == 1 { + newResp.Data = data[0] + } + return newResp +} diff --git a/server/canteen/canteen.go b/server/canteen/canteen.go index 993573fb..eb2e1f27 100644 --- a/server/canteen/canteen.go +++ b/server/canteen/canteen.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/canteen/internal/config" "fusenapi/server/canteen/internal/handler" @@ -23,8 +22,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/canteen/etc/canteen.yaml b/server/canteen/etc/canteen.yaml index 4b363db8..16b26a52 100644 --- a/server/canteen/etc/canteen.yaml +++ b/server/canteen/etc/canteen.yaml @@ -1,6 +1,7 @@ Name: canteen Host: 0.0.0.0 Port: 9902 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/data-transfer/data-transfer.go b/server/data-transfer/data-transfer.go index af86ccc2..8ad3fa67 100644 --- a/server/data-transfer/data-transfer.go +++ b/server/data-transfer/data-transfer.go @@ -8,7 +8,6 @@ import ( svc2 "fusenapi/server/data-transfer/internal/svc" "fusenapi/utils/auth" "net/http" - "time" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/rest" @@ -21,7 +20,6 @@ func main() { var c config2.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/data-transfer/etc/data-transfer.yaml b/server/data-transfer/etc/data-transfer.yaml index 4a3e767d..758542f8 100644 --- a/server/data-transfer/etc/data-transfer.yaml +++ b/server/data-transfer/etc/data-transfer.yaml @@ -1,6 +1,7 @@ Name: data-transfer Host: 0.0.0.0 Port: 9903 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/home-user-auth/etc/home-user-auth.yaml b/server/home-user-auth/etc/home-user-auth.yaml index 31722119..e9a7b8c8 100644 --- a/server/home-user-auth/etc/home-user-auth.yaml +++ b/server/home-user-auth/etc/home-user-auth.yaml @@ -1,6 +1,7 @@ Name: home-user-auth Host: 0.0.0.0 Port: 9904 +Timeout: 15000 #服务超时时间 MainAddress: "http://localhost:9900" SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest diff --git a/server/home-user-auth/home-user-auth.go b/server/home-user-auth/home-user-auth.go index 28598d4f..911ae5de 100644 --- a/server/home-user-auth/home-user-auth.go +++ b/server/home-user-auth/home-user-auth.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/home-user-auth/internal/config" "fusenapi/server/home-user-auth/internal/handler" @@ -23,7 +22,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/home-user-auth/internal/handler/routes.go b/server/home-user-auth/internal/handler/routes.go index 607e6278..c6957627 100644 --- a/server/home-user-auth/internal/handler/routes.go +++ b/server/home-user-auth/internal/handler/routes.go @@ -102,6 +102,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/user/one-more-order", Handler: UserAgainOrderHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/user/set_user_info", + Handler: UserInfoSetHandler(serverCtx), + }, }, ) } diff --git a/server/home-user-auth/internal/handler/userinfosethandler.go b/server/home-user-auth/internal/handler/userinfosethandler.go new file mode 100644 index 00000000..8593b501 --- /dev/null +++ b/server/home-user-auth/internal/handler/userinfosethandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/home-user-auth/internal/logic" + "fusenapi/server/home-user-auth/internal/svc" + "fusenapi/server/home-user-auth/internal/types" +) + +func UserInfoSetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.UserInfoSetReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewUserInfoSetLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.UserInfoSet(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/home-user-auth/internal/logic/userinfosetlogic.go b/server/home-user-auth/internal/logic/userinfosetlogic.go new file mode 100644 index 00000000..c27836b8 --- /dev/null +++ b/server/home-user-auth/internal/logic/userinfosetlogic.go @@ -0,0 +1,95 @@ +package logic + +import ( + "fusenapi/model/gmodel" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + "fusenapi/utils/validate" + "time" + + "context" + + "fusenapi/server/home-user-auth/internal/svc" + "fusenapi/server/home-user-auth/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UserInfoSetLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewUserInfoSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoSetLogic { + return &UserInfoSetLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *UserInfoSetLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *UserInfoSetLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } + +func (l *UserInfoSetLogic) UserInfoSet(req *types.UserInfoSetReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + if userinfo.IsOnlooker() { + // 如果是,返回未授权的错误码 + return resp.SetStatus(basic.CodeUnAuth) + } + + var userId int64 + var guestId int64 + + // 检查用户是否是游客 + if userinfo.IsGuest() { + // 如果是,使用游客ID和游客键名格式 + guestId = userinfo.GuestId + } else { + // 否则,使用用户ID和用户键名格式 + userId = userinfo.UserId + } + + _, err := validate.Validate(&req.Module, &req.Metadata) + if err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeRequestParamsErr, "UserInfoSet error Validate failed") + } + + // 根据模块类型检查数据 + var userInfo = &gmodel.FsUserInfo{} + fsUserInfoModel := gmodel.NewFsUserInfoModel(l.svcCtx.MysqlConn) + BuilderDB := fsUserInfoModel.BuilderDB(l.ctx, nil).Model(&gmodel.FsUserInfo{}) + BuilderDB1 := BuilderDB.Where("module = ?", req.Module).Where("user_id=?", userId).Where("guest_id=?", guestId) + userInfo, err = fsUserInfoModel.FindOne(BuilderDB1, nil) + if err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeDbSqlErr, "UserInfoSet error system failed") + } + var nowTime = time.Now().Unix() + if userInfo.Id != 0 { + userInfo.Metadata = &req.Metadata + userInfo.Utime = &nowTime + } else { + userInfo.GuestId = &guestId + userInfo.UserId = &userId + userInfo.Module = &req.Module + userInfo.Metadata = &req.Metadata + userInfo.Ctime = &nowTime + } + _, err = fsUserInfoModel.CreateOrUpdate(BuilderDB, userInfo) + if err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeDbSqlErr, "UserInfoSet error system failed") + } + + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/home-user-auth/internal/logic/userordercancellogic.go b/server/home-user-auth/internal/logic/userordercancellogic.go index 13211fcf..6164da9c 100644 --- a/server/home-user-auth/internal/logic/userordercancellogic.go +++ b/server/home-user-auth/internal/logic/userordercancellogic.go @@ -80,14 +80,14 @@ func (l *UserOrderCancelLogic) UserOrderCancel(req *types.UserOrderCancelReq, us err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error { // 修改订单信息 orderModelTS := gmodel.NewFsOrderModel(tx) - err = orderModelTS.Update(ctx, orderInfo) + err = orderModelTS.RBUpdate(ctx, orderInfo) if err != nil { return err } // 新增退款记录 var isRefund int64 = 0 refundReasonModelTS := gmodel.NewFsRefundReasonModel(tx) - refundReasonModelTS.CreateOrUpdate(ctx, &gmodel.FsRefundReason{ + refundReasonModelTS.RBCreateOrUpdate(ctx, &gmodel.FsRefundReason{ IsRefund: &isRefund, RefundReasonId: &req.RefundReasonId, RefundReason: &req.RefundReason, diff --git a/server/home-user-auth/internal/types/types.go b/server/home-user-auth/internal/types/types.go index b183ef86..6bbf9f49 100644 --- a/server/home-user-auth/internal/types/types.go +++ b/server/home-user-auth/internal/types/types.go @@ -5,6 +5,11 @@ import ( "fusenapi/utils/basic" ) +type UserInfoSetReq struct { + Module string `form:"module,options=[merchant_category]"` // json格式字符串 + Metadata string `form:"metadata"` // json格式字符串 +} + type UserAgainOrderReq struct { Sn string `form:"sn"` // 订单编号 } diff --git a/server/inventory/etc/inventory.yaml b/server/inventory/etc/inventory.yaml index 3633f1b0..afd8bfa7 100644 --- a/server/inventory/etc/inventory.yaml +++ b/server/inventory/etc/inventory.yaml @@ -1,7 +1,7 @@ Name: inventory Host: 0.0.0.0 Port: 9905 - +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/inventory/inventory.go b/server/inventory/inventory.go index f623a627..10661756 100644 --- a/server/inventory/inventory.go +++ b/server/inventory/inventory.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/inventory/internal/config" "fusenapi/server/inventory/internal/handler" @@ -22,7 +21,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/map-library/etc/map-library.yaml b/server/map-library/etc/map-library.yaml index 0dc22627..2ab101a4 100644 --- a/server/map-library/etc/map-library.yaml +++ b/server/map-library/etc/map-library.yaml @@ -1,6 +1,7 @@ Name: map-library Host: 0.0.0.0 Port: 9906 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/map-library/internal/logic/getmaplibrarylistlogic.go b/server/map-library/internal/logic/getmaplibrarylistlogic.go index aa7ec7a8..1ecf5167 100644 --- a/server/map-library/internal/logic/getmaplibrarylistlogic.go +++ b/server/map-library/internal/logic/getmaplibrarylistlogic.go @@ -66,7 +66,7 @@ func (l *GetMapLibraryListLogic) GetMapLibraryList(req *types.Request, userinfo if tagIndex, ok := mapTag[*v.TagId]; ok { data.Tag = &types.MapLibraryListTag{ Id: templateTagList[tagIndex].Id, - Title: *templateTagList[tagIndex].Title, + Title: *templateTagList[tagIndex].TemplateTag, } } //解析info diff --git a/server/map-library/map-library.go b/server/map-library/map-library.go index 54ee66f6..b8f7e38b 100644 --- a/server/map-library/map-library.go +++ b/server/map-library/map-library.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/map-library/internal/config" "fusenapi/server/map-library/internal/handler" @@ -22,7 +21,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/orders/etc/orders.yaml b/server/orders/etc/orders.yaml index 77573dcf..b8bc7a88 100644 --- a/server/orders/etc/orders.yaml +++ b/server/orders/etc/orders.yaml @@ -1,6 +1,7 @@ Name: orders Host: 0.0.0.0 Port: 9907 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/orders/orders.go b/server/orders/orders.go index a4707bea..fc951aa8 100644 --- a/server/orders/orders.go +++ b/server/orders/orders.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/orders/internal/config" "fusenapi/server/orders/internal/handler" @@ -22,7 +21,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/pay/etc/pay.yaml b/server/pay/etc/pay.yaml index 831292a9..1d2b1f75 100644 --- a/server/pay/etc/pay.yaml +++ b/server/pay/etc/pay.yaml @@ -1,6 +1,7 @@ Name: pay Host: 0.0.0.0 Port: 9915 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/pay/internal/logic/orderpaymentintentlogic.go b/server/pay/internal/logic/orderpaymentintentlogic.go index fdc608ad..85946f40 100644 --- a/server/pay/internal/logic/orderpaymentintentlogic.go +++ b/server/pay/internal/logic/orderpaymentintentlogic.go @@ -116,7 +116,7 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte var fspay *gmodel.FsPay newFsPayModel := gmodel.NewFsPayModel(connGorm) if *orderInfo.Status == int64(constants.STATUS_NEW_NOT_PAY) { - fspay, err = newFsPayModel.GetListByOrderNumberStage(ctx, *orderInfo.Sn, 1) + fspay, err = newFsPayModel.RBGetListByOrderNumberStage(ctx, *orderInfo.Sn, 1) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { return err @@ -124,7 +124,7 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte } payStage = 1 } else { - fspay, err = newFsPayModel.GetListByOrderNumberStage(ctx, *orderInfo.Sn, 2) + fspay, err = newFsPayModel.RBGetListByOrderNumberStage(ctx, *orderInfo.Sn, 2) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { return err @@ -146,7 +146,7 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte } // 订单信息--修改 - err = gmodel.NewFsOrderModel(connGorm).Update(ctx, orderInfo) + err = gmodel.NewFsOrderModel(connGorm).RBUpdate(ctx, orderInfo) if err != nil { return err } @@ -167,7 +167,7 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte fspay.OrderSource = &orderSource fspay.PayStatus = &payStatus - _, err = newFsPayModel.CreateOrUpdate(ctx, fspay) + _, err = newFsPayModel.RBCreateOrUpdate(ctx, fspay) if err != nil { return err } diff --git a/server/pay/internal/logic/stripewebhooklogic.go b/server/pay/internal/logic/stripewebhooklogic.go index 5f327ab5..a0fe1dd2 100644 --- a/server/pay/internal/logic/stripewebhooklogic.go +++ b/server/pay/internal/logic/stripewebhooklogic.go @@ -157,7 +157,7 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge) err = l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error { // 查询支付记录 payModelT := gmodel.NewFsPayModel(connGorm) - payModelTRSB := payModelT.RowSelectBuilder(nil) + payModelTRSB := payModelT.BuilderTrans(nil) payModelTRSB1 := payModelTRSB.Where("trade_no = ?", chargeRefunded.PaymentIntent.ID).Where("pay_status = ?", constants.PAYSTATUS_SUCCESS).Where("is_refund = ?", 0) payInfo, err := payModelT.FindOneByQuery(ctx, payModelTRSB1, nil) if err != nil { @@ -165,7 +165,7 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge) } // 更新支付记录 *payInfo.IsRefund = 1 - _, err = payModelT.CreateOrUpdate(ctx, payInfo) + _, err = payModelT.RBCreateOrUpdate(ctx, payInfo) if err != nil { return err } @@ -175,7 +175,7 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge) if count == 0 { // 退款完成更新订单状态 orderModelT := gmodel.NewFsOrderModel(connGorm) - orderModelTRSB := orderModelT.RowSelectBuilder(nil).Where("sn =?", payInfo.OrderNumber) + orderModelTRSB := orderModelT.BuilderTrans(nil).Where("sn =?", payInfo.OrderNumber) orderInfoRel, err := orderModelT.FindOneByQuery(ctx, orderModelTRSB, nil) if err != nil { return err @@ -192,13 +192,14 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge) // 记录退款原因 refundReasonModelT := gmodel.NewFsRefundReasonModel(connGorm) - refundReasonModelTRSB := refundReasonModelT.RowSelectBuilder(nil).Where("order_id =?", orderInfoRel.Id) - refundReasonInfo, err := refundReasonModelT.FindOneByQuery(ctx, refundReasonModelTRSB, nil) + refundReasonModelTRSB := refundReasonModelT.BuilderTrans(nil) + refundReasonModelTRSB1 := refundReasonModelTRSB.Where("order_id =?", orderInfoRel.Id) + refundReasonInfo, err := refundReasonModelT.FindOneByQuery(ctx, refundReasonModelTRSB1, nil) if err != nil { return err } *refundReasonInfo.IsRefund = 1 - _, err = refundReasonModelT.CreateOrUpdate(ctx, refundReasonInfo) + _, err = refundReasonModelT.RBCreateOrUpdate(ctx, refundReasonInfo) if err != nil { return err } @@ -304,15 +305,16 @@ func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe. *payInfo.CardNo = card *payInfo.Brand = brand *payInfo.TradeNo = paymentIntent.ID - _, err = payModelT.CreateOrUpdate(ctx, payInfo) + _, err = payModelT.RBCreateOrUpdate(ctx, payInfo) if err != nil { return err } // 更新设计数据 productDesignModelT := gmodel.NewFsProductDesignModel(connGorm) + productDesignModelTRSB := productDesignModelT.BuilderTrans(ctx, nil) var isPay int64 = 1 - err = productDesignModelT.UpdateByIds(ctx, designIds, &gmodel.FsProductDesign{IsPay: &isPay}) + err = productDesignModelT.RBUpdateByIds(productDesignModelTRSB, designIds, &gmodel.FsProductDesign{IsPay: &isPay}) if err != nil { return err } @@ -331,7 +333,8 @@ func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe. // 删除购物车 cartModelT := gmodel.NewFsCartModel(connGorm) - err = cartModelT.DeleteCartsByIds(ctx, cartIds) + cartModelTRSB := cartModelT.BuilderTrans(ctx, nil) + err = cartModelT.RBDeleteCartsByIds(cartModelTRSB, cartIds) if err != nil { return err } @@ -353,7 +356,7 @@ func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe. orderInfo.Ptime = &nowTime orderInfo.PayedAmount = &orderPayedAmount orderModelT := gmodel.NewFsOrderModel(connGorm) - err = orderModelT.Update(ctx, orderInfo) + err = orderModelT.RBUpdate(ctx, orderInfo) if err != nil { return err } diff --git a/server/pay/pay.go b/server/pay/pay.go index 08c53e12..ecfedfef 100644 --- a/server/pay/pay.go +++ b/server/pay/pay.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/utils/auth" @@ -23,7 +22,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() diff --git a/server/product-model/product-model.go b/server/product-model/product-model.go index e0cabc28..a6374de1 100644 --- a/server/product-model/product-model.go +++ b/server/product-model/product-model.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/product-model/internal/config" "fusenapi/server/product-model/internal/handler" @@ -22,7 +21,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/product-template-tag/etc/product-template-tag.yaml b/server/product-template-tag/etc/product-template-tag.yaml index 253828fb..af29ff0a 100644 --- a/server/product-template-tag/etc/product-template-tag.yaml +++ b/server/product-template-tag/etc/product-template-tag.yaml @@ -1,6 +1,7 @@ Name: product-template-tag Host: 0.0.0.0 -Port: 9916 +Port: 9917 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index 815ef07c..cf89a9b4 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -1,10 +1,13 @@ package logic import ( + "context" + "encoding/json" + "errors" + "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" - - "context" + "gorm.io/gorm" "fusenapi/server/product-template-tag/internal/svc" "fusenapi/server/product-template-tag/internal/types" @@ -37,9 +40,41 @@ func NewGetProductTemplateTagsLogic(ctx context.Context, svcCtx *svc.ServiceCont func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProductTemplateTagsReq, userinfo *auth.UserInfo) (resp *basic.Response) { if req.Limit <= 0 || req.Limit > 100 { - req.Limit = 4 + req.Limit = 5 + } + var ( + productTemplateTags []gmodel.FsProductTemplateTags + ) + //获取用户元数据 + userMaterial, err := l.svcCtx.AllModels.FsUserMaterial.GetListByUser(l.ctx, userinfo.UserId, userinfo.GuestId, req.Limit) + if err != nil { + if !errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get ai recommend product template tag list") + } + // 返回固定模板标签列表 + productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetList(l.ctx, 1, req.Limit, "`id` DESC") + } else { + //元数据是空的 + if userMaterial.Metadata == nil || *userMaterial.Metadata == "" { + // 返回固定模板标签列表 + productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetList(l.ctx, 1, req.Limit, "`id` DESC") + } else { + //解析元数据 + var metaData map[string]interface{} + if err = json.Unmarshal([]byte(*userMaterial.Metadata), &metaData); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") + } + var templateTagNameList []string + b, _ := json.Marshal(metaData["template_tagid"]) + if err = json.Unmarshal(b, &templateTagNameList); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tagid") + } + productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, "id DESC") + } } - productTemplateTags, err := l.svcCtx.AllModels.FsProductTemplateTags.GetList(l.ctx, 1, req.Limit, "`id` DESC") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") @@ -47,9 +82,9 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags)) for _, v := range productTemplateTags { list = append(list, types.GetProductTemplateTagsRsp{ - Id: v.Id, - Tag: *v.Title, - Cover: *v.CoverImg, + Id: v.Id, + TemplateTag: *v.TemplateTag, + Cover: *v.Cover, }) } return resp.SetStatusWithMessage(basic.CodeOK, "success", list) diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index a89ea882..60cb80ca 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -10,9 +10,9 @@ type GetProductTemplateTagsReq struct { } type GetProductTemplateTagsRsp struct { - Id int64 `json:"id"` - Tag string `json:"tag"` - Cover string `json:"cover"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + Cover string `json:"cover"` } type Request struct { diff --git a/server/product-template-tag/product-template-tag.go b/server/product-template-tag/product-template-tag.go index 18898784..5f1bd6cd 100644 --- a/server/product-template-tag/product-template-tag.go +++ b/server/product-template-tag/product-template-tag.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/utils/auth" @@ -23,7 +22,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() diff --git a/server/product-template/etc/product-template.yaml b/server/product-template/etc/product-template.yaml index 287b4a33..e8700c9c 100644 --- a/server/product-template/etc/product-template.yaml +++ b/server/product-template/etc/product-template.yaml @@ -1,6 +1,7 @@ Name: product-template Host: 0.0.0.0 Port: 9910 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/product-template/internal/logic/gettemplatevdetaillogic.go b/server/product-template/internal/logic/gettemplatevdetaillogic.go index 12324f50..7ef73a14 100644 --- a/server/product-template/internal/logic/gettemplatevdetaillogic.go +++ b/server/product-template/internal/logic/gettemplatevdetaillogic.go @@ -8,7 +8,6 @@ import ( "fusenapi/utils/basic" "fusenapi/utils/format" "gorm.io/gorm" - "strconv" "strings" "context" @@ -62,13 +61,7 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template info") } //获取模板标签 - templateTagModel := gmodel.NewFsProductTemplateTagsModel(l.svcCtx.MysqlConn) - tagId, err := strconv.ParseInt(*templatev2Info.Tag, 10, 64) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "parse int tag id err") - } - templateTagInfo, err := templateTagModel.FindOne(l.ctx, tagId, "id,title") + templateTagInfo, err := l.svcCtx.AllModels.FsProductTemplateTags.FindOneByTagName(l.ctx, *templatev2Info.TemplateTag, "id,title") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template tag info is not exists") @@ -125,7 +118,7 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta } templateInfoRsp["tag"] = map[string]interface{}{ "id": templateTagInfo.Id, - "title": *templateTagInfo.Title, + "title": *templateTagInfo.TemplateTag, } response := types.GetTemplatevDetailRsp{ ProductModelInfo: productModelInfoRsp, diff --git a/server/product-template/product-template.go b/server/product-template/product-template.go index 522be699..3819752a 100644 --- a/server/product-template/product-template.go +++ b/server/product-template/product-template.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/product-template/internal/config" "fusenapi/server/product-template/internal/handler" @@ -22,7 +21,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/product/etc/product.yaml b/server/product/etc/product.yaml index 658e5411..39181b84 100644 --- a/server/product/etc/product.yaml +++ b/server/product/etc/product.yaml @@ -1,6 +1,7 @@ Name: product Host: 0.0.0.0 Port: 9908 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/product/internal/logic/getfittingbypidlogic.go b/server/product/internal/logic/getfittingbypidlogic.go index fb7a6bce..18f76892 100644 --- a/server/product/internal/logic/getfittingbypidlogic.go +++ b/server/product/internal/logic/getfittingbypidlogic.go @@ -73,7 +73,7 @@ func (l *GetFittingByPidLogic) GetFittingByPid(req *types.GetFittingByPidReq, us partIds = append(partIds, *v.PartId) } //获取配件数据 - fittingList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, partIds, "is_popular DESC,price ASC") + fittingList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, partIds, "is_hot DESC,price ASC") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get part list") @@ -110,7 +110,7 @@ func (l *GetFittingByPidLogic) GetFittingByPid(req *types.GetFittingByPidReq, us Title: *fitting.Title, Price: *fitting.Price, ModelInfo: modelInfo, - IsPopular: *fitting.IsPopular > 0, + IsPopular: *fitting.IsHot > 0, }) } return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp) diff --git a/server/product/internal/logic/getproductinfologic.go b/server/product/internal/logic/getproductinfologic.go index 8047752a..1a768d3c 100644 --- a/server/product/internal/logic/getproductinfologic.go +++ b/server/product/internal/logic/getproductinfologic.go @@ -109,8 +109,8 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri tagIds := make([]int64, 0, len(productTemplateList)) for _, v := range productTemplateList { mapTemplateModelId[*v.ModelId] = struct{}{} - if v.Tag != nil && *v.Tag != "" { - tagId, err := strconv.ParseInt(*v.Tag, 10, 64) + if v.TemplateTag != nil && *v.TemplateTag != "" { + tagId, err := strconv.ParseInt(*v.TemplateTag, 10, 64) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "tag is not a number") @@ -296,7 +296,7 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri partListRsp = append(partListRsp, thisInfo) } tagName := "" - if tagData, ok := mapTag[*tmp.Tag]; ok { + if tagData, ok := mapTag[*tmp.TemplateTag]; ok { tagName = *tagData.Title } //按照材质和尺寸来存放模板信息 diff --git a/server/product/internal/logic/getproductlistlogic.go b/server/product/internal/logic/getproductlistlogic.go index f45b8418..d12bc4dd 100644 --- a/server/product/internal/logic/getproductlistlogic.go +++ b/server/product/internal/logic/getproductlistlogic.go @@ -99,7 +99,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri } //获取模板 productTemplateModel := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) - productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds) + productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds, "") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index f3bf72be..7f082fef 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -36,7 +36,7 @@ func NewGetRecommandProductListLogic(ctx context.Context, svcCtx *svc.ServiceCon func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRecommandProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) { req.Num = 4 //写死4个 if req.Size > 0 { - req.Size = image.GetCurrentSize(req.Size) + req.Size = int32(image.GetCurrentSize(uint32(req.Size))) } productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Sn) if err != nil { @@ -113,14 +113,27 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec } } //获取用户信息(不用判断存在) - user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId) + /*user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId) if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user") + }*/ + //获取产品标签相关属性 + productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property") + } + mapTagProp := make(map[int64][]types.CoverDefaultItem) + for _, v := range productTagPropList { + mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{ + Tag: v.TemplateTag, + Cover: *v.Cover, + }) } list := make([]types.GetRecommandProductListRsp, 0, len(recommendProductList)) for _, v := range recommendProductList { - r := image.ThousandFaceImageFormatReq{ + /*r := image.ThousandFaceImageFormatReq{ Size: int(req.Size), IsThousandFace: 0, Cover: *v.Cover, @@ -133,7 +146,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec r.IsThousandFace = int(*user.IsThousandFace) } //千人前面处理 - image.ThousandFaceImageFormat(&r) + image.ThousandFaceImageFormat(&r)*/ isRecommend := int64(0) if _, ok := mapRecommend[v.Id]; ok { isRecommend = 1 @@ -142,18 +155,22 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec if minVal, ok := mapProductMinPrice[v.Id]; ok { minPrice = minVal } - list = append(list, types.GetRecommandProductListRsp{ + item := types.GetRecommandProductListRsp{ Id: v.Id, Sn: *v.Sn, Title: *v.Title, TitleCn: *v.TitleCn, - Cover: r.Cover, - CoverImg: r.CoverImg, - CoverDefault: r.CoverDefault, + Cover: *productInfo.Cover, + CoverImg: *productInfo.CoverImg, + CoverDefault: []types.CoverDefaultItem{}, Intro: *v.Intro, IsRecommend: isRecommend, MinPrice: minPrice, - }) + } + if _, ok := mapTagProp[productInfo.Id]; ok { + item.CoverDefault = mapTagProp[productInfo.Id] + } + list = append(list, item) } return resp.SetStatusWithMessage(basic.CodeOK, "success", list) } diff --git a/server/product/internal/logic/getsizebypidlogic.go b/server/product/internal/logic/getsizebypidlogic.go index 55a0471c..3f508762 100644 --- a/server/product/internal/logic/getsizebypidlogic.go +++ b/server/product/internal/logic/getsizebypidlogic.go @@ -48,7 +48,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") } //获取产品尺寸列表(需要正序排序) - sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "is_popular DESC,sort ASC") + sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "is_hot DESC,sort ASC") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list") @@ -118,7 +118,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a Cover: *sizeInfo.Cover, PartsCanDeleted: *sizeInfo.PartsCanDeleted > 0, ModelId: modelList[modelIndex].Id, - IsPopular: *sizeInfo.IsPopular > 0, + IsPopular: *sizeInfo.IsHot > 0, MinPrice: float64(minPrice) / 100, }) } diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 8c6f5a3c..8d51e6fa 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -90,7 +90,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方) productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方) mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map - mapProductTemplate = make(map[int64]struct{}) //产品模板map + mapProductTemplate = make(map[int64]int64) //产品模板map ) //携带产品 if req.WithProduct { @@ -138,7 +138,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR } for _, v := range productTagPropList { mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{ - Tag: v.Title, + Tag: v.TemplateTag, Cover: *v.Cover, }) } @@ -169,14 +169,15 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR mapProductMinPrice[v.ProductId] = int64(priceSlice[0]) } } - //获取模板(只是获取产品product_id) - productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "product_id") + //获取模板(只是获取产品product_id,id) + productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") } + //只存第一个 for _, v := range productTemplatesV2 { - mapProductTemplate[*v.ProductId] = struct{}{} + mapProductTemplate[*v.ProductId] = v.Id } //获取产品尺寸数量 productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1) @@ -209,9 +210,11 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR logx.Error(err) return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data") } + //组装等级从属关系 + rspTagList, TotalCategoryProduct := l.organizationLevelRelation(minLevel, mapTagLevel) return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ - TotalCategoryProduct: len(productList), - TagList: l.organizationLevelRelation(minLevel, mapTagLevel), //组装等级从属关系 + TotalCategoryProduct: TotalCategoryProduct, + TagList: rspTagList, }) } @@ -223,7 +226,7 @@ type dealWithTagMenuDataReq struct { MapTagProp map[int64][]types.CoverDefaultItem ProductTagPropList []gmodel.FsProductTagProp MapProductMinPrice map[int64]int64 - MapProductTemplate map[int64]struct{} + MapProductTemplate map[int64]int64 MapProductSizeCount map[int64]int64 MapTagLevel map[string]*types.TagItem MapProductHaveOptionFitting map[int64]struct{} @@ -274,7 +277,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) } // 组织等级从属关系 -func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) []types.TagItem { +func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) (rspTagList []types.TagItem, productCount int) { mapTop := make(map[string]struct{}) //设置归属关系 for prefix, tagItem := range mapTagLevel { @@ -312,22 +315,27 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL //最终值提取最高级别那一层出来 rspList := make([]types.TagItem, 0, len(mapTagLevel)) for prefix, _ := range mapTop { + //大类下没有任何产品则不显示 + if len(mapTagLevel[prefix].TagProductList) == 0 { + continue + } + productCount += len(mapTagLevel[prefix].TagProductList) rspList = append(rspList, *mapTagLevel[prefix]) } //排序 sort.SliceStable(rspList, func(i, j int) bool { return rspList[i].Sort < rspList[j].Sort }) - return rspList + return rspList, productCount } -// 获取对应tag的产品列表 +// 获取某个tag的直属产品 type getTagProductsReq struct { TagId int64 ProductList []gmodel.FsProduct MapTagProp map[int64][]types.CoverDefaultItem MapProductMinPrice map[int64]int64 - MapProductTemplate map[int64]struct{} + MapProductTemplate map[int64]int64 MapProductSizeCount map[int64]int64 MapProductHaveOptionFitting map[int64]struct{} Size uint32 @@ -343,7 +351,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL continue } minPrice, ok := req.MapProductMinPrice[productInfo.Id] - _, tmpOk := req.MapProductTemplate[productInfo.Id] + templateId, tmpOk := req.MapProductTemplate[productInfo.Id] //无最小价格则不显示 || 没有模板也不显示 if !ok || !tmpOk { continue @@ -363,15 +371,17 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL Title: *productInfo.Title, SizeNum: uint32(sizeNum), CoverDefault: []types.CoverDefaultItem{}, + DefaultTemplateId: templateId, MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, Recommended: *productInfo.IsRecommend > 0, + Cover: *productInfo.Cover, } if _, ok = req.MapTagProp[productInfo.Id]; ok { item.CoverDefault = req.MapTagProp[productInfo.Id] } //千人千面处理 - r := image.ThousandFaceImageFormatReq{ + /*r := image.ThousandFaceImageFormatReq{ Size: int(req.Size), IsThousandFace: 0, Cover: *productInfo.Cover, @@ -383,7 +393,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL r.IsThousandFace = int(*req.User.IsThousandFace) } image.ThousandFaceImageFormat(&r) - item.Cover = r.Cover + item.Cover = r.Cover*/ //加入分类产品切片 productListRsp = append(productListRsp, item) } diff --git a/server/product/internal/logic/gettemplatebypidlogic.go b/server/product/internal/logic/gettemplatebypidlogic.go index 18ccb887..a96152e2 100644 --- a/server/product/internal/logic/gettemplatebypidlogic.go +++ b/server/product/internal/logic/gettemplatebypidlogic.go @@ -7,9 +7,7 @@ import ( "fusenapi/constants" "fusenapi/utils/auth" "fusenapi/utils/basic" - "fusenapi/utils/image" "gorm.io/gorm" - "strconv" "strings" "context" @@ -39,13 +37,10 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, if req.Pid == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty") } - if req.Size > 0 { - req.Size = image.GetCurrentSize(req.Size) + if req.TemplateTag == "" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:template_tag") } - if req.ProductTemplateTagId <= 0 { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product_template_tag_id") - } - //获取产品信息(只是获取id) + //获取产品信息(只获取id) productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { @@ -54,27 +49,32 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") } - //获取尺寸ids(只获取id) - sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list") + //没有指定物料 + sizeIds := make([]int64, 0, 10) + if req.ProductSizeId <= 0 { + //获取产品所有物料 + sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "failed to get product size list") + } + if len(sizeList) == 0 { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product size list is empty") + } + for _, v := range sizeList { + sizeIds = append(sizeIds, v.Id) + } + } else { //指定物料 + sizeIds = append(sizeIds, req.ProductSizeId) } - if len(sizeList) == 0 { - return resp.SetStatusWithMessage(basic.CodeOK, "success:size list is empty") - } - sizeIds := make([]int64, 0, len(sizeList)) - for _, v := range sizeList { - sizeIds = append(sizeIds, v.Id) - } - //获取模型数据 - modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,size_id") + //根据尺寸id获取模型 + modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list") } if len(modelList) == 0 { - return resp.SetStatusWithMessage(basic.CodeOK, "success:model list is empty") + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "model list is empty") } modelIds := make([]int64, 0, len(modelList)) mapModel := make(map[int64]int) @@ -82,71 +82,65 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, modelIds = append(modelIds, v.Id) mapModel[v.Id] = k } - //获取模板数据 - productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, fmt.Sprintf("%d", req.ProductTemplateTagId), "sort DESC") + //查询模型ids下对应tag标签的模板 + templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, req.TemplateTag, "") if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product templates") + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list") } - if len(productTemplateList) == 0 { - return resp.SetStatusWithMessage(basic.CodeOK, "success:product template list is empty") - } - tagIds := make([]int64, 0, len(productTemplateList)) - for _, v := range productTemplateList { - if *v.Tag == "" { + rsp := make(map[string]interface{}) + for _, templateInfo := range templateList { + //没有设置模板据不要 + if templateInfo.TemplateInfo == nil || *templateInfo.TemplateInfo == "" { continue } - tag, err := strconv.ParseInt(*v.Tag, 10, 64) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "template tag is not a number:"+*v.Tag) - } - tagIds = append(tagIds, tag) - } - //获取模板标签列表 - templateTagList, err := l.svcCtx.AllModels.FsProductTemplateTags.GetListByIds(l.ctx, tagIds) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tag list") - } - mapTemplateTag := make(map[string]int) - for k, v := range templateTagList { - mapTemplateTag[fmt.Sprintf("%d", v.Id)] = k - } - mapRsp := make(map[string][]interface{}) - for _, v := range productTemplateList { - //过滤没有设置详细数据的模板 - if v.TemplateInfo == nil || *v.TemplateInfo == "" { - continue - } - var templateInfo map[string]interface{} - if err = json.Unmarshal([]byte(*v.TemplateInfo), &templateInfo); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse json:template info") - } - if templateInfo["cover"] != nil && templateInfo["cover"].(string) != "" { - cover := strings.Split(templateInfo["cover"].(string), ".") - if req.Size >= 200 && len(cover) >= 2 { - templateInfo["cover"] = fmt.Sprintf("%s_%d.%s", cover[0], req.Size, cover[1]) - } - } else { - templateInfo["cover"] = "" - } - templateInfo["tag_name"] = "" - if tagIndex, ok := mapTemplateTag[*v.Tag]; ok { - templateInfo["tag_name"] = *templateTagList[tagIndex].Title - } - templateInfo["title"] = *v.Title - modelIndex, ok := mapModel[*v.ModelId] + modelIndex, ok := mapModel[*templateInfo.ModelId] if !ok { continue } - key := fmt.Sprintf("_%d", *modelList[modelIndex].SizeId) - if _, ok = mapRsp[key]; ok { - mapRsp[key] = append(mapRsp[key], templateInfo) - } else { - mapRsp[key] = []interface{}{templateInfo} + //基础模板信息 + var info interface{} + if err = json.Unmarshal([]byte(*templateInfo.TemplateInfo), &info); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse json product template info(may be old data):%d", templateInfo.Id)) + } + //后台隐藏/显示信息(现在下面是写死了) + /*var switchInfo interface{} + if templateInfo.SwitchInfo != nil && *templateInfo.SwitchInfo != "" { + _ = json.Unmarshal([]byte(*templateInfo.SwitchInfo), &switchInfo) + }*/ + modelInfo := modelList[modelIndex] + mapKey := fmt.Sprintf("_%d", *modelInfo.SizeId) + rsp[mapKey] = map[string]interface{}{ + "id": templateInfo.Id, + "material": *templateInfo.MaterialImg, + //写死的数据 + "material_data": map[string]interface{}{ + "QRcode": map[string]interface{}{ + "if_show": true, + "text": "二维码", + "default_val": "默认二维码", + }, + "website": map[string]interface{}{ + "if_show": true, + "text": "网站", + "default_val": "默认网站", + }, + "slogan": map[string]interface{}{ + "if_show": true, + "text": "slogan", + "default_val": "默认slogan", + }, + "phone": map[string]interface{}{ + "if_show": true, + "text": "phone", + "default_val": "默认phone", + }, + "logo": map[string]interface{}{ + "material": "/image/logo/aHnT1_rzubdwax_scale.png", + }, + }, } } - return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp) + return resp.SetStatusWithMessage(basic.CodeOK, "success", rsp) } diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index b41c7dd0..9c70f5ca 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -7,7 +7,6 @@ import ( "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/format" - "fusenapi/utils/image" "gorm.io/gorm" "sort" "strings" @@ -36,28 +35,51 @@ func NewHomePageRecommendProductListLogic(ctx context.Context, svcCtx *svc.Servi func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *types.HomePageRecommendProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) { //查询用户信息(不用判断存在) - user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId) + _, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId) if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err") } var ( + merchantInfo *gmodel.FsMerchantCategory recommendProductList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方) productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表 - mapProductHaveOptionFitting = make(map[int64]struct{}) - productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方) - mapProductMinPrice = make(map[int64]int64) //产品最小价格map - productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方) - productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方) - mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map - mapProductTemplate = make(map[int64]struct{}) //产品模板map + mapProductHaveOptionFitting = make(map[int64]struct{}) //是否有配件map + productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方) + mapProductMinPrice = make(map[int64]int64) //产品最小价格map + productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方) + productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方) + mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map + mapProductTemplate = make(map[int64]struct{}) //产品模板map ) + //选了商家类型 + if req.MerchantType > 0 { + merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindOne(l.ctx, req.MerchantType) + } else { + //随机获取一个商家类型 + merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindRandOne(l.ctx) + } + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "none of merchant type found") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant type info") + } + if *merchantInfo.RecommendProduct == "" { + return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{}) + } + recommendProductIds, err := format.StrSlicToInt64Slice(strings.Split(*merchantInfo.RecommendProduct, ",")) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse recommend product") + } //获取列表推荐产品 - recommendProductList, _, err = l.svcCtx.AllModels.FsProductRecommend.GetRecommendProductList(gmodel.GetRecommendProductListReq{ - Ctx: l.ctx, - Page: 1, - Limit: 500, //设置最大500 - }) + recommendProductList, err = l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, recommendProductIds, "sort-desc") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list") + } if len(recommendProductList) == 0 { return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{}) } @@ -108,7 +130,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty } } //获取模板(只是获取产品product_id) - productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "product_id") + productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "", "product_id") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") @@ -125,6 +147,19 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty for _, v := range productSizeCountList { mapProductSizeCount[v.ProductId] = v.Num } + //获取产品标签相关属性 + productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property") + } + mapTagProp := make(map[int64][]types.CoverDefaultItem) + for _, v := range productTagPropList { + mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{ + Tag: v.TemplateTag, + Cover: *v.Cover, + }) + } //组装返回 listRsp := make([]types.HomePageRecommendProductListRsp, 0, len(recommendProductList)) for _, productInfo := range recommendProductList { @@ -147,12 +182,17 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty Id: productInfo.Id, Sn: *productInfo.Sn, Title: *productInfo.Title, + Cover: *productInfo.Cover, + CoverDefault: []types.CoverDefaultItem{}, SizeNum: uint32(sizeNum), MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, } + if _, ok = mapTagProp[productInfo.Id]; ok { + item.CoverDefault = mapTagProp[productInfo.Id] + } //千人千面处理 - r := image.ThousandFaceImageFormatReq{ + /*r := image.ThousandFaceImageFormatReq{ Size: int(req.Size), IsThousandFace: 0, Cover: *productInfo.Cover, @@ -166,7 +206,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty } image.ThousandFaceImageFormat(&r) item.Cover = r.Cover - item.CoverDefault = r.CoverDefault + item.CoverDefault = r.CoverDefault*/ //加入分类产品切片 listRsp = append(listRsp, item) } diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index cf94b40b..7d511c6e 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -228,22 +228,22 @@ type OtherProductListRsp struct { } type GetRecommandProductListReq struct { - Size uint32 `form:"size,optional"` + Size int32 `form:"size,optional"` Num int64 `form:"num,optional"` Sn string `form:"sn"` } type GetRecommandProductListRsp struct { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - TitleCn string `json:"title_cn"` - Cover string `json:"cover"` - CoverImg string `json:"cover_img"` - CoverDefault string `json:"cover_default"` - Intro string `json:"intro"` - IsRecommend int64 `json:"is_recommend"` - MinPrice int64 `json:"min_price"` + Id int64 `json:"id"` + Sn string `json:"sn"` + Title string `json:"title"` + TitleCn string `json:"title_cn"` + Cover string `json:"cover"` + CoverImg string `json:"cover_img"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + Intro string `json:"intro"` + IsRecommend int64 `json:"is_recommend"` + MinPrice int64 `json:"min_price"` } type GetTagProductListReq struct { @@ -275,6 +275,7 @@ type TagProduct struct { SizeNum uint32 `json:"size_num"` MinPrice int64 `json:"min_price"` CoverDefault []CoverDefaultItem `json:"cover_default"` + DefaultTemplateId int64 `json:"default_template_id"` HaveOptionalFitting bool `json:"have_optional_fitting"` Recommended bool `json:"recommended"` } @@ -340,9 +341,9 @@ type GetSizeByPidRsp struct { } type GetTemplateByPidReq struct { - Pid string `form:"pid"` - Size uint32 `form:"size"` - ProductTemplateTagId int64 `form:"product_template_tag_id"` + Pid string `form:"pid"` + ProductSizeId int64 `form:"product_size_id,optional"` + TemplateTag string `form:"template_tag"` } type GetFittingByPidReq struct { @@ -390,18 +391,19 @@ type GetLastProductDesignRsp struct { } type HomePageRecommendProductListReq struct { - Size uint32 `form:"size"` + Size uint32 `form:"size"` + MerchantType int64 `form:"merchant_type"` } type HomePageRecommendProductListRsp struct { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - Cover string `json:"cover"` - SizeNum uint32 `json:"size_num"` - MinPrice int64 `json:"min_price"` - CoverDefault string `json:"cover_default"` - HaveOptionalFitting bool `json:"have_optional_fitting"` + Id int64 `json:"id"` + Sn string `json:"sn"` + Title string `json:"title"` + Cover string `json:"cover"` + SizeNum uint32 `json:"size_num"` + MinPrice int64 `json:"min_price"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + HaveOptionalFitting bool `json:"have_optional_fitting"` } type Request struct { diff --git a/server/product/product.go b/server/product/product.go index 6b212bba..13fba403 100644 --- a/server/product/product.go +++ b/server/product/product.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/product/internal/config" "fusenapi/server/product/internal/handler" @@ -22,7 +21,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/render/consumer/assemble_render_data.go b/server/render/consumer/assemble_render_data.go deleted file mode 100644 index 5334db5b..00000000 --- a/server/render/consumer/assemble_render_data.go +++ /dev/null @@ -1,265 +0,0 @@ -package consumer - -import ( - "bytes" - "context" - "encoding/json" - "errors" - "fmt" - "fusenapi/constants" - "fusenapi/initalize" - "fusenapi/model/gmodel" - "fusenapi/server/render/internal/svc" - "fusenapi/utils/curl" - "fusenapi/utils/file" - "fusenapi/utils/hash" - "fusenapi/utils/websocket_data" - "github.com/zeromicro/go-zero/core/logx" - "gorm.io/gorm" - "io/ioutil" - "strconv" -) - -// 这里请求的py接口返回数据 -type pythonApiRsp struct { - Id string `json:"id"` //物料模板的id - LogoUrl string `json:"logo_url"` //logo地址 - result string `json:"result"` //图片base64 -} - -// 消费渲染需要组装的数据 -type MqConsumerRenderAssemble struct { -} - -func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { - logx.Info("收到需要组装的消息:", string(data)) - var parseInfo websocket_data.AssembleRenderData - if err := json.Unmarshal(data, &parseInfo); err != nil { - logx.Error("MqConsumerRenderAssemble数据格式错误:", err) - return nil //不返回错误就删除消息 - } - val := ctx.Value("svcctx") - if val == nil { - logx.Error("svcctx is nil") - return nil //不返回错误就删除消息 - } - svcCtx, ok := val.(*svc.ServiceContext) - if !ok { - logx.Error("svcctx is nil!!") - return nil //不返回错误就删除消息 - } - rabbitmq := initalize.RabbitMqHandle{} - //获取模板(产品第一个sku的模板) - productTemplate, err := svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId)) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - logx.Error("template info is not found") - return nil //不返回错误就删除消息 - } - logx.Error("failed to get template info:", err) - return nil //不返回错误就删除消息 - } - combineImage := "" //刀版图 - combineHash := hash.JsonHashKey(parseInfo) //区别于云渲染的taskid,这个用获取刀版图缓存 - //获取该hash值下有没有对应的资源 - resource, err := svcCtx.AllModels.FsResource.FindOneById(ctx, combineHash) - if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - logx.Error("failed to get resource :", err) - return nil //不返回错误就删除消息 - } - //如果不存在,则请求生成刀版图 - if errors.Is(err, gorm.ErrRecordNotFound) { - combineImage, err = getCombineImage(ctx, svcCtx, parseInfo, productTemplate, combineHash) - if err != nil { - return nil //不返回错误就删除消息 - } - } else { - combineImage = *resource.ResourceUrl - } - //获取渲染设置信息 - element, err := svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(ctx, *productTemplate.ModelId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - logx.Error("element info is not found,model_id = ?", *productTemplate.ModelId) - return nil //不返回错误就删除消息 - } - logx.Error("failed to get element list,", err) - return nil //不返回错误就删除消息 - } - //组装数据 - refletion := -1 - if element.Refletion != nil && *element.Refletion != "" { - refletion, err = strconv.Atoi(*element.Refletion) - } - //组装data数据 - var mode map[string]interface{} - if element.Mode != nil && *element.Mode != "" { - if err = json.Unmarshal([]byte(*element.Mode), &mode); err != nil { - logx.Error("faile to parse element mode json:", err) - return nil //不返回错误就删除消息 - } - } - tempData := make([]map[string]interface{}, 0, 3) - if element.Base != nil && *element.Base != "" { - tempData = append(tempData, map[string]interface{}{ - "name": "model", - "data": "0," + combineImage + "," + *element.Base, - "type": "other", - "layer": "0", - "is_update": 1, - "mode": mode["model"], - }) - } - if element.Shadow != nil && *element.Shadow != "" { - tempData = append(tempData, map[string]interface{}{ - "name": "shadow", - "data": *element.Shadow, - "type": "other", - "layer": "0", - "is_update": 0, - "mode": mode["shadow"], - }) - } - if element.ModelP != nil && *element.ModelP != "" { - tempData = append(tempData, map[string]interface{}{ - "name": "model_P", - "data": "0," + *element.ModelP, - "type": "other", - "layer": "0", - "is_update": 0, - "mode": mode["model_P"], - }) - } - result := []interface{}{ - map[string]interface{}{ - "light": *element.Light, - "refletion": refletion, - "scale": *element.Scale, - "sku_id": parseInfo.RenderData.ProductId, - "tid": *element.Title, - "rotation": *element.Rotation, - "filePath": "", //todo 文件路径,针对千人千面 - "data": tempData, - }, - } - sendData := map[string]interface{}{ - "id": parseInfo.TaskId, - "order_id": 0, - "user_id": parseInfo.RenderData.UserId, - "guest_id": parseInfo.RenderData.GuestId, - "sku_ids": []int64{parseInfo.RenderData.ProductId}, - "tids": []string{*element.Title}, - "data": result, - "is_thousand_face": 0, - "folder": "", //todo 千人千面需要使用 - } - b, _ := json.Marshal(sendData) - if err = rabbitmq.SendMsg(constants.RABBIT_MQ_TO_UNITY, b); err != nil { - logx.Error("发送渲染组装数据到rabbitmq失败:", err) - return nil //不返回错误就删除消息 - } - logx.Info("发送渲染组装数据到unity成功") - return nil -} - -// 获取刀版图 -func getCombineImage(ctx context.Context, svcCtx *svc.ServiceContext, parseInfo websocket_data.AssembleRenderData, productTemplate *gmodel.FsProductTemplateV2, combineHash string) (image string, err error) { - if productTemplate.TemplateInfo == nil || *productTemplate.TemplateInfo == "" { - logx.Error("product template info`template_info is empty") - return "", errors.New("product template info`template_info is empty") - } - //反序列化替换其中一些参数 - var combineInfo map[string]interface{} - if err = json.Unmarshal([]byte(*productTemplate.TemplateInfo), &combineInfo); err != nil { - logx.Error("failed to parse json:template_info:", err) - return "", err - } - //需要替换的参数 - replaceData := map[string]interface{}{ - "logo_url": parseInfo.RenderData.Logo, - "website": "", - "slogan": "", - "address": "", - "phone": "", - "colors": []string{}, - "template_tagid": []string{"b1a"}, - "is_crop": false, - "shape": "", - "ratio": 0, - "line": "", - "other": "", - "other1": "", - } - //获取用户素材信息 - if parseInfo.RenderData.UserMaterialId > 0 { - userMaterial, err := svcCtx.AllModels.FsUserMaterial.FindOneById(ctx, parseInfo.RenderData.UserMaterialId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - logx.Error("user material not exists:", parseInfo.RenderData.UserMaterialId) - return "", errors.New("user material not exists") - } - logx.Error("err failed to get user material info") - } - if userMaterial.Metadata != nil && *userMaterial.Metadata != "" { - //解析元数据 - var materialMetaData map[string]interface{} - if err = json.Unmarshal([]byte(*userMaterial.Metadata), &materialMetaData); err != nil { - logx.Error("failed to parse user material`matadata: ", err) - return "", err - } - //赋值 - replaceData["colors"] = materialMetaData["colors"] - replaceData["logo_url"] = materialMetaData["logo_url"] - replaceData["shape"] = materialMetaData["shape"] - replaceData["is_crop"] = materialMetaData["is_crop"] - replaceData["ratio"] = materialMetaData["ratio"] - replaceData["line"] = materialMetaData["line"] - replaceData["other"] = materialMetaData["other"] - replaceData["other1"] = materialMetaData["other1"] - } - } - combineInfo["param_data"] = replaceData - postData, _ := json.Marshal(combineInfo) - //请求合成图片 - url := svcCtx.Config.PythonApi.CombineImageUrl - header := make(map[string]string) - header["content-type"] = "application/json" - /*f, _ := os.Create("a.txt") - defer f.Close() - f.Write(postData)*/ - httpRsp, err := curl.ApiCall(url, "POST", header, bytes.NewReader(postData), 20) - if err != nil { - logx.Error("failed to combine logo:", err) - return "", err - } - defer httpRsp.Body.Close() - bytes, err := ioutil.ReadAll(httpRsp.Body) - if err != nil { - logx.Error("failed to read python api rsp body:", err) - return "", err - } - var pythonApiInfo pythonApiRsp - if err = json.Unmarshal(bytes, &pythonApiInfo); err != nil { - logx.Error("failed to parse python api rsp:", err) - return "", err - } - //上传刀版图 - var upload = file.Upload{ - Ctx: ctx, - MysqlConn: svcCtx.MysqlConn, - AwsSession: svcCtx.AwsSession, - } - uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ - FileHash: combineHash, - FileData: pythonApiInfo.result, - UploadBucket: 1, - ApiType: 2, - UserId: parseInfo.RenderData.UserId, - GuestId: parseInfo.RenderData.GuestId, - }) - if err != nil { - logx.Error("上传刀版图到s3失败:", err) - return "", err - } - return uploadRes.ResourceUrl, nil -} diff --git a/server/render/etc/render.yaml b/server/render/etc/render.yaml index 7081d46b..ccacf731 100644 --- a/server/render/etc/render.yaml +++ b/server/render/etc/render.yaml @@ -1,6 +1,7 @@ Name: render Host: 0.0.0.0 Port: 9919 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 @@ -13,5 +14,8 @@ AWS: AccessKeyID: AKIAZB2JKUXDPNRP4YT2 Secret: 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 Token: -PythonApi: #python接口 - CombineImageUrl: http://192.168.1.7:45678/LogoCombine #合成刀版图接口 \ No newline at end of file +BLMService: + Url: "http://18.119.109.254:8999" + LogoCombine: + #Url: "http://192.168.1.7:8999/LogoCombine" + Url: "http://18.119.109.254:8999/LogoCombine" \ No newline at end of file diff --git a/server/render/internal/config/config.go b/server/render/internal/config/config.go index 3cc5089e..a180c7da 100644 --- a/server/render/internal/config/config.go +++ b/server/render/internal/config/config.go @@ -19,7 +19,10 @@ type Config struct { } } } - PythonApi struct { - CombineImageUrl string //合图url + BLMService struct { + Url string + LogoCombine struct { + Url string + } } } diff --git a/server/render/internal/handler/routes.go b/server/render/internal/handler/routes.go index 26ad8b15..03e1cab2 100644 --- a/server/render/internal/handler/routes.go +++ b/server/render/internal/handler/routes.go @@ -12,11 +12,6 @@ import ( func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ - { - Method: http.MethodPost, - Path: "/api/render/render_notify", - Handler: RenderNotifyHandler(serverCtx), - }, { Method: http.MethodPost, Path: "/api/render/get_face_slice", diff --git a/server/render/internal/logic/rendernotifylogic.go b/server/render/internal/logic/rendernotifylogic.go deleted file mode 100644 index 6a11f4bf..00000000 --- a/server/render/internal/logic/rendernotifylogic.go +++ /dev/null @@ -1,95 +0,0 @@ -package logic - -import ( - "context" - "encoding/json" - "fusenapi/constants" - "fusenapi/utils/auth" - "fusenapi/utils/basic" - "fusenapi/utils/file" - "fusenapi/utils/websocket_data" - - "fusenapi/server/render/internal/svc" - "fusenapi/server/render/internal/types" - - "github.com/zeromicro/go-zero/core/logx" -) - -type RenderNotifyLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewRenderNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RenderNotifyLogic { - return &RenderNotifyLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -// 处理进入前逻辑w,r -// func (l *RenderNotifyLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { -// } - -// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 -// func (l *RenderNotifyLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { -// // httpx.OkJsonCtx(r.Context(), w, resp) -// } - -func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) { - /*if time.Now().Unix()-120 > req.Time || req.Time > time.Now().Unix() { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param time") - }*/ - if req.Info.TaskId == "" { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param task_id") - } - if req.Info.Image == "" { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image") - } - if req.Info.UserId == 0 && req.Info.GuestId == 0 { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid user_id or guest_id") - } - /* if req.Sign == "" { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param sign") - }*/ - //验证签名 sha256 - /*notifyByte, _ := json.Marshal(req.Info) - h := sha256.New() - h.Write([]byte(fmt.Sprintf(constants.RENDER_NOTIFY_SIGN_KEY, string(notifyByte), req.Time))) - signHex := h.Sum(nil) - sign := hex.EncodeToString(signHex) - if req.Sign != sign { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid sign") - }*/ - // 上传文件 - var upload = file.Upload{ - Ctx: l.ctx, - MysqlConn: l.svcCtx.MysqlConn, - AwsSession: l.svcCtx.AwsSession, - } - uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ - FileHash: req.Info.TaskId, - FileData: req.Info.Image, - UploadBucket: 1, - ApiType: 2, - UserId: req.Info.UserId, - GuestId: req.Info.GuestId, - }) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image") - } - //发送消息到对应的rabbitmq - data := websocket_data.RenderImageNotify{ - TaskId: req.Info.TaskId, - Image: uploadRes.ResourceUrl, - } - d, _ := json.Marshal(data) - if err = l.svcCtx.RabbitMq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d); err != nil { - logx.Error(err) - return resp.SetStatus(basic.CodeServiceErr, "failed to send data") - } - return resp.SetStatus(basic.CodeOK) -} diff --git a/server/render/internal/svc/servicecontext.go b/server/render/internal/svc/servicecontext.go index 08a78653..a0a334b7 100644 --- a/server/render/internal/svc/servicecontext.go +++ b/server/render/internal/svc/servicecontext.go @@ -17,11 +17,12 @@ import ( ) type ServiceContext struct { - Config config.Config - MysqlConn *gorm.DB - AllModels *gmodel.AllModelsGen - RabbitMq *initalize.RabbitMqHandle - AwsSession *session.Session + Config config.Config + MysqlConn *gorm.DB + AllModels *gmodel.AllModelsGen + RabbitMq *initalize.RabbitMqHandle + AwsSession *session.Session + Repositories *initalize.Repositories } func NewServiceContext(c config.Config) *ServiceContext { @@ -34,6 +35,11 @@ func NewServiceContext(c config.Config) *ServiceContext { AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), AwsSession: session.Must(session.NewSession(&config)), + Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{ + GormDB: initalize.InitMysql(c.SourceMysql), + BLMServiceUrl: &c.BLMService.Url, + AwsSession: session.Must(session.NewSession(&config)), + }), } } diff --git a/server/render/internal/types/types.go b/server/render/internal/types/types.go index 959af2ce..70ec268a 100644 --- a/server/render/internal/types/types.go +++ b/server/render/internal/types/types.go @@ -5,25 +5,6 @@ import ( "fusenapi/utils/basic" ) -type RequestToUnity struct { -} - -type RequestReadImages struct { -} - -type RenderNotifyReq struct { - Sign string `json:"sign"` - Time int64 `json:"time"` - Info NotifyInfo `json:"info"` -} - -type NotifyInfo struct { - TaskId string `json:"task_id"` //任务id - UserId int64 `json:"user_id"` - GuestId int64 `json:"guest_id"` - Image string `json:"image"` -} - type Request struct { } diff --git a/server/render/render.go b/server/render/render.go index f3cdafef..9790b18a 100644 --- a/server/render/render.go +++ b/server/render/render.go @@ -1,13 +1,9 @@ package main import ( - "context" "flag" "fmt" - "fusenapi/constants" - "fusenapi/server/render/consumer" "net/http" - "time" "fusenapi/utils/auth" @@ -26,18 +22,11 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() ctx := svc.NewServiceContext(c) - //消费渲染前组装数据队列 - ctx1 := context.Background() - ctx2, cancel := context.WithCancel(ctx1) - ctx2 = context.WithValue(ctx2, "svcctx", ctx) - defer cancel() - go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, &consumer.MqConsumerRenderAssemble{}) handler.RegisterHandlers(server, ctx) fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) server.Start() diff --git a/server/resource/etc/resource.yaml b/server/resource/etc/resource.yaml index b57c5f1c..099a6460 100644 --- a/server/resource/etc/resource.yaml +++ b/server/resource/etc/resource.yaml @@ -1,7 +1,7 @@ Name: resource Host: 0.0.0.0 Port: 9916 -Timeout: 15000 #服务超时时间(毫秒) +Timeout: 150000 #服务超时时间(毫秒) SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 @@ -15,5 +15,8 @@ AWS: Secret: sjCEv0JxATnPCxno2KNLm0X8oDc7srUR+4vkYhvm Token: BLMService: + # Url: "http://18.119.109.254:8999" + Url: "http://192.168.1.7:8999" LogoCombine: - Url: "http://192.168.1.7:45678/LogoCombine" \ No newline at end of file + #Url: "http://192.168.1.7:8999/LogoCombine" + Url: "http://18.119.109.254:8999/LogoCombine" \ No newline at end of file diff --git a/server/resource/internal/config/config.go b/server/resource/internal/config/config.go index 51aad1c7..e8569f26 100644 --- a/server/resource/internal/config/config.go +++ b/server/resource/internal/config/config.go @@ -21,6 +21,7 @@ type Config struct { } } BLMService struct { + Url string LogoCombine struct { Url string } diff --git a/server/resource/internal/handler/logoremovebghandler.go b/server/resource/internal/handler/logoremovebghandler.go new file mode 100644 index 00000000..b68ab38b --- /dev/null +++ b/server/resource/internal/handler/logoremovebghandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/resource/internal/logic" + "fusenapi/server/resource/internal/svc" + "fusenapi/server/resource/internal/types" +) + +func LogoRemovebgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.LogoRemovebgReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewLogoRemovebgLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.LogoRemovebg(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/resource/internal/handler/routes.go b/server/resource/internal/handler/routes.go index 581fdcb1..50884ef8 100644 --- a/server/resource/internal/handler/routes.go +++ b/server/resource/internal/handler/routes.go @@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/resource/logo-combine", Handler: LogoCombineHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/resource/logo-removebg", + Handler: LogoRemovebgHandler(serverCtx), + }, { Method: http.MethodGet, Path: "/api/resource/info", diff --git a/server/resource/internal/logic/logocombinelogic.go b/server/resource/internal/logic/logocombinelogic.go index 71fca87d..53b02768 100644 --- a/server/resource/internal/logic/logocombinelogic.go +++ b/server/resource/internal/logic/logocombinelogic.go @@ -1,15 +1,9 @@ package logic import ( - "encoding/json" - "fusenapi/model/gmodel" + "fusenapi/service/repositories" "fusenapi/utils/auth" "fusenapi/utils/basic" - "fusenapi/utils/file" - "fusenapi/utils/hash" - "io" - "net/http" - "strings" "context" @@ -62,118 +56,27 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth // 否则,使用用户ID和用户键名格式 userId = userinfo.UserId } + res, err := l.svcCtx.Repositories.ImageHandle.LogoCombine(l.ctx, &repositories.LogoCombineReq{ + UserId: userId, + GuestId: guestId, + TemplateId: req.TemplateId, + TemplateTag: req.TemplateTag, + Website: req.Website, + Slogan: req.Slogan, + Phone: req.Phone, + Address: req.Address, - // 根据hash 查询数据资源 - var resourceId string = hash.JsonHashKey(req.ResourceKey) - resourceModel := gmodel.NewFsResourceModel(l.svcCtx.MysqlConn) - resourceInfo, err := resourceModel.FindOneById(l.ctx, resourceId) - if err == nil && resourceInfo.ResourceId != "" { - return resp.SetStatus(basic.CodeOK, map[string]interface{}{ - "resource_id": resourceId, - "resource_url": resourceInfo.ResourceUrl, - "resource_metadata": resourceInfo.Metadata, - }) - } else { - if err != nil { - logx.Error(err) - return resp.SetStatus(basic.CodeDbSqlErr, "LogoCombine error") - } - } - - // 没有查到,先根据模版id 查询模版数据 请求算法数据 - productTemplateV2Model := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) - productTemplateV2Info, err := productTemplateV2Model.FindOne(l.ctx, req.TemplateId) - - if err != nil { - logx.Error(err) - return resp.SetStatus(basic.CodeDbSqlErr, "LogoCombine error") - } - var groupOptions map[string]interface{} - if productTemplateV2Info.GroupOptions != nil { - err = json.Unmarshal([]byte(*productTemplateV2Info.GroupOptions), &groupOptions) - - if err != nil { - logx.Error(err) - return resp.SetStatus(basic.CodeDbSqlErr, "LogoCombine error Unmarshal groupOptions") - } - } - - var materialList []interface{} - if productTemplateV2Info.TemplateInfo != nil { - var templateInfo map[string]interface{} - err = json.Unmarshal([]byte(*productTemplateV2Info.TemplateInfo), &templateInfo) - - if err != nil { - logx.Error(err) - return resp.SetStatus(basic.CodeDbSqlErr, "LogoCombine error Unmarshal templateInfo") - } - materialList = templateInfo["materialList"].([]interface{}) - } - - var moduleDataMap = make(map[string]interface{}, 4) - moduleDataMap["id"] = productTemplateV2Info.Id - moduleDataMap["material"] = productTemplateV2Info.MaterialImg - moduleDataMap["groupOptions"] = groupOptions - moduleDataMap["materialList"] = materialList - - var combineParam map[string]interface{} - json.Unmarshal([]byte(req.CombineParam), &combineParam) - var postMap = make(map[string]interface{}, 2) - postMap["module_data"] = moduleDataMap - postMap["param_data"] = combineParam - postMapB, _ := json.Marshal(postMap) - - result, err := http.Post(l.svcCtx.Config.BLMService.LogoCombine.Url, "application/json", strings.NewReader(string(postMapB))) - if err != nil { - logx.Error(err) - return resp.SetStatus(basic.CodeFileLogoCombineErr, "service post fail") - } - defer result.Body.Close() - b, err := io.ReadAll(result.Body) - if err != nil { - logx.Error(err) - return resp.SetStatus(basic.CodeFileLogoCombineErr, "service read fail") - } - - if string(b) == "Internal Server Error" { - return resp.SetStatus(basic.CodeFileLogoCombineErr, "service read fail") - } - - var resultData map[string]interface{} - err = json.Unmarshal(b, &resultData) - if err != nil { - logx.Error(err) - return resp.SetStatus(basic.CodeFileLogoCombineErr, "service read fail") - } - // { - // id: "", - // logo_url:"https://s3.amazon.com/xxxx", - // result: "$saa541afaldjaldjasldjsadjsapsaasda" - // } - var fileBase = resultData["result"] - - // 上传文件 - var upload = file.Upload{ - Ctx: l.ctx, - MysqlConn: l.svcCtx.MysqlConn, - AwsSession: l.svcCtx.AwsSession, - } - uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ - FileHash: resourceId, - FileData: fileBase.(string), - UploadBucket: 1, - ApiType: 2, - UserId: userId, - GuestId: guestId, + Qrcode: req.Qrcode, }) + if err != nil { - logx.Error(err) - return resp.SetStatus(basic.CodeFileLogoCombineErr, "LogoCombine error upload file failed") + return resp.SetStatus(basic.CodeServiceErr) } + // 返回成功的响应和上传URL return resp.SetStatus(basic.CodeOK, map[string]interface{}{ - "resource_id": resourceId, - "resource_url": uploadRes.ResourceUrl, + "resource_id": res.ResourceId, + "resource_url": res.ResourceUrl, "resource_metadata": "", }) } diff --git a/server/resource/internal/logic/logoremovebglogic.go b/server/resource/internal/logic/logoremovebglogic.go new file mode 100644 index 00000000..4091c7a0 --- /dev/null +++ b/server/resource/internal/logic/logoremovebglogic.go @@ -0,0 +1,61 @@ +package logic + +import ( + "fusenapi/service/repositories" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/resource/internal/svc" + "fusenapi/server/resource/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type LogoRemovebgLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewLogoRemovebgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoRemovebgLogic { + return &LogoRemovebgLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *LogoRemovebgLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *LogoRemovebgLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } + +func (l *LogoRemovebgLogic) LogoRemovebg(req *types.LogoRemovebgReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + res, err := l.svcCtx.Repositories.ImageHandle.LogoStandard(l.ctx, &repositories.LogoStandardReq{ + IsRemoveBg: req.IsRemoveBg, + LogoFile: req.LogoFile, + Width: req.Width, + Height: req.Height, + Proportion: req.Proportion, + }) + + if err != nil { + return resp.SetStatus(basic.CodeServiceErr) + } + + // 返回成功的响应和上传URL + return resp.SetStatus(basic.CodeOK, map[string]interface{}{ + "resource_id": res.ResourceId, + "resource_url": res.ResourceUrl, + "ismax_proportion": res.IsmaxProportion, + "img_color": res.ImgColor, + }) +} diff --git a/server/resource/internal/svc/servicecontext.go b/server/resource/internal/svc/servicecontext.go index a81a0767..e006fbce 100644 --- a/server/resource/internal/svc/servicecontext.go +++ b/server/resource/internal/svc/servicecontext.go @@ -19,10 +19,11 @@ import ( type ServiceContext struct { Config config.Config - MysqlConn *gorm.DB - AllModels *gmodel.AllModelsGen - RabbitMq *initalize.RabbitMqHandle - AwsSession *session.Session + MysqlConn *gorm.DB + AllModels *gmodel.AllModelsGen + RabbitMq *initalize.RabbitMqHandle + AwsSession *session.Session + Repositories *initalize.Repositories } func NewServiceContext(c config.Config) *ServiceContext { @@ -35,6 +36,11 @@ func NewServiceContext(c config.Config) *ServiceContext { AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), AwsSession: session.Must(session.NewSession(&config)), + Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{ + GormDB: initalize.InitMysql(c.SourceMysql), + BLMServiceUrl: &c.BLMService.Url, + AwsSession: session.Must(session.NewSession(&config)), + }), } } diff --git a/server/resource/internal/types/types.go b/server/resource/internal/types/types.go index 47e38155..ccf8d112 100644 --- a/server/resource/internal/types/types.go +++ b/server/resource/internal/types/types.go @@ -5,15 +5,27 @@ import ( "fusenapi/utils/basic" ) +type LogoRemovebgReq struct { + IsRemoveBg string `form:"is_remove_bg"` + LogoFile string `form:"logo_file"` + Width string `form:"width"` + Height string `form:"height"` + Proportion int64 `form:"proportion"` +} + type ResourceInfoReq struct { ResourceId string `form:"resource_id,optional"` // 资源ID ResourceKey string `form:"resource_key,optional"` // 资源唯一标识 } type LogoCombineReq struct { - ResourceKey string `form:"resource_key"` // 资源唯一标识 - CombineParam string `form:"combine_param"` // 合图参数 - TemplateId int64 `form:"template_id"` // 合图参数 + TemplateId int64 `form:"template_id"` // 合图参数 + TemplateTag string `form:"template_tag"` // 合图参数 + Website string `form:"website,optional"` // 合图参数 + Slogan string `form:"slogan,optional"` // 合图参数 + Address string `form:"address,optional"` // 合图参数 + Phone string `form:"phone,optional"` // 合图参数 + Qrcode string `form:"qrcode,optional"` // 合图参数 } type Request struct { diff --git a/server/resource/resource.go b/server/resource/resource.go index 6a09918b..29887332 100644 --- a/server/resource/resource.go +++ b/server/resource/resource.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/utils/auth" @@ -23,7 +22,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() diff --git a/server/resource/resource_test.go b/server/resource/resource_test.go index d035c13a..80820ef2 100644 --- a/server/resource/resource_test.go +++ b/server/resource/resource_test.go @@ -4,9 +4,6 @@ import ( "testing" ) -// var configFile = flag.String("f", "etc/home-user-auth.yaml", "the config file") - func TestMain(t *testing.T) { - // log.Println(model.RawFieldNames[FsCanteenType]()) main() } diff --git a/server/shopping-cart-confirmation/etc/shopping-cart-confirmation.yaml b/server/shopping-cart-confirmation/etc/shopping-cart-confirmation.yaml index fa40bb45..58a74824 100644 --- a/server/shopping-cart-confirmation/etc/shopping-cart-confirmation.yaml +++ b/server/shopping-cart-confirmation/etc/shopping-cart-confirmation.yaml @@ -1,6 +1,7 @@ Name: shopping-cart-confirmation Host: 0.0.0.0 Port: 9911 +Timeout: 15000 #服务超时时间 SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest Auth: AccessSecret: fusen2023 diff --git a/server/shopping-cart-confirmation/shopping-cart-confirmation.go b/server/shopping-cart-confirmation/shopping-cart-confirmation.go index 55f29602..c5f6711c 100644 --- a/server/shopping-cart-confirmation/shopping-cart-confirmation.go +++ b/server/shopping-cart-confirmation/shopping-cart-confirmation.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/shopping-cart-confirmation/internal/config" "fusenapi/server/shopping-cart-confirmation/internal/handler" @@ -22,7 +21,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/upload/etc/upload.yaml b/server/upload/etc/upload.yaml index 5a8a5cb6..a2a2cb4b 100644 --- a/server/upload/etc/upload.yaml +++ b/server/upload/etc/upload.yaml @@ -1,6 +1,7 @@ Name: upload Host: 0.0.0.0 Port: 9912 +Timeout: 150000 #服务超时时间 SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest" Env: "test" Auth: @@ -15,4 +16,5 @@ AWS: Token: BLMService: ImageProcess: - Url: "http://192.168.1.7:45678/FeatureExtraction" + # Url: "http://192.168.1.7:8999/FeatureExtraction" + Url: "http://18.119.109.254:8999/FeatureExtraction" diff --git a/server/upload/internal/handler/routes.go b/server/upload/internal/handler/routes.go index e33dc5a8..03536a1d 100644 --- a/server/upload/internal/handler/routes.go +++ b/server/upload/internal/handler/routes.go @@ -57,6 +57,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/upload/upload-file-base", Handler: UploadFileBaseHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/upload/up-standard-logo", + Handler: UploadLogoStandardHandler(serverCtx), + }, }, ) } diff --git a/server/upload/internal/handler/uploadlogohandler.go b/server/upload/internal/handler/uploadlogohandler.go index 52c58424..6fee9634 100644 --- a/server/upload/internal/handler/uploadlogohandler.go +++ b/server/upload/internal/handler/uploadlogohandler.go @@ -21,7 +21,7 @@ func UploadLogoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { } // 创建一个业务逻辑层实例 - l := logic.NewUploadLogoLogic(r.Context(), svcCtx) + l := logic.NewUploadLogoLogic(r, svcCtx) rl := reflect.ValueOf(l) basic.BeforeLogic(w, r, rl) diff --git a/server/upload/internal/handler/uploadlogostandardhandler.go b/server/upload/internal/handler/uploadlogostandardhandler.go new file mode 100644 index 00000000..813f1978 --- /dev/null +++ b/server/upload/internal/handler/uploadlogostandardhandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/upload/internal/logic" + "fusenapi/server/upload/internal/svc" + "fusenapi/server/upload/internal/types" +) + +func UploadLogoStandardHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.UploadLogoStandardReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewUploadLogoStandardLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.UploadLogoStandard(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/upload/internal/logic/uploadcallbacklogic.go b/server/upload/internal/logic/uploadcallbacklogic.go index 4c67de50..796016ba 100644 --- a/server/upload/internal/logic/uploadcallbacklogic.go +++ b/server/upload/internal/logic/uploadcallbacklogic.go @@ -66,8 +66,10 @@ func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, useri ctx := l.ctx err := l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error { - resourceModelTS := gmodel.NewFsResourceModel(l.svcCtx.MysqlConn) - resourceInfo, err := resourceModelTS.FindOneById(ctx, req.ResourceId) + resourceModelTS := gmodel.NewFsResourceModel(connGorm) + transBuilder := resourceModelTS.BuilderTrans(nil) + transBuilderFind := transBuilder.Where("resource_id =?", req.ResourceId) + resourceInfo, err := resourceModelTS.FindOneByQuery(ctx, transBuilderFind, nil) if err != nil { return err } @@ -81,12 +83,14 @@ func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, useri fsResource.ResourceUrl = &req.ResourceUrl fsResource.Metadata = &req.Metadata fsResource.ApiType = &req.ApiType + fsResource.Source = &req.Source fsResource.BucketName = bucketName fsResource.Version = &version + if resourceInfo.ResourceId == "" { - _, err = resourceModelTS.Create(ctx, fsResource) + _, err = resourceModelTS.BuilderCreate(ctx, transBuilder, fsResource) } else { - _, err = resourceModelTS.Update(ctx, fsResource) + _, err = resourceModelTS.BuilderUpdate(ctx, transBuilder, fsResource) } return err }) diff --git a/server/upload/internal/logic/uploadfilebackendlogic.go b/server/upload/internal/logic/uploadfilebackendlogic.go index 32a577c8..8e817639 100644 --- a/server/upload/internal/logic/uploadfilebackendlogic.go +++ b/server/upload/internal/logic/uploadfilebackendlogic.go @@ -1,6 +1,7 @@ package logic import ( + "fmt" "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/file" @@ -44,28 +45,25 @@ func NewUploadFileBackendLogic(r *http.Request, svcCtx *svc.ServiceContext) *Upl func (l *UploadFileBackendLogic) UploadFileBackend(req *types.UploadFileBackendReq, userinfo *auth.UserInfo) (resp *basic.Response) { // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // userinfo 传入值时, 一定不为null - if userinfo.IsOnlooker() { - // 如果是,返回未授权的错误码 - return resp.SetStatus(basic.CodeUnAuth) - } - - // 定义用户ID和S3键名格式 - var userId int64 - var guestId int64 + var userId int64 = 0 + var guestId int64 = 0 // 检查用户是否是游客 - if userinfo.IsGuest() { - // 如果是,使用游客ID和游客键名格式 - guestId = userinfo.GuestId - } else { - // 否则,使用用户ID和用户键名格式 - userId = userinfo.UserId + if userinfo != nil { + if userinfo.IsGuest() { + // 如果是,使用游客ID和游客键名格式 + guestId = userinfo.GuestId + } else { + // 否则,使用用户ID和用户键名格式 + userId = userinfo.UserId + } } //设置内存大小 l.r.ParseMultipartForm(32 << 20) fileObject, _, err := l.r.FormFile("file") + fmt.Printf("%#v", fileObject) if err != nil { logx.Error(err) return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,no files") @@ -92,6 +90,7 @@ func (l *UploadFileBackendLogic) UploadFileBackend(req *types.UploadFileBackendR ApiType: req.ApiType, UserId: userId, GuestId: guestId, + Source: req.Source, }) if err != nil { diff --git a/server/upload/internal/logic/uploadfilebaselogic.go b/server/upload/internal/logic/uploadfilebaselogic.go index 0e079884..55326ac1 100644 --- a/server/upload/internal/logic/uploadfilebaselogic.go +++ b/server/upload/internal/logic/uploadfilebaselogic.go @@ -77,6 +77,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri ApiType: req.ApiType, UserId: userId, GuestId: guestId, + Source: req.Source, }) if err != nil { diff --git a/server/upload/internal/logic/uploadfilesbackendlogic.go b/server/upload/internal/logic/uploadfilesbackendlogic.go index 6995b0c7..cedbb8de 100644 --- a/server/upload/internal/logic/uploadfilesbackendlogic.go +++ b/server/upload/internal/logic/uploadfilesbackendlogic.go @@ -123,6 +123,7 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq, ApiType: req.ApiType, Bucket: bucketName, HashKey: hashKey, + Source: req.Source, } } }, func(item interface{}, writer mr.Writer[interface{}], cancel func(error)) { @@ -148,6 +149,7 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq, ApiType: req.ApiType, UserId: userId, GuestId: guestId, + Source: uploadDataInfo.Source, }) if err == nil { uploadUrl.Status = 1 @@ -201,6 +203,7 @@ type UploadData struct { Bucket *string `json:"bucket"` HashKey string `json:"hash_key"` FileData []byte `fsfile:"data"` + Source string `json:"source"` } type UploadUrl struct { diff --git a/server/upload/internal/logic/uploadlogologic.go b/server/upload/internal/logic/uploadlogologic.go index 7bbc20e2..bd495c61 100644 --- a/server/upload/internal/logic/uploadlogologic.go +++ b/server/upload/internal/logic/uploadlogologic.go @@ -2,11 +2,15 @@ package logic import ( "encoding/json" + "errors" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/curl" + "fusenapi/utils/file" + "fusenapi/utils/hash" "io" + "net/http" "strings" "time" @@ -22,13 +26,15 @@ type UploadLogoLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + r *http.Request } -func NewUploadLogoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogoLogic { +func NewUploadLogoLogic(r *http.Request, svcCtx *svc.ServiceContext) *UploadLogoLogic { return &UploadLogoLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, + Logger: logx.WithContext(r.Context()), + ctx: r.Context(), svcCtx: svcCtx, + r: r, } } @@ -61,6 +67,63 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us userId = userinfo.UserId } + //设置内存大小 + l.r.ParseMultipartForm(32 << 20) + + fileObject, fileHeader, err := l.r.FormFile("file") + if err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,no files") + } + defer fileObject.Close() + + // 获取文件的MIME类型 + fileType := fileHeader.Header.Get("Content-Type") + var imageTypes = make(map[string]struct{}, 7) + imageTypes["image/jpg"] = struct{}{} + imageTypes["image/jpeg"] = struct{}{} + imageTypes["image/png"] = struct{}{} + imageTypes["image/gif"] = struct{}{} + imageTypes["image/bmp"] = struct{}{} + imageTypes["image/tiff"] = struct{}{} + imageTypes["image/webp"] = struct{}{} + imageTypes["image/svg+xml"] = struct{}{} + + // 判断文件类型是否为图片 + _, ok := imageTypes[fileType] + if !ok { + return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,file is not image") + } + + // 读取数据流 + ioData, err := io.ReadAll(fileObject) + if err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,no files") + } + + // 上传文件 + var upload = file.Upload{ + Ctx: l.ctx, + MysqlConn: l.svcCtx.MysqlConn, + AwsSession: l.svcCtx.AwsSession, + } + var resourceId string = hash.JsonHashKey(req.FileKey) + uploadRes, err := upload.UploadFileByByte(&file.UploadBaseReq{ + FileHash: resourceId, + FileByte: ioData, + UploadBucket: 1, + ApiType: 2, + UserId: userId, + GuestId: guestId, + Source: "upload-logo", + }) + + if err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeFileUploadErr, "upload file failed") + } + var logoWidth int64 var logoHeight int64 // 查看sku是否存在 @@ -82,32 +145,49 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us logoHeight = 200 } var resultStr string - var err error var postMap = make(map[string]interface{}, 1) - postMap["logo_url"] = req.ResourceUrl + postMap["logo_url"] = uploadRes.ResourceUrl postMapB, _ := json.Marshal(postMap) - //result, err := http.Post(l.svcCtx.Config.BLMService.ImageProcess.Url, "application/json", strings.NewReader(string(postMapB))) - var headerData = make(map[string]string, 1) headerData["Content-Type"] = "application/json" - result, err := curl.ApiCall(l.svcCtx.Config.BLMService.ImageProcess.Url, "POST", headerData, strings.NewReader(string(postMapB)), 20) + result, err := curl.ApiCall(l.svcCtx.Config.BLMService.ImageProcess.Url, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5) if err != nil { logx.Error(err) - return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") + return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 01") } defer result.Body.Close() b, err := io.ReadAll(result.Body) if err != nil { logx.Error(err) - return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") + return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 02") } - resultStr = string(b) - if resultStr == "Internal Server Error" { - return resp.SetStatus(basic.CodeFileUploadLogoErr, resultStr) + if string(b) == "Internal Server Error" { + err = errors.New("BLMService fail Internal Server Error") + logx.Error(err) + return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 03") + } else { + var resData map[string]interface{} + err = json.Unmarshal(b, &resData) + if err != nil || resData == nil { + logx.Error(err) + return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 04") + } + + if resData != nil { + if resData["code"].(string) == "200" { + resultStr = resData["data"].(string) + } else { + logx.Error(err) + return resp.SetStatus(basic.CodeFileUploadLogoErrType, "service fail 05") + } + } else { + logx.Error(err) + return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail 06") + } } var module = "logo" @@ -118,8 +198,8 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us Module: &module, UserId: &userId, GuestId: &guestId, - ResourceId: &req.ResourceId, - ResourceUrl: &req.ResourceUrl, + ResourceId: &uploadRes.ResourceId, + ResourceUrl: &uploadRes.ResourceUrl, Metadata: &resultStr, CreateAt: &nowTime, }) @@ -129,5 +209,12 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us return resp.SetStatus(basic.CodeFileUploadLogoErr, "service fail") } - return resp.SetStatus(basic.CodeOK) + // 返回成功的响应和上传URL + return resp.SetStatus(basic.CodeOK, map[string]interface{}{ + "upload_data": UploadUrl{ + Status: 1, + ResourceId: uploadRes.ResourceId, + ResourceUrl: uploadRes.ResourceUrl, + }, + }) } diff --git a/server/upload/internal/logic/uploadlogostandardlogic.go b/server/upload/internal/logic/uploadlogostandardlogic.go new file mode 100644 index 00000000..7f2c3a30 --- /dev/null +++ b/server/upload/internal/logic/uploadlogostandardlogic.go @@ -0,0 +1,43 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/upload/internal/svc" + "fusenapi/server/upload/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UploadLogoStandardLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewUploadLogoStandardLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogoStandardLogic { + return &UploadLogoStandardLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *UploadLogoStandardLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *UploadLogoStandardLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } + +func (l *UploadLogoStandardLogic) UploadLogoStandard(req *types.UploadLogoStandardReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/upload/internal/types/types.go b/server/upload/internal/types/types.go index b6363f9f..8aa84e78 100644 --- a/server/upload/internal/types/types.go +++ b/server/upload/internal/types/types.go @@ -5,6 +5,14 @@ import ( "fusenapi/utils/basic" ) +type UploadLogoStandardReq struct { + IsRemoveBg string `form:"is_remove_bg"` + LogoFile string `form:"logo_file"` + Width string `form:"width"` + Height string `form:"height"` + Proportion int64 `form:"proportion"` +} + type UploadFileBaseReq struct { ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 FileKey string `form:"file_key"` // 上传唯一标识信息 @@ -13,14 +21,14 @@ type UploadFileBaseReq struct { UserId int64 `form:"user_id,optional"` // 上传文件额外信息 GuestId int64 `form:"guest_id,optional"` // 上传文件额外信息 UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 + Source string `form:"source"` // 上传来源 } type UploadLogoReq struct { - ResourceId string `form:"resource_id"` // 资源ID - ResourceUrl string `form:"resource_url"` // 资源URL - IsRemoveBg int64 `form:"is_remove_bg,optional"` // 是否要去掉背景 - Proportion int64 `form:"proportion,default=60"` // 贴图在模型面板上的比例 - SkuId int64 `form:"sku_id,default=0"` // 模板ID + FileKey string `form:"file_key"` // 上传logo唯一标识信息 + IsRemoveBg int64 `form:"is_remove_bg,optional"` // 是否要去掉背景 + Proportion int64 `form:"proportion,default=60"` // 贴图在模型面板上的比例 + SkuId int64 `form:"sku_id,default=0"` // 模板ID } type UploadFileBackendReq struct { @@ -29,12 +37,14 @@ type UploadFileBackendReq struct { FileKey string `form:"file_key"` // 上传唯一标识信息 FileSize int64 `form:"file_size,optional"` // 上传唯一标识信息 Metadata string `form:"meta_data,optional"` // 上传文件额外信息 + Source string `form:"source"` // 上传来源 } type UploadFilesReq struct { ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 UploadInfo string `form:"upload_info"` // 上传信息 json + Source string `form:"source"` // 上传来源 } type UploadCallbackReq struct { @@ -44,6 +54,7 @@ type UploadCallbackReq struct { ResourceUrl string `form:"resource_url"` // 资源URL Metadata string `form:"metadata,optional"` // 元数据,json格式,存储图像分率 ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 + Source string `form:"source"` // 上传来源 } type RequestUpFile struct { diff --git a/server/upload/upload.go b/server/upload/upload.go index 603fe25a..bea4af45 100644 --- a/server/upload/upload.go +++ b/server/upload/upload.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/upload/internal/config" "fusenapi/server/upload/internal/handler" @@ -22,7 +21,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/webset/etc/webset.yaml b/server/webset/etc/webset.yaml index 4d7bb858..828b657b 100644 --- a/server/webset/etc/webset.yaml +++ b/server/webset/etc/webset.yaml @@ -1,6 +1,7 @@ Name: webset Host: 0.0.0.0 Port: 9913 +Timeout: 15000 #服务超时时间 SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest" Auth: AccessSecret: fusen2023 diff --git a/server/webset/webset.go b/server/webset/webset.go index 0b8d0ea7..ab154b3b 100644 --- a/server/webset/webset.go +++ b/server/webset/webset.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "net/http" - "time" "fusenapi/server/webset/internal/config" "fusenapi/server/webset/internal/handler" @@ -22,7 +21,6 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/websocket/etc/websocket.yaml b/server/websocket/etc/websocket.yaml index d47e1243..f287bbb9 100644 --- a/server/websocket/etc/websocket.yaml +++ b/server/websocket/etc/websocket.yaml @@ -7,4 +7,17 @@ Auth: AccessSecret: fusen2023 AccessExpire: 2592000 RefreshAfter: 1592000 -SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672 \ No newline at end of file +SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672 +AWS: + S3: + Credentials: + AccessKeyID: AKIAZB2JKUXDPNRP4YT2 + Secret: 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 + Token: +BLMService: + Url: "http://18.119.109.254:8999" + LogoCombine: + #Url: "http://192.168.1.7:8999/LogoCombine" + Url: "http://18.119.109.254:8999/LogoCombine" +Unity: + Host: http://api.fusen.3718.cn:4050 \ No newline at end of file diff --git a/server/websocket/internal/config/config.go b/server/websocket/internal/config/config.go index ee0f22f7..6dd60c29 100644 --- a/server/websocket/internal/config/config.go +++ b/server/websocket/internal/config/config.go @@ -10,4 +10,22 @@ type Config struct { SourceMysql string Auth types.Auth SourceRabbitMq string + AWS struct { + S3 struct { + Credentials struct { + AccessKeyID string + Secret string + Token string + } + } + } + BLMService struct { + Url string + LogoCombine struct { + Url string + } + } + Unity struct { + Host string + } } diff --git a/server/websocket/internal/handler/datatransferhandler.go b/server/websocket/internal/handler/datatransferhandler.go index 8ef09842..c167b31c 100644 --- a/server/websocket/internal/handler/datatransferhandler.go +++ b/server/websocket/internal/handler/datatransferhandler.go @@ -10,6 +10,6 @@ func DataTransferHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // 创建一个业务逻辑层实例 l := logic.NewDataTransferLogic(r.Context(), svcCtx) - l.DataTransfer(svcCtx, w, r) + l.DataTransfer(w, r) } } diff --git a/server/render/internal/handler/rendernotifyhandler.go b/server/websocket/internal/handler/rendernotifyhandler.go similarity index 82% rename from server/render/internal/handler/rendernotifyhandler.go rename to server/websocket/internal/handler/rendernotifyhandler.go index a8d01c9c..63a84e1f 100644 --- a/server/render/internal/handler/rendernotifyhandler.go +++ b/server/websocket/internal/handler/rendernotifyhandler.go @@ -6,9 +6,9 @@ import ( "fusenapi/utils/basic" - "fusenapi/server/render/internal/logic" - "fusenapi/server/render/internal/svc" - "fusenapi/server/render/internal/types" + "fusenapi/server/websocket/internal/logic" + "fusenapi/server/websocket/internal/svc" + "fusenapi/server/websocket/internal/types" ) func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { diff --git a/server/websocket/internal/handler/routes.go b/server/websocket/internal/handler/routes.go index fd3200e4..859ecc5b 100644 --- a/server/websocket/internal/handler/routes.go +++ b/server/websocket/internal/handler/routes.go @@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/websocket/data_transfer", Handler: DataTransferHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/websocket/render_notify", + Handler: RenderNotifyHandler(serverCtx), + }, }, ) } diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 44dc3e82..b5929a92 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -4,11 +4,10 @@ import ( "bytes" "encoding/json" "fusenapi/constants" - "fusenapi/initalize" - "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/id_generator" "fusenapi/utils/websocket_data" + "github.com/google/uuid" "github.com/gorilla/websocket" "net/http" "sync" @@ -60,26 +59,32 @@ var ( } //websocket连接存储 mapConnPool = sync.Map{} + //公共互斥锁 + publicMutex sync.Mutex ) // 每个连接的连接基本属性 type wsConnectItem struct { - conn *websocket.Conn //websocket的连接 - ctx context.Context - rabbitMq *initalize.RabbitMqHandle - allModels *gmodel.AllModelsGen - closeChan chan struct{} //ws连接关闭chan - isClose bool //是否已经关闭 - uniqueId uint64 //ws连接唯一标识 - inChan chan []byte //接受消息缓冲通道 - outChan chan []byte //发送回客户端的消息 - mutex sync.Mutex //互斥锁 - userId int64 //用户id - guestId int64 //游客id - renderProperty renderProperty //扩展云渲染属性 + conn *websocket.Conn //websocket的连接 + logic *DataTransferLogic //logic + closeChan chan struct{} //ws连接关闭chan + isClose bool //是否已经关闭 + uniqueId string //ws连接唯一标识 + inChan chan []byte //接受消息缓冲通道 + outChan chan []byte //发送回客户端的消息 + mutex sync.Mutex //互斥锁 + userId int64 //用户id + guestId int64 //游客id + renderProperty renderProperty //扩展云渲染属性 } -func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.ResponseWriter, r *http.Request) { +// 请求建立连接,升级websocket协议 +func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) { + //把子协议携带的token设置到标准token头信息中 + token := r.Header.Get("Sec-Websocket-Protocol") + r.Header.Set("Authorization", "Bearer "+token) + //设置Sec-Websocket-Protocol + upgrade.Subprotocols = []string{token} //升级websocket conn, err := upgrade.Upgrade(w, r, nil) if err != nil { @@ -88,54 +93,19 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp } defer conn.Close() //鉴权不成功后断开 - /*var ( + var ( userInfo *auth.UserInfo isAuth bool ) - isAuth, userInfo = l.checkAuth(svcCtx, r) + isAuth, userInfo = l.checkAuth(r) if !isAuth { - time.Sleep(time.Second * 4) //兼容下火狐 - rsp := websocket_data.DataTransferData{ - T: constants.WEBSOCKET_UNAUTH, - D: nil, - } - b, _ := json.Marshal(rsp) - //先发一条正常信息 - _ = conn.WriteMessage(websocket.TextMessage, b) - //发送关闭信息 - _ = conn.WriteMessage(websocket.CloseMessage, nil) + //未授权响应消息 + l.unAuthResponse(conn) return - }*/ - //测试的目前写死 39 - var userInfo auth.UserInfo - userInfo.UserId = 39 - //生成连接唯一标识 - uniqueId := websocketIdGenerator.Get() - ws := wsConnectItem{ - conn: conn, - ctx: l.ctx, - rabbitMq: l.svcCtx.RabbitMq, - allModels: l.svcCtx.AllModels, - uniqueId: uniqueId, - closeChan: make(chan struct{}, 1), - inChan: make(chan []byte, 1000), - outChan: make(chan []byte, 1000), - userId: userInfo.UserId, - guestId: userInfo.GuestId, - renderProperty: renderProperty{ - renderImageTask: make(map[string]string), - renderImageTaskCtlChan: make(chan renderImageControlChanItem, 100), - }, } - //保存连接 - mapConnPool.Store(uniqueId, ws) + //设置连接 + ws := l.setConnPool(conn, *userInfo) defer ws.close() - go func() { - //把连接成功消息发回去 - time.Sleep(time.Second * 4) //兼容下火狐 - b := ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, uniqueId) - _ = conn.WriteMessage(websocket.TextMessage, b) - }() //循环读客户端信息 go ws.readLoop() //循环把数据发送给客户端 @@ -144,16 +114,60 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp go ws.sendLoop() //操作连接中渲染任务的增加/删除 go ws.operationRenderTask() + //消费渲染缓冲队列 + go ws.renderImage() //心跳 ws.heartbeat() } +// 设置连接 +func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.UserInfo) wsConnectItem { + publicMutex.Lock() + defer publicMutex.Unlock() + //生成连接唯一标识 + uniqueId := l.getUniqueId(userInfo) + ws := wsConnectItem{ + conn: conn, + logic: l, + uniqueId: uniqueId, + closeChan: make(chan struct{}, 1), + inChan: make(chan []byte, 100), + outChan: make(chan []byte, 100), + userId: userInfo.UserId, + guestId: userInfo.GuestId, + renderProperty: renderProperty{ + renderImageTask: make(map[string]string), + renderImageTaskCtlChan: make(chan renderImageControlChanItem, 100), + renderChan: make(chan []byte, 100), + }, + } + //保存连接 + mapConnPool.Store(uniqueId, ws) + go func() { + //把连接成功消息发回去 + time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究) + ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, uniqueId)) + }() + return ws +} + +// 获取唯一id +func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo) string { + //后面拼接上用户id + uniqueId := uuid.New().String() + getUserJoinPart(userInfo.UserId, userInfo.GuestId) + if _, ok := mapConnPool.Load(uniqueId); ok { + uniqueId = l.getUniqueId(userInfo) + } + return uniqueId +} + // 鉴权 -func (l *DataTransferLogic) checkAuth(svcCtx *svc.ServiceContext, r *http.Request) (isAuth bool, userInfo *auth.UserInfo) { +func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *auth.UserInfo) { // 解析JWT token,并对空用户进行判断 - claims, err := svcCtx.ParseJwtToken(r) + claims, err := l.svcCtx.ParseJwtToken(r) // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 if err != nil { + logx.Error(err) return false, nil } if claims != nil { @@ -161,6 +175,7 @@ func (l *DataTransferLogic) checkAuth(svcCtx *svc.ServiceContext, r *http.Reques userInfo, err = auth.GetUserInfoFormMapClaims(claims) // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 if err != nil { + logx.Error(err) return false, nil } //不是登录用户也不是游客 @@ -172,6 +187,22 @@ func (l *DataTransferLogic) checkAuth(svcCtx *svc.ServiceContext, r *http.Reques return false, nil } +// 鉴权失败通知 +func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn) { + time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究) + rsp := websocket_data.DataTransferData{ + T: constants.WEBSOCKET_UNAUTH, + D: nil, + } + b, _ := json.Marshal(rsp) + //先发一条正常信息 + _ = conn.WriteMessage(websocket.TextMessage, b) + //发送关闭信息 + _ = conn.WriteMessage(websocket.CloseMessage, nil) + //关闭连接 + conn.Close() +} + // 心跳 func (w *wsConnectItem) heartbeat() { tick := time.Tick(time.Second * 5) @@ -263,7 +294,9 @@ func (w *wsConnectItem) sendToOutChan(data []byte) { case <-w.closeChan: return case w.outChan <- data: - logx.Info("notify send render result to out chan") + return + case <-time.After(time.Second * 3): //阻塞超过3秒丢弃 + return } } @@ -281,8 +314,8 @@ func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []by func (w *wsConnectItem) dealwithReciveData(data []byte) { var parseInfo websocket_data.DataTransferData if err := json.Unmarshal(data, &parseInfo); err != nil { - logx.Error("invalid format of websocket message") - w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket message:"+string(data)) + logx.Error("invalid format of websocket message:", err) + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket message:"+string(data))) return } d, _ := json.Marshal(parseInfo.D) @@ -290,7 +323,10 @@ func (w *wsConnectItem) dealwithReciveData(data []byte) { switch parseInfo.T { //图片渲染 case constants.WEBSOCKET_RENDER_IMAGE: - w.renderImage(d) + w.sendToRenderChan(d) + //刷新重连请求恢复上次连接的标识 + case constants.WEBSOCKET_REQUEST_REUSE_LAST_CONNECT: + w.reuseLastConnect(d) default: } diff --git a/server/websocket/internal/logic/mq_consumer.go b/server/websocket/internal/logic/mq_consumer.go deleted file mode 100644 index 7488e229..00000000 --- a/server/websocket/internal/logic/mq_consumer.go +++ /dev/null @@ -1,53 +0,0 @@ -package logic - -import ( - "context" - "encoding/json" - "fusenapi/constants" - "fusenapi/utils/websocket_data" - "github.com/zeromicro/go-zero/core/logx" -) - -// 消费渲染结果数据 -type MqConsumerRenderResult struct { -} - -func (m *MqConsumerRenderResult) Run(ctx context.Context, data []byte) error { - logx.Info("接收到MqConsumerRenderResult数据:", string(data)) - var parseInfo websocket_data.RenderImageNotify - if err := json.Unmarshal(data, &parseInfo); err != nil { - logx.Error("MqConsumerRenderResult data format err:", err) - return nil //不返回错误则就删掉该消息 - } - //遍历websocket链接把数据传进去 - mapConnPool.Range(func(key, value any) bool { - //断言连接 - ws, ok := value.(wsConnectItem) - if !ok { - return true - } - //关闭标识 - if ws.isClose { - return true - } - //查询有无该渲染任务 - renderId, ok := ws.renderProperty.renderImageTask[parseInfo.TaskId] - if !ok { - return true - } - b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ - RenderId: renderId, - Image: parseInfo.Image, - }) - //删除对应的需要渲染的图片map - ws.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{ - Option: 0, //0删除 1添加 - TaskId: parseInfo.TaskId, - RenderId: renderId, - } - //发送数据到out chan - ws.sendToOutChan(b) - return true - }) - return nil -} diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go new file mode 100644 index 00000000..e14983d4 --- /dev/null +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -0,0 +1,111 @@ +package logic + +import ( + "fusenapi/constants" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + "fusenapi/utils/file" + "fusenapi/utils/websocket_data" + "time" + + "context" + + "fusenapi/server/websocket/internal/svc" + "fusenapi/server/websocket/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type RenderNotifyLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewRenderNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RenderNotifyLogic { + return &RenderNotifyLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *RenderNotifyLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *RenderNotifyLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } + +func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) { + if req.TaskId == "" { + logx.Error("渲染回调参数错误:invalid param task_id") + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param task_id") + } + if req.Image == "" { + logx.Error("渲染回调参数错误:invalid param image") + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image") + } + // 上传文件 + var upload = file.Upload{ + Ctx: l.ctx, + MysqlConn: l.svcCtx.MysqlConn, + AwsSession: l.svcCtx.AwsSession, + } + uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ + Source: "unity cloud render", + FileHash: req.TaskId, + FileData: req.Image, + Metadata: "", + UploadBucket: 1, + ApiType: 2, + UserId: req.UserId, + GuestId: req.GuestId, + FileByte: nil, + }) + if err != nil { + logx.Error("渲染回调上传文件失败:", err) + return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image") + } + //遍历websocket链接把数据传进去 + mapConnPool.Range(func(key, value any) bool { + //断言连接 + ws, ok := value.(wsConnectItem) + if !ok { + logx.Error("渲染回调断言websocket连接失败") + return true + } + //关闭标识 + if ws.isClose { + return true + } + //查询有无该渲染任务 + renderId, ok := ws.renderProperty.renderImageTask[req.TaskId] + if !ok { + return true + } + b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ + RenderId: renderId, + Image: uploadRes.ResourceUrl, + }) + deleteTask := renderImageControlChanItem{ + Option: 0, //0删除 1添加 + TaskId: req.TaskId, + RenderId: renderId, + } + select { + case <-ws.closeChan: //关闭了 + return true + case ws.renderProperty.renderImageTaskCtlChan <- deleteTask: //删除对应的需要渲染的图片map + //发送数据到out chan + ws.sendToOutChan(b) + return true + case <-time.After(time.Second * 3): //超时丢弃 + return true + } + }) + logx.Info("渲染回调成功######################") + return resp.SetStatusWithMessage(basic.CodeOK, "success") +} diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 1aadd993..5f225038 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -1,19 +1,25 @@ package logic import ( + "bytes" "encoding/json" "errors" "fusenapi/constants" + "fusenapi/service/repositories" + "fusenapi/utils/curl" "fusenapi/utils/hash" "fusenapi/utils/websocket_data" "github.com/zeromicro/go-zero/core/logx" "gorm.io/gorm" + "strconv" + "time" ) // 云渲染属性 type renderProperty struct { renderImageTask map[string]string //需要渲染的图片任务 key是taskId val 是renderId renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增移除的控制通道 + renderChan chan []byte //渲染的缓冲队列 } // 渲染任务新增移除的控制通道的数据 @@ -23,52 +29,97 @@ type renderImageControlChanItem struct { RenderId string // map的val } +// 发送到渲染缓冲池 +func (w *wsConnectItem) sendToRenderChan(data []byte) { + select { + case <-w.closeChan: //已经关闭 + return + case w.renderProperty.renderChan <- data: + return + case <-time.After(time.Second * 3): + return + } +} + // 渲染发送到组装数据组装数据 -func (w *wsConnectItem) renderImage(data []byte) { +func (w *wsConnectItem) renderImage() { + defer func() { + if err := recover(); err != nil { + logx.Error("renderImage panic:", err) + } + }() + for { + select { + case <-w.closeChan: //已关闭 + return + case data := <-w.renderProperty.renderChan: + w.consumeRenderCache(data) + } + } + +} + +// 消费渲染缓冲数据 +func (w *wsConnectItem) consumeRenderCache(data []byte) { + logx.Info("消费渲染数据:", string(data)) var renderImageData websocket_data.RenderImageReqMsg if err := json.Unmarshal(data, &renderImageData); err != nil { - w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data)) + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data))) logx.Error("invalid format of websocket render image message", err) return } - logx.Info("收到请求云渲染图片数据:", renderImageData) if renderImageData.RenderId == "" { - w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:render_id is empty") + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:render_id is empty")) logx.Error("invalid format of websocket render image message:render_id is empty") return } if renderImageData.RenderData.ProductId <= 0 { - w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:product_id ") + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:product_id ")) logx.Error("invalid format of websocket render image message:product_id") return } - if renderImageData.RenderData.TemplateTagId <= 0 { - w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:template_tag_id ") - logx.Error("invalid format of websocket render image message:template_tag_id") + if renderImageData.RenderData.TemplateTag == "" { + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:template_tag ")) + logx.Error("invalid format of websocket render image message:template_tag") return } //获取上传最近的logo - userMaterial, err := w.allModels.FsUserMaterial.FindLatestOne(w.ctx, w.userId, w.guestId) + userMaterial, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindLatestOne(w.logic.ctx, w.userId, w.guestId) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { - w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "failed to get user logo") + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "failed to get user logo")) logx.Error("failed to get user logo") return } - //使用默认logo(写死一个默认) - renderImageData.RenderData.Logo = "https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/f5ccd11365099fa47a6316b1cd639f6dd6064dcd2d37c8d2fcd0a322160b33cc" + //使用默认logo(id=0) + userMaterialDefault, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindOneById(w.logic.ctx, 0) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "default logo is not exists")) + return + } + logx.Error("default logo is not exists") + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "failed to get default logo")) + return + } + renderImageData.RenderData.Logo = *userMaterialDefault.ResourceUrl } else { renderImageData.RenderData.Logo = *userMaterial.ResourceUrl - renderImageData.RenderData.UserMaterialId = userMaterial.Id } //用户id赋值 renderImageData.RenderData.UserId = w.userId renderImageData.RenderData.GuestId = w.guestId - //生成任务id - taskId := hash.JsonHashKey(renderImageData.RenderData) + //生成任务id(需要把user_id,guest_id设为0) + hashVal := renderImageData.RenderData + hashVal.UserId = 0 + hashVal.GuestId = 0 + hashByte, _ := json.Marshal(hashVal) + var hashData map[string]interface{} + _ = json.Unmarshal(hashByte, &hashData) + taskId := hash.JsonHashKey(hashData) //查询有没有缓存的资源,有就返回###################### - resource, err := w.allModels.FsResource.FindOneById(w.ctx, taskId) + resource, err := w.logic.svcCtx.AllModels.FsResource.FindOneById(w.logic.ctx, taskId) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { logx.Error("failed to find render resource:", err) @@ -91,18 +142,154 @@ func (w *wsConnectItem) renderImage(data []byte) { TaskId: taskId, RenderId: renderImageData.RenderId, } - tmpData := websocket_data.AssembleRenderData{ - TaskId: taskId, - RenderId: renderImageData.RenderId, - RenderData: renderImageData.RenderData, - } - d, _ := json.Marshal(tmpData) - //发送给对应的流水线组装数据 - if err := w.rabbitMq.SendMsg(constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, d); err != nil { - logx.Error("发送渲染任务数据到MQ失败:", string(d), "err:", err) + //组装数据 + if err = w.assembleRenderData(taskId, renderImageData); err != nil { + logx.Error("组装数据失败:", err) return } - logx.Info("发送渲染数据到rabbitmq成功:", string(d)) +} + +// 组装数据发送给unity +func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.RenderImageReqMsg) error { + defer func() { + if err := recover(); err != nil { + logx.Error("assembleRenderData panic:", err) + } + }() + //获取模板 + productTemplate, err := w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(w.logic.ctx, info.RenderData.ProductId, info.RenderData.TemplateTag) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error("template info is not found") + return err + } + logx.Error("failed to get template info:", err) + return err + } + //获取刀版图 + combineReq := repositories.LogoCombineReq{ + UserId: info.RenderData.UserId, + GuestId: info.RenderData.GuestId, + TemplateId: productTemplate.Id, + TemplateTag: info.RenderData.TemplateTag, + Website: info.RenderData.Website, + Slogan: info.RenderData.Slogan, + Address: info.RenderData.Address, + Phone: info.RenderData.Phone, + } + res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) + if err != nil { + logx.Error("合成刀版图失败:", err) + return err + } + combineImage := "" //刀版图 + if res != nil && res.ResourceUrl != nil { + combineImage = *res.ResourceUrl + } else { + logx.Error("合成刀版图失败,合成的刀版图是空指针:", err) + return err + } + logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",模板id:", productTemplate.Id, ",原logo:", info.RenderData.Logo, "刀版图:", *res.ResourceUrl) + //获取渲染设置信息 + element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.logic.ctx, *productTemplate.ModelId) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error("element info is not found,model_id = ", *productTemplate.ModelId) + return err + } + logx.Error("failed to get element list,", err) + return err + } + //组装数据 + refletion := -1 + if element.Refletion != nil && *element.Refletion != "" { + refletion, err = strconv.Atoi(*element.Refletion) + if err != nil { + logx.Error("err refletion:set default -1") + } + } + //组装data数据 + var mode map[string]interface{} + if element.Mode != nil && *element.Mode != "" { + if err = json.Unmarshal([]byte(*element.Mode), &mode); err != nil { + logx.Error("faile to parse element mode json:", err) + return err + } + } + tempData := make([]map[string]interface{}, 0, 3) + if element.Base != nil && *element.Base != "" { + tempData = append(tempData, map[string]interface{}{ + "name": "model", + "data": "0," + combineImage + "," + *element.Base, + "type": "other", + "layer": "0", + "is_update": 1, + "mode": mode["model"], + }) + } + if element.Shadow != nil && *element.Shadow != "" { + tempData = append(tempData, map[string]interface{}{ + "name": "shadow", + "data": *element.Shadow, + "type": "other", + "layer": "0", + "is_update": 0, + "mode": mode["shadow"], + }) + } + if element.ModelP != nil && *element.ModelP != "" { + tempData = append(tempData, map[string]interface{}{ + "name": "model_P", + "data": "0," + *element.ModelP, + "type": "other", + "layer": "0", + "is_update": 0, + "mode": mode["model_P"], + }) + } + result := []interface{}{ + map[string]interface{}{ + "light": *element.Light, + "refletion": refletion, + "scale": *element.Scale, + "sku_id": info.RenderData.ProductId, + "tid": *element.Title, + "rotation": *element.Rotation, + "filePath": "", //todo 文件路径,针对千人千面 + "data": tempData, + }, + } + sendData := map[string]interface{}{ + "id": taskId, + "order_id": 0, + "user_id": info.RenderData.UserId, + "guest_id": info.RenderData.GuestId, + "sku_ids": []int64{info.RenderData.ProductId}, + "tids": []string{*element.Title}, + "data": result, + "is_thousand_face": 0, + "folder": "", //todo 千人千面需要使用 + } + //请求unity接口 + url := w.logic.svcCtx.Config.Unity.Host + "/api/render/queue/push" + header := make(map[string]string) + header["content-type"] = "application/json" + t := time.Now().UTC() + postData := map[string]interface{}{ + "group": "unity3d", + "source": "home page", + "priority": 1, + "create_at": t, + "render_data": sendData, + } + p, _ := json.Marshal(postData) + _, err = curl.ApiCall(url, "POST", header, bytes.NewReader(p), time.Second*10) + if err != nil { + logx.Error("failed to send data to unity") + return err + } + logx.Info("发送到unity成功################") + return nil } // 操作连接中渲染任务的增加/删除 diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go new file mode 100644 index 00000000..b31ee320 --- /dev/null +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -0,0 +1,68 @@ +package logic + +import ( + "encoding/json" + "fmt" + "fusenapi/constants" + "github.com/zeromicro/go-zero/core/logx" +) + +// 刷新重连请求恢复上次连接的标识 +func (w *wsConnectItem) reuseLastConnect(data []byte) { + logx.Info("收到请求恢复上次连接标识数据:", string(data)) + var clientId string + if err := json.Unmarshal(data, &clientId); err != nil { + logx.Error(" invalid format of client id :", clientId) + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "invalid format of client id")) + return + } + lenClientId := len(clientId) + //id长度不对 + if lenClientId > 100 { + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "length of client id is to long")) + return + } + //合成client后缀,不是同个后缀的不能复用 + userPart := getUserJoinPart(w.userId, w.guestId) + lenUserPart := len(userPart) + if lenClientId <= lenUserPart { + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "length of client id is to short")) + return + } + //尾部不同不能复用 + if clientId[lenClientId-lenUserPart:] != userPart { + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "the client id is not belong you before")) + return + } + publicMutex.Lock() + defer publicMutex.Unlock() + //存在是不能给他申请重新绑定 + if v, ok := mapConnPool.Load(clientId); ok { + obj, ok := v.(wsConnectItem) + if !ok { + logx.Error("连接断言失败") + } + //是当前自己占用 + if obj.uniqueId == w.uniqueId { + //重新绑定 + w.uniqueId = clientId + rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, clientId) + w.sendToOutChan(rsp) + return + } else { + rsp := w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "id has bound by other connect ") + w.sendToOutChan(rsp) + return + } + } + //重新绑定 + w.uniqueId = clientId + rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, clientId) + w.sendToOutChan(rsp) + return +} + +// 获取用户拼接部分(复用标识用到) +func getUserJoinPart(userId, guestId int64) string { + return fmt.Sprintf("_%d_%d", userId, guestId) +} diff --git a/server/websocket/internal/svc/servicecontext.go b/server/websocket/internal/svc/servicecontext.go index df41e0b3..cff40090 100644 --- a/server/websocket/internal/svc/servicecontext.go +++ b/server/websocket/internal/svc/servicecontext.go @@ -4,6 +4,9 @@ import ( "errors" "fmt" "fusenapi/server/websocket/internal/config" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/session" "net/http" "fusenapi/initalize" @@ -16,17 +19,28 @@ import ( type ServiceContext struct { Config config.Config - MysqlConn *gorm.DB - AllModels *gmodel.AllModelsGen - RabbitMq *initalize.RabbitMqHandle + MysqlConn *gorm.DB + AllModels *gmodel.AllModelsGen + RabbitMq *initalize.RabbitMqHandle + AwsSession *session.Session + Repositories *initalize.Repositories } func NewServiceContext(c config.Config) *ServiceContext { + config := aws.Config{ + Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token), + } return &ServiceContext{ - Config: c, - MysqlConn: initalize.InitMysql(c.SourceMysql), - AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), - RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), + Config: c, + MysqlConn: initalize.InitMysql(c.SourceMysql), + AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), + RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), + AwsSession: session.Must(session.NewSession(&config)), + Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{ + GormDB: initalize.InitMysql(c.SourceMysql), + BLMServiceUrl: &c.BLMService.Url, + AwsSession: session.Must(session.NewSession(&config)), + }), } } diff --git a/server/websocket/internal/types/types.go b/server/websocket/internal/types/types.go index 70ec268a..1cd1f5b4 100644 --- a/server/websocket/internal/types/types.go +++ b/server/websocket/internal/types/types.go @@ -5,6 +5,13 @@ import ( "fusenapi/utils/basic" ) +type RenderNotifyReq struct { + TaskId string `json:"task_id"` //任务id + UserId int64 `json:"user_id"` + GuestId int64 `json:"guest_id"` + Image string `json:"image"` +} + type Request struct { } diff --git a/server/websocket/websocket.go b/server/websocket/websocket.go index cfc775f7..b6c469b6 100644 --- a/server/websocket/websocket.go +++ b/server/websocket/websocket.go @@ -1,11 +1,8 @@ package main import ( - "context" "flag" "fmt" - "fusenapi/constants" - "fusenapi/server/websocket/internal/logic" "net/http" "fusenapi/utils/auth" @@ -30,12 +27,6 @@ func main() { defer server.Stop() ctx := svc.NewServiceContext(c) - //消费渲染结果队列 - ctx1 := context.Background() - ctx2, cancel := context.WithCancel(ctx1) - ctx2 = context.WithValue(ctx2, "allmodels", ctx.AllModels) - defer cancel() - go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_RENDER_RESULT_DATA, &logic.MqConsumerRenderResult{}) handler.RegisterHandlers(server, ctx) fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) server.Start() diff --git a/server_api/base.api b/server_api/base.api new file mode 100644 index 00000000..3a174324 --- /dev/null +++ b/server_api/base.api @@ -0,0 +1,20 @@ +syntax = "v1" + +info ( + title: // TODO: add title + desc: // TODO: add description + author: "" + email: "" +) + +import "basic.api" + +service base { + @handler MerchantCategoryListHandler + get /api/base/merchant_category_list(MerchantCategoryListReq) returns (response); +} + +type ( + MerchantCategoryListReq { + } +) \ No newline at end of file diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api index 3b686163..62ae1f35 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -75,8 +75,19 @@ service home-user-auth { // 再来一单 @handler UserAgainOrderHandler get /api/user/one-more-order (UserAgainOrderReq) returns (response); + + // 保存商户信息 + @handler UserInfoSetHandler + post /api/user/set_user_info (UserInfoSetReq) returns (response); } +type ( + UserInfoSetReq { + Module string `form:"module,options=[merchant_category]"` // json格式字符串 + Metadata string `form:"metadata"` // json格式字符串 + } +) + type ( UserAgainOrderReq { Sn string `form:"sn"` // 订单编号 diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index c8b1a2cc..a565ee01 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -20,7 +20,7 @@ type GetProductTemplateTagsReq { Limit int `form:"limit"` } type GetProductTemplateTagsRsp { - Id int64 `json:"id"` - Tag string `json:"tag"` - Cover string `json:"cover"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + Cover string `json:"cover"` } \ No newline at end of file diff --git a/server_api/product.api b/server_api/product.api index b4aca200..8a6fdbf8 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -50,7 +50,7 @@ service product { //获取产品尺寸列表 @handler GetSizeByPidHandler get /api/product/get_size_by_pid(GetSizeByPidReq) returns (response); - //获取产品模板列表 + //获取产品模板 @handler GetTemplateByPidHandler get /api/product/get_template_by_pid(GetTemplateByPidReq) returns (response); //获取产品配件数据 @@ -281,21 +281,21 @@ type OtherProductListRsp { } //获取详情页推荐产品列表 type GetRecommandProductListReq { - Size uint32 `form:"size,optional"` + Size int32 `form:"size,optional"` Num int64 `form:"num,optional"` Sn string `form:"sn"` } type GetRecommandProductListRsp { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - TitleCn string `json:"title_cn"` - Cover string `json:"cover"` - CoverImg string `json:"cover_img"` - CoverDefault string `json:"cover_default"` - Intro string `json:"intro"` - IsRecommend int64 `json:"is_recommend"` - MinPrice int64 `json:"min_price"` + Id int64 `json:"id"` + Sn string `json:"sn"` + Title string `json:"title"` + TitleCn string `json:"title_cn"` + Cover string `json:"cover"` + CoverImg string `json:"cover_img"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + Intro string `json:"intro"` + IsRecommend int64 `json:"is_recommend"` + MinPrice int64 `json:"min_price"` } //获取分类产品列表 type GetTagProductListReq { @@ -325,6 +325,7 @@ type TagProduct { MinPrice int64 `json:"min_price"` //彩膜列表 CoverDefault []CoverDefaultItem `json:"cover_default"` + DefaultTemplateId int64 `json:"default_template_id"` HaveOptionalFitting bool `json:"have_optional_fitting"` Recommended bool `json:"recommended"` } @@ -383,11 +384,11 @@ type GetSizeByPidRsp { IsPopular bool `json:"is_popular"` //是否受欢迎 MinPrice float64 `json:"min_price"` //最小价格 } -//获取产品模板列表 +//获取产品模板 type GetTemplateByPidReq { - Pid string `form:"pid"` - Size uint32 `form:"size"` - ProductTemplateTagId int64 `form:"product_template_tag_id"` + Pid string `form:"pid"` + ProductSizeId int64 `form:"product_size_id,optional"` + TemplateTag string `form:"template_tag"` } //获取产品配件数据 type GetFittingByPidReq { @@ -433,15 +434,16 @@ type GetLastProductDesignRsp { } //获取列表页推荐产品(返回是这个维度数组) type HomePageRecommendProductListReq { - Size uint32 `form:"size"` + Size uint32 `form:"size"` + MerchantType int64 `form:"merchant_type"` } type HomePageRecommendProductListRsp { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - Cover string `json:"cover"` - SizeNum uint32 `json:"size_num"` - MinPrice int64 `json:"min_price"` - CoverDefault string `json:"cover_default"` - HaveOptionalFitting bool `json:"have_optional_fitting"` + Id int64 `json:"id"` + Sn string `json:"sn"` + Title string `json:"title"` + Cover string `json:"cover"` + SizeNum uint32 `json:"size_num"` + MinPrice int64 `json:"min_price"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + HaveOptionalFitting bool `json:"have_optional_fitting"` } \ No newline at end of file diff --git a/server_api/render.api b/server_api/render.api index 1fdfa90a..c860476f 100644 --- a/server_api/render.api +++ b/server_api/render.api @@ -8,31 +8,8 @@ info ( ) import "basic.api" - -type RequestToUnity { -} - -type RequestReadImages { -} - service render { - //云渲染完了通知接口 - @handler RenderNotifyHandler - post /api/render/render_notify(RenderNotifyReq) returns (response); //获取面片信息 @handler GetFaceSliceHandler post /api/render/get_face_slice(request) returns (response); -} - -//渲染完了通知接口 -type RenderNotifyReq { - Sign string `json:"sign"` - Time int64 `json:"time"` - Info NotifyInfo `json:"info"` -} -type NotifyInfo { - TaskId string `json:"task_id"` //任务id - UserId int64 `json:"user_id"` - GuestId int64 `json:"guest_id"` - Image string `json:"image"` } \ No newline at end of file diff --git a/server_api/resource.api b/server_api/resource.api index 0a37f93f..f78dae89 100644 --- a/server_api/resource.api +++ b/server_api/resource.api @@ -13,10 +13,23 @@ service resource { @handler LogoCombineHandler post /api/resource/logo-combine(LogoCombineReq) returns (response); + @handler LogoRemovebgHandler + post /api/resource/logo-removebg(LogoRemovebgReq) returns (response); + @handler ResourceInfoHandler get /api/resource/info(ResourceInfoReq) returns (response); } +type ( + LogoRemovebgReq { + IsRemoveBg string `form:"is_remove_bg"` + LogoFile string `form:"logo_file"` + Width string `form:"width"` + Height string `form:"height"` + Proportion int64 `form:"proportion"` + } +) + type ( ResourceInfoReq { ResourceId string `form:"resource_id,optional"` // 资源ID @@ -26,8 +39,12 @@ type ( type ( LogoCombineReq { - ResourceKey string `form:"resource_key"` // 资源唯一标识 - CombineParam string `form:"combine_param"` // 合图参数 - TemplateId int64 `form:"template_id"` // 合图参数 + TemplateId int64 `form:"template_id"` // 合图参数 + TemplateTag string `form:"template_tag"` // 合图参数 + Website string `form:"website,optional"` // 合图参数 + Slogan string `form:"slogan,optional"` // 合图参数 + Address string `form:"address,optional"` // 合图参数 + Phone string `form:"phone,optional"` // 合图参数 + Qrcode string `form:"qrcode,optional"` // 合图参数 } ) \ No newline at end of file diff --git a/server_api/upload.api b/server_api/upload.api index a9581adf..7aaa9ec0 100644 --- a/server_api/upload.api +++ b/server_api/upload.api @@ -42,8 +42,21 @@ service upload { @handler UploadFileBaseHandler post /api/upload/upload-file-base(UploadFileBaseReq) returns (response); + @handler UploadLogoStandardHandler + post /api/upload/up-standard-logo(UploadLogoStandardReq) returns (response); + } +type ( + UploadLogoStandardReq { + IsRemoveBg string `form:"is_remove_bg"` + LogoFile string `form:"logo_file"` + Width string `form:"width"` + Height string `form:"height"` + Proportion int64 `form:"proportion"` + } +) + type ( UploadFileBaseReq { ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 @@ -53,16 +66,16 @@ type ( UserId int64 `form:"user_id,optional"` // 上传文件额外信息 GuestId int64 `form:"guest_id,optional"` // 上传文件额外信息 UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 + Source string `form:"source"` // 上传来源 } ) type ( UploadLogoReq { - ResourceId string `form:"resource_id"` // 资源ID - ResourceUrl string `form:"resource_url"` // 资源URL - IsRemoveBg int64 `form:"is_remove_bg,optional"` // 是否要去掉背景 - Proportion int64 `form:"proportion,default=60"` // 贴图在模型面板上的比例 - SkuId int64 `form:"sku_id,default=0"` // 模板ID + FileKey string `form:"file_key"` // 上传logo唯一标识信息 + IsRemoveBg int64 `form:"is_remove_bg,optional"` // 是否要去掉背景 + Proportion int64 `form:"proportion,default=60"` // 贴图在模型面板上的比例 + SkuId int64 `form:"sku_id,default=0"` // 模板ID } ) @@ -73,12 +86,14 @@ type ( FileKey string `form:"file_key"` // 上传唯一标识信息 FileSize int64 `form:"file_size,optional"` // 上传唯一标识信息 Metadata string `form:"meta_data,optional"` // 上传文件额外信息 + Source string `form:"source"` // 上传来源 } UploadFilesReq { ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 UploadInfo string `form:"upload_info"` // 上传信息 json + Source string `form:"source"` // 上传来源 } UploadCallbackReq { UploadBucket int64 `form:"upload_bucket,options=[1,2],default=1"` // 上传桶名:1=缓存,2=持久 @@ -87,6 +102,7 @@ type ( ResourceUrl string `form:"resource_url"` // 资源URL Metadata string `form:"metadata,optional"` // 元数据,json格式,存储图像分率 ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内 + Source string `form:"source"` // 上传来源 } ) diff --git a/server_api/websocket.api b/server_api/websocket.api index ef24d79f..b5adb666 100644 --- a/server_api/websocket.api +++ b/server_api/websocket.api @@ -12,4 +12,15 @@ service websocket { //websocket数据交互 @handler DataTransferHandler get /api/websocket/data_transfer(request) returns (response); + //云渲染完了通知接口 + @handler RenderNotifyHandler + post /api/websocket/render_notify(RenderNotifyReq) returns (response); +} + +//渲染完了通知接口 +type RenderNotifyReq { + TaskId string `json:"task_id"` //任务id + UserId int64 `json:"user_id"` + GuestId int64 `json:"guest_id"` + Image string `json:"image"` } \ No newline at end of file diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go new file mode 100644 index 00000000..d16e8704 --- /dev/null +++ b/service/repositories/image_handle.go @@ -0,0 +1,350 @@ +package repositories + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "fusenapi/constants" + "fusenapi/model/gmodel" + "fusenapi/utils/curl" + "fusenapi/utils/file" + "fusenapi/utils/hash" + "io" + "strings" + "time" + + "github.com/aws/aws-sdk-go/aws/session" + "github.com/zeromicro/go-zero/core/logx" + "gorm.io/gorm" +) + +func NewImageHandle(gormDB *gorm.DB, bLMServiceUrl *string, awsSession *session.Session) ImageHandle { + return &defaultImageHandle{ + MysqlConn: gormDB, + BLMServiceUrl: bLMServiceUrl, + AwsSession: awsSession, + } +} + +type ( + defaultImageHandle struct { + MysqlConn *gorm.DB + BLMServiceUrl *string + AwsSession *session.Session + } + + ImageHandle = interface { + + // logo合图 + LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) + + // logo裁剪 + LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) + } +) + +/* logo合图 */ +type ( + LogoCombineReq struct { + UserId int64 `json:"user_id"` + GuestId int64 `json:"guest_id"` + TemplateId int64 `json:"template_id"` + TemplateTag string `json:"template_tag"` + Website string `json:"website"` // 合图参数 + Slogan string `json:"slogan"` // 合图参数 + Address string `json:"address"` // 合图参数 + Phone string `json:"phone"` // 合图参数 + Qrcode string `json:"qrcode"` // 合图参数 + LogoUrl string `json:"logo_url"` // 合图参数 + } + LogoCombineRes struct { + ResourceId string + ResourceUrl *string + Metadata *string + } +) + +func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { + // 查询logo最新基础信息 + var metadata *string + userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn) + userMaterialInfo, err := userMaterialModel.FindLatestOne(ctx, in.UserId, in.GuestId) + + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + userMaterialInfoDefault, err := userMaterialModel.FindOneById(ctx, 0) + if err != nil { + logx.Error(err) + return nil, err + } + metadata = userMaterialInfoDefault.Metadata + } else { + logx.Error(err) + return nil, err + } + } else { + metadata = userMaterialInfo.Metadata + } + + // 根据hash 查询数据资源 + var hashKeyData = *in + hashKeyData.GuestId = 0 + hashKeyData.UserId = 0 + hashKeyData.LogoUrl = *userMaterialInfo.ResourceUrl + var resourceId string = hash.JsonHashKey(hashKeyData) + + fmt.Println("hashKeyData:", hashKeyData) + + fmt.Println("resourceId:", resourceId) + + resourceModel := gmodel.NewFsResourceModel(l.MysqlConn) + resourceInfo, err := resourceModel.FindOneById(ctx, resourceId) + if err == nil && resourceInfo.ResourceId != "" { + return &LogoCombineRes{ + ResourceId: resourceId, + ResourceUrl: resourceInfo.ResourceUrl, + }, nil + } else { + if err != nil { + if !errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error(err) + return nil, err + } + } + } + + // 没有查到,先根据模版id 查询模版数据 请求算法数据 + productTemplateV2Model := gmodel.NewFsProductTemplateV2Model(l.MysqlConn) + productTemplateV2Info, err := productTemplateV2Model.FindOne(ctx, in.TemplateId) + + if err != nil { + logx.Error(err) + return nil, err + } + var groupOptions map[string]interface{} + var materialList []interface{} + if productTemplateV2Info.TemplateInfo != nil { + var templateInfo map[string]interface{} + err = json.Unmarshal([]byte(*productTemplateV2Info.TemplateInfo), &templateInfo) + + if err != nil { + logx.Error(err) + return nil, err + } + materialList = templateInfo["materialList"].([]interface{}) + groupOptions = templateInfo["groupOptions"].(map[string]interface{}) + } + + fmt.Println("合图开始时间:", time.Now()) + + var moduleDataMap = make(map[string]interface{}, 4) + moduleDataMap["id"] = productTemplateV2Info.Id + moduleDataMap["material"] = productTemplateV2Info.MaterialImg + moduleDataMap["groupOptions"] = groupOptions + moduleDataMap["materialList"] = materialList + + var combineParam map[string]interface{} + json.Unmarshal([]byte(*metadata), &combineParam) + combineParam["template_tagid"] = in.TemplateTag + combineParam["website"] = in.Website + combineParam["slogan"] = in.Slogan + combineParam["phone"] = in.Phone + combineParam["address"] = in.Address + combineParam["qrcode"] = in.Qrcode + + var postMap = make(map[string]interface{}, 2) + fmt.Println(combineParam) + postMap["module_data"] = moduleDataMap + postMap["param_data"] = combineParam + postMapB, _ := json.Marshal(postMap) + + var headerData = make(map[string]string, 1) + headerData["Content-Type"] = "application/json" + result, err := curl.ApiCall(*l.BLMServiceUrl+constants.BLMServiceUrlLogoCombine, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5) + + if err != nil { + logx.Error(err) + return nil, err + } + defer result.Body.Close() + b, err := io.ReadAll(result.Body) + if err != nil { + logx.Error(err) + return nil, err + } + var resultStr string + if string(b) == "Internal Server Error" { + err = errors.New("BLMService fail Internal Server Error") + logx.Error(err) + return nil, err + } else { + var resData map[string]interface{} + err = json.Unmarshal(b, &resData) + if err != nil || resData == nil { + logx.Error(err) + return nil, err + } + + if resData != nil { + if resData["code"].(string) == "200" { + resultStr = resData["data"].(string) + } else { + logx.Error(err) + return nil, err + } + } else { + logx.Error(err) + return nil, err + } + } + + var resultData map[string]interface{} + err = json.Unmarshal([]byte(resultStr), &resultData) + if err != nil || resultData == nil { + logx.Error(err) + return nil, err + } + + fmt.Println("合图结束时间:", time.Now()) + // { + // id: "", + // logo_url:"https://s3.amazon.com/xxxx", + // result: "$saa541afaldjaldjasldjsadjsapsaasda" + // } + var fileBase = resultData["result"].(string) + + // 上传文件 + var upload = file.Upload{ + Ctx: ctx, + MysqlConn: l.MysqlConn, + AwsSession: l.AwsSession, + } + uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ + Source: "combine-image", + FileHash: resourceId, + FileData: fileBase, + UploadBucket: 1, + ApiType: 2, + UserId: in.UserId, + GuestId: in.GuestId, + }) + if err != nil { + logx.Error(err) + return nil, err + } + return &LogoCombineRes{ + ResourceId: uploadRes.ResourceId, + ResourceUrl: &uploadRes.ResourceUrl, + }, nil +} + +/* logo合图 */ +type ( + LogoStandardReq struct { + IsRemoveBg string `json:"is_remove_bg"` + LogoFile string `json:"logo_file"` + Width string `json:"width"` + Height string `json:"height"` + Proportion int64 `json:"proportion"` + } + LogoStandardRes struct { + ResourceId string + ResourceUrl string + IsmaxProportion bool + ImgColor []string + } +) + +/* 图片裁剪 */ +func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) { + var resourceId string = hash.JsonHashKey(in) + var postMap = make(map[string]interface{}, 5) + postMap["is_remove_bg"] = in.IsRemoveBg + postMap["logo_file"] = in.LogoFile + postMap["width"] = in.Width + postMap["height"] = in.Height + postMap["proportion"] = in.Proportion + postMapB, _ := json.Marshal(postMap) + + var headerData = make(map[string]string, 1) + headerData["Content-Type"] = "application/json" + result, err := curl.ApiCall(*l.BLMServiceUrl+constants.BLMServiceUrlLogoRemovebg, "POST", headerData, strings.NewReader(string(postMapB)), time.Minute*5) + if err != nil { + logx.Error(err) + return nil, err + } + defer result.Body.Close() + b, err := io.ReadAll(result.Body) + if err != nil { + logx.Error(err) + return nil, err + } + var resultStr string + if string(b) == "Internal Server Error" { + err = errors.New("BLMService fail Internal Server Error") + logx.Error(err) + return nil, err + } else { + var resData map[string]interface{} + err = json.Unmarshal(b, &resData) + if err != nil || resData == nil { + logx.Error(err) + return nil, err + } + + if resData != nil { + if resData["code"].(string) == "200" { + resultStr = resData["data"].(string) + } else { + logx.Error(err) + return nil, err + } + } else { + logx.Error(err) + return nil, err + } + } + + var resultData map[string]interface{} + err = json.Unmarshal([]byte(resultStr), &resultData) + if err != nil || resultData == nil { + logx.Error(err) + return nil, err + } + //$removeBg ='{"nobg_url": "/test/dIE10gGfXM_scale.png", "thumbnail_url": "/test/dIE10gGfXM_thumbnail.png", "ismax_proportion": true, "img_color": ["#000000", "#EEF5FB", "#6AAFE6", "#9ECDF1", "#298EDC", "#0C7BD1"]}' + + var fileBase = resultData["nobg_url"].(string) + var ismaxProportion = resultData["ismax_proportion"].(bool) + + var imgColor []string + for _, v := range resultData["img_color"].([]interface{}) { + imgColor = append(imgColor, v.(string)) + } + + // 上传文件 + var upload = file.Upload{ + Ctx: ctx, + MysqlConn: l.MysqlConn, + AwsSession: l.AwsSession, + } + uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ + Source: "combine-removebg", + FileHash: resourceId, + FileData: fileBase, + UploadBucket: 1, + ApiType: 2, + }) + if err != nil { + logx.Error(err) + return nil, err + } + return &LogoStandardRes{ + ResourceId: uploadRes.ResourceId, + ResourceUrl: uploadRes.ResourceUrl, + IsmaxProportion: ismaxProportion, + ImgColor: imgColor, + }, nil +} + +/* 图片裁剪 */ diff --git a/utils/basic/basic.go b/utils/basic/basic.go index d5d99288..cb69830e 100644 --- a/utils/basic/basic.go +++ b/utils/basic/basic.go @@ -77,9 +77,10 @@ var ( CodeAesCbcEncryptionErr = &StatusResponse{5106, "encryption data err"} // 加密数据失败 CodeAesCbcDecryptionErr = &StatusResponse{5107, "decryption data err"} // 解密数据失败 - CodeFileUploadErr = &StatusResponse{5110, "file upload err"} // 文件上传失败 - CodeFileUploadLogoErr = &StatusResponse{5111, "logo upload err"} // 用户上传LOGO失败 - CodeFileLogoCombineErr = &StatusResponse{5112, "logo upload err"} // 用户合图失败 + CodeFileUploadErr = &StatusResponse{5110, "file upload err"} // 文件上传失败 + CodeFileUploadLogoErr = &StatusResponse{5111, "logo upload err"} // 用户上传LOGO失败 + CodeFileUploadLogoErrType = &StatusResponse{5111, "logo upload err file is not image"} // 用户上位LOGO失败"} + CodeFileLogoCombineErr = &StatusResponse{5112, "logo upload err"} // 用户合图失败 ) type Response struct { diff --git a/utils/file/upload.go b/utils/file/upload.go index d19752e7..d561ae28 100644 --- a/utils/file/upload.go +++ b/utils/file/upload.go @@ -22,6 +22,7 @@ type Upload struct { } type UploadBaseReq struct { + Source string FileHash string FileData string Metadata string @@ -119,6 +120,7 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er Metadata: &req.Metadata, ApiType: &apiType, BucketName: bucketName, + Source: &req.Source, }).Error if err != nil { logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql") @@ -212,6 +214,7 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro Metadata: &req.Metadata, ApiType: &apiType, BucketName: bucketName, + Source: &req.Source, }).Error if err != nil { logx.Errorf("err:%+v,desc:%+v", err, "fail.upload.resourceInfoAdd.mysql") diff --git a/utils/validate/user_info.go b/utils/validate/user_info.go new file mode 100644 index 00000000..9e0342ec --- /dev/null +++ b/utils/validate/user_info.go @@ -0,0 +1,26 @@ +package validate + +import ( + "encoding/json" + "errors" +) + +type MerchantCategory struct { + CategoryId int64 `json:"category_id"` +} + +func Validate(module *string, metadata *string) (interface{}, error) { + if *module == "merchant_category" { + var merchantCategory MerchantCategory + err := json.Unmarshal([]byte(*metadata), &merchantCategory) + if err != nil { + return nil, err + } else { + if merchantCategory.CategoryId == 0 { + return nil, errors.New("merchant_category.category_id is required") + } + return merchantCategory, nil + } + } + return nil, nil +} diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 8bde5dbe..0238bcfa 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -12,12 +12,15 @@ type RenderImageReqMsg struct { RenderData RenderData `json:"render_data"` } type RenderData struct { - TemplateTagId int64 `json:"template_tag_id"` //模板标签id - ProductId int64 `json:"product_id"` //产品id - UserMaterialId int64 `json:"user_material_id"` //用户素材id - Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) - UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) - GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) + TemplateTag string `json:"template_tag"` //模板标签(必须) + ProductId int64 `json:"product_id"` //产品id(必须) + Website string `json:"website"` //网站(可选) + Slogan string `json:"slogan"` //slogan(可选) + Address string `json:"address"` //地址(可选) + Phone string `json:"phone"` //电话(可选) + UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) + GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) + Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) } // websocket发送渲染完的数据 @@ -25,20 +28,7 @@ type RenderImageRspMsg struct { RenderId string `json:"render_id"` //渲染id Image string `json:"image"` //渲染结果图片 } - -// 渲染服务器回调数据 -type RenderImageNotify struct { - TaskId string `json:"task_id"` - Image string `json:"image"` -} type ThirdPartyLoginRspMsg struct { //websocket三方登录的通知数据 Token string `json:"token"` } - -// 发送到渲染组装的mq数据 -type AssembleRenderData struct { - TaskId string `json:"task_id"` - RenderId string `json:"render_id"` - RenderData RenderData `json:"render_data"` -}