RIceWqy 2 years ago
parent c0c9c249b8
commit 6d4bf6474f

@ -5,6 +5,6 @@
"Dsn":"root:root@tcp(localhost:3306)/fushouxian?charset=utf8mb4", "Dsn":"root:root@tcp(localhost:3306)/fushouxian?charset=utf8mb4",
"sqlMaxIdleConns":1, "sqlMaxIdleConns":1,
"sqlMaxOpenConns":1, "sqlMaxOpenConns":1,
"sqlLogLevel":2 "sqlLogLevel":1
} }
] ]

@ -87,7 +87,7 @@ func main() {
func start() { func start() {
moduleClientInit() //moduleClientInit()
conf := struct { conf := struct {
Serverport string `json:"serverport"` Serverport string `json:"serverport"`

@ -7,3 +7,4 @@ import _ "src/module/service"
import _ "src/module/skuPrice" import _ "src/module/skuPrice"
import _ "src/module/activity" import _ "src/module/activity"
import _ "src/module/itemGoodsSkuPrice" import _ "src/module/itemGoodsSkuPrice"
import _ "src/module/good_category_re"

@ -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()
}

@ -2,10 +2,13 @@ package goods
import ( import (
"github.com/towgo/towgo/dao/basedboperat" "github.com/towgo/towgo/dao/basedboperat"
"log"
"src/module/activity" "src/module/activity"
coupon "src/module/coupon" coupon "src/module/coupon"
"src/module/good_category_re"
service "src/module/service" service "src/module/service"
skuPrice "src/module/skuPrice" skuPrice "src/module/skuPrice"
"strconv"
"strings" "strings"
) )
@ -20,7 +23,7 @@ type Goods struct {
Title string `json:"title"` // 产品标题 Title string `json:"title"` // 产品标题
Subtitle string `json:"subtitle"` // 产品副标题 Subtitle string `json:"subtitle"` // 产品副标题
Weigh int64 `json:"weigh"` // 产品权重 Weigh int64 `json:"weigh"` // 产品权重
CategoryIds string `json:"category_ids"` // 类别ID CategoryIds string `json:"category_ids" xorm:"-"` // 类别ID
Image string `json:"image"` // 产品图片 Image string `json:"image"` // 产品图片
Images []string `json:"images"` // 产品图片数组 Images []string `json:"images"` // 产品图片数组
Params []Param `json:"params"` // 产品参数 Params []Param `json:"params"` // 产品参数
@ -92,6 +95,32 @@ func (good *Goods) AfterQuery(session basedboperat.DbTransactionSession) error {
} }
good.Service = serverList 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 cs []coupon.Coupon
var c coupon.Coupon var c coupon.Coupon
var list2 basedboperat.List var list2 basedboperat.List

@ -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(&params)
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…
Cancel
Save