This commit is contained in:
suyl
2021-07-12 16:27:33 +08:00
parent 60277b42d4
commit 5e493288f0
3 changed files with 10 additions and 211 deletions

View File

@@ -2,7 +2,6 @@ package cms
import (
"errors"
"fmt"
"sync"
"time"
@@ -116,94 +115,3 @@ func DisableUser(ctx *jxcontext.Context, userID string) (err error) {
}
return err
}
func DeleteUserDeliveryAddress(ctx *jxcontext.Context, userID string, addressID int) (err error) {
num, err := dao.DeleteEntityLogically(dao.GetDB(), &model.UserDeliveryAddress{}, nil, ctx.GetUserName(), map[string]interface{}{
model.FieldID: addressID,
"UserID": userID,
})
if err == nil {
if num == 0 {
err = fmt.Errorf("地址ID:%d不存在", addressID)
}
}
return err
}
func SaveUserCart(ctx *jxcontext.Context, userID string, storeID int, cartItems []*model.UserCartItem) (err error) {
if userID == "" || storeID == 0 {
return fmt.Errorf("用户与门店必须要指定")
}
for _, v := range cartItems {
v.UserID = userID
v.StoreID = storeID
dao.WrapAddIDCULEntity(v, userID)
}
db := dao.GetDB()
txDB, _ := dao.Begin(db)
defer func() {
if r := recover(); r != nil || err != nil {
dao.Rollback(db, txDB)
if r != nil {
panic(r)
}
}
}()
_, err = dao.ExecuteSQL(db, `
DELETE t1
FROM user_cart_item t1
WHERE t1.user_id = ? AND t1.store_id = ?
`, userID, storeID)
if err != nil {
return err
}
if len(cartItems) > 0 {
err = dao.CreateMultiEntities(db, cartItems)
}
if err == nil {
dao.Commit(db, txDB)
}
return err
}
func LoadUserCart(ctx *jxcontext.Context, userID string, storeIDs []int) (cartItems []*model.UserCartItem, err error) {
if userID == "" || len(storeIDs) == 0 {
return nil, fmt.Errorf("用户与门店必须要指定")
}
sql := `
SELECT t1.*
FROM user_cart_item t1
WHERE t1.user_id = ? AND t1.store_id IN (` + dao.GenQuestionMarks(len(storeIDs)) + `)
ORDER BY t1.sku_id
`
err = dao.GetRows(dao.GetDB(), &cartItems, sql, userID, storeIDs)
return cartItems, err
}
type GetUserSerachKeywordResult struct {
AllSpan []*model.UserSearch `json:"allSpan"`
UserSpan []*model.UserSearch `json:"userSpan"`
}
func GetUserSerachKeyword(ctx *jxcontext.Context) (getUserSerachKeywordResult *GetUserSerachKeywordResult, err error) {
var (
db = dao.GetDB()
userID = ctx.GetUserID()
userSearchAll []*model.UserSearch
userSearch []*model.UserSearch
)
getUserSerachKeywordResult = &GetUserSerachKeywordResult{}
sql := `
SELECT keyword, SUM(count) count FROM user_search WHERE created_at > ? GROUP BY 1 ORDER BY SUM(count) DESC LIMIT 20
`
sqlParams := []interface{}{time.Now().AddDate(0, -1, 0)}
err = dao.GetRows(db, &userSearchAll, sql, sqlParams)
getUserSerachKeywordResult.AllSpan = userSearchAll
sql2 := `
SELECT keyword, SUM(count) count FROM user_search WHERE created_at > ? AND user_id = ? GROUP BY 1 ORDER BY SUM(count) DESC LIMIT 20
`
sqlParams2 := []interface{}{time.Now().AddDate(0, -1, 0), userID}
err = dao.GetRows(db, &userSearch, sql2, sqlParams2)
getUserSerachKeywordResult.UserSpan = userSearch
return getUserSerachKeywordResult, err
}

View File

