Quellcode durchsuchen

修改了商品排序功能

Administrator vor 1 Jahr
Ursprung
Commit
81c8a0b6fc

+ 0 - 40
configs/config.go

@@ -20,46 +20,6 @@ var (
 	WxPay   WxPayConfig
 )
 
-//type User struct {
-//	Id            int64  `xorm:"'id'" json:"id"`
-//	Username      string `xorm:"'username'" json:"username"`
-//	Password      string `xorm:"'password'" json:"password"`
-//	Creation_time int    `xorm:"'creation_time'" json:"creation_Time"`
-//	Login_time    int    `xorm:"'login_time'" json:"login_Time"`
-//	Status        int    `xorm:"'status'" json:"status"`
-//	Role_id       int    `xorm:"'role_id'" json:"role_id"`
-//	Phone         string `xorm:"'phone'" json:"phone"`
-//	Email         string `xorm:"'email'" json:"email"`
-//	Name          string `xorm:"'name'" json:"name"`
-//	Avatar        string `xorm:"'avatar'" json:"avatar"`
-//	RecommendCode string `xorm:"'recommend_code'" json:"recommend_code"`
-//}
-//
-//func (receiver User) String() string {
-//	return fmt.Sprintf("User{Id:%d, Username:%s, Password:%s, Creation_time:%d, Login_time:%d, Status:%d, Role_id:%d, Phone:%s, Email:%s, Name:%s, Avatar:%s, RecommendCode:%s}", receiver.Id, receiver.Username, receiver.Password, receiver.Creation_time, receiver.Login_time, receiver.Status, receiver.Role_id, receiver.Phone, receiver.Email, receiver.Name, receiver.Avatar, receiver.RecommendCode)
-//}
-//
-//type Role struct {
-//	Id        int    `xorm:"'id'" json:"id"`
-//	Role_name string `xorm:"'role_name'" json:"role_Name"`
-//}
-//type Role_authority struct {
-//	Authority_id int `xorm:"'authority_id'" json:"authority_id"`
-//	Role_id      int `xorm:"'role_id'" json:"role_id"`
-//}
-//type Authority struct {
-//	Id             int    `xorm:"'id'" json:"id"`
-//	Authority_name string `xorm:"'authority_name'" json:"authority_Name"`
-//	Authority_path string `xorm:"'authority_path'" json:"authority_Path"`
-//}
-//
-//type MysqlData struct {
-//	User           `xorm:"extends"`
-//	Role           `xorm:"extends"`
-//	Role_authority `xorm:"extends"`
-//	Authority      `xorm:"extends"`
-//}
-
 func ConfigInit() {
 	//获取项目的执行路径
 	path, err := os.Getwd()

+ 3 - 27
data/dao/DetailDao.go

@@ -8,10 +8,10 @@ import (
 )
 
 // 排序
-func GetGoodsTagList(goodsTag domain.GoodsTag, pageNum, pageSize int) (vo.BaseListVo, error) {
+func GetGoodsTagList(goodsTag domain.GoodsTag, goodsTags string) (vo.BaseListVo, error) {
 	var arr []domain.GoodsTag
 	Count, err := configs.Engine.Table("goods_tag").
-		Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsTag)
+		Where("find_in_set(goods_tag.id,?)", goodsTags).FindAndCount(&arr, &goodsTag)
 	var vo vo.BaseListVo
 	if err != nil {
 		return vo, err
@@ -19,8 +19,6 @@ func GetGoodsTagList(goodsTag domain.GoodsTag, pageNum, pageSize int) (vo.BaseLi
 	if err != nil {
 		return vo, err
 	}
-	vo.PageNum = pageNum
-	vo.PageSize = pageSize
 	vo.List = make([]any, len(arr))
 	for i, v := range arr {
 		vo.List[i] = v
@@ -178,7 +176,7 @@ func SelectSkuInfoBySkuId(skuId int64) (vo.DetailInfoVo, error) {
 	//根据skuid 获取GoodsId
 	var sku domain.GoodsSku
 	var infoVo vo.DetailInfoVo
-	_, err := configs.Engine.Table("goods_sku").Where("id = ?", skuId).Get(&sku)
+	_, err := configs.Engine.Table("goods_sku").Where("id = ?", skuId).OrderBy("sort").Get(&sku)
 	if err != nil || sku.GoodsId == 0 {
 		return infoVo, err
 	}
@@ -195,28 +193,6 @@ func SelectSkuInfoBySkuId(skuId int64) (vo.DetailInfoVo, error) {
 
 	var intrs = make([]domain.GoodsIntroduction, 0)
 
-	//{
-	//	intrIds := make([]int64, 0)
-	//	intrIds = append(intrIds, goods.IntroductionId)
-	//
-	//	for i := range areas {
-	//		if areas[i].DetailIntroductionId != 0 {
-	//			intrIds = append(intrIds, areas[i].DetailIntroductionId)
-	//		}
-	//	}
-	//
-	//	var iis = ""
-	//	for i := range intrIds {
-	//		iis += fmt.Sprint(",", intrIds[i])
-	//	}
-	//	iis = iis[1:]
-	//
-	//	err = configs.Engine.Table("goods_introduction").
-	//		Where("FIND_IN_SET(id,?)", iis).Find(&intrs)
-	//	if err != nil {
-	//		return infoVo, err
-	//	}
-	//}
 	{
 		sign := false
 		if goods.IntroductionId != 0 {

+ 8 - 0
file/resources/image/.idea/.gitignore

@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 9 - 0
file/resources/image/.idea/image.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="Go" enabled="true" />
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 8 - 0
file/resources/image/.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/image.iml" filepath="$PROJECT_DIR$/.idea/image.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
file/resources/image/.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
+  </component>
+</project>

+ 2 - 0
main.go

@@ -11,8 +11,10 @@ import (
 func init() {
 	configs.ConfigInit()
 }
+
 func main() {
 	runGin()
+	//Test()
 }
 
 // 接口前缀

+ 14 - 14
router/TestRouter.go

@@ -109,36 +109,36 @@ func Topic(c *gin.Context) {
 func Detail(c *gin.Context) {
 	skuId := c.Query("skuId")
 	m := make(map[string]interface{})
-	//标签
-	tagList, err := dao.GetGoodsTagList(domain.GoodsTag{}, 1, 10000)
+
+	//规格查询
+	vo, err := dao.SelectSkuInfoBySkuId(cast.ToInt64(skuId))
 	if err != nil {
-		c.JSON(200, CreateResultError(401, "文章标签查询失败"))
+		c.JSON(200, CreateResultError(401, "规格查询失败"))
 		return
 	}
-	tagMap := map[string]interface{}{
-		"tags": tagList.List,
-	}
-	tagString, err := json.Marshal(tagMap)
+	dm, err := json.Marshal(vo)
 	if err != nil {
 		fmt.Println(err)
 		c.JSON(200, CreateResultError(401, "json转换失败"))
 		return
 	}
-	json.Unmarshal(tagString, &m)
-	//文章内容
-	vo, err := dao.SelectSkuInfoBySkuId(cast.ToInt64(skuId))
+	json.Unmarshal(dm, &m)
+	//标签
+	tagList, err := dao.GetGoodsTagList(domain.GoodsTag{}, vo.Goods.TagIds)
 	if err != nil {
-		c.JSON(200, CreateResultError(401, "文章查询失败"))
+		c.JSON(200, CreateResultError(401, "文章标签查询失败"))
 		return
 	}
-	dm, err := json.Marshal(vo)
+	tagMap := map[string]interface{}{
+		"tags": tagList.List,
+	}
+	tagString, err := json.Marshal(tagMap)
 	if err != nil {
 		fmt.Println(err)
 		c.JSON(200, CreateResultError(401, "json转换失败"))
 		return
 	}
-	json.Unmarshal(dm, &m)
-
+	json.Unmarshal(tagString, &m)
 	fmt.Println("data:", m)
 	c.HTML(http.StatusOK, "detail.html", m)
 }