248 lines
7.2 KiB
Go
248 lines
7.2 KiB
Go
package cms
|
||
|
||
import (
|
||
"fmt"
|
||
"reflect"
|
||
"regexp"
|
||
"strconv"
|
||
"time"
|
||
|
||
"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 (
|
||
SendMsgTypeOpenStoreRequest = "openStoreRequest"
|
||
SendMsgTypeSuggestRequest = "suggestRequest"
|
||
)
|
||
|
||
type SysConfigLimit struct {
|
||
ValueType reflect.Kind
|
||
MinValue int64
|
||
MaxValue int64
|
||
AfterChanged func() error
|
||
}
|
||
|
||
var (
|
||
serviceInfo map[string]interface{}
|
||
regexpMsgContentOpID = regexp.MustCompile(`"openid":"(.*?)"`)
|
||
)
|
||
|
||
func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||
buildTimeStr := ""
|
||
if !utils.IsTimeZero(buildTime) {
|
||
buildTimeStr = utils.Time2Str(buildTime)
|
||
}
|
||
serviceInfo = map[string]interface{}{
|
||
"startupTime": utils.Time2Str(time.Now()),
|
||
"version": version,
|
||
"buildTime": buildTimeStr,
|
||
"gitCommit": gitCommit,
|
||
"metaData": map[string]interface{}{
|
||
"vendorTypeName": model.VendorTypeName,
|
||
"vendorName": model.VendorChineseNames,
|
||
"vendorImg": model.VendorImg,
|
||
"orderStatus": model.OrderStatusName,
|
||
"waybillStatus": model.WaybillStatusName,
|
||
"orderTypeName": model.OrderTypeName,
|
||
"taskStatusName": tasksch.TaskStatusName,
|
||
"storeMsgSendStatusName": model.StoreMsgSendStatusName,
|
||
"shopChineseNames": model.ShopChineseNames,
|
||
"printerVendorInfo": model.PrinterVendorInfo,
|
||
"purchaseVendorInfo": model.PurchaseVendorInfo,
|
||
"afsReasonTypeName": model.AfsReasonTypeName,
|
||
"afsAppealTypeName": model.AfsAppealTypeName,
|
||
"actTypeName": model.ActTypeName,
|
||
"actStatusName": model.ActStatusName,
|
||
"actCreateTypeName": model.ActCreateTypeName,
|
||
"configTypeName": model.ConfigTypeName,
|
||
"userTypeName": model.UserTypeName,
|
||
"payStatusName": model.PayStatusName,
|
||
"refundStatusName": model.RefundStatusName,
|
||
"complaintReasons": model.ComplaintReasons,
|
||
"supplementType": model.SupplementTypeName,
|
||
"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": "不限次"
|
||
},{
|
||
"id":` + utils.Int2Str(1111111) +
|
||
`,"value": "测试"
|
||
}]`,
|
||
},
|
||
}
|
||
}
|
||
|
||
func GetServiceInfo(ctx *jxcontext.Context) map[string]interface{} {
|
||
return serviceInfo
|
||
}
|
||
|
||
func GetPlaces(ctx *jxcontext.Context, keyword string, includeDisabled bool, params map[string]interface{}) ([]*model.Place, error) {
|
||
sql := `
|
||
SELECT *
|
||
FROM place t1
|
||
WHERE 1 = 1
|
||
`
|
||
if !includeDisabled {
|
||
sql += " AND enabled = 1"
|
||
}
|
||
sqlParams := make([]interface{}, 0)
|
||
if keyword != "" {
|
||
sql += " AND (t1.name LIKE ?"
|
||
sqlParams = append(sqlParams, "%"+keyword+"%")
|
||
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
|
||
sql += " OR t1.code = ?"
|
||
sqlParams = append(sqlParams, keywordInt64)
|
||
}
|
||
sql += ")"
|
||
}
|
||
if params["parentCode"] != nil {
|
||
sql += " AND t1.parent_code = ?"
|
||
sqlParams = append(sqlParams, params["parentCode"])
|
||
}
|
||
if params["level"] != nil {
|
||
sql += " AND t1.level = ?"
|
||
sqlParams = append(sqlParams, params["level"])
|
||
}
|
||
sql += " ORDER BY t1.level, t1.name"
|
||
// globals.SugarLogger.Debug(sql)
|
||
places := []*model.Place{}
|
||
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
|
||
}
|
||
|
||
func AddConfig(ctx *jxcontext.Context, key, configType, value string) (err error) {
|
||
// if err = checkConfig(model.SyncFlagNewMask, configType, key, value); err != nil {
|
||
// return err
|
||
// }
|
||
|
||
db := dao.GetDB()
|
||
conf := &model.NewConfig{
|
||
Key: key,
|
||
Type: configType,
|
||
Value: value,
|
||
}
|
||
dao.WrapAddIDCULDEntity(conf, ctx.GetUserName())
|
||
err = dao.CreateEntity(db, conf)
|
||
if configType == model.ConfigTypeSys && err == nil {
|
||
// err = onSysConfigChanged(key, value)
|
||
}
|
||
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")
|
||
}
|
||
hint = "1"
|
||
|
||
db := dao.GetDB()
|
||
dao.Begin(db)
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
dao.Rollback(db)
|
||
panic(r)
|
||
}
|
||
}()
|
||
configList, err := dao.QueryConfigs(db, key, configType, "")
|
||
if err != nil {
|
||
dao.Rollback(db)
|
||
return "", err
|
||
}
|
||
if _, err = dao.UpdateEntityLogically(db, configList[0], map[string]interface{}{
|
||
"Value": value,
|
||
}, ctx.GetUserName(), nil); err != nil {
|
||
dao.Rollback(db)
|
||
return "", err
|
||
}
|
||
switch configType {
|
||
case model.ConfigTypePricePack:
|
||
|
||
default:
|
||
dao.Commit(db)
|
||
}
|
||
if configType == model.ConfigTypeSys && err == nil {
|
||
// err = onSysConfigChanged(key, value)
|
||
}
|
||
return hint, err
|
||
}
|
||
|
||
func QueryConfigs(key, configType, keyword string) (configList []*model.NewConfig, err error) {
|
||
return dao.QueryConfigs(dao.GetDB(), key, configType, keyword)
|
||
}
|