243 lines
7.2 KiB
Go
243 lines
7.2 KiB
Go
package cms
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"git.rosy.net.cn/baseapi/platformapi/mtunionapi"
|
|
"git.rosy.net.cn/baseapi/platformapi/tbunionapi"
|
|
"reflect"
|
|
"regexp"
|
|
"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"
|
|
"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,
|
|
"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: "券包推广",
|
|
},
|
|
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)
|
|
}
|
|
|
|
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)
|
|
}
|