wangfei пре 6 година
родитељ
комит
4d2e477142
4 измењених фајлова са 75 додато и 2 уклоњено
  1. 11
    0
      controllers/message/location.go
  2. 33
    1
      models/message/location.go
  3. 2
    0
      routers/common.go
  4. 29
    1
      service/message/location.go

+ 11
- 0
controllers/message/location.go Прегледај датотеку

@@ -45,3 +45,14 @@ func (c *MessageController) DelLocation() {
45 45
 	}
46 46
 	c.ResponseJSON("删除成功!")
47 47
 }
48
+
49
+// UpdateLocationSort 修改位置的排序
50
+func (c *MessageController) UpdateLocationSort() {
51
+	locations := c.GetString("locations")
52
+
53
+	err := c.dao.UpdateLocationSort(locations)
54
+	if err != nil {
55
+		c.ResponseError(err)
56
+	}
57
+	c.ResponseJSON("操作成功!")
58
+}

+ 33
- 1
models/message/location.go Прегледај датотеку

@@ -18,10 +18,25 @@ func (m *MessageDAO) GetLocationList(issys, org_id string) ([]model.TdCmsImageLo
18 18
 	if issys != "" {
19 19
 		s = s.And("is_sys=?", issys)
20 20
 	}
21
-	err := s.Find(&locations)
21
+	err := s.Asc("order_no").Find(&locations)
22 22
 	return locations, err
23 23
 }
24 24
 
25
+// GetLocationMaxSort 获取最大的位置
26
+func (m *MessageDAO) GetLocationMaxSort(issys, org_id string) (int, error) {
27
+	var location []map[string][]byte
28
+	sql := `select max(order_no) as order_no from td_cms_image_location where issys=` + issys + ` and org_id ='` + org_id + `'`
29
+	location, err := m.db.Query(sql)
30
+	if err != nil {
31
+		return 0, err
32
+	}
33
+	if len(location) > 0 {
34
+		sortno, err := strconv.Atoi(string(location[0]["order_no"]))
35
+		return sortno, err
36
+	}
37
+	return 0, nil
38
+}
39
+
25 40
 // GetLocationById 根据ID获取明细
26 41
 func (m *MessageDAO) GetLocationById(id string) (*model.TdCmsImageLocation, error) {
27 42
 	var location []model.TdCmsImageLocation
@@ -67,3 +82,20 @@ func (m *MessageDAO) DelLocation(location_id string) error {
67 82
 	_, err := m.db.Cols(cols...).Where("location_id=?", location.LocationId).Update(location)
68 83
 	return err
69 84
 }
85
+
86
+// UpdateLocationSort 修改顺序
87
+func (m *MessageDAO) UpdateLocationSort(loc []string) error {
88
+	orderno, err := strconv.Atoi(loc[1])
89
+	if err != nil {
90
+		return err
91
+	}
92
+	var location = model.TdCmsImageLocation{
93
+		LocationId: loc[0],
94
+		OrderNo:    orderno,
95
+	}
96
+	var cols = []string{
97
+		"order_no",
98
+	}
99
+	_, err = m.db.Cols(cols...).Where("location_id=?", location.LocationId).Update(location)
100
+	return err
101
+}

+ 2
- 0
routers/common.go Прегледај датотеку

@@ -56,6 +56,8 @@ func getCommonRoutes() beego.LinkNamespace {
56 56
 		beego.NSRouter("/cms/location/:locationid", &message.MessageController{}, "put:SaveLocation"),
57 57
 		beego.NSRouter("/cms/location/:locationid", &message.MessageController{}, "delete:DelLocation"),
58 58
 
59
+		beego.NSRouter("/cms/location/:locationid/sort", &message.MessageController{}, "put:UpdateLocationSort"),
60
+
59 61
 		// cms
60 62
 		beego.NSRouter("/cms/info", &message.MessageController{}, "get:GetCmsInfoList"),
61 63
 		beego.NSRouter("/cms/info/:infoid", &message.MessageController{}, "get:GetCmsInfoByID"),

+ 29
- 1
service/message/location.go Прегледај датотеку

@@ -1,6 +1,10 @@
1 1
 package message
2 2
 
3
-import "spaceofcheng/services/models/model"
3
+import (
4
+	"spaceofcheng/services/models/model"
5
+	"spaceofcheng/services/utils"
6
+	"strings"
7
+)
4 8
 
5 9
 // GetLocationList 获取列表
6 10
 func (s *MessageServ) GetLocationList(issys, orgid string) ([]model.TdCmsImageLocation, error) {
@@ -17,6 +21,11 @@ func (s *MessageServ) GetLocationByID(id string) (*model.TdCmsImageLocation, err
17 21
 // SaveLocation 保存
18 22
 func (s *MessageServ) SaveLocation(location model.TdCmsImageLocation) (*model.TdCmsImageLocation, error) {
19 23
 	if location.LocationId == "" {
24
+		sort, err := s.dao.GetLocationMaxSort("0", location.OrgId)
25
+		if err != nil {
26
+			return nil, err
27
+		}
28
+		location.OrderNo = sort
20 29
 		newlocation, err := s.dao.AddLocation(location)
21 30
 		return newlocation, err
22 31
 	}
@@ -29,3 +38,22 @@ func (s *MessageServ) DelLocation(locationID string) error {
29 38
 	err := s.dao.DelLocation(locationID)
30 39
 	return err
31 40
 }
41
+
42
+// UpdateLocationSort 更新顺序
43
+func (s *MessageServ) UpdateLocationSort(locations string) error {
44
+	if locations == "" {
45
+		return utils.LogError("没有需要修改的5A信息!")
46
+	}
47
+	arrlocation := strings.Split(locations, ",")
48
+	for _, loc := range arrlocation {
49
+		loc := strings.Split(loc, ":")
50
+		if len(loc) < 2 {
51
+			return utils.LogError("修改信息不全!")
52
+		}
53
+		err := s.dao.UpdateLocationSort(loc)
54
+		if err != nil {
55
+			return err
56
+		}
57
+	}
58
+	return nil
59
+}