diff --git a/apps/fushouxian-server/config/dbconfig.json b/apps/fushouxian-server/config/dbconfig.json index 8a1c955..ccc2bac 100644 --- a/apps/fushouxian-server/config/dbconfig.json +++ b/apps/fushouxian-server/config/dbconfig.json @@ -5,6 +5,6 @@ "Dsn":"root:root@tcp(localhost:3306)/fushouxian?charset=utf8mb4", "sqlMaxIdleConns":1, "sqlMaxOpenConns":1, - "sqlLogLevel":2 + "sqlLogLevel":1 } ] diff --git a/apps/fushouxian-server/fushouxian-server.go b/apps/fushouxian-server/fushouxian-server.go index 8e6113c..bad294e 100644 --- a/apps/fushouxian-server/fushouxian-server.go +++ b/apps/fushouxian-server/fushouxian-server.go @@ -87,7 +87,7 @@ func main() { func start() { - moduleClientInit() + //moduleClientInit() conf := struct { Serverport string `json:"serverport"` diff --git a/init/init.go b/init/init.go index 8d196c2..5d97b1c 100644 --- a/init/init.go +++ b/init/init.go @@ -7,3 +7,4 @@ import _ "src/module/service" import _ "src/module/skuPrice" import _ "src/module/activity" import _ "src/module/itemGoodsSkuPrice" +import _ "src/module/good_category_re" diff --git a/module/good_category_re/GoodCategoryRe.go b/module/good_category_re/GoodCategoryRe.go new file mode 100644 index 0000000..17aa41c --- /dev/null +++ b/module/good_category_re/GoodCategoryRe.go @@ -0,0 +1,12 @@ +package good_category_re + +func (GoodCategoryRe) TableName() string { + return "good_category_re" +} + +// GoodCategoryRe 结构体表示产品信息 +type GoodCategoryRe struct { + Id int64 `json:"id"` + GoodsId int64 `json:"goodsId"` + CategoryId int64 `json:"categoryId"` +} diff --git a/module/good_category_re/init.go b/module/good_category_re/init.go new file mode 100644 index 0000000..faea10a --- /dev/null +++ b/module/good_category_re/init.go @@ -0,0 +1,12 @@ +package good_category_re + +import ( + "github.com/towgo/towgo/dao/ormDriver/xormDriver" + "github.com/towgo/towgo/towgo" +) + +func init() { + xormDriver.Sync2(new(GoodCategoryRe)) + towgo.NewCRUDJsonrpcAPI("/goodCategoryRe", GoodCategoryRe{}, []GoodCategoryRe{}).RegAPI() + +} diff --git a/module/goods/Goods.go b/module/goods/Goods.go index c915fee..b38b65e 100644 --- a/module/goods/Goods.go +++ b/module/goods/Goods.go @@ -2,10 +2,13 @@ package goods import ( "github.com/towgo/towgo/dao/basedboperat" + "log" "src/module/activity" coupon "src/module/coupon" + "src/module/good_category_re" service "src/module/service" skuPrice "src/module/skuPrice" + "strconv" "strings" ) @@ -20,7 +23,7 @@ type Goods struct { Title string `json:"title"` // 产品标题 Subtitle string `json:"subtitle"` // 产品副标题 Weigh int64 `json:"weigh"` // 产品权重 - CategoryIds string `json:"category_ids"` // 类别ID + CategoryIds string `json:"category_ids" xorm:"-"` // 类别ID Image string `json:"image"` // 产品图片 Images []string `json:"images"` // 产品图片数组 Params []Param `json:"params"` // 产品参数 @@ -92,6 +95,32 @@ func (good *Goods) AfterQuery(session basedboperat.DbTransactionSession) error { } good.Service = serverList + var gcr good_category_re.GoodCategoryRe + var gcrs []good_category_re.GoodCategoryRe + var list2 basedboperat.List + list2.Limit = -1 + list2.Where = append(list.Where, basedboperat.Condition{ + Field: "goods_id", + Operator: "=", + Value: good.ID, + }) + session.ListScan(&list2, &gcr, &gcrs) // 传递切片的指针 + log.Println("goodid", good.ID) + + log.Println("gcrs", gcrs) + var tempIds []string + + for _, v := range gcrs { + tempIds = append(tempIds, strconv.FormatInt(v.CategoryId, 10)) + } + result := "" + if len(tempIds) > 1 { + result = strings.Join(tempIds, ",") + } else if len(tempIds) == 1 { + result = tempIds[0] + } + good.CategoryIds = result + /* var cs []coupon.Coupon var c coupon.Coupon var list2 basedboperat.List diff --git a/module/goods/init.go b/module/goods/init.go index e820442..d66349e 100644 --- a/module/goods/init.go +++ b/module/goods/init.go @@ -1,12 +1,69 @@ package goods import ( + "github.com/towgo/towgo/dao/basedboperat" "github.com/towgo/towgo/dao/ormDriver/xormDriver" "github.com/towgo/towgo/towgo" + "log" + "src/module/good_category_re" ) func init() { xormDriver.Sync2(new(Goods)) towgo.NewCRUDJsonrpcAPI("/goods", Goods{}, []Goods{}).RegAPI() + towgo.SetFunc("/goods/list2", List2) +} + +type List2Params struct { + CategoryId int64 `json:"category_id"` + Keywords string `json:"keywords"` + Page int64 `json:"page"` +} + +func List2(rpcConn towgo.JsonRpcConnection) { + var params List2Params + err := rpcConn.ReadParams(¶ms) + if err != nil { + log.Println(err) + return + } + var good Goods + var goods []Goods + var gcr good_category_re.GoodCategoryRe + var gcrs []good_category_re.GoodCategoryRe + var listGcr basedboperat.List + var listGood basedboperat.List + if params.CategoryId != 0 { + listGcr.Where = append(listGcr.Where, basedboperat.Condition{ + Field: "category_id", + Operator: "=", + Value: params.CategoryId, + }) + } + tempMap := make(map[string][]string) + if params.Keywords != "" { + tempMap["title"] = "%" + params.Keywords + "%" + listGood.Like = tempMap + append(listGood.Where, basedboperat.Condition{ + Field: "title", + Operator: "like", + Value: "%" + params.Keywords + "%", + }) + } + basedboperat.ListScan(&listGcr, &gcr, &gcrs) + basedboperat.ListScan(&listGood, &good, &goods) + mapGcrs := make(map[int64]int64) + for _, v := range gcrs { + mapGcrs[v.GoodsId] = v.CategoryId + } + var resultGoods []Goods + for _, v := range goods { + if mapGcrs[v.ID] != 0 { + resultGoods = append(resultGoods, v) + + } + } + + rpcConn.WriteResult(resultGoods) }