删除一些不要的
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
)
|
||||
|
||||
// todo 是否需要将Store.MarketManPhone与OperatorPhone成角色?
|
||||
|
||||
func TransferLegacyWeixins(mobile string) (err error) {
|
||||
globals.SugarLogger.Debugf("TransferLegacyWeixins mobile:%s", mobile)
|
||||
if !globals.EnableWXAuth2 || globals.DisableWXAuth1 {
|
||||
return nil
|
||||
}
|
||||
remark4Transfer := "transfer"
|
||||
// DELETE t1
|
||||
// FROM auth_bind t1
|
||||
// WHERE t1.remark = 'transfer';
|
||||
|
||||
// DELETE t1
|
||||
// FROM user t1
|
||||
// WHERE t1.remark = 'transfer';
|
||||
|
||||
// TRUNCATE TABLE casbin_rule;
|
||||
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM weixins t1
|
||||
LEFT JOIN user t2 ON t2.mobile = t1.tel
|
||||
LEFT JOIN auth_bind t3 ON t3.auth_id = t1.openid AND t3.type = 'weixinsns'
|
||||
LEFT JOIN auth_bind t4 ON t4.auth_id = t1.openid_mini AND t4.type = 'weixinmini'
|
||||
WHERE`
|
||||
sqlParams := []interface{}{}
|
||||
if mobile != "" {
|
||||
remark4Transfer = "transfer2"
|
||||
sql += " t1.tel = ?"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
} else {
|
||||
sql += " t2.id IS NULL OR (t1.openid <> '' AND t3.id IS NULL) OR (t1.openid_mini <> '' AND t4.id IS NULL)"
|
||||
}
|
||||
sql += " ORDER BY t1.parentid;"
|
||||
var weixinList []*legacymodel.WeiXins
|
||||
db := dao.GetDB()
|
||||
err = dao.GetRows(db, &weixinList, sql, sqlParams...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
parentMap := make(map[int]*legacymodel.WeiXins)
|
||||
for _, v := range weixinList {
|
||||
if v.ParentID == -1 {
|
||||
parentMap[v.ID] = v
|
||||
} else {
|
||||
if parentMap[v.ParentID] != nil {
|
||||
v.JxStoreID = parentMap[v.ParentID].JxStoreID
|
||||
}
|
||||
}
|
||||
if v.Tel != "" {
|
||||
user := &model.User{
|
||||
UserID2: v.Tel,
|
||||
Name: v.NickName,
|
||||
Mobile: &v.Tel,
|
||||
Type: model.UserTypeStoreBoss,
|
||||
Remark: remark4Transfer,
|
||||
}
|
||||
if user.Name == "" {
|
||||
user.Name = user.GetMobile()
|
||||
}
|
||||
userList, _, err2 := dao.GetUsers(db, 0, "", "", nil, nil, []string{v.Tel}, 0, -1)
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(user, false))
|
||||
if len(userList) == 0 {
|
||||
err = CreateUser(user, v.LastOperator)
|
||||
} else {
|
||||
user = userList[0]
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if v.OpenID != "" {
|
||||
auth2.AddAuthBind(user, &auth2.AuthInfo{
|
||||
AuthBindInfo: &auth2.AuthBindEx{
|
||||
AuthBind: model.AuthBind{
|
||||
Type: weixin.AuthTypeMP,
|
||||
AuthID: v.OpenID,
|
||||
AuthID2: v.OpenIDUnion,
|
||||
Remark: remark4Transfer,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
if v.OpenIDMini != "" {
|
||||
auth2.AddAuthBind(user, &auth2.AuthInfo{
|
||||
AuthBindInfo: &auth2.AuthBindEx{
|
||||
AuthBind: model.AuthBind{
|
||||
Type: weixin.AuthTypeMini,
|
||||
AuthID: v.OpenIDMini,
|
||||
AuthID2: v.OpenIDUnion,
|
||||
Remark: remark4Transfer,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
if v.JxStoreID > 0 { // 运营就不加到门店老板组里了
|
||||
if user.Type&model.UserTypeOperator == 0 {
|
||||
api2.RoleMan.AddRole4User(user.GetID(), autils.NewStoreBossRole(v.JxStoreID))
|
||||
}
|
||||
} else {
|
||||
if mobile != "" {
|
||||
rList, err2 := api2.RoleMan.GetUserRoleList(user.GetID())
|
||||
if err = err2; err == nil {
|
||||
for _, role := range rList {
|
||||
if role.StoreID > 0 {
|
||||
api2.RoleMan.DeleteRole4User(user.GetID(), autils.NewStoreBossRole(role.StoreID))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -12,18 +12,11 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/ejyapi"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -154,15 +147,6 @@ func GetPlaces(ctx *jxcontext.Context, keyword string, includeDisabled bool, par
|
||||
return places, dao.GetRows(nil, &places, sql, sqlParams)
|
||||
}
|
||||
|
||||
func GetCoordinateDistrictCode(ctx *jxcontext.Context, lng, lat float64) (code int, err error) {
|
||||
return api.AutonaviAPI.GetCoordinateDistrictCode(lng, lat), nil
|
||||
}
|
||||
|
||||
func GetCoordinateCityInfo(ctx *jxcontext.Context, lng, lat float64) (name string, err error) {
|
||||
name, _ = api.AutonaviAPI.GetCoordinateCityInfo(lng, lat)
|
||||
return name, err
|
||||
}
|
||||
|
||||
func SendMsg2Somebody(ctx *jxcontext.Context, mobileNum, verifyCode, msgType, msgContent string) (err error) {
|
||||
|
||||
return err
|
||||
@@ -187,47 +171,6 @@ func AddConfig(ctx *jxcontext.Context, key, configType, value string) (err error
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
|
||||
// if err = checkConfig(model.SyncFlagDeletedMask, configType, key, ""); err != nil {
|
||||
// return err
|
||||
// }
|
||||
db := dao.GetDB()
|
||||
switch configType {
|
||||
case model.ConfigTypePricePack:
|
||||
|
||||
case model.ConfigTypeFreightPack:
|
||||
|
||||
case model.ConfigTypeBank:
|
||||
//todo
|
||||
return fmt.Errorf("暂不支持删除银行")
|
||||
case model.ConfigTypeRole:
|
||||
errList := errlist.New()
|
||||
userIDs, err2 := api2.RoleMan.GetRoleUserList(autils.NewRole(key, 0))
|
||||
if err = err2; err == nil && len(userIDs) > 0 {
|
||||
userList, totalCount, err2 := dao.GetUsers(dao.GetDB(), 0, "", "", userIDs, nil, nil, 0, -1)
|
||||
if err = err2; err == nil && totalCount > 0 {
|
||||
// todo
|
||||
// err = fmt.Errorf("还有人员在使用角色:%s,人员信息:%s", key, utils.MustMarshal(utils.Struct2Map(userList, "compact")))
|
||||
err = fmt.Errorf("还有人员在使用角色:%s,人员信息:%s", key, utils.Format4Output(userList, false))
|
||||
}
|
||||
}
|
||||
errList.AddErr(err)
|
||||
|
||||
errList.AddErr(err)
|
||||
err = errList.GetErrListAsOne()
|
||||
}
|
||||
if err == nil {
|
||||
_, err = dao.DeleteEntityLogically(db, &model.NewConfig{}, nil, ctx.GetUserName(), map[string]interface{}{
|
||||
"Key": key,
|
||||
"Type": configType,
|
||||
})
|
||||
}
|
||||
if configType == model.ConfigTypeSys && err == nil {
|
||||
// err = onSysConfigChanged(key, "")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint string, err error) {
|
||||
if key == "" {
|
||||
return "", fmt.Errorf("修改配置必须给定key")
|
||||
@@ -269,74 +212,6 @@ func QueryConfigs(key, configType, keyword string) (configList []*model.NewConfi
|
||||
return dao.QueryConfigs(dao.GetDB(), key, configType, keyword)
|
||||
}
|
||||
|
||||
func InitStation(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
stationMap = make(map[string]*model.StationInfo)
|
||||
stationEjyMap = make(map[string]*ejyapi.GetStationListResult)
|
||||
addList []*model.StationInfo
|
||||
updateList []*model.StationInfo
|
||||
deleteList []*model.StationInfo
|
||||
)
|
||||
api.EjyAPI.SetTimestamp(time.Now().Unix())
|
||||
if stations, err := dao.GetStationList(db); len(stations) > 0 && err == nil {
|
||||
for _, v := range stations {
|
||||
stationMap[v.StationID] = v
|
||||
}
|
||||
}
|
||||
if getStationListResult, err := api.EjyAPI.GetStationList(); len(getStationListResult) > 0 && err == nil {
|
||||
for _, v := range getStationListResult {
|
||||
stationEjyMap[v.StationID] = v
|
||||
if stationMap[v.StationID] == nil {
|
||||
addList = append(addList, EjyStationToStationInfo(v))
|
||||
} else {
|
||||
updateList = append(updateList, stationMap[v.StationID])
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, v := range stationMap {
|
||||
if stationEjyMap[v.StationID] == nil {
|
||||
deleteList = append(deleteList, v)
|
||||
}
|
||||
}
|
||||
task := tasksch.NewParallelTask("InitStation", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 0:
|
||||
if len(addList) > 0 {
|
||||
err = dao.CreateMultiEntities(db, addList)
|
||||
}
|
||||
case 1:
|
||||
if len(updateList) > 0 {
|
||||
task := tasksch.NewParallelTask("updateList", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
station := batchItemList[0].(*model.StationInfo)
|
||||
dao.UpdateEntity(db, station)
|
||||
return retVal, err
|
||||
}, updateList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
case 2:
|
||||
if len(deleteList) > 0 {
|
||||
task := tasksch.NewParallelTask("deleteList", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
station := batchItemList[0].(*model.StationInfo)
|
||||
dao.DeleteEntity(db, station)
|
||||
return retVal, err
|
||||
}, deleteList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{0, 1, 2})
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
return err
|
||||
}
|
||||
|
||||
func EjyStationToStationInfo(station *ejyapi.GetStationListResult) (stationInfo *model.StationInfo) {
|
||||
stationInfo = &model.StationInfo{
|
||||
StationID: station.StationID,
|
||||
|
||||
Reference in New Issue
Block a user