|
@@ -5,6 +5,8 @@ import (
|
5
|
5
|
"spaceofcheng/services/models"
|
6
|
6
|
"spaceofcheng/services/models/model"
|
7
|
7
|
"spaceofcheng/services/utils"
|
|
8
|
+ "strconv"
|
|
9
|
+ "strings"
|
8
|
10
|
"time"
|
9
|
11
|
|
10
|
12
|
"github.com/yl10/kit/guid"
|
|
@@ -32,43 +34,49 @@ func (m *GoodsDAO) GetGoodsListPageNavi(name, typeID, caseID string, limit []int
|
32
|
34
|
sql := `
|
33
|
35
|
SELECT *
|
34
|
36
|
FROM
|
35
|
|
- ta_goods t
|
|
37
|
+ ta_goods
|
36
|
38
|
WHERE
|
37
|
|
- t.case_id = ?
|
|
39
|
+ case_id in ('` + strings.Replace(caseID, ",", "','", -1) + `')
|
38
|
40
|
`
|
39
|
41
|
|
40
|
42
|
if name != "" {
|
41
|
43
|
sql += `
|
42
|
|
- AND LOWER(t.goods_name) LIKE '%` + name + `%'
|
|
44
|
+ AND goods_name LIKE '%` + name + `%'
|
43
|
45
|
`
|
44
|
46
|
}
|
45
|
47
|
|
46
|
48
|
if typeID != "" {
|
47
|
49
|
sql += `
|
48
|
|
- AND t.type_id = '` + typeID + `'
|
|
50
|
+ AND type_id = '` + typeID + `'
|
49
|
51
|
`
|
50
|
52
|
}
|
51
|
53
|
|
52
|
54
|
sql += `
|
53
|
|
- AND t.status > ?
|
|
55
|
+ AND status > ` + strconv.Itoa(models.STATUS_DEL) + `
|
54
|
56
|
ORDER BY
|
55
|
|
- t.type_id,
|
56
|
|
- t.create_date
|
|
57
|
+ type_id,
|
|
58
|
+ create_date
|
57
|
59
|
`
|
58
|
60
|
|
|
61
|
+ // sql += ` limit ` + strconv.Itoa(limit[0]) + ` OFFSET ` + strconv.Itoa(limit[1])
|
|
62
|
+
|
59
|
63
|
var goodsList []GoodsWithSpec
|
60
|
|
- cnt, err := utils.NewPageNaviEngine(m.ctx).GetPageList(&goodsList, sql, limit, caseID, models.STATUS_DEL)
|
|
64
|
+ cnt, err := utils.NewPageNaviEngine(m.ctx).GetPageList(&goodsList, sql, limit)
|
61
|
65
|
if err != nil {
|
62
|
66
|
return nil, 0, err
|
63
|
67
|
}
|
64
|
|
-
|
65
|
68
|
for inx, goods := range goodsList {
|
66
|
69
|
specs, err := m.GetSpecWithPrice(goods.GoodsId)
|
67
|
70
|
if err != nil {
|
68
|
71
|
return nil, 0, err
|
69
|
72
|
}
|
70
|
|
-
|
71
|
73
|
goodsList[inx].Specs = specs
|
|
74
|
+
|
|
75
|
+ imgs, err := m.GetGoodsImgByGoodsID(goods.GoodsId)
|
|
76
|
+ if err != nil {
|
|
77
|
+ return nil, 0, err
|
|
78
|
+ }
|
|
79
|
+ goodsList[inx].Images = imgs
|
72
|
80
|
}
|
73
|
81
|
|
74
|
82
|
return goodsList, cnt, nil
|
|
@@ -98,9 +106,9 @@ func (m *GoodsDAO) GetGoodsListOfCase(caseID string) ([]GoodsWithSpec, error) {
|
98
|
106
|
|
99
|
107
|
// GetSpecWithPrice 获取商品规格 含 金额
|
100
|
108
|
func (m *GoodsDAO) GetSpecWithPrice(goodsID string) ([]SpecWithPrice, error) {
|
101
|
|
- sql := `SELECT * FROM td_spec t
|
|
109
|
+ sql := `SELECT t.*,s.goods_price FROM td_spec t
|
102
|
110
|
JOIN ta_goods_spec s ON t.spec_id = s.spec_id
|
103
|
|
- WHERE t.status = ? AND s.goods_id = ?
|
|
111
|
+ WHERE t.status > ? AND s.goods_id = ?
|
104
|
112
|
`
|
105
|
113
|
|
106
|
114
|
var specs []SpecWithPrice
|
|
@@ -162,9 +170,15 @@ func (m *GoodsDAO) GetGoodsWithSpecByID(id string) (*GoodsWithSpec, error) {
|
162
|
170
|
return nil, err
|
163
|
171
|
}
|
164
|
172
|
|
|
173
|
+ imgs, err := m.GetGoodsImgByGoodsID(id)
|
|
174
|
+ if err != nil {
|
|
175
|
+ return nil, err
|
|
176
|
+ }
|
|
177
|
+
|
165
|
178
|
return &GoodsWithSpec{
|
166
|
179
|
TaGoods: *goods,
|
167
|
180
|
Specs: specs,
|
|
181
|
+ Images: imgs,
|
168
|
182
|
}, nil
|
169
|
183
|
}
|
170
|
184
|
|
|
@@ -293,3 +307,10 @@ func (m *GoodsDAO) DeleteGoods(id string) error {
|
293
|
307
|
|
294
|
308
|
return nil
|
295
|
309
|
}
|
|
310
|
+
|
|
311
|
+// GetGoodsImgByGoodsID 根据商品ID获取商品图片信息
|
|
312
|
+func (m *GoodsDAO) GetGoodsImgByGoodsID(goodsid string) ([]model.TaGoodsImg, error) {
|
|
313
|
+ var goodsimg []model.TaGoodsImg
|
|
314
|
+ err := m.db.Where("goods_id=?", goodsid).Find(&goodsimg)
|
|
315
|
+ return goodsimg, err
|
|
316
|
+}
|