Files
jx-callback/business/jxstore/cms/cms.go
2021-07-08 11:41:25 +08:00

187 lines
5.2 KiB
Go

package cms
import (
"fmt"
"git.rosy.net.cn/baseapi/platformapi/mtunionapi"
"git.rosy.net.cn/baseapi/platformapi/tbunionapi"
"reflect"
"regexp"
"strconv"
"time"
"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"
)
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,
"vendorColors": model.VendorColors,
"orderStatus": model.OrderStatusName,
"waybillStatus": model.WaybillStatusName,
"orderTypeName": model.OrderTypeName,
"taskStatusName": tasksch.TaskStatusName,
"storeMsgSendStatusName": model.StoreMsgSendStatusName,
"printerVendorInfo": model.PrinterVendorInfo,
"purchaseVendorInfo": model.PurchaseVendorInfo,
"afsReasonTypeName": model.AfsReasonTypeName,
"afsAppealTypeName": model.AfsAppealTypeName,
"configTypeName": model.ConfigTypeName,
"userTypeName": model.UserTypeName,
"complaintReasons": model.ComplaintReasons,
"supplementType": model.SupplementTypeName,
"operateType": model.OperateTypeName,
"apiFunctionName": model.ApiFunctionName,
"vendorStatus": model.VendorStatus,
"unionActTypeNames": map[int]map[int]interface{}{
model.VendorIDMTWM: map[int]interface{}{
mtunionapi.ActTypeQB: "券包推广",
},
model.VendorIDTB: map[int]interface{}{
tbunionapi.TbElmActTypeBDH: "本地化",
},
model.VendorIDPDD: map[int]interface{}{
1: "进行中的活动",
},
model.VendorIDJDShop: map[int]interface{}{
2: "进行中",
},
},
"unionOrderStatusName": model.UnionOrderStatusName,
},
}
}
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 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 UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint string, err error) {
if key == "" {
return "", fmt.Errorf("修改配置必须给定key")
}
hint = "1"
db := dao.GetDB()
txDB, _ := dao.Begin(db)
defer func() {
if r := recover(); r != nil {
dao.Rollback(db, txDB)
panic(r)
}
}()
configList, err := dao.QueryConfigs(db, key, configType, "")
if err != nil {
dao.Rollback(db, txDB)
return "", err
}
if _, err = dao.UpdateEntityLogically(db, configList[0], map[string]interface{}{
"Value": value,
}, ctx.GetUserName(), nil); err != nil {
dao.Rollback(db, txDB)
return "", err
}
switch configType {
case model.ConfigTypePricePack:
default:
dao.Commit(db, txDB)
}
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)
}