删一些东西
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtunionapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/tbunionapi"
|
||||
@@ -10,8 +9,6 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/ejyapi"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
@@ -67,24 +64,6 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||
"operateType": model.OperateTypeName,
|
||||
"apiFunctionName": model.ApiFunctionName,
|
||||
"vendorStatus": model.VendorStatus,
|
||||
"jobLimitCountType": `[{
|
||||
"id":` + utils.Int2Str(model.JobLimitCountTypePO) +
|
||||
`,"value": "每人一次"
|
||||
},{
|
||||
"id":` + utils.Int2Str(model.JobLimitCountTypePDO) +
|
||||
`,"value": "每人每天一次"
|
||||
},{
|
||||
"id":` + utils.Int2Str(model.JobLimitCountTypePWO) +
|
||||
`,"value": "每人每周一次"
|
||||
},{
|
||||
"id":` + utils.Int2Str(model.JobLimitCountTypeNoLimit) +
|
||||
`,"value": "不限次"
|
||||
}]`,
|
||||
"billTypeNames": model.BillTypeNames,
|
||||
"deliveryStatusName": model.DeliveryStatusName,
|
||||
"cashbackName": model.CashbackName,
|
||||
"consumeName": model.ConsumeName,
|
||||
"txWaybillNames": model.TxWaybillNames,
|
||||
"unionActTypeNames": map[int]map[int]interface{}{
|
||||
model.VendorIDMTWM: map[int]interface{}{
|
||||
mtunionapi.ActTypeQB: "券包推广",
|
||||
@@ -205,38 +184,3 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
|
||||
func QueryConfigs(key, configType, keyword string) (configList []*model.NewConfig, err error) {
|
||||
return dao.QueryConfigs(dao.GetDB(), key, configType, keyword)
|
||||
}
|
||||
|
||||
func EjyStationToStationInfo(station *ejyapi.GetStationListResult) (stationInfo *model.StationInfo) {
|
||||
stationInfo = &model.StationInfo{
|
||||
StationID: station.StationID,
|
||||
StationName: station.StationName,
|
||||
ProvinceName: station.ProvinceName,
|
||||
ProvinceID: station.ProvinceID,
|
||||
CityName: station.CityName,
|
||||
Latitude: utils.Str2Float64(station.Latitude),
|
||||
Longitude: utils.Str2Float64(station.Longitude),
|
||||
Location: station.Location,
|
||||
StarNum: station.StarNum,
|
||||
Phone: station.Phone,
|
||||
StationPic: station.StationPic,
|
||||
StationBannerPic: station.StationBannerPic,
|
||||
District: station.District,
|
||||
CityID: station.CityID,
|
||||
StationType: station.StationType,
|
||||
}
|
||||
if station.Prices != nil {
|
||||
if data, err := json.Marshal(station.Prices); err == nil {
|
||||
stationInfo.Prices = string(data)
|
||||
}
|
||||
}
|
||||
if station.Adverts != nil {
|
||||
if data, err := json.Marshal(station.Adverts); err == nil {
|
||||
stationInfo.Adverts = string(data)
|
||||
}
|
||||
}
|
||||
return stationInfo
|
||||
}
|
||||
|
||||
func GetStationList(ctx *jxcontext.Context, stationName string, cityCode int, lat, lng float64, oilCode string, sortType, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
return dao.GetStationInfoList(dao.GetDB(), stationName, cityCode, lat, lng, oilCode, sortType, offset, pageSize)
|
||||
}
|
||||
|
||||
@@ -1,287 +0,0 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func GetMenu(ctx *jxcontext.Context, userID string) (menus []*model.Menu, err error) {
|
||||
if userID == "" {
|
||||
return dao.GetMenu(dao.GetDB(), "", 0, userID)
|
||||
} else {
|
||||
return dao.GetMenuWithUser(dao.GetDB(), "", 0, userID)
|
||||
}
|
||||
}
|
||||
|
||||
func AddMenu(ctx *jxcontext.Context, menu *model.Menu) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if menu == nil {
|
||||
return fmt.Errorf("添加失败!menu nil")
|
||||
}
|
||||
if menu.Name == "" || menu.Level == 0 {
|
||||
return fmt.Errorf("添加失败!menu 名称和等级必须有值!")
|
||||
}
|
||||
menus, err := dao.GetMenu(db, menu.Name, menu.Level, "")
|
||||
if len(menus) > 0 {
|
||||
return fmt.Errorf("添加失败!已存在相同名称的 menu name : %v", menu.Name)
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
dao.WrapAddIDCULDEntity(menu, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, menu)
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateMenu(ctx *jxcontext.Context, menuID int, payload map[string]interface{}, isDelete bool) (num int64, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
menu := &model.Menu{}
|
||||
menu.ID = menuID
|
||||
err = dao.GetEntity(db, menu)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if !isDelete {
|
||||
valid := dao.StrictMakeMapByStructObject(payload, menu, ctx.GetUserName())
|
||||
if len(valid) > 0 {
|
||||
if num, err = dao.UpdateEntityLogically(db, menu, valid, ctx.GetUserName(), nil); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
menu.DeletedAt = time.Now()
|
||||
num, err = dao.UpdateEntity(db, menu, "DeletedAt")
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func GetRole(ctx *jxcontext.Context) (roles []*model.Role, err error) {
|
||||
return dao.GetRole(dao.GetDB(), "")
|
||||
}
|
||||
|
||||
func AddRole(ctx *jxcontext.Context, name string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
roles, err := dao.GetRole(db, name)
|
||||
if len(roles) > 0 {
|
||||
return fmt.Errorf("添加失败!已存在相同名称的 role name : %v", name)
|
||||
}
|
||||
role := &model.Role{
|
||||
Name: name,
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
dao.WrapAddIDCULDEntity(role, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, role)
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateRole(ctx *jxcontext.Context, roleID int, name string, isDelete bool) (num int64, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if roleID == 1 {
|
||||
return 0, fmt.Errorf("管理员不允许修改!")
|
||||
}
|
||||
role := &model.Role{}
|
||||
role.ID = roleID
|
||||
err = dao.GetEntity(db, role)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if !isDelete {
|
||||
role.Name = name
|
||||
role.UpdatedAt = time.Now()
|
||||
role.LastOperator = ctx.GetUserName()
|
||||
num, err = dao.UpdateEntity(db, role, "Name", "UpdatedAt", "LastOperator")
|
||||
} else {
|
||||
role.DeletedAt = time.Now()
|
||||
num, err = dao.UpdateEntity(db, role, "DeletedAt")
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func GetUserRole(ctx *jxcontext.Context, userID string) (userRoles []*model.UserRole, err error) {
|
||||
return dao.GetUserRole(dao.GetDB(), []string{userID}, nil)
|
||||
}
|
||||
|
||||
func UpdateUserRole(ctx *jxcontext.Context, userIDs []string, roleIDs []int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
roleIDMap = make(map[int]int)
|
||||
nowRoleIDMap = make(map[int]int)
|
||||
userRoleMap = make(map[string][]int)
|
||||
addUserRoleMap = make(map[string][]int)
|
||||
deleteUserRoleMap = make(map[string][]int)
|
||||
)
|
||||
for _, v := range roleIDs {
|
||||
roleIDMap[v] = 1
|
||||
}
|
||||
userRoles, err := dao.GetUserRole(db, userIDs, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(userRoles) > 0 {
|
||||
for _, v := range userRoles {
|
||||
userRoleMap[v.UserID] = append(userRoleMap[v.UserID], v.RoleID)
|
||||
}
|
||||
}
|
||||
for _, userID := range userIDs {
|
||||
nowRoleIDs := userRoleMap[userID]
|
||||
for _, nowRoleID := range nowRoleIDs {
|
||||
if roleIDMap[nowRoleID] == 0 {
|
||||
deleteUserRoleMap[userID] = append(deleteUserRoleMap[userID], nowRoleID)
|
||||
}
|
||||
nowRoleIDMap[nowRoleID] = 1
|
||||
}
|
||||
for _, roleID := range roleIDMap {
|
||||
if nowRoleIDMap[roleID] == 0 {
|
||||
addUserRoleMap[userID] = append(addUserRoleMap[userID], roleID)
|
||||
}
|
||||
}
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if len(addUserRoleMap) > 0 {
|
||||
for userID, roleIDs := range addUserRoleMap {
|
||||
for _, roleID := range roleIDs {
|
||||
userRole := &model.UserRole{
|
||||
UserID: userID,
|
||||
RoleID: roleID,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(userRole, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, userRole)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(deleteUserRoleMap) > 0 {
|
||||
for userID, roleIDs := range deleteUserRoleMap {
|
||||
for _, roleID := range roleIDs {
|
||||
userRoles, _ := dao.GetUserRole(db, []string{userID}, []int{roleID})
|
||||
if len(userRoles) > 0 {
|
||||
userRoles[0].DeletedAt = time.Now()
|
||||
userRoles[0].LastOperator = ctx.GetUserName()
|
||||
_, err = dao.UpdateEntity(db, userRoles[0], "DeletedAt", "LastOperator")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetRoleMenu(ctx *jxcontext.Context, roleID int) (roleMenus []*model.RoleMenu, err error) {
|
||||
return dao.GetRoleMenu(dao.GetDB(), []int{roleID}, nil)
|
||||
}
|
||||
|
||||
func UpdateRoleMenu(ctx *jxcontext.Context, roleIDs, menuIDs []int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
menuIDMap = make(map[int]int)
|
||||
nowMenuIDMap = make(map[int]int)
|
||||
roleMenuMap = make(map[int][]int)
|
||||
addRoleMenuMap = make(map[int][]int)
|
||||
deleteRoleMenuMap = make(map[int][]int)
|
||||
)
|
||||
for _, v := range menuIDs {
|
||||
menuIDMap[v] = 1
|
||||
}
|
||||
roleMenus, err := dao.GetRoleMenu(db, roleIDs, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(roleMenus) > 0 {
|
||||
for _, v := range roleMenus {
|
||||
roleMenuMap[v.RoleID] = append(roleMenuMap[v.RoleID], v.MenuID)
|
||||
}
|
||||
}
|
||||
for _, roleID := range roleIDs {
|
||||
nowMenuIDs := roleMenuMap[roleID]
|
||||
for _, nowMenuID := range nowMenuIDs {
|
||||
if menuIDMap[nowMenuID] == 0 {
|
||||
deleteRoleMenuMap[roleID] = append(deleteRoleMenuMap[roleID], nowMenuID)
|
||||
}
|
||||
nowMenuIDMap[nowMenuID] = 1
|
||||
}
|
||||
for _, menuID := range menuIDMap {
|
||||
if nowMenuIDMap[menuID] == 0 {
|
||||
addRoleMenuMap[menuID] = append(addRoleMenuMap[menuID], menuID)
|
||||
}
|
||||
}
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if len(addRoleMenuMap) > 0 {
|
||||
for roleID, menuIDs := range addRoleMenuMap {
|
||||
for _, menuID := range menuIDs {
|
||||
roleMenu := &model.RoleMenu{
|
||||
RoleID: roleID,
|
||||
MenuID: menuID,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(roleMenu, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, roleMenu)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(deleteRoleMenuMap) > 0 {
|
||||
for roleID, menuIDs := range deleteRoleMenuMap {
|
||||
for _, menuID := range menuIDs {
|
||||
roleMenus, _ := dao.GetRoleMenu(db, []int{roleID}, []int{menuID})
|
||||
if len(roleMenus) > 0 {
|
||||
roleMenus[0].DeletedAt = time.Now()
|
||||
roleMenus[0].LastOperator = ctx.GetUserName()
|
||||
_, err = dao.UpdateEntity(db, roleMenus[0], "DeletedAt", "LastOperator")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
return err
|
||||
}
|
||||
@@ -92,6 +92,7 @@ func DoPrint(appID int, msgID, printNo, content string, orderNo int) (err error)
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
//打印机必须绑定在该应用下才能打印
|
||||
|
||||
printMsg := &model.PrintMsg{
|
||||
PrintNo: printNo,
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package cms
|
||||
|
||||
var (
|
||||
textChan chan string
|
||||
)
|
||||
|
||||
func TestTemp() {
|
||||
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"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"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -50,18 +49,6 @@ type JdUserStruct struct {
|
||||
type UserProvider struct {
|
||||
}
|
||||
|
||||
func (*UserProvider) GetUser(authID, authIDType string) (user auth2.IUser) {
|
||||
globals.SugarLogger.Debugf("GetUser, authID:%s, authIDType:%s", authID, authIDType)
|
||||
fieldName := authTypeFieldMap[authIDType]
|
||||
if fieldName != "" {
|
||||
user2, err := dao.GetUserByID(dao.GetDB(), fieldName, authID)
|
||||
if err == nil {
|
||||
user = user2 // 这样写的原因是golang nil的比较问题
|
||||
}
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
func (*UserProvider) UpdateUserMobile(userID string, mobile string) (err error) {
|
||||
_, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
|
||||
"Mobile": mobile,
|
||||
@@ -110,10 +97,6 @@ func (*UserProvider) UpdateLastLogin(userID string, lastLoginType, fromIP string
|
||||
return err
|
||||
}
|
||||
|
||||
func init() {
|
||||
auth2.Init(userProvider)
|
||||
}
|
||||
|
||||
func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, err error) {
|
||||
authInfo, err := ctx.GetV2AuthInfo()
|
||||
if err == nil {
|
||||
@@ -134,28 +117,6 @@ func DisableUser(ctx *jxcontext.Context, userID string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUsers(ctx *jxcontext.Context, keyword string, userID string, pop int, mobile string, fromTime, toTime string, timeType int, cityCodes, consumeTypes []int, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
return dao.GetUsers2(dao.GetDB(), keyword, userID, pop, mobile, utils.Str2Time(fromTime), utils.Str2Time(toTime), timeType, cityCodes, consumeTypes, offset, pageSize)
|
||||
}
|
||||
|
||||
func GetUser(ctx *jxcontext.Context, userID string) (user *model.GetUserResult, err error) {
|
||||
return dao.GetUser(dao.GetDB(), userID)
|
||||
}
|
||||
|
||||
func checkUserType(userID string, userType int8) (err error) {
|
||||
userList, _, err := dao.GetUsers(dao.GetDB(), 0, "", "", []string{userID}, nil, nil, 0, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(userList) == 0 {
|
||||
return fmt.Errorf("找不到用户:%s", userID)
|
||||
}
|
||||
if userList[0].Type&userType == 0 {
|
||||
return fmt.Errorf("用户:%s不能用于当前操作", userID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -169,28 +130,6 @@ func DeleteUserDeliveryAddress(ctx *jxcontext.Context, userID string, addressID
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteMyDeliveryAddress(ctx *jxcontext.Context, addressID int) (err error) {
|
||||
_, userID := ctx.GetMobileAndUserID()
|
||||
return DeleteUserDeliveryAddress(ctx, userID, addressID)
|
||||
}
|
||||
|
||||
func QueryUserDeliveryAddress(ctx *jxcontext.Context, userIDs []string, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
addressList, totalCount, err := dao.QueryUserDeliveryAddress(dao.GetDB(), 0, userIDs, 0, offset, pageSize)
|
||||
if err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
TotalCount: totalCount,
|
||||
Data: addressList,
|
||||
}
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func QueryMyDeliveryAddress(ctx *jxcontext.Context, addType int) (addressList []*dao.UserDeliveryAddressEx, err error) {
|
||||
_, userID := ctx.GetMobileAndUserID()
|
||||
addressList, _, err = dao.QueryUserDeliveryAddress(dao.GetDB(), 0, []string{userID}, addType, 0, model.UnlimitedPageSize)
|
||||
return addressList, err
|
||||
}
|
||||
|
||||
func SaveUserCart(ctx *jxcontext.Context, userID string, storeID int, cartItems []*model.UserCartItem) (err error) {
|
||||
if userID == "" || storeID == 0 {
|
||||
return fmt.Errorf("用户与门店必须要指定")
|
||||
@@ -241,20 +180,6 @@ func LoadUserCart(ctx *jxcontext.Context, userID string, storeIDs []int) (cartIt
|
||||
return cartItems, err
|
||||
}
|
||||
|
||||
func RefreshUserMemberStatus(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
userMembers, err := dao.GetUserMember(db, "", 0)
|
||||
for _, userMember := range userMembers {
|
||||
if time.Now().Sub(userMember.EndAt) > 0 {
|
||||
userMember.DeletedAt = time.Now()
|
||||
dao.UpdateEntity(db, userMember, "DeletedAt")
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
type GetUserSerachKeywordResult struct {
|
||||
AllSpan []*model.UserSearch `json:"allSpan"`
|
||||
UserSpan []*model.UserSearch `json:"userSpan"`
|
||||
|
||||
Reference in New Issue
Block a user