This commit is contained in:
苏尹岚
2020-10-12 17:22:09 +08:00
parent 49c149c531
commit 81d8f3e421
9 changed files with 159 additions and 783 deletions

View File

@@ -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
}

View File

@@ -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")
}
}

View File

@@ -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
}

View File

@@ -99,6 +99,110 @@ func (user *User) GetAvatar() string {
return user.Avatar
}
type StoreBoss struct {
ModelIDCULD
UserID string `orm:"size(48);column(user_id);unique" json:"userID"` // 内部唯一标识
BossName string `orm:"size(48);index" json:"bossName"` // 门店老板真实姓名
StoreID int `orm:"column(store_id)" json:"storeID"`
ParentUserID string `orm:"size(48);column(parent_user_id)" json:"-"`
ReferrerID string `orm:"size(48);index" json:"referrerID"` // 推荐人ID
ReferrerName string `orm:"size(48);index" json:"referrerName"` // 推荐人姓名
CityCode int `json:"cityCode"` // 期望开店所在的城市
IDCardFront string `orm:"size(255);column(id_card_front)" json:"idCardFront"`
IDCardBack string `orm:"size(255);column(id_card_back)" json:"idCardBack"`
IDCardHand string `orm:"size(255);column(id_card_hand)" json:"idCardHand"`
Licence string `orm:"size(255)" json:"licence"`
LicenceCode string `orm:"size(32);index" json:"licenceCode"`
Remark string `orm:"type(text)" json:"-"`
}
// const (
// PaymentType
// )
type UserPayment struct {
ModelIDCULD
UserID string `orm:"size(48);column(user_id)" json:"userID"` // 内部唯一标识
Type int8 //
}
type UserDeliveryAddress struct {
ModelIDCULD
UserID string `orm:"size(48);column(user_id)" json:"userID"` // 内部唯一标识
Tag string `orm:"size(32)" json:"tag"`
ConsigneeName string `orm:"size(32)" json:"consigneeName"`
ConsigneeMobile string `orm:"size(32)" json:"consigneeMobile"`
Address string `orm:"size(255)" json:"address"` // 地址(区县以下,门牌号以上的地址信息)
DetailAddress string `orm:"size(255)" json:"detailAddress"` // 门牌号
Lng float64 `orm:"digits(10);decimals(6)" json:"lng"`
Lat float64 `orm:"digits(10);decimals(6)" json:"lat"`
AutoAddress string `orm:"size(255)" json:"autoAddress"` // 这个是通过坐标自动获取的结构化的地址
CityCode int `orm:"default(0);null" json:"cityCode"` // 根据坐标获得
DistrictCode int `orm:"default(0);null" json:"districtCode"` // 根据坐标获得
Remark string `orm:"type(text)" json:"remark"`
IsDefault int8 `json:"isDefault"`
}
func (*UserDeliveryAddress) TableUnique() [][]string {
return [][]string{
// []string{"UserID", "ConsigneeMobile", "DeletedAt"},
}
}
type UserCartItem struct {
ID int64 `orm:"column(id)" json:"-"`
CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
UpdatedAt time.Time `orm:"auto_now;type(datetime)" json:"-"`
LastOperator string `orm:"size(32)" json:"-"` // 最后操作员
UserID string `orm:"size(48);column(user_id)" json:"userID"`
StoreID int `orm:"column(store_id)" json:"storeID"`
SkuID int `orm:"column(sku_id)" json:"skuID"`
ActID int `orm:"column(act_id)" json:"actID"`
Count int `json:"count"`
Price int `json:"price"`
IsChecked int8 `json:"isChecked"`
}
func (*UserCartItem) TableUnique() [][]string {
return [][]string{
[]string{"UserID", "StoreID", "SkuID", "ActID"},
}
}
type UserAgreement struct {
ModelIDCULD
Name string `orm:"size(32);index" json:"name"` // 外部显示标识(当前可以重复)
Mobile string `orm:"size(32)" json:"mobile"`
IDNumber string `orm:"column(id_number);size(20)" json:"idNumber"`
BankNumber string `orm:"size(32)" json:"bankNumber"`
}
type UserOrderSms struct {
ID int64 `orm:"column(id)" json:"-"`
CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
UpdatedAt time.Time `orm:"auto_now;type(datetime)" json:"-"`
LastOperator string `orm:"size(32)" json:"-"` // 最后操作员
Mobile string `orm:"size(32)" json:"mobile"`
Name string `orm:"size(32)" json:"name"`
VendorUserID string `orm:"column(vendor_user_id)" json:"vendorUserID"`
SMSMark int `orm:"column(sms_mark)" json:"smsMark"`
TotalCount int `json:"totalCount"`
}
func (*UserOrderSms) TableUnique() [][]string {
return [][]string{
[]string{"Mobile"},
}
}
type UserMember struct {
ModelIDCULD
@@ -116,3 +220,58 @@ func (v *UserMember) TableIndex() [][]string {
[]string{"CreatedAt"},
}
}
type Role struct {
ModelIDCULD
Name string `json:"name"` //角色名
}
func (*Role) TableUnique() [][]string {
return [][]string{
[]string{"Name", "DeletedAt"},
}
}
type UserRole struct {
ModelIDCULD
UserID string `orm:"column(user_id)" json:"userID"` //用户ID
RoleID int `orm:"column(role_id)" json:"roleID"` //角色ID
}
func (*UserRole) TableUnique() [][]string {
return [][]string{
[]string{"UserID", "RoleID", "DeletedAt"},
}
}
type Menu struct {
ModelIDCULD
Name string `json:"name"` //功能名
URL string `orm:"column(url)" json:"url"` //路径
ImgURL string `orm:"column(img_url)" json:"imgURL"` //图标
Level int `json:"level"` //级别
ParentID int `orm:"column(parent_id)" json:"parentID"` //父功能ID
Color string `json:"color"` //颜色
}
func (*Menu) TableUnique() [][]string {
return [][]string{
[]string{"Name", "DeletedAt"},
}
}
type RoleMenu struct {
ModelIDCULD
RoleID int `orm:"column(role_id)" json:"roleID"` //角色ID
MenuID int `orm:"column(menu_id)" json:"menuID"` //功能ID
}
func (*RoleMenu) TableUnique() [][]string {
return [][]string{
[]string{"MenuID", "RoleID", "DeletedAt"},
}
}