- 菜谱相关
This commit is contained in:
31
business/model/common.go
Normal file
31
business/model/common.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package model
|
||||
|
||||
var (
|
||||
ValideMimeTypes = map[string]int{
|
||||
"image/jpeg": 1,
|
||||
"image/png": 1,
|
||||
|
||||
"video/mpeg": 1,
|
||||
"video/mp4": 1,
|
||||
}
|
||||
)
|
||||
|
||||
type DataResource struct {
|
||||
ModelIDCUL
|
||||
|
||||
HashCode string `orm:"size(48);unique" json:"hash_code"`
|
||||
ResoureType string // 资料的mime type
|
||||
|
||||
Name string `orm:"size(48)" json:"name"`
|
||||
|
||||
MainURL string
|
||||
QiniuURL string
|
||||
EbaiURL string
|
||||
MtwmURL string
|
||||
}
|
||||
|
||||
func (*DataResource) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"HashCode", "ResoureType"},
|
||||
}
|
||||
}
|
||||
2
business/model/dao/food_recipe.go
Normal file
2
business/model/dao/food_recipe.go
Normal file
@@ -0,0 +1,2 @@
|
||||
package dao
|
||||
|
||||
105
business/model/food_recipe.go
Normal file
105
business/model/food_recipe.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
RecipeActionCollect = 1 // 收藏
|
||||
RecipeActionUpvote = 2 // 顶
|
||||
RecipeActionDownvote = 4 // 踩
|
||||
)
|
||||
|
||||
type FoodRecipe struct {
|
||||
ModelIDCULD
|
||||
|
||||
Name string `orm:"size(48)" json:"name"`
|
||||
AuthorID string `orm:"size(48);column(author_id);index" json:"authorID"`
|
||||
|
||||
Description string `orm:"size(4096)" json:"description"`
|
||||
Img string `orm:"size(48)" json:"img"`
|
||||
TimeInMinute int `json:"timeInMinute"` // 大约时间(分钟)
|
||||
UpvoteCount int `json:"upvoteCount"`
|
||||
DownvoteCount int `json:"downvoteCount"`
|
||||
Score int `json:"score"` // 分数
|
||||
|
||||
TagCategory string `orm:"size(48)" json:"tagCategory"` // 菜系(川,粤,鲁等等)
|
||||
TagCookType string `orm:"size(48)" json:"tagCookType"` // 制作工艺(煮,炒,蒸等等)
|
||||
TagTaste string `orm:"size(48)" json:"tagTaste"` // 口味(辣,麻,甜)
|
||||
}
|
||||
|
||||
func (*FoodRecipe) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"Name", "AuthorID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
// 菜谱步骤
|
||||
type FoodRecipeStep struct {
|
||||
ModelIDCULD
|
||||
|
||||
RecipeID int `orm:"column(recipe_id)" json:"recipeID"`
|
||||
Index int8 `json:"index"` // 步骤序号,从1开始
|
||||
|
||||
Name string `orm:"size(48)" json:"name"`
|
||||
Description string `orm:"size(4096)" json:"description"`
|
||||
Img string `orm:"size(48)" json:"img"`
|
||||
}
|
||||
|
||||
func (*FoodRecipeStep) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"RecipeID", "Index", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
// 菜谱配料
|
||||
type FoodRecipeItem struct {
|
||||
ModelIDCULD
|
||||
|
||||
RecipeID int `orm:"column(recipe_id)" json:"recipeID"`
|
||||
Index int8 `json:"index"` // 配料序号,从1开始
|
||||
|
||||
Name string `orm:"size(48)" json:"name"`
|
||||
|
||||
// SpecQuality float32 `json:"specQuality"`
|
||||
// SpecUnit string `orm:"size(8)" json:"specUnit"` // 质量或容量
|
||||
}
|
||||
|
||||
func (*FoodRecipeItem) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"RecipeID", "Index", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
// 菜谱配料选择
|
||||
type FoodRecipeItemChoice struct {
|
||||
ModelIDCULD
|
||||
|
||||
RecipeID int `orm:"column(recipe_id)" json:"recipeID"`
|
||||
Index int8 `json:"index"` // 配料序号,从1开始
|
||||
SkuID int `orm:"column(sku_id)" json:"skuID"`
|
||||
|
||||
ChoiceIndex int8 `json:"choiceIndex"` // 选择序号,从1开始
|
||||
}
|
||||
|
||||
func (*FoodRecipeItemChoice) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"RecipeID", "Index", "SkuID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
type FoodRecipeUser struct {
|
||||
ModelIDCULD
|
||||
|
||||
RecipeID int `orm:"column(recipe_id)" json:"recipeID"`
|
||||
UserID string `orm:"size(48);column(user_id)" json:"userID" compact:"userID"`
|
||||
ActionType int8 `json:"actionType"`
|
||||
}
|
||||
|
||||
func (*FoodRecipeUser) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"RecipeID", "UserID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
func (*FoodRecipeUser) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"UserID", "RecipeID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
93
business/userstore/food_recipe.go
Normal file
93
business/userstore/food_recipe.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package userstore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
type FoodRecipeItemParam struct {
|
||||
Name string `json:"name"`
|
||||
SkuIDs []int `json:"skuIDs"`
|
||||
}
|
||||
|
||||
type FoodRecipeStepParam struct {
|
||||
Name string `orm:"size(48)" json:"name"`
|
||||
Description string `orm:"size(4096)" json:"description"`
|
||||
Img string `orm:"size(48)" json:"img"`
|
||||
}
|
||||
|
||||
func CreateFoodRecipe(ctx *jxcontext.Context, foodRecipe *model.FoodRecipe, itemList []*FoodRecipeItemParam, stepList []*FoodRecipeStepParam) (err error) {
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
_, foodRecipe.AuthorID = ctx.GetMobileAndUserID()
|
||||
dao.WrapAddIDCULEntity(foodRecipe, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, foodRecipe); err != nil {
|
||||
return err
|
||||
}
|
||||
for k, v := range itemList {
|
||||
if len(v.SkuIDs) == 0 {
|
||||
return fmt.Errorf("SkuIDs必须要有值")
|
||||
}
|
||||
skuIDs, err2 := dao.GetSkus(db, v.SkuIDs, nil, nil, nil)
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
if len(v.SkuIDs) != len(skuIDs) {
|
||||
return fmt.Errorf("某些SkuIDs不存在")
|
||||
}
|
||||
|
||||
item := &model.FoodRecipeItem{
|
||||
RecipeID: foodRecipe.ID,
|
||||
Index: int8(k + 1),
|
||||
Name: v.Name,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(item, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, item); err != nil {
|
||||
return err
|
||||
}
|
||||
for k2, v2 := range v.SkuIDs {
|
||||
choice := &model.FoodRecipeItemChoice{
|
||||
RecipeID: foodRecipe.ID,
|
||||
Index: item.Index,
|
||||
SkuID: v2,
|
||||
|
||||
ChoiceIndex: int8(k2 + 1),
|
||||
}
|
||||
dao.WrapAddIDCULEntity(choice, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, choice); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range stepList {
|
||||
step := &model.FoodRecipeStep{
|
||||
RecipeID: foodRecipe.ID,
|
||||
Index: int8(k + 1),
|
||||
Name: v.Name,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(step, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, step); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateFoodRecipe(ctx *jxcontext.Context, foodRecipe *model.FoodRecipe, itemList []*FoodRecipeItemParam, stepList []*FoodRecipeStepParam) (err error) {
|
||||
return err
|
||||
}
|
||||
43
controllers/cmd_food_recipe.go
Normal file
43
controllers/cmd_food_recipe.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/userstore"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type FoodRecipeController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title 创建活动
|
||||
// @Description 创建活动
|
||||
// @Param token header string true "认证token"
|
||||
// @Param name formData string true "菜谱名"
|
||||
// @Param description formData string true "菜谱描述"
|
||||
// @Param img formData string true "图片""
|
||||
// @Param timeInMinute formData string true "大约需要时间(分钟)"
|
||||
// @Param recipeItems formData string true "菜谱配料"
|
||||
// @Param recipeSteps formData string true "菜谱步骤"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /CreateFoodRecipe [post]
|
||||
func (c *FoodRecipeController) CreateFoodRecipe() {
|
||||
c.callCreateFoodRecipe(func(params *tFoodrecipeCreateFoodRecipeParams) (retVal interface{}, errCode string, err error) {
|
||||
var (
|
||||
foodRecipe *model.FoodRecipe
|
||||
itemList []*userstore.FoodRecipeItemParam
|
||||
stepList []*userstore.FoodRecipeStepParam
|
||||
)
|
||||
if err = jxutils.Strings2Objs(params.RecipeItems, &itemList, params.RecipeSteps, &stepList); err == nil {
|
||||
foodRecipe = &model.FoodRecipe{
|
||||
Name: params.Name,
|
||||
Description: params.Description,
|
||||
Img: params.Img,
|
||||
}
|
||||
err = userstore.CreateFoodRecipe(params.Ctx, foodRecipe, itemList, stepList)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -54,6 +54,9 @@ func Init() {
|
||||
|
||||
orm.RegisterModel(&model.CasbinRule{})
|
||||
orm.RegisterModel(&model.SensitiveWord{})
|
||||
|
||||
orm.RegisterModel(&model.FoodRecipe{}, &model.FoodRecipeStep{}, &model.FoodRecipeItem{}, &model.FoodRecipeItemChoice{}, &model.FoodRecipeUser{})
|
||||
|
||||
// create table
|
||||
orm.RunSyncdb("default", false, true)
|
||||
}
|
||||
|
||||
@@ -116,6 +116,11 @@ func init() {
|
||||
&controllers.JxShopController{},
|
||||
),
|
||||
),
|
||||
beego.NSNamespace("/foodrecipe",
|
||||
beego.NSInclude(
|
||||
&controllers.FoodRecipeController{},
|
||||
),
|
||||
),
|
||||
)
|
||||
beego.AddNamespace(ns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user