! remove all non order code.
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
const (
|
||||
DefTokenDuration = 7 * 24 * time.Hour // 7天
|
||||
)
|
||||
|
||||
type IAuther interface {
|
||||
Login(id, secret string) error
|
||||
Logout(id string) error
|
||||
}
|
||||
|
||||
var (
|
||||
authers map[string]IAuther
|
||||
)
|
||||
|
||||
var (
|
||||
ErrLoginTypeNotSupported = errors.New("不支持指定的登录类型")
|
||||
)
|
||||
|
||||
type LoginInfo struct {
|
||||
ID string
|
||||
LoginType string
|
||||
ExpiresIn int64
|
||||
Token string
|
||||
}
|
||||
|
||||
func init() {
|
||||
authers = make(map[string]IAuther)
|
||||
}
|
||||
|
||||
func RegisterAuther(loginType string, handler IAuther) {
|
||||
authers[loginType] = handler
|
||||
}
|
||||
|
||||
func Login(id, loginType, secret string) (loginInfo *LoginInfo, err error) {
|
||||
if handler := authers[loginType]; handler != nil {
|
||||
if err = handler.Login(id, secret); err == nil {
|
||||
token := utils.GetUUID()
|
||||
loginInfo = &LoginInfo{
|
||||
ID: id,
|
||||
LoginType: loginType,
|
||||
ExpiresIn: time.Now().Add(DefTokenDuration).Unix(),
|
||||
Token: token,
|
||||
}
|
||||
globals.Cacher.Set(token, loginInfo, DefTokenDuration)
|
||||
return loginInfo, nil
|
||||
}
|
||||
} else {
|
||||
err = ErrLoginTypeNotSupported
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func Logout(token string) (err error) {
|
||||
loginInfo := new(LoginInfo)
|
||||
if err = globals.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
if handler := authers[loginInfo.LoginType]; handler != nil {
|
||||
err = handler.Logout(loginInfo.ID)
|
||||
}
|
||||
globals.Cacher.Del(token)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUserInfo(token string) (loginInfo *LoginInfo, err error) {
|
||||
loginInfo = new(LoginInfo)
|
||||
if err = globals.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
return loginInfo, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package weixin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinsnsapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
LoginType = "weixinsns"
|
||||
DefTempPasswordDuration = 5 * time.Minute // 登录时间限制在5分钟内
|
||||
)
|
||||
|
||||
var (
|
||||
ErrLoginFailed = errors.New("登录失败")
|
||||
StrStateIsWrong = "state:%s状态不对"
|
||||
)
|
||||
|
||||
type Auther struct {
|
||||
}
|
||||
|
||||
type UserInfoExt struct {
|
||||
weixinsnsapi.UserInfo
|
||||
TempPassword string `json:"tempPassword"` // 一段时间有效的登录密码
|
||||
}
|
||||
|
||||
func init() {
|
||||
auth.RegisterAuther(LoginType, new(Auther))
|
||||
}
|
||||
|
||||
func GetUserInfo(code string, state string) (token *UserInfoExt, err error) {
|
||||
if state == "" {
|
||||
wxapi := weixinsnsapi.New(api.WeixinAPI.GetAppID(), api.WeixinAPI.GetSecret())
|
||||
token, err2 := wxapi.RefreshToken(code)
|
||||
if err = err2; err == nil {
|
||||
wxUserinfo, err2 := wxapi.GetUserInfo(token.OpenID)
|
||||
if err = err2; err == nil {
|
||||
pwd := utils.GetUUID()
|
||||
globals.Cacher.Set(wxUserinfo.OpenID, pwd, DefTempPasswordDuration)
|
||||
return &UserInfoExt{
|
||||
UserInfo: *wxUserinfo,
|
||||
TempPassword: pwd,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf(StrStateIsWrong, state)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (a *Auther) Login(openid, password string) error {
|
||||
if value := globals.Cacher.Get(openid); value != nil {
|
||||
if password == value.(string) {
|
||||
globals.Cacher.Del(openid)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return ErrLoginFailed
|
||||
}
|
||||
|
||||
func (a *Auther) Logout(openid string) error {
|
||||
return globals.Cacher.Del(openid)
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
||||
"github.com/qor/admin"
|
||||
"github.com/qor/qor"
|
||||
"github.com/qor/qor/resource"
|
||||
)
|
||||
|
||||
var (
|
||||
curAdmin *admin.Admin
|
||||
)
|
||||
|
||||
func Init() {
|
||||
gormdb.Init()
|
||||
curAdmin = admin.New(&admin.AdminConfig{
|
||||
DB: gormdb.GetDB(),
|
||||
SiteName: "京西管理系统v0.0.1",
|
||||
})
|
||||
storeRes := curAdmin.AddResource(&model.Store{})
|
||||
lngMeta := storeRes.GetMeta("Lng")
|
||||
lngMeta.Type = "float"
|
||||
lngMeta.SetSetter(func(record interface{}, metaValue *resource.MetaValue, context *qor.Context) {
|
||||
store := record.(*model.Store)
|
||||
store.Lng = int(utils.Str2Float64((metaValue.Value.([]string))[0]) * 1000000)
|
||||
globals.SugarLogger.Debugf("metaValue:%v", reflect.TypeOf(metaValue.Value))
|
||||
})
|
||||
lngMeta.SetValuer(func(record interface{}, context *qor.Context) (result interface{}) {
|
||||
store := record.(*model.Store)
|
||||
result = float64(store.Lng) / 1000000
|
||||
return result
|
||||
})
|
||||
curAdmin.AddResource(&model.StoreSub{})
|
||||
|
||||
curAdmin.AddResource(&model.Sku{})
|
||||
curAdmin.AddResource(&model.SkuName{})
|
||||
}
|
||||
|
||||
func GetAdmin() *admin.Admin {
|
||||
return curAdmin
|
||||
}
|
||||
|
||||
// func SaveMapSlice2DB(db *gorm.DB, data []map[string]interface{}, tableName string, keyMaps map[string]string) {
|
||||
// if len(data) == 0 {
|
||||
// return
|
||||
// }
|
||||
|
||||
// sql := "INSERT INTO " + tableName + "("
|
||||
// for k := range data[0] {
|
||||
// realK, ok := keyMaps[k]
|
||||
// if !ok {
|
||||
// realK = k
|
||||
// }
|
||||
// sql += realK + ","
|
||||
// }
|
||||
// sql = sql[:len(sql)-1] + ") "
|
||||
|
||||
// for _, dataRow := range data {
|
||||
// for k, v := range dataRow {
|
||||
// realK, ok := keyMaps[k]
|
||||
// if !ok {
|
||||
// realK = k
|
||||
// }
|
||||
// sql += "("
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -1,33 +0,0 @@
|
||||
package skuman
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
const (
|
||||
defJdCategoryID = 20462
|
||||
)
|
||||
|
||||
type Sku struct {
|
||||
*model.Sku
|
||||
}
|
||||
|
||||
func New(sku *model.Sku) *Sku {
|
||||
return &Sku{
|
||||
Sku: sku,
|
||||
}
|
||||
}
|
||||
|
||||
func GetJdCategoryID(sku *model.Sku) int {
|
||||
cat, _ := dao.GetCategory(sku.CategoryID, nil)
|
||||
jdCategoryID := defJdCategoryID
|
||||
if cat != nil && cat.JdCategoryID != 0 {
|
||||
jdCategoryID = cat.JdCategoryID
|
||||
}
|
||||
return jdCategoryID
|
||||
}
|
||||
|
||||
func GetCategories(sku *model.Sku) []int {
|
||||
return nil
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
func GetCategory(ID int, db *gorm.DB) (*model.SkuCategory, error) {
|
||||
if db == nil {
|
||||
db = gormdb.GetDB()
|
||||
}
|
||||
item := &model.SkuCategory{}
|
||||
item.ID = ID
|
||||
err := utils.CallFuncLogError(func() error {
|
||||
return db.First(item).Error
|
||||
}, "GetCategory")
|
||||
return item, err
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
func GetStore(ID int, db *gorm.DB) (*model.Store, error) {
|
||||
if db == nil {
|
||||
db = gormdb.GetDB()
|
||||
}
|
||||
item := &model.Store{}
|
||||
item.ID = ID
|
||||
err := utils.CallFuncLogError(func() error {
|
||||
return db.First(item).Error
|
||||
}, "GetStore")
|
||||
return item, err
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type ModelO struct {
|
||||
ID int `gorm:"primary_key"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt *time.Time `sql:"index"`
|
||||
LastOperator string `gorm:"type:varchar(32)"` // 最后操作员
|
||||
}
|
||||
|
||||
type ModelIDCU struct {
|
||||
ID int `gorm:"primary_key"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type ModelIDCUO struct {
|
||||
ID int `gorm:"primary_key"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
LastOperator string `gorm:"type:varchar(32)"` // 最后操作员
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// https://github.com/videni/pcr
|
||||
const (
|
||||
CityLevelProvince = 1
|
||||
CityLevelCity = 2
|
||||
CityLevelDistrict = 3
|
||||
)
|
||||
|
||||
type Place struct {
|
||||
ID int
|
||||
Code int `gorm:"unique_index"` // 国家标准代码
|
||||
Name string `gorm:"type:varchar(16);index"` // 如果是直辖市,省的概念不加“市”来区别
|
||||
ParentCode int // 上级代码
|
||||
PostCode string `gorm:"type:varchar(8);index"`
|
||||
Level int8 // 城市级别,参见相关常量定义
|
||||
TelCode string `gorm:"type:varchar(8);index"`
|
||||
JdCode int `gorm:"index"` // 对应的京东代码
|
||||
Enabled int8 // 是否启用
|
||||
MtpsPrice int // 分为单位
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
SkuCategoryNormal = 0
|
||||
SkuCategorySpecial = 1
|
||||
)
|
||||
|
||||
const (
|
||||
SpecUnitG = 0
|
||||
SpecUnitKG = 1
|
||||
SpecUnitL = 2
|
||||
SpecUnitML = 3
|
||||
)
|
||||
|
||||
var (
|
||||
SpecUnitNames = []string{
|
||||
"g",
|
||||
"kg",
|
||||
"L",
|
||||
"ml",
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
UnitNames = []string{
|
||||
"份",
|
||||
"袋",
|
||||
"瓶",
|
||||
"只",
|
||||
"组",
|
||||
"个",
|
||||
"盒",
|
||||
"把",
|
||||
"半只",
|
||||
"包",
|
||||
"条",
|
||||
"根",
|
||||
"箱",
|
||||
"听",
|
||||
"套",
|
||||
"罐",
|
||||
"件",
|
||||
"块",
|
||||
"片",
|
||||
"支",
|
||||
"杯",
|
||||
}
|
||||
)
|
||||
|
||||
// 这个指的是京东自已的商品分类,与商家自己的商品分类是两回事
|
||||
type SkuJdCategory struct {
|
||||
ModelIDCUO
|
||||
Name string `gorm:"type:varchar(255);index"`
|
||||
Level int
|
||||
ParentID int
|
||||
}
|
||||
|
||||
type SkuCategory struct {
|
||||
ModelIDCUO
|
||||
Name string `gorm:"type:varchar(255);unique_index"`
|
||||
ParentID int
|
||||
Level int8
|
||||
Type int8 // 类别类型
|
||||
Seq int
|
||||
|
||||
JdID int `gorm:"index"` // 这个是指商家自己的商品类别在京东平台上的ID
|
||||
JdCategoryID int // 这个是指对应的京东商品类别
|
||||
ElmID string `gorm:"type:varchar(48);index"`
|
||||
MtID string `gorm:"type:varchar(48);index"`
|
||||
DidiID string `gorm:"type:varchar(48);index"`
|
||||
}
|
||||
|
||||
type StoreSkuCategoryMap struct {
|
||||
ModelIDCUO
|
||||
StoreID int
|
||||
SkuCategoryID int
|
||||
|
||||
ElmID string `gorm:"type:varchar(48)"`
|
||||
}
|
||||
|
||||
type SkuName struct {
|
||||
ModelIDCUO
|
||||
Prefix string `gorm:"type:varchar(255)"`
|
||||
Name string `gorm:"type:varchar(255)"`
|
||||
Comment string `gorm:"type:varchar(255)"`
|
||||
|
||||
CategoryID int // 标准类别
|
||||
Status int
|
||||
|
||||
IsGlobal int8 `gorm:"default:1"` // 是否是全部(全国)可见,如果否的话,可见性由SkuPlace决定
|
||||
Unit string `gorm:"type:varchar(8)"`
|
||||
Price int // 单位为分,标准价,不为份的就为实际标准价,为份的为每市斤价,实际还要乘质量。todo 为份的确定必须有质量
|
||||
Img string `gorm:"type:varchar(255)"`
|
||||
ElmImgHashCode string `gorm:"type:varchar(64)"`
|
||||
}
|
||||
|
||||
type Sku struct {
|
||||
ModelIDCUO
|
||||
CategoryID int // 特殊类别,一般用于秒杀,特价之类的特殊类别
|
||||
NameID int `gorm:"index:unique_index_name_Id_quality"` // todo 这个索引应该要求唯一
|
||||
SpecQuality float32 `gorm:"index:unique_index_name_Id_quality"`
|
||||
SpecUnit string `gorm:"type:varchar(8)"`
|
||||
|
||||
Weight int // 单位为克,当相应的SkuName的SpecUnit为g或kg时,必须等于SpecQuality
|
||||
|
||||
JdID string `gorm:"type:varchar(48)"`
|
||||
}
|
||||
|
||||
type SkuNamePlaceBind struct {
|
||||
ModelIDCUO
|
||||
SkuNameID int `gorm:"unique_index:unique_sku_name_id_sku_place_id"`
|
||||
PlaceID int `gorm:"unique_index:unique_sku_name_id_sku_place_id"`
|
||||
}
|
||||
|
||||
type StoreSkuBind struct {
|
||||
ModelIDCUO
|
||||
StoreID int `gorm:"unique_index:unique_store_id_sku_id"`
|
||||
SkuID int `gorm:"unique_index:unique_store_id_sku_id"`
|
||||
SubStoreID int
|
||||
Price int // 单位为分,不用int64的原因是这里不需要累加
|
||||
Status int
|
||||
ElmID string `gorm:"type:varchar(48)"`
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
StoreStatusDisabled = -1
|
||||
StoreStatusClosed = 0
|
||||
StoreStatusOpened = 1
|
||||
)
|
||||
|
||||
const (
|
||||
MainSubStoreName = "本店"
|
||||
MainSubStoreAddress = "本店"
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
ModelIDCUO
|
||||
Name string `gorm:"type:varchar(255);unique_index"`
|
||||
CityCode int
|
||||
DistrictCode int
|
||||
Address string `gorm:"type:varchar(255)"`
|
||||
OpenTime1 int // 930就表示9点半,用两个的原因是为了支持中午休息,1与2的时间段不能交叉,为0表示没有
|
||||
CloseTime1 int // 格式同上
|
||||
OpenTime2 int // 格式同上
|
||||
CloseTime2 int // 格式同上
|
||||
Lng int // 乘了10的6次方
|
||||
Lat int // 乘了10的6次方
|
||||
Status int
|
||||
}
|
||||
|
||||
type StoreSub struct {
|
||||
ModelIDCUO
|
||||
StoreID int `gorm:"unique_index:unique_index1"`
|
||||
Index int `gorm:"unique_index:unique_index1"` // 子店序号,为0表示主店
|
||||
Name string `gorm:"type:varchar(255)"`
|
||||
Address string `gorm:"type:varchar(255)"`
|
||||
Status int
|
||||
Mobile1 string `gorm:"type:varchar(32)"`
|
||||
Mobile2 string `gorm:"type:varchar(32)"`
|
||||
Mobile3 string `gorm:"type:varchar(32)"`
|
||||
}
|
||||
|
||||
type StoreMap struct {
|
||||
ModelIDCUO
|
||||
StoreID int `gorm:"unique_index:storemap1"`
|
||||
VendorID int `gorm:"unique_index:storemap1"`
|
||||
VendorStoreID string `gorm:"type:varchar(48);unique_index"`
|
||||
Status int
|
||||
|
||||
AutoPickup int8 // 是否自动拣货
|
||||
DeliveryType int8 // 配送类型
|
||||
DeliveryCompetition int8 // 是否支持配送竞争
|
||||
}
|
||||
|
||||
type StoreCourierMap struct {
|
||||
ModelIDCUO
|
||||
StoreID int `gorm:"unique_index:storemap1"`
|
||||
VendorID int `gorm:"unique_index:storemap1"`
|
||||
VendorStoreID string `gorm:"type:varchar(48);unique_index"`
|
||||
Status int
|
||||
}
|
||||
@@ -36,25 +36,3 @@ func JdOperationTime2JxOperationTime(value1 interface{}) int {
|
||||
func JxOperationTime2JdOperationTime(value int) int {
|
||||
return (value/100)*2 + (value % 30)
|
||||
}
|
||||
|
||||
func JdStoreStatus2JxStatus(yn, closeStatus interface{}) int {
|
||||
yn2 := utils.Interface2Int64WithDefault(yn, 0)
|
||||
closeStatus2 := utils.Interface2Int64WithDefault(closeStatus, 0)
|
||||
if yn2 == 1 {
|
||||
return model.StoreStatusDisabled
|
||||
} else if closeStatus2 == 1 {
|
||||
return model.StoreStatusClosed
|
||||
}
|
||||
return model.StoreStatusOpened
|
||||
}
|
||||
|
||||
func JxStoreStatus2JdStatus(status int) (yn, closeStatus int) {
|
||||
switch status {
|
||||
case model.StoreStatusDisabled:
|
||||
return 1, 0
|
||||
case model.StoreStatusClosed:
|
||||
return 0, 1
|
||||
default:
|
||||
return 0, 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func (p *PurchaseHandler) AddSku(sku *model.Sku) error {
|
||||
// params := map[string]interface{}{
|
||||
// "outSkuId": utils.Int2Str(int(sku.ID)),
|
||||
// "categoryId": skuman.GetJdCategoryID(sku),
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error) {
|
||||
result, err := api.JdAPI.GetStoreInfoByStationNo(vendorStoreID)
|
||||
if err == nil {
|
||||
retVal := &model.Store{
|
||||
Name: utils.Interface2String(result["stationName"]),
|
||||
Address: utils.Interface2String(result["stationAddress"]),
|
||||
OpenTime1: JdOperationTime2JxOperationTime(result["serviceTimeStart1"]),
|
||||
CloseTime1: JdOperationTime2JxOperationTime(result["serviceTimeEnd1"]),
|
||||
OpenTime2: JdOperationTime2JxOperationTime(result["serviceTimeStart2"]),
|
||||
CloseTime2: JdOperationTime2JxOperationTime(result["serviceTimeEnd2"]),
|
||||
Status: JdStoreStatus2JxStatus(result["yn"], result["closeStatus"]),
|
||||
}
|
||||
retVal.ID = int(utils.Str2Int64WithDefault(utils.Interface2String(result["outSystemId"]), 0))
|
||||
return retVal, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStore(vendorStoreID string, store *model.Store, userName string) error {
|
||||
params := map[string]interface{}{
|
||||
"outSystemId": utils.Int2Str(int(store.ID)),
|
||||
"stationName": store.Name,
|
||||
"stationAddress": store.Address,
|
||||
"serviceTimeStart1": JxOperationTime2JdOperationTime(store.OpenTime1),
|
||||
"serviceTimeEnd1": JxOperationTime2JdOperationTime(store.CloseTime1),
|
||||
"serviceTimeStart2": JxOperationTime2JdOperationTime(store.OpenTime2),
|
||||
"serviceTimeEnd2": JxOperationTime2JdOperationTime(store.CloseTime2),
|
||||
}
|
||||
_, params["closeStatus"] = JxStoreStatus2JdStatus(store.Status)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(params, false))
|
||||
return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
||||
}
|
||||
|
||||
// 没用
|
||||
// func (p *PurchaseHandler) DeleteStore(vendorStoreID, userName string) error {
|
||||
// params := map[string]interface{}{
|
||||
// "yn": 1,
|
||||
// }
|
||||
// _, err := api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
||||
// return err
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error {
|
||||
_, err := api.JdAPI.UpdateStoreConfig4Open(vendorStoreID, isEnabled)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) OpenStore(vendorStoreID string, userName string) error {
|
||||
params := map[string]interface{}{
|
||||
"closeStatus": 0,
|
||||
"storeNotice": "",
|
||||
}
|
||||
return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CloseStore(vendorStoreID, closeNotice, userName string) error {
|
||||
params := map[string]interface{}{
|
||||
"closeStatus": 1,
|
||||
"storeNotice": closeNotice,
|
||||
}
|
||||
return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
func (p *PurchaseHandler) GetAllStoreIDsFromRemote() ([]string, error) {
|
||||
result, err := api.JdAPI.GetStationsByVenderId()
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetAllStoresFromRemote() ([]*model.Store, error) {
|
||||
ids, err := p.GetAllStoreIDsFromRemote()
|
||||
if err == nil {
|
||||
retVal := make([]*model.Store, len(ids))
|
||||
for index, id := range ids {
|
||||
store, err2 := p.ReadStore(id)
|
||||
if err2 == nil {
|
||||
retVal[index] = store
|
||||
} else {
|
||||
return nil, err2
|
||||
}
|
||||
}
|
||||
return retVal, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auth/weixin"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type WeixinCallbackResult struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// 认证相关API
|
||||
type AuthController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
var (
|
||||
ErrParameterIsIllegal = "参数不全或不合法"
|
||||
)
|
||||
|
||||
// @Title 给微信用的回调接口
|
||||
// @Description 给微信用的回调接口,自己不能直接调用
|
||||
// @Param code query string true "门店ID"
|
||||
// @Param block query string true "门店所属的厂商ID"
|
||||
// @Param state query string false "门店所属的厂商ID"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetWeiXinUserInfo [get]
|
||||
func (c *AuthController) GetWeiXinUserInfo() {
|
||||
retVal := &WeixinCallbackResult{}
|
||||
var err error
|
||||
code := c.GetString("code")
|
||||
block := c.GetString("block")
|
||||
state := c.GetString("state")
|
||||
if block != "" {
|
||||
if code != "" {
|
||||
result, err2 := weixin.GetUserInfo(code, state)
|
||||
if err = err2; err == nil {
|
||||
retVal.Code = 1
|
||||
retVal.Msg = "微信登录成功"
|
||||
retVal.Data = result
|
||||
} else {
|
||||
retVal.Msg = err.Error()
|
||||
}
|
||||
} else {
|
||||
retVal.Msg = "code为空"
|
||||
}
|
||||
} else {
|
||||
retVal.Msg = "没有block"
|
||||
}
|
||||
c.Redirect(fmt.Sprintf("%s?info=%s", block, base64.StdEncoding.EncodeToString(utils.MustMarshal(retVal))), http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
// @Title 登录接口
|
||||
// @Description 登录接口
|
||||
// @Param id query string true "登录ID"
|
||||
// @Param type query string true "登录类型,当前支持[weixinsns,password]"
|
||||
// @Param secret query string true "不同登录类型的登录秘密"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /Login [post]
|
||||
func (c *AuthController) Login() {
|
||||
c.callLogin(func(params *tAuthLoginParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = auth.Login(params.Id, params.Type, params.Secret)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 登出接口
|
||||
// @Description 登出接口
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /Logout [delete]
|
||||
func (c *AuthController) Logout() {
|
||||
c.callLogout(func(params *tAuthLogoutParams) (retVal interface{}, errCode string, err error) {
|
||||
err = auth.Logout(params.Token)
|
||||
globals.SugarLogger.Debug(err)
|
||||
return nil, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 得到用户信息
|
||||
// @Description 得到用户信息(从token中)
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetUserInfo [get]
|
||||
func (c *AuthController) GetUserInfo() {
|
||||
c.callGetUserInfo(func(params *tAuthGetUserInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = auth.GetUserInfo(params.Token)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package gormdb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
dbStr string
|
||||
)
|
||||
|
||||
func Init() {
|
||||
dbStr = beego.AppConfig.String("dbConnectStr")
|
||||
AutoMigrate()
|
||||
// globals.SugarLogger.Debug("fuck")
|
||||
}
|
||||
|
||||
func GetDB() *gorm.DB {
|
||||
db, err := gorm.Open("mysql", dbStr)
|
||||
if err == nil {
|
||||
return db
|
||||
}
|
||||
panic(fmt.Sprintf("AutoMigrate failed with error:%v", err))
|
||||
}
|
||||
|
||||
func AutoMigrate() {
|
||||
db := GetDB()
|
||||
db.SingularTable(true)
|
||||
|
||||
// db.DropTableIfExists(&model.Place{})
|
||||
// db.DropTableIfExists(&model.Store{}, &model.StoreSub{}, &model.StoreMap{})
|
||||
// db.DropTableIfExists(&model.SkuCategory{}, &model.SkuJdCategory{}, &model.StoreSkuCategoryMap{}, &model.SkuName{}, &model.Sku{}, &model.SkuNamePlaceBind{}, &model.StoreSkuBind{})
|
||||
|
||||
db.AutoMigrate(&model.Place{})
|
||||
db.AutoMigrate(&model.Store{}, &model.StoreSub{}, &model.StoreMap{})
|
||||
db.AutoMigrate(&model.SkuJdCategory{}, &model.StoreSkuCategoryMap{}, &model.SkuName{}, &model.Sku{}, &model.SkuNamePlaceBind{}, &model.StoreSkuBind{})
|
||||
db.Set("gorm:table_options", "CHARSET=utf8mb4").AutoMigrate(&model.SkuCategory{})
|
||||
}
|
||||
9
main.go
9
main.go
@@ -3,11 +3,9 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||
@@ -86,13 +84,6 @@ func main() {
|
||||
}
|
||||
orderman.LoadPendingOrders()
|
||||
}
|
||||
if beego.AppConfig.DefaultBool("enableStore", false) {
|
||||
cms.Init()
|
||||
mux := http.NewServeMux()
|
||||
curAdmin := cms.GetAdmin()
|
||||
curAdmin.MountTo("/admin", mux)
|
||||
beego.Handler("/admin/*", mux)
|
||||
}
|
||||
|
||||
if beego.BConfig.RunMode != "prod" {
|
||||
beego.BConfig.WebConfig.DirectoryIndex = true
|
||||
|
||||
@@ -7,38 +7,6 @@ import (
|
||||
|
||||
func init() {
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetUserInfo",
|
||||
Router: `/GetUserInfo`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetWeiXinUserInfo",
|
||||
Router: `/GetWeiXinUserInfo`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "Login",
|
||||
Router: `/Login`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:AuthController"],
|
||||
beego.ControllerComments{
|
||||
Method: "Logout",
|
||||
Router: `/Logout`,
|
||||
AllowHTTPMethods: []string{"delete"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "CreateWaybillOnProviders",
|
||||
|
||||
@@ -21,11 +21,6 @@ func init() {
|
||||
&controllers.OrderController{},
|
||||
),
|
||||
),
|
||||
beego.NSNamespace("/auth",
|
||||
beego.NSInclude(
|
||||
&controllers.AuthController{},
|
||||
),
|
||||
),
|
||||
)
|
||||
beego.AddNamespace(ns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user