@@ -1,108 +0,0 @@
package dao
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
)
func GetMenu(db *DaoDB, name string, level int, userID string) (menus []*model.Menu, err error) {
sqlParams := []interface{}{}
sql := `
SELECT DISTINCT a.*
FROM menu a
`
if userID != "" {
sql += `
JOIN menu d ON d.parent_id = a.id
JOIN user_role b ON b.user_id = ?
JOIN role_menu c ON c.menu_id = d.id AND c.role_id = b.role_id
`
sqlParams = append(sqlParams, userID)
}
sql += " WHERE a.deleted_at = ?"
sqlParams = append(sqlParams, utils.DefaultTimeValue)
if name != "" {
sql += " AND a.name LIKE ?"
sqlParams = append(sqlParams, "%"+name+"%")
}
if level != 0 {
sql += " AND a.level = ?"
sqlParams = append(sqlParams, level)
}
err = GetRows(db, &menus, sql, sqlParams)
return menus, err
}
func GetMenuWithUser(db *DaoDB, name string, level int, userID string) (menus []*model.Menu, err error) {
sql := `
SELECT DISTINCT b.* FROM (
SELECT a.id,a.parent_id
FROM menu a
JOIN user_role b ON b.user_id = ?
JOIN role_menu c ON c.menu_id = a.id AND c.role_id = b.role_id
WHERE a.deleted_at = ?)a
JOIN menu b ON (b.id = a.id OR b.id = a.parent_id)
`
sqlParams := []interface{}{userID, utils.DefaultTimeValue}
err = GetRows(db, &menus, sql, sqlParams)
return menus, err
}
func GetRole(db *DaoDB, name string) (roles []*model.Role, err error) {
sql := `
SELECT *
FROM role
WHERE deleted_at = ?
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
}
if name != "" {
sql += " AND name LIKE ?"
sqlParams = append(sqlParams, "%"+name+"%")
}
err = GetRows(db, &roles, sql, sqlParams)
return roles, err
}
func GetUserRole(db *DaoDB, userIDs []string, roleIDs []int) (userRoles []*model.UserRole, err error) {
sql := `
SELECT *
FROM user_role
WHERE deleted_at = ?
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
}
if len(userIDs) > 0 {
sql += " AND user_id IN (" + GenQuestionMarks(len(userIDs)) + ")"
sqlParams = append(sqlParams, userIDs)
}
if len(roleIDs) > 0 {
sql += " AND role_id IN (" + GenQuestionMarks(len(roleIDs)) + ")"
sqlParams = append(sqlParams, roleIDs)
}
err = GetRows(db, &userRoles, sql, sqlParams)
return userRoles, err
}
func GetRoleMenu(db *DaoDB, roleIDs, menuIDs []int) (roleMenus []*model.RoleMenu, err error) {
sql := `
SELECT *
FROM role_menu
WHERE deleted_at = ?
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
}
if len(roleIDs) > 0 {
sql += " AND role_id IN (" + GenQuestionMarks(len(roleIDs)) + ")"
sqlParams = append(sqlParams, roleIDs)
}
if len(menuIDs) > 0 {
sql += " AND menu_id IN (" + GenQuestionMarks(len(menuIDs)) + ")"
sqlParams = append(sqlParams, menuIDs)
}
err = GetRows(db, &roleMenus, sql, sqlParams)
return roleMenus, err
}

View File

@@ -59,17 +59,16 @@ func (*MessageStatus) TableIndex() [][]string {
type ImMessageRecord struct {
ModelIDCULD
UserID string `orm:"size(48);column(user_id)" json:"userID"` //发消息的userID
GroupID int `orm:"column(group_id)" json:"groupID"` //组ID
Content string `orm:"type(text)" json:"content"` //消息内容
MessageType int `json:"messageType"` //消息类型1文字2图片,3音频
Seq int64 `json:"seq"`
Weight int `json:"weight"`
Height int `json:"height"`
AudioLength string `json:"audioLength"`
Key string `orm:"-" json:"key"`
ToUserID string `orm:"size(48);column(to_user_id)" json:"toUserID"` //收消息的userID
UserInfo *GetUserResult `orm:"-" json:"userInfo"`
UserID string `orm:"size(48);column(user_id)" json:"userID"` //发消息的userID
GroupID int `orm:"column(group_id)" json:"groupID"` //组ID
Content string `orm:"type(text)" json:"content"` //消息内容
MessageType int `json:"messageType"` //消息类型1文字2图片,3音频
Seq int64 `json:"seq"`
Weight int `json:"weight"`
Height int `json:"height"`
AudioLength string `json:"audioLength"`
Key string `orm:"-" json:"key"`
ToUserID string `orm:"size(48);column(to_user_id)" json:"toUserID"` //收消息的userID
}
func (*ImMessageRecord) TableIndex() [][]string {