shan
This commit is contained in:
@@ -1,150 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type FoodRecipeWithAction struct {
|
||||
model.FoodRecipe
|
||||
AuthorName string `json:"authorName"`
|
||||
ActionType int8 `json:"actionType"`
|
||||
}
|
||||
|
||||
type FoodRecipeItemChoiceExt struct {
|
||||
model.FoodRecipeItemChoice
|
||||
|
||||
Img string `orm:"size(255)" json:"img"`
|
||||
SkuName string `json:"skuName"`
|
||||
|
||||
Prefix string `json:"-"`
|
||||
SkuNameName string `orm:"column(sku_name_name)" json:"-"`
|
||||
Unit string `orm:"size(8)" json:"-"`
|
||||
SpecQuality float32 `json:"-"`
|
||||
SpecUnit string `json:"-"`
|
||||
Comment string `json:"-"`
|
||||
}
|
||||
|
||||
func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID string, skuIDs []int, offset, pageSize int) (recipeList []*FoodRecipeWithAction, totalCount int, err error) {
|
||||
var sql string
|
||||
var sqlParams []interface{}
|
||||
if userID != "" {
|
||||
sql = `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.*, t2.action_type, t3.name author_name
|
||||
FROM food_recipe t1
|
||||
LEFT JOIN food_recipe_user t2 ON t2.recipe_id = t1.id AND t2.user_id = ? AND t2.deleted_at = ?
|
||||
LEFT JOIN user t3 ON t3.user_id = t1.author_id
|
||||
WHERE t1.deleted_at = ?`
|
||||
sqlParams = []interface{}{
|
||||
userID,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
} else {
|
||||
sql = `
|
||||
SELECT SQL_CALC_FOUND_ROWS t1.*
|
||||
FROM food_recipe t1
|
||||
WHERE t1.deleted_at = ?`
|
||||
sqlParams = []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
}
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " AND (t1.name LIKE ?"
|
||||
sqlParams = append(sqlParams, keywordLike)
|
||||
sql += ")"
|
||||
}
|
||||
if recipeID > 0 {
|
||||
sql += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, recipeID)
|
||||
}
|
||||
if authorID != "" {
|
||||
sql += " AND t1.author_id = ?"
|
||||
sqlParams = append(sqlParams, authorID)
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += ` AND (
|
||||
SELECT COUNT(*)
|
||||
FROM food_recipe_item_choice t11
|
||||
WHERE t11.recipe_id = t1.id AND t11.sku_id IN (` + GenQuestionMarks(len(skuIDs)) + `)
|
||||
) > 0`
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sql += `
|
||||
ORDER BY t1.created_at DESC
|
||||
LIMIT ? OFFSET ?`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
if err = GetRows(db, &recipeList, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
return recipeList, totalCount, err
|
||||
}
|
||||
|
||||
func GetRecommendFoodRecipes(db *DaoDB, keyword, userID string, offset, pageSize int) (recipeList []*model.FoodRecipe, totalCount int, err error) {
|
||||
list, totalCount, err := QueryFoodRecipes(db, keyword, 0, userID, "", nil, offset, pageSize)
|
||||
if err == nil {
|
||||
recipeList = FoodRecipeWithActionList2Recipe(list)
|
||||
}
|
||||
return recipeList, totalCount, err
|
||||
}
|
||||
|
||||
func FoodRecipeWithActionList2Recipe(recipeList []*FoodRecipeWithAction) (outRecipeList []*model.FoodRecipe) {
|
||||
for _, v := range recipeList {
|
||||
outRecipeList = append(outRecipeList, &v.FoodRecipe)
|
||||
}
|
||||
return outRecipeList
|
||||
}
|
||||
|
||||
func QueryFoodRecipesItems(db *DaoDB, recipeID int) (recipeItemList []*model.FoodRecipeItem, err error) {
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM food_recipe_item t1
|
||||
WHERE t1.deleted_at = ? AND t1.recipe_id = ?`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
recipeID,
|
||||
}
|
||||
sql += " ORDER BY t1.index"
|
||||
err = GetRows(db, &recipeItemList, sql, sqlParams...)
|
||||
return recipeItemList, err
|
||||
}
|
||||
|
||||
func QueryFoodRecipesItemChoices(db *DaoDB, recipeID int) (recipeItemChoiceList []*FoodRecipeItemChoiceExt, err error) {
|
||||
sql := `
|
||||
SELECT t1.*,
|
||||
t2.spec_quality, t2.spec_unit, t2.comment,
|
||||
t3.img, t3.prefix, t3.name sku_name_name, t3.unit
|
||||
FROM food_recipe_item_choice t1
|
||||
LEFT JOIN sku t2 ON t2.id = t1.sku_id
|
||||
LEFT JOIN sku_name t3 ON t3.id = t2.name_id
|
||||
WHERE t1.deleted_at = ? AND t1.recipe_id = ?`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
recipeID,
|
||||
}
|
||||
sql += " ORDER BY t1.index, t1.choice_index"
|
||||
err = GetRows(db, &recipeItemChoiceList, sql, sqlParams...)
|
||||
return recipeItemChoiceList, err
|
||||
}
|
||||
|
||||
func QueryFoodRecipesSteps(db *DaoDB, recipeID int) (recipeStepList []*model.FoodRecipeStep, err error) {
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM food_recipe_step t1
|
||||
WHERE t1.deleted_at = ? AND t1.recipe_id = ?`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
recipeID,
|
||||
}
|
||||
sql += " ORDER BY t1.index"
|
||||
err = GetRows(db, &recipeStepList, sql, sqlParams...)
|
||||
return recipeStepList, err
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestQueryRecipes(t *testing.T) {
|
||||
db := GetDB()
|
||||
recipeList, _, err := QueryFoodRecipes(db, "", 0, "", "", nil, 0, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(recipeList) > 0 {
|
||||
t.Fatal("should not return list")
|
||||
}
|
||||
|
||||
recipeItemList, err := QueryFoodRecipesItems(db, -1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(recipeItemList) > 0 {
|
||||
t.Fatal("should not return list")
|
||||
}
|
||||
|
||||
choiceList, err := QueryFoodRecipesItemChoices(db, -1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(choiceList) > 0 {
|
||||
t.Fatal("should not return list")
|
||||
}
|
||||
|
||||
stepList, err := QueryFoodRecipesSteps(db, -1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(stepList) > 0 {
|
||||
t.Fatal("should not return list")
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type PageShopWithPlaceName struct {
|
||||
model.PageShop
|
||||
|
||||
CityName string `json:"cityName"`
|
||||
DistrictName string `json:"districtName"`
|
||||
Distance int `json:"distance"`
|
||||
}
|
||||
|
||||
func QueryPageStores(db *DaoDB, pageSize, offset int, keyword string, vendorStoreID string, vendorID int, orgCode string,
|
||||
cityCode, districtCode int, tel string, minShopScore float32, minRecentOrderNum, minSkuCount int,
|
||||
lng1, lat1, lng2, lat2 float64) (pagedInfo *model.PagedInfo, err error) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
t1.*,
|
||||
t2.name city_name, t3.name district_name
|
||||
FROM page_shop t1
|
||||
LEFT JOIN place t2 ON t2.code = t1.city_code
|
||||
LEFT JOIN place t3 ON t3.code = t1.district_code
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
|
||||
if vendorStoreID != "" {
|
||||
sql += " AND t1.vendor_store_id = ?"
|
||||
sqlParams = append(sqlParams, vendorStoreID)
|
||||
}
|
||||
if vendorID != -1 {
|
||||
sql += " AND t1.vendor_id = ?"
|
||||
sqlParams = append(sqlParams, vendorID)
|
||||
}
|
||||
if orgCode != "" {
|
||||
sql += " AND t1.org_code = ?"
|
||||
sqlParams = append(sqlParams, orgCode)
|
||||
}
|
||||
if cityCode != 0 {
|
||||
sql += " AND t1.city_code = ?"
|
||||
sqlParams = append(sqlParams, cityCode)
|
||||
}
|
||||
if districtCode != 0 {
|
||||
sql += " AND t1.district_code = ?"
|
||||
sqlParams = append(sqlParams, districtCode)
|
||||
}
|
||||
if tel != "" {
|
||||
sql += " AND t1.tel1 = ?"
|
||||
sqlParams = append(sqlParams, tel)
|
||||
}
|
||||
if minShopScore > 0 {
|
||||
sql += " AND t1.shop_score >= ?"
|
||||
sqlParams = append(sqlParams, minShopScore)
|
||||
}
|
||||
if minRecentOrderNum > 0 {
|
||||
sql += " AND t1.recent_order_num >= ?"
|
||||
sqlParams = append(sqlParams, minRecentOrderNum)
|
||||
}
|
||||
if minSkuCount > 0 {
|
||||
sql += " AND t1.sku_count >= ?"
|
||||
sqlParams = append(sqlParams, minSkuCount)
|
||||
}
|
||||
if lng1 > 0 {
|
||||
sql += " AND t1.lng >= ? AND t1.lat >= ? AND t1.lng <= ? AND t1.lat <= ?"
|
||||
sqlParams = append(sqlParams, lng1, lat1, lng2, lat2)
|
||||
}
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " AND (t1.name LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.org_code LIKE ? OR t1.address LIKE ? OR t2.name LIKE ? OR t3.name LIKE ? OR t1.licence_code LIKE ?"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
sql += ")"
|
||||
}
|
||||
sql += `
|
||||
ORDER BY t1.recent_order_num DESC
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
var shopList []*PageShopWithPlaceName
|
||||
Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if err = GetRows(db, &shopList, sql, sqlParams...); err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCount(db),
|
||||
Data: shopList,
|
||||
}
|
||||
Commit(db)
|
||||
} else {
|
||||
Rollback(db)
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
Reference in New Issue
Block a user