浏览代码

Merge branch 'master' of http://git.ycjcjy.com/default/wechat-conf

wangfei 6 年前
父节点
当前提交
4d4414ed59

+ 14
- 1
controllers/autoreply/autoreply.go 查看文件

@@ -39,11 +39,12 @@ func (c *AutoreplyController) GetAutoReplyById() {
39 39
 	c.ResponseJSON(autoreply)
40 40
 }
41 41
 func (c *AutoreplyController) SaveAutoreply() {
42
+	user := c.Context.Get("user").(*model.SysUser)
42 43
 	autoreply := model.TaAutoReply{}
43 44
 	if err := c.ParseForm(&autoreply); err != nil {
44 45
 		c.ResponseError(err)
45 46
 	}
46
-	newAuto, err := c.dao.SaveAutoReply(autoreply)
47
+	newAuto, err := c.dao.SaveAutoReply(autoreply, user.OrgId)
47 48
 	if err != nil {
48 49
 		c.ResponseError(err)
49 50
 	}
@@ -57,3 +58,15 @@ func (c *AutoreplyController) DeleteAutoReply() {
57 58
 	}
58 59
 	c.ResponseJSON("删除成功")
59 60
 }
61
+
62
+func (c *AutoreplyController) ChangeIsUse() {
63
+	user := c.Context.Get("user").(*model.SysUser)
64
+	autoType := c.GetString(":autoType")
65
+	isUse := c.GetString(":isUse")
66
+	err := c.dao.DisableAutoreply(autoType, user.OrgId, isUse)
67
+	if err != nil {
68
+		c.ResponseError(err)
69
+	}
70
+	c.ResponseJSON("修改成功")
71
+
72
+}

+ 14
- 0
models/autoreply/autoreply.go 查看文件

@@ -53,6 +53,7 @@ func (m *AutoreplyDAO) AddAutoReply(auto model.TaAutoReply) (*model.TaAutoReply,
53 53
 	auto.CreateDate = time.Now()
54 54
 	auto.Status = models.STATUS_NORMAL
55 55
 	auto.AutoReplyId = utils.GetGUID()
56
+	auto.IsUse = models.AUTOREPLY_IS_USE_ON
56 57
 	_, err := m.db.Insert(auto)
57 58
 	return &auto, err
58 59
 }
@@ -170,3 +171,16 @@ func (m *AutoreplyDAO) GetSubscribeByAppID(appid string) (*model.TaAutoReply, er
170 171
 	}
171 172
 	return nil, nil
172 173
 }
174
+
175
+func (m *AutoreplyDAO) DisableAutoreply(autoType, orgId, isUse string) error {
176
+	var auto = model.TaAutoReply{
177
+		AutoType: autoType,
178
+		OrgId:    orgId,
179
+		IsUse:    isUse,
180
+	}
181
+	var cols = []string{
182
+		"is_use",
183
+	}
184
+	_, err := m.db.Cols(cols...).Where("auto_type = ?", auto.AutoType).And("org_id = ?", auto.OrgId).Update(auto)
185
+	return err
186
+}

+ 6
- 0
models/constant.go 查看文件

@@ -54,3 +54,9 @@ const (
54 54
 	// 图文
55 55
 	MESSAGE_TYPE_CONTENT = "content"
56 56
 )
57
+
58
+// 是否启用自动回复
59
+const (
60
+	AUTOREPLY_IS_USE_ON  = "on"
61
+	AUTOREPLY_IS_USE_OFF = "off"
62
+)

+ 2
- 1
models/model/ta_auto_reply.go 查看文件

@@ -16,5 +16,6 @@ type TaAutoReply struct {
16 16
 	CreateDate       time.Time `xorm:"DATETIME"`
17 17
 	Status           int       `xorm:"SMALLINT(6)"`
18 18
 	OrgId            string    `xorm:"VARCHAR(64)"`
19
-	KeyWords         string    `xorm:"TEXT"`
19
+	Keywords         string    `xorm:"TEXT"`
20
+	IsUse            string    `xorm:"VARCHAR(32)"`
20 21
 }

+ 4
- 0
routers/router.go 查看文件

@@ -27,6 +27,9 @@ func RouteInit() {
27 27
 		// 登陆
28 28
 		beego.NSRouter("/user/login", &controllers.UserController{}, "post:Login"),
29 29
 		beego.NSNamespace("/admin",
30
+			beego.NSRouter("/user/pwd", &controllers.UserController{}, "put:UpdatePassword"),
31
+			beego.NSRouter("/user/sign", &controllers.UserController{}, "post:SignOut"),
32
+
30 33
 			// 菜单
31 34
 			beego.NSRouter("/menu", &menu.MenuController{}, "get:GetMenuList"),
32 35
 			// 自动回复
@@ -35,6 +38,7 @@ func RouteInit() {
35 38
 			beego.NSRouter("/autoreply", &autoreply.AutoreplyController{}, "post:SaveAutoreply"),
36 39
 			beego.NSRouter("/autoreply", &autoreply.AutoreplyController{}, "put:SaveAutoreply"),
37 40
 			beego.NSRouter("/autoreply/:autoreplyId", &autoreply.AutoreplyController{}, "delete:DeleteAutoReply"),
41
+			beego.NSRouter("/autoreply/isUse/:autoType/:isUse", &autoreply.AutoreplyController{}, "put:ChangeIsUse"),
38 42
 			// 图片资源
39 43
 			beego.NSRouter("/wechatimg", &wechatimg.WechatImgController{}, "get:GetWechatImgList"),
40 44
 			beego.NSRouter("/wechatimg/sync", &wechatimg.WechatImgController{}, "put:SyncWechatImg"),

+ 25
- 11
service/autoreply/autoreply.go 查看文件

@@ -3,6 +3,7 @@ package autoreply
3 3
 import (
4 4
 	"errors"
5 5
 	"strings"
6
+	"wechat-conf/models"
6 7
 	"wechat-conf/models/autoreply"
7 8
 	"wechat-conf/models/model"
8 9
 	"wechat-conf/service"
@@ -53,28 +54,32 @@ func (s *AutoreplyServ) GetAutoReplyById(autoReplyId string) (*model.TaAutoReply
53 54
 	return autoreply, nil
54 55
 }
55 56
 
56
-func (s *AutoreplyServ) SaveAutoReply(autoreply model.TaAutoReply) (*model.TaAutoReply, error) {
57
+func (s *AutoreplyServ) SaveAutoReply(autoreply model.TaAutoReply, orgId string) (*model.TaAutoReply, error) {
57 58
 	var newAutoreply *model.TaAutoReply
58 59
 	var err error
59 60
 	if autoreply.AutoReplyId == "" {
61
+		autoreply.OrgId = orgId
60 62
 		newAutoreply, err = s.dao.AddAutoReply(autoreply)
61 63
 	} else {
62 64
 		err = s.dao.DeleteKeywords(autoreply.AutoReplyId)
63 65
 		err = s.dao.UpdateAutoRelpy(autoreply)
64 66
 		newAutoreply = &autoreply
65 67
 	}
66
-	keywords := strings.Split(autoreply.KeyWords, ",")
67
-	for i := 0; i < len(keywords); i++ {
68
-		var keyword = model.TaAutoReplyKeywords{
69
-			AutoReplyId: newAutoreply.AutoReplyId,
70
-			Keywords:    keywords[i],
68
+	if autoreply.AutoType == models.AUTOREPLY_KEYWORDS {
69
+		keywords := strings.Split(autoreply.Keywords, ",")
70
+		for i := 0; i < len(keywords); i++ {
71
+			var keyword = model.TaAutoReplyKeywords{
72
+				AutoReplyId: newAutoreply.AutoReplyId,
73
+				Keywords:    keywords[i],
74
+			}
75
+			err = s.dao.AddKeyword(keyword)
76
+		}
77
+		if err != nil {
78
+			utils.LogError("保存自动回复失败: " + err.Error())
79
+			return nil, errors.New("保存自动回复失败")
71 80
 		}
72
-		err = s.dao.AddKeyword(keyword)
73
-	}
74
-	if err != nil {
75
-		utils.LogError("保存自动回复失败: " + err.Error())
76
-		return nil, errors.New("保存自动回复失败")
77 81
 	}
82
+
78 83
 	return newAutoreply, nil
79 84
 }
80 85
 
@@ -107,3 +112,12 @@ func (s *AutoreplyServ) GetSubscribeByAppID(appid string) (*model.TaAutoReply, e
107 112
 	}
108 113
 	return autoReplay, err
109 114
 }
115
+
116
+func (s *AutoreplyServ) DisableAutoreply(autoType, orgId, isUse string) error {
117
+	err := s.dao.DisableAutoreply(autoType, orgId, isUse)
118
+	if err != nil {
119
+		utils.LogError("修改状态失败: " + err.Error())
120
+		return errors.New("修改状态失败")
121
+	}
122
+	return nil
123
+}