parent
c0c9c249b8
commit
6d4bf6474f
@ -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"`
|
||||||
|
}
|
||||||
@ -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()
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,12 +1,69 @@
|
|||||||
package goods
|
package goods
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/towgo/towgo/dao/basedboperat"
|
||||||
"github.com/towgo/towgo/dao/ormDriver/xormDriver"
|
"github.com/towgo/towgo/dao/ormDriver/xormDriver"
|
||||||
"github.com/towgo/towgo/towgo"
|
"github.com/towgo/towgo/towgo"
|
||||||
|
"log"
|
||||||
|
"src/module/good_category_re"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
xormDriver.Sync2(new(Goods))
|
xormDriver.Sync2(new(Goods))
|
||||||
towgo.NewCRUDJsonrpcAPI("/goods", Goods{}, []Goods{}).RegAPI()
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in new issue