diff --git a/business/models/models.go b/business/models/models.go deleted file mode 100644 index 91adbb296..000000000 --- a/business/models/models.go +++ /dev/null @@ -1,14 +0,0 @@ -package models - -import ( - "time" -) - -type BlackClient struct { - ID int `orm:"column(id)"` - Mobile string `orm:"size(16);unique"` - Name string `orm:"size(8)"` - Note string `orm:"size(256)"` - CreatedAt time.Time `orm:"auto_now_add;type(datetime);null"` - UpdatedAt time.Time `orm:"auto_now;type(datetime);null"` -} diff --git a/controllers/dada_order.go b/controllers/dada_order.go index af46edab1..c58bbea17 100644 --- a/controllers/dada_order.go +++ b/controllers/dada_order.go @@ -2,8 +2,8 @@ package controllers import ( "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/dada/controller" - "git.rosy.net.cn/jx-callback/globals/globals2" + "git.rosy.net.cn/jx-callback/globals/api" + "git.rosy.net.cn/jx-callback/legacy/dada/controller" "github.com/astaxie/beego" ) @@ -22,7 +22,7 @@ func (c *DadaOrderController) URLMapping() { // @Failure 403 body is empty // @router /msg [post] func (c *DadaOrderController) OrderStatusChanged() { - obj, callbackResponse := globals2.DadaAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody) + obj, callbackResponse := api.DadaAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody) if callbackResponse == nil { cc := &controller.OrderController{} callbackResponse = cc.OrderStatusChanged(obj) diff --git a/controllers/elm_order.go b/controllers/elm_order.go index c4ff39078..bfdc0ebec 100644 --- a/controllers/elm_order.go +++ b/controllers/elm_order.go @@ -2,8 +2,8 @@ package controllers import ( "git.rosy.net.cn/baseapi/platformapi/elmapi" - "git.rosy.net.cn/jx-callback/business/elm/controller" - "git.rosy.net.cn/jx-callback/globals/globals2" + "git.rosy.net.cn/jx-callback/globals/api" + "git.rosy.net.cn/jx-callback/legacy/elm/controller" "github.com/astaxie/beego" ) @@ -23,7 +23,7 @@ func (c *ELMOrderController) URLMapping() { // @Failure 403 body is empty // @router /msg [post] func (c *ELMOrderController) MsgPost() { - obj, callbackResponse := globals2.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) + obj, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) if callbackResponse == nil { cc := &controller.OrderController{} callbackResponse = cc.OrderMessage(obj) diff --git a/controllers/jd_order.go b/controllers/jd_order.go index 2d7bc2e9b..8e580e34c 100644 --- a/controllers/jd_order.go +++ b/controllers/jd_order.go @@ -1,8 +1,8 @@ package controllers import ( - "git.rosy.net.cn/jx-callback/business/jd/controller" - "git.rosy.net.cn/jx-callback/globals/globals2" + "git.rosy.net.cn/jx-callback/globals/api" + "git.rosy.net.cn/jx-callback/legacy/jd/controller" "github.com/astaxie/beego" ) @@ -24,7 +24,7 @@ func (c *JDOrderController) URLMapping() { } func (c *JDOrderController) orderStatus() { - obj, callbackResponse := globals2.Jdapi.GetOrderCallbackMsg(c.Ctx.Input.RequestBody) + obj, callbackResponse := api.Jdapi.GetOrderCallbackMsg(c.Ctx.Input.RequestBody) if callbackResponse == nil { cc := controller.OrderController{} callbackResponse = cc.OrderStatus(obj) @@ -120,7 +120,7 @@ func (c *JDOrderController) UserCancelOrder() { // @Failure 403 body is empty // @router /applyCancelOrder [post] func (c *JDOrderController) ApplyCancelOrder() { - obj, callbackResponse := globals2.Jdapi.GetOrderApplyCancelCallbackMsg(c.Ctx.Input.RequestBody) + obj, callbackResponse := api.Jdapi.GetOrderApplyCancelCallbackMsg(c.Ctx.Input.RequestBody) if callbackResponse == nil { cc := controller.OrderController{} callbackResponse = cc.OrderStatus(obj) @@ -136,7 +136,7 @@ func (c *JDOrderController) ApplyCancelOrder() { // @Failure 403 body is empty // @router /pushDeliveryStatus [post] func (c *JDOrderController) PushDeliveryStatus() { - obj, callbackResponse := globals2.Jdapi.GetOrderDeliveryCallbackMsg(c.Ctx.Input.RequestBody) + obj, callbackResponse := api.Jdapi.GetOrderDeliveryCallbackMsg(c.Ctx.Input.RequestBody) if callbackResponse == nil { cc := controller.OrderController{} callbackResponse = cc.OrderDeliveryStatus(obj) diff --git a/controllers/mtps_order.go b/controllers/mtps_order.go index 96b3e8c8a..3dda3b4ff 100644 --- a/controllers/mtps_order.go +++ b/controllers/mtps_order.go @@ -1,8 +1,8 @@ package controllers import ( - "git.rosy.net.cn/jx-callback/business/mtps/controller" - "git.rosy.net.cn/jx-callback/globals/globals2" + "git.rosy.net.cn/jx-callback/globals/api" + "git.rosy.net.cn/jx-callback/legacy/mtps/controller" "github.com/astaxie/beego" ) @@ -22,7 +22,7 @@ func (c *MTPSOrderController) URLMapping() { // @Failure 403 body is empty // @router /status [post] func (c *MTPSOrderController) Status() { - obj, callbackResponse := globals2.MtpsAPI.GetOrderCallbackMsg(c.Ctx.Request) + obj, callbackResponse := api.MtpsAPI.GetOrderCallbackMsg(c.Ctx.Request) if callbackResponse == nil { cc := &controller.OrderController{} callbackResponse = cc.OrderStatusChanged(obj) @@ -37,7 +37,7 @@ func (c *MTPSOrderController) Status() { // @Failure 403 body is empty // @router /except [Post] func (c *MTPSOrderController) Except() { - obj, callbackResponse := globals2.MtpsAPI.GetOrderExceptionCallbackMsg(c.Ctx.Request) + obj, callbackResponse := api.MtpsAPI.GetOrderExceptionCallbackMsg(c.Ctx.Request) if callbackResponse == nil { cc := &controller.OrderController{} callbackResponse = cc.OrderException(obj) diff --git a/globals/globals2/globals2.go b/globals/api/api.go similarity index 63% rename from globals/globals2/globals2.go rename to globals/api/api.go index f1178a189..e3912c0ef 100644 --- a/globals/globals2/globals2.go +++ b/globals/api/api.go @@ -1,4 +1,4 @@ -package globals2 +package api import ( "git.rosy.net.cn/baseapi/platformapi/dadaapi" @@ -7,25 +7,13 @@ import ( "git.rosy.net.cn/baseapi/platformapi/mtpsapi" "git.rosy.net.cn/baseapi/platformapi/weixinapi" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/baseapi/utils/routinepool" - elmmodels "git.rosy.net.cn/jx-callback/business/elm/models" - "git.rosy.net.cn/jx-callback/business/freshfood" - jdmodels "git.rosy.net.cn/jx-callback/business/jd/models" - "git.rosy.net.cn/jx-callback/business/models" "github.com/astaxie/beego" "github.com/astaxie/beego/orm" _ "github.com/go-sql-driver/mysql" // import your used driver ) -const ( - ErrStrAccessDB = "Error when access DB" -) - var ( - RoutinePool *routinepool.Pool - FreshFoodAPI *freshfood.FreshFoodAPI - Jdapi *jdapi.API ElmAPI *elmapi.API MtpsAPI *mtpsapi.API @@ -34,10 +22,6 @@ var ( ) func init() { - initDB() - routinePoolSize := beego.AppConfig.DefaultInt("routinePoolSize", 0) - RoutinePool = routinepool.New(routinePoolSize, routinePoolSize) - FreshFoodAPI = freshfood.NewFreshFoodAPI(beego.AppConfig.String("freshFoodServerURL")) Jdapi = jdapi.New(beego.AppConfig.String("jdToken"), beego.AppConfig.String("jdAppKey"), beego.AppConfig.String("jdSecret")) initElm() MtpsAPI = mtpsapi.New(beego.AppConfig.String("mtpsAppKey"), beego.AppConfig.String("mtpsSecret")) @@ -63,17 +47,3 @@ func initElm() { } ElmAPI = elmapi.New(token, beego.AppConfig.String("elmAppKey"), beego.AppConfig.String("elmSecret"), beego.AppConfig.DefaultBool("elmIsProd", false)) } - -func initDB() { - // set default database - orm.RegisterDataBase("default", "mysql", beego.AppConfig.String("dbConnectStr"), 30) - - // register model - orm.RegisterModel(new(jdmodels.Jdorder)) - orm.RegisterModel(new(elmmodels.ELMOrder)) - orm.RegisterModel(new(models.Config)) - orm.RegisterModel(new(models.BlackClient)) - - // create table - orm.RunSyncdb("default", false, true) -} diff --git a/globals/globals.go b/globals/globals.go index 6f0dfbe1a..1d3846753 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -2,12 +2,18 @@ package globals import ( "git.rosy.net.cn/baseapi" + "git.rosy.net.cn/jx-callback/legacy/models" "github.com/astaxie/beego" "github.com/astaxie/beego/logs" + "github.com/astaxie/beego/orm" _ "github.com/go-sql-driver/mysql" // import your used driver "go.uber.org/zap" ) +const ( + ErrStrAccessDB = "Error when access DB" +) + var ( SugarLogger *zap.SugaredLogger ) @@ -19,4 +25,13 @@ func init() { logger, _ := zap.NewDevelopment() SugarLogger = logger.Sugar() baseapi.Init(SugarLogger) + initDB() +} + +func initDB() { + // set default database + orm.RegisterDataBase("default", "mysql", beego.AppConfig.String("dbConnectStr"), 30) + models.RegisterModels() + // create table + orm.RunSyncdb("default", false, true) } diff --git a/business/controllers/business.go b/legacy/controllers/business.go similarity index 95% rename from business/controllers/business.go rename to legacy/controllers/business.go index 07e2ace59..0c620eb88 100644 --- a/business/controllers/business.go +++ b/legacy/controllers/business.go @@ -1,8 +1,8 @@ package controllers import ( - "git.rosy.net.cn/jx-callback/business/models" "git.rosy.net.cn/jx-callback/globals" + "git.rosy.net.cn/jx-callback/legacy/models" "github.com/astaxie/beego/orm" ) diff --git a/business/dada/controller/order.go b/legacy/dada/controller/order.go similarity index 74% rename from business/dada/controller/order.go rename to legacy/dada/controller/order.go index 9db4af47e..fbfead554 100644 --- a/business/dada/controller/order.go +++ b/legacy/dada/controller/order.go @@ -2,7 +2,7 @@ package controller import ( "git.rosy.net.cn/baseapi/platformapi/dadaapi" - "git.rosy.net.cn/jx-callback/globals/globals2" + "git.rosy.net.cn/jx-callback/legacy/freshfood" ) type OrderController struct { @@ -16,5 +16,5 @@ func Error2Response(err error) *dadaapi.CallbackResponse { } func (o *OrderController) OrderStatusChanged(msg *dadaapi.CallbackMsg) *dadaapi.CallbackResponse { - return Error2Response(globals2.FreshFoodAPI.DadaOrderStatusChanged(msg)) + return Error2Response(freshfood.FreshFoodAPI.DadaOrderStatusChanged(msg)) } diff --git a/business/elm/controller/order.go b/legacy/elm/controller/order.go similarity index 86% rename from business/elm/controller/order.go rename to legacy/elm/controller/order.go index f02480039..accb51483 100644 --- a/business/elm/controller/order.go +++ b/legacy/elm/controller/order.go @@ -6,10 +6,12 @@ import ( "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/platformapi/elmapi" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/controllers" - "git.rosy.net.cn/jx-callback/business/elm/models" "git.rosy.net.cn/jx-callback/globals" - "git.rosy.net.cn/jx-callback/globals/globals2" + "git.rosy.net.cn/jx-callback/globals/api" + "git.rosy.net.cn/jx-callback/legacy" + "git.rosy.net.cn/jx-callback/legacy/controllers" + "git.rosy.net.cn/jx-callback/legacy/elm/models" + "git.rosy.net.cn/jx-callback/legacy/freshfood" "github.com/astaxie/beego/orm" ) @@ -32,7 +34,7 @@ func (o *OrderController) OrderMessage(msg *elmapi.CallbackMsg) (retVal *elmapi. retVal = elmapi.SuccessResponse orderID := innerMsg["orderId"].(string) - globals2.RoutinePool.CallFun(func() { + legacy.RoutinePool.CallFun(func() { if msg.Type == elmapi.MsgTypeOrderValid { userMobile := "" if phoneList, ok := innerMsg["phoneList"].([]interface{}); ok && len(phoneList) >= 1 { @@ -52,9 +54,9 @@ func (o *OrderController) OrderMessage(msg *elmapi.CallbackMsg) (retVal *elmapi. func OnNewOrder(orderID string, userMobile string) { controllers.OnNewOrder(orderID, controllers.ELM_VENDERID, userMobile, 0, nil, func(acceptIt bool) { if acceptIt { - globals2.ElmAPI.ConfirmOrder(orderID) + api.ElmAPI.ConfirmOrder(orderID) } else { - globals2.ElmAPI.CancelOrder(orderID, elmapi.CancelOrderTypeOthers, "") + api.ElmAPI.CancelOrder(orderID, elmapi.CancelOrderTypeOthers, "") } }) } @@ -74,7 +76,7 @@ func (o *OrderController) NewOrder(msg *elmapi.CallbackMsg, orderId string, user } else { if created || rec.Type < msg.Type { // todo 回调消息里已经有详情,这里是否有必要再取一次? - result, err := globals2.ElmAPI.GetOrder(orderId) + result, err := api.ElmAPI.GetOrder(orderId) if err != nil { retVal = errResponseCallELMAPIError } else { @@ -89,7 +91,7 @@ func (o *OrderController) NewOrder(msg *elmapi.CallbackMsg, orderId string, user globals.SugarLogger.Warnf("error in updating order data:%v, error:%v, num:%d", msg, err, num) retVal = errResponseDataError } else { - err = globals2.FreshFoodAPI.NewELMOrder(result) + err = freshfood.FreshFoodAPI.NewELMOrder(result) if err != nil { retVal = errResponseInternal } @@ -114,13 +116,13 @@ func (o *OrderController) OrderStatusChanged(msg *elmapi.CallbackMsg, orderId st globals.SugarLogger.Warnf("error when calling ReadOrCreate, error:%v, rec:%v", err, rec) } else { if rec.Type < msg.Type { - err = globals2.FreshFoodAPI.ELMOrderStatus(orderId, msg.Type, utils.GetCurTimeStr()) + err = freshfood.FreshFoodAPI.ELMOrderStatus(orderId, msg.Type, utils.GetCurTimeStr()) if err == nil { rec.Type = msg.Type err = utils.CallFuncLogError(func() error { _, err := db.Update(rec, "Type") return err - }, globals2.ErrStrAccessDB) + }, globals.ErrStrAccessDB) } } else { globals.SugarLogger.Infof("duplicate elm msg received:%v", msg) diff --git a/business/elm/models/order.go b/legacy/elm/models/order.go similarity index 100% rename from business/elm/models/order.go rename to legacy/elm/models/order.go diff --git a/business/freshfood/freshfood.go b/legacy/freshfood/freshfood.go similarity index 87% rename from business/freshfood/freshfood.go rename to legacy/freshfood/freshfood.go index da494f1b5..f89c4baa9 100644 --- a/business/freshfood/freshfood.go +++ b/legacy/freshfood/freshfood.go @@ -7,13 +7,14 @@ import ( "time" "git.rosy.net.cn/baseapi/platformapi/dadaapi" + "github.com/astaxie/beego" "git.rosy.net.cn/baseapi/platformapi/jdapi" "git.rosy.net.cn/baseapi/platformapi/mtpsapi" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/controllers" - "git.rosy.net.cn/jx-callback/business/jd/models" "git.rosy.net.cn/jx-callback/globals" + "git.rosy.net.cn/jx-callback/legacy/controllers" + "git.rosy.net.cn/jx-callback/legacy/jd/models" ) const ( @@ -93,7 +94,7 @@ const ( retryCount = 2 ) -type FreshFoodAPI struct { +type API struct { baseURL string client *http.Client } @@ -102,11 +103,19 @@ var ( ErrFreshFooddReturnNot200 = errors.New("freshfood return code is not 200") ) -func NewFreshFoodAPI(baseURL string) *FreshFoodAPI { - return &FreshFoodAPI{baseURL, &http.Client{Timeout: time.Second * 5}} +var ( + FreshFoodAPI *API +) + +func init() { + FreshFoodAPI = New(beego.AppConfig.String("freshFoodServerURL")) } -func (f *FreshFoodAPI) AccessFreshFood(apiStr string, params url.Values) error { +func New(baseURL string) *API { + return &API{baseURL, &http.Client{Timeout: time.Second * 5}} +} + +func (f *API) AccessFreshFood(apiStr string, params url.Values) error { var err error var response *http.Response fullURL := f.baseURL + "/" + apiStr @@ -137,7 +146,7 @@ func (f *FreshFoodAPI) AccessFreshFood(apiStr string, params url.Values) error { } // jd api -func (f *FreshFoodAPI) NewJDOrder(jdorder *models.Jdorder, isNew bool) error { +func (f *API) NewJDOrder(jdorder *models.Jdorder, isNew bool) error { params := make(url.Values) params.Set(URL_FRESHFOOD_PARA_JDORDER, string(utils.MustMarshal(jdorder))) @@ -147,7 +156,7 @@ func (f *FreshFoodAPI) NewJDOrder(jdorder *models.Jdorder, isNew bool) error { return f.AccessFreshFood(URL_FRESHFOOD_ORDER_MODIFY, params) } -func (f *FreshFoodAPI) JDOrderStatus(msg *jdapi.CallbackOrderMsg) error { +func (f *API) JDOrderStatus(msg *jdapi.CallbackOrderMsg) error { params := make(url.Values) params.Set(URL_FRESHFOOD_PARA_VENDERID, utils.Int2Str(controllers.JD_VENDERID)) params.Set(URL_FRESHFOOD_PARA_ORDERID, msg.BillID) @@ -158,7 +167,7 @@ func (f *FreshFoodAPI) JDOrderStatus(msg *jdapi.CallbackOrderMsg) error { return f.AccessFreshFood(URL_FRESHFOOD_ORDER_STATUS, params) } -func (f *FreshFoodAPI) JDOrderComment(msg *jdapi.CallbackOrderMsg) error { +func (f *API) JDOrderComment(msg *jdapi.CallbackOrderMsg) error { params := make(url.Values) params.Set(URL_FRESHFOOD_PARA_BILLID, msg.BillID) params.Set(URL_FRESHFOOD_PARA_STATUSID, msg.StatusID) @@ -166,7 +175,7 @@ func (f *FreshFoodAPI) JDOrderComment(msg *jdapi.CallbackOrderMsg) error { return f.AccessFreshFood(URL_FRESHFOOD_ORDER_COMMENT, params) } -func (f *FreshFoodAPI) JDOrderDeliveryStatus(jdOrderDeliveryStatusMsg *jdapi.CallbackDeliveryStatusMsg) error { +func (f *API) JDOrderDeliveryStatus(jdOrderDeliveryStatusMsg *jdapi.CallbackDeliveryStatusMsg) error { params := make(url.Values) cityName := "all" @@ -186,14 +195,14 @@ func (f *FreshFoodAPI) JDOrderDeliveryStatus(jdOrderDeliveryStatusMsg *jdapi.Cal } // elm api -func (f *FreshFoodAPI) NewELMOrder(order map[string]interface{}) error { +func (f *API) NewELMOrder(order map[string]interface{}) error { params := make(url.Values) params.Set(URL_FRESHFOOD_PARA_ELEMEORDER, string(utils.MustMarshal(order))) return f.AccessFreshFood(URL_FRESHFOOD_ORDER_CREATE_ELEME, params) } -func (f *FreshFoodAPI) ELMOrderStatus(orderId string, status int, statusTime string) error { +func (f *API) ELMOrderStatus(orderId string, status int, statusTime string) error { params := make(url.Values) params.Set(URL_FRESHFOOD_PARA_VENDERID, utils.Int2Str(controllers.ELM_VENDERID)) params.Set(URL_FRESHFOOD_PARA_ORDERID, orderId) @@ -204,7 +213,7 @@ func (f *FreshFoodAPI) ELMOrderStatus(orderId string, status int, statusTime str } // mtps api -func (f *FreshFoodAPI) MtpsOrderStatusChanged(order *mtpsapi.CallbackOrderMsg) error { +func (f *API) MtpsOrderStatusChanged(order *mtpsapi.CallbackOrderMsg) error { params := make(url.Values) params.Set(URL_FRESHFOOD_PARA_DELIVERYID, utils.Int64ToStr(order.DeliveryID)) params.Set(URL_FRESHFOOD_PARA_MTPEISONID, order.MtPeisongID) @@ -221,7 +230,7 @@ func (f *FreshFoodAPI) MtpsOrderStatusChanged(order *mtpsapi.CallbackOrderMsg) e return f.AccessFreshFood(URL_FRESHFOOD_MTPS_DELIVERYSTATUS, params) } -func (f *FreshFoodAPI) MtpsOrderException(order *mtpsapi.CallbackOrderExceptionMsg) error { +func (f *API) MtpsOrderException(order *mtpsapi.CallbackOrderExceptionMsg) error { params := make(url.Values) params.Set(URL_FRESHFOOD_PARA_DELIVERYID, utils.Int64ToStr(order.DeliveryID)) params.Set(URL_FRESHFOOD_PARA_MTPEISONID, order.MtPeisongID) @@ -241,7 +250,7 @@ func (f *FreshFoodAPI) MtpsOrderException(order *mtpsapi.CallbackOrderExceptionM // dada -func (f *FreshFoodAPI) DadaOrderStatusChanged(msg *dadaapi.CallbackMsg) error { +func (f *API) DadaOrderStatusChanged(msg *dadaapi.CallbackMsg) error { params := make(url.Values) params.Set(URL_FRESHFOOD_PARA_CLIENTID, msg.ClientID) params.Set(URL_FRESHFOOD_PARA_ORDERID, msg.OrderID) @@ -256,10 +265,10 @@ func (f *FreshFoodAPI) DadaOrderStatusChanged(msg *dadaapi.CallbackMsg) error { return f.AccessFreshFood(URL_FRESHFOOD_DADADELIVERY_STATUS, params) } -func (f *FreshFoodAPI) RefreshWeixinToken() error { +func (f *API) RefreshWeixinToken() error { return f.AccessFreshFood(URL_WX_UPDATE_ACCESSTOKEN, nil) } -func (f *FreshFoodAPI) RefreshElmToken() error { +func (f *API) RefreshElmToken() error { return f.AccessFreshFood(URL_FRESHFOOD_ELEME_TOKENUPDATE, nil) } diff --git a/business/jd/controller/order.go b/legacy/jd/controller/order.go similarity index 90% rename from business/jd/controller/order.go rename to legacy/jd/controller/order.go index 7ba57ab6e..3a3c55ee7 100644 --- a/business/jd/controller/order.go +++ b/legacy/jd/controller/order.go @@ -5,10 +5,11 @@ import ( "git.rosy.net.cn/baseapi/platformapi/jdapi" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/controllers" - "git.rosy.net.cn/jx-callback/business/jd/models" "git.rosy.net.cn/jx-callback/globals" - "git.rosy.net.cn/jx-callback/globals/globals2" + "git.rosy.net.cn/jx-callback/globals/api" + "git.rosy.net.cn/jx-callback/legacy/controllers" + "git.rosy.net.cn/jx-callback/legacy/freshfood" + "git.rosy.net.cn/jx-callback/legacy/jd/models" "github.com/astaxie/beego/orm" ) @@ -117,7 +118,7 @@ func (c *OrderController) OrderStatus(msg *jdapi.CallbackOrderMsg) *jdapi.Callba utils.CallFuncLogError(func() error { _, err := db.Update(rec, "OrderStatus", "OrderStatusTime", "Code") return err - }, globals2.ErrStrAccessDB) + }, globals.ErrStrAccessDB) addOrderMsg(msg) } } else { @@ -133,7 +134,7 @@ func (c *OrderController) OrderStatus(msg *jdapi.CallbackOrderMsg) *jdapi.Callba } func (c *OrderController) OrderDeliveryStatus(jdOrderDeliveryStatusMsg *jdapi.CallbackDeliveryStatusMsg) *jdapi.CallbackResponse { - if err := globals2.FreshFoodAPI.JDOrderDeliveryStatus(jdOrderDeliveryStatusMsg); err != nil { + if err := freshfood.FreshFoodAPI.JDOrderDeliveryStatus(jdOrderDeliveryStatusMsg); err != nil { return jdapi.Err2CallbackResponse(err, "") } return jdapi.SuccessResponse @@ -143,12 +144,12 @@ func (c *OrderController) OrderDeliveryStatus(jdOrderDeliveryStatusMsg *jdapi.Ca func OnNewOrder(msg *jdapi.CallbackOrderMsg, userMobile string, db orm.Ormer) { controllers.OnNewOrder(msg.BillID, controllers.JD_VENDERID, userMobile, 0, db, func(acceptIt bool) { globals.SugarLogger.Infof("OrderAcceptOperate billid:%v, acceptIt:%v", msg.BillID, acceptIt) - globals2.Jdapi.OrderAcceptOperate(msg.BillID, acceptIt) + api.Jdapi.OrderAcceptOperate(msg.BillID, acceptIt) }) } func newOrder(msg *jdapi.CallbackOrderMsg) error { - result, err := globals2.Jdapi.LegacyQuerySingleOrder(msg.BillID) + result, err := api.Jdapi.LegacyQuerySingleOrder(msg.BillID) userMobile := "" var db orm.Ormer if err == nil { @@ -181,8 +182,8 @@ func newOrder(msg *jdapi.CallbackOrderMsg) error { db = orm.NewOrm() _, err := db.Update(rec, "Data", "Code", "Msg", "Success", "CityName", "OrderStatus", "OrderStatusTime") return err - }, globals2.ErrStrAccessDB) - globals2.FreshFoodAPI.NewJDOrder(rec, msg.StatusID == jdapi.OrderStatusNew) + }, globals.ErrStrAccessDB) + freshfood.FreshFoodAPI.NewJDOrder(rec, msg.StatusID == jdapi.OrderStatusNew) } else { globals.SugarLogger.Errorf("can not get jdorder info:%v", msg.BillID) } @@ -197,7 +198,7 @@ func adjustOrder(msg *jdapi.CallbackOrderMsg) error { func normalOrderStatus(msg *jdapi.CallbackOrderMsg) (err error) { if msg.StatusID == jdapi.OrderStatusAddComment || msg.StatusID == jdapi.OrderStatusModifyComment { - err = globals2.FreshFoodAPI.JDOrderComment(msg) + err = freshfood.FreshFoodAPI.JDOrderComment(msg) } else { db := orm.NewOrm() rec := &models.Jdorder{ @@ -211,14 +212,14 @@ func normalOrderStatus(msg *jdapi.CallbackOrderMsg) (err error) { if rec.OrderStatus == int(utils.Str2Int64(msg.StatusID)) { globals.SugarLogger.Infof("Duplicate message msg:%v", msg) } else { - if err = globals2.FreshFoodAPI.JDOrderStatus(msg); err == nil { + if err = freshfood.FreshFoodAPI.JDOrderStatus(msg); err == nil { rec.OrderStatus = int(utils.Str2Int64(msg.StatusID)) rec.OrderStatusTime = msg.Timestamp rec.Code = "0" err = utils.CallFuncLogError(func() error { _, err := db.Update(rec, "OrderStatus", "OrderStatusTime", "Code") return err - }, globals2.ErrStrAccessDB) + }, globals.ErrStrAccessDB) } } } diff --git a/business/jd/models/order.go b/legacy/jd/models/order.go similarity index 100% rename from business/jd/models/order.go rename to legacy/jd/models/order.go diff --git a/legacy/legacy.go b/legacy/legacy.go new file mode 100644 index 000000000..2b5519954 --- /dev/null +++ b/legacy/legacy.go @@ -0,0 +1,15 @@ +package legacy + +import ( + "git.rosy.net.cn/baseapi/utils/routinepool" + "github.com/astaxie/beego" +) + +var ( + RoutinePool *routinepool.Pool +) + +func init() { + routinePoolSize := beego.AppConfig.DefaultInt("routinePoolSize", 0) + RoutinePool = routinepool.New(routinePoolSize, routinePoolSize) +} diff --git a/business/models/config.go b/legacy/models/config.go similarity index 100% rename from business/models/config.go rename to legacy/models/config.go diff --git a/legacy/models/models.go b/legacy/models/models.go new file mode 100644 index 000000000..9046974c8 --- /dev/null +++ b/legacy/models/models.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" + + elmmodels "git.rosy.net.cn/jx-callback/legacy/elm/models" + jdmodels "git.rosy.net.cn/jx-callback/legacy/jd/models" + "github.com/astaxie/beego/orm" +) + +type BlackClient struct { + ID int `orm:"column(id)"` + Mobile string `orm:"size(16);unique"` + Name string `orm:"size(8)"` + Note string `orm:"size(256)"` + CreatedAt time.Time `orm:"auto_now_add;type(datetime);null"` + UpdatedAt time.Time `orm:"auto_now;type(datetime);null"` +} + +func RegisterModels() { + // register model + orm.RegisterModel(new(jdmodels.Jdorder)) + orm.RegisterModel(new(elmmodels.ELMOrder)) + orm.RegisterModel(new(Config)) + orm.RegisterModel(new(BlackClient)) +} diff --git a/business/mtps/controller/order.go b/legacy/mtps/controller/order.go similarity index 71% rename from business/mtps/controller/order.go rename to legacy/mtps/controller/order.go index 66c0331d6..65a26fc44 100644 --- a/business/mtps/controller/order.go +++ b/legacy/mtps/controller/order.go @@ -2,7 +2,7 @@ package controller import ( "git.rosy.net.cn/baseapi/platformapi/mtpsapi" - "git.rosy.net.cn/jx-callback/globals/globals2" + "git.rosy.net.cn/jx-callback/legacy/freshfood" ) type OrderController struct { @@ -18,9 +18,9 @@ func Error2Response(err error) *mtpsapi.CallbackResponse { } func (c *OrderController) OrderStatusChanged(order *mtpsapi.CallbackOrderMsg) *mtpsapi.CallbackResponse { - return Error2Response(globals2.FreshFoodAPI.MtpsOrderStatusChanged(order)) + return Error2Response(freshfood.FreshFoodAPI.MtpsOrderStatusChanged(order)) } func (c *OrderController) OrderException(order *mtpsapi.CallbackOrderExceptionMsg) *mtpsapi.CallbackResponse { - return Error2Response(globals2.FreshFoodAPI.MtpsOrderException(order)) + return Error2Response(freshfood.FreshFoodAPI.MtpsOrderException(order)) } diff --git a/business/mtps/models/order.go b/legacy/mtps/models/order.go similarity index 100% rename from business/mtps/models/order.go rename to legacy/mtps/models/order.go diff --git a/business/tasks/configrefresh.go b/legacy/tasks/configrefresh.go similarity index 86% rename from business/tasks/configrefresh.go rename to legacy/tasks/configrefresh.go index cacc366e5..4e7e1b5a9 100644 --- a/business/tasks/configrefresh.go +++ b/legacy/tasks/configrefresh.go @@ -3,12 +3,13 @@ package tasks import ( "time" - "git.rosy.net.cn/jx-callback/globals/globals2" + "git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/globals" - "git.rosy.net.cn/jx-callback/business/models" + "git.rosy.net.cn/jx-callback/legacy/freshfood" + "git.rosy.net.cn/jx-callback/legacy/models" "github.com/astaxie/beego/orm" ) @@ -82,19 +83,19 @@ func RefreshConfig(configKey string, expiresTime time.Duration, configGetter fun func RefreshWeixinToken() { RefreshConfig("wechat", weixinTokenExpires, func() string { - if tokenInfo, err := globals2.WeixinAPI.RefreshToken(); err == nil { + if tokenInfo, err := api.WeixinAPI.RefreshToken(); err == nil { return tokenInfo.AccessToken } return "" }, func(value string) { - globals2.WeixinAPI.SetToken(value) - globals2.FreshFoodAPI.RefreshWeixinToken() + api.WeixinAPI.SetToken(value) + freshfood.FreshFoodAPI.RefreshWeixinToken() }) } func RefreshElmToken() { RefreshConfig("eleme", elmTokenExpires, func() string { - if tokenInfo, err := globals2.ElmAPI.RefreshTokenIndividual(); err == nil { + if tokenInfo, err := api.ElmAPI.RefreshTokenIndividual(); err == nil { tokenInfo2 := &ElmTokenForCompatible{ Error: "", ErrorDescription: "", @@ -111,8 +112,8 @@ func RefreshElmToken() { var tokenInfo ElmTokenForCompatible err := utils.UnmarshalUseNumber([]byte(value), &tokenInfo) if err == nil { - globals2.ElmAPI.SetToken(tokenInfo.AccessToken) - globals2.FreshFoodAPI.RefreshElmToken() + api.ElmAPI.SetToken(tokenInfo.AccessToken) + freshfood.FreshFoodAPI.RefreshElmToken() } }) } diff --git a/main.go b/main.go index fbb9532ab..6be8b5286 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,8 @@ package main import ( - "git.rosy.net.cn/jx-callback/business/jd/controller" - "git.rosy.net.cn/jx-callback/business/tasks" + "git.rosy.net.cn/jx-callback/legacy/jd/controller" + "git.rosy.net.cn/jx-callback/legacy/tasks" _ "git.rosy.net.cn/jx-callback/routers" "github.com/astaxie/beego" )