You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.6 KiB
70 lines
1.6 KiB
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)
|
|
|
|
}
|