RIceWqy 2 years ago
parent d4534efecd
commit a392c4502a

@ -2,7 +2,7 @@
{ {
"DbType":"mysql", "DbType":"mysql",
"IsMaster":true, "IsMaster":true,
"Dsn":"server=127.0.0.1;user id=root;password=root;database=fushouxian", "Dsn":"root:root@tcp(localhost:3306)/fushouxian?charset=utf8mb4",
"sqlMaxIdleConns":1, "sqlMaxIdleConns":1,
"sqlMaxOpenConns":1, "sqlMaxOpenConns":1,
"sqlLogLevel":2 "sqlLogLevel":2

@ -1,16 +1,13 @@
package main package main
import ( import (
"fmt"
"log" "log"
"net/http" "net/http"
"os"
_ "src/init" _ "src/init"
"github.com/towgo/towgo/dao/basedboperat" "github.com/towgo/towgo/dao/basedboperat"
"github.com/towgo/towgo/dao/ormDriver/gormDriver" "github.com/towgo/towgo/dao/ormDriver/gormDriver"
"github.com/towgo/towgo/dao/ormDriver/xormDriver" "github.com/towgo/towgo/dao/ormDriver/xormDriver"
"github.com/towgo/towgo/lib/processmanager"
"github.com/towgo/towgo/lib/system" "github.com/towgo/towgo/lib/system"
"github.com/towgo/towgo/towgo" "github.com/towgo/towgo/towgo"
) )
@ -18,17 +15,18 @@ import (
var appName string = "fushouxian-server" var appName string = "fushouxian-server"
var appVersion string = "1.0.0" var appVersion string = "1.0.0"
var basePath = system.GetPathOfProgram() // var basePath = system.GetPathOfProgram()
var basePath = "E:\\workfile\\FuShouXian-Backend\\apps\\fushouxian-server"
func init() { func init() {
//初始化xorm数据库驱动 //初始化xorm数据库驱动
var dbconfig []xormDriver.DsnConfig var dbconfig []xormDriver.DsnConfig
system.ScanConfigJson(basePath+"/config/dbconfig.json", &dbconfig) system.ScanConfigJson(basePath+"\\config\\dbconfig.json", &dbconfig)
xormDriver.New(dbconfig) xormDriver.New(dbconfig)
//初始化gorm数据库驱动 //初始化gorm数据库驱动
var gormdbconfig []gormDriver.DsnConfig var gormdbconfig []gormDriver.DsnConfig
system.ScanConfigJson(basePath+"/config/dbconfig.json", &gormdbconfig) system.ScanConfigJson(basePath+"\\config\\dbconfig.json", &gormdbconfig)
gormDriver.New(gormdbconfig) gormDriver.New(gormdbconfig)
//设定默认orm引擎 //设定默认orm引擎
@ -39,7 +37,7 @@ func init() {
} }
func main() { func main() {
pm := processmanager.GetManager() /*pm := processmanager.GetManager()
for k, v := range os.Args { for k, v := range os.Args {
switch v { switch v {
case "start": case "start":
@ -83,7 +81,8 @@ func main() {
} }
} }
log.Print("参数传递错误,有效参数如下:\n" + os.Args[0] + " start | stop | reload | stop") log.Print("参数传递错误,有效参数如下:\n" + os.Args[0] + " start | stop | reload | stop")
*/
start()
} }
func start() { func start() {
@ -93,7 +92,7 @@ func start() {
conf := struct { conf := struct {
Serverport string `json:"serverport"` Serverport string `json:"serverport"`
}{} }{}
system.ScanConfigJson(basePath+"/config/config.json", &conf) system.ScanConfigJson(basePath+"\\config\\config.json", &conf)
http.HandleFunc("/jsonrpc", towgo.HttpHandller) http.HandleFunc("/jsonrpc", towgo.HttpHandller)
@ -103,7 +102,7 @@ func start() {
func moduleClientInit() { func moduleClientInit() {
var node towgo.EdgeServerNodeConfig var node towgo.EdgeServerNodeConfig
system.ScanConfigJson(basePath+"config/togocdn.client.config.json", &node) system.ScanConfigJson(basePath+"\\config\\togocdn.client.config.json", &node)
node.Methods = towgo.GetMethods() node.Methods = towgo.GetMethods()
node.ModuleName = appName node.ModuleName = appName
for _, v := range node.ServerUrls { for _, v := range node.ServerUrls {

@ -1,3 +0,0 @@
package init
import _ "src/module/category"

@ -0,0 +1,7 @@
package init
import _ "src/module/category"
import _ "src/module/coupon"
import _ "src/module/goods"
import _ "src/module/service"
import _ "src/module/skuPrice"

@ -17,10 +17,30 @@ type Category struct {
} }
func (c *Category) AfterQuery(session basedboperat.DbTransactionSession) { func (c *Category) AfterQuery(session basedboperat.DbTransactionSession) {
c.getChildens(session)
if len(c.Children) > 0 {
}
}
func (c *Category) getChildens(session basedboperat.DbTransactionSession) {
var children []Category var children []Category
var list basedboperat.List var list basedboperat.List
list.Limit = -1 list.Limit = -1
session.ListScan(&list, c, &children) session.ListScan(&list, c, &children)
c.Children = children c.Children = children
}
// 递归查询子集方法
func findChildren(categories []Category, parentId int64, session basedboperat.DbTransactionSession) []Category {
var result []Category
for _, category := range categories {
if category.ParentId == parentId {
children := findChildren(categories, category.Id)
category.Children = children
result = append(result, category)
}
}
return result
} }

@ -0,0 +1,12 @@
package goods
import (
"github.com/towgo/towgo/dao/ormDriver/xormDriver"
"github.com/towgo/towgo/towgo"
)
func init() {
xormDriver.Sync2(new(Coupon))
towgo.NewCRUDJsonrpcAPI("/coupon", Coupon{}, []Coupon{}).RegAPI()
}

@ -1 +1,12 @@
package goods package goods
import (
"github.com/towgo/towgo/dao/ormDriver/xormDriver"
"github.com/towgo/towgo/towgo"
)
func init() {
xormDriver.Sync2(new(Goods))
towgo.NewCRUDJsonrpcAPI("/goods", Goods{}, []Goods{}).RegAPI()
}

@ -0,0 +1,12 @@
package goods
import (
"github.com/towgo/towgo/dao/ormDriver/xormDriver"
"github.com/towgo/towgo/towgo"
)
func init() {
xormDriver.Sync2(new(Service))
towgo.NewCRUDJsonrpcAPI("/service", Service{}, []Service{}).RegAPI()
}

@ -0,0 +1,12 @@
package goods
import (
"github.com/towgo/towgo/dao/ormDriver/xormDriver"
"github.com/towgo/towgo/towgo"
)
func init() {
xormDriver.Sync2(new(SKUPrice))
towgo.NewCRUDJsonrpcAPI("/skuprice", SKUPrice{}, []SKUPrice{}).RegAPI()
}
Loading…
Cancel
Save