Browse Source

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

wangfei 6 years ago
parent
commit
4d4414ed59

+ 14
- 1
controllers/autoreply/autoreply.go View File

39
 	c.ResponseJSON(autoreply)
39
 	c.ResponseJSON(autoreply)
40
 }
40
 }
41
 func (c *AutoreplyController) SaveAutoreply() {
41
 func (c *AutoreplyController) SaveAutoreply() {
42
+	user := c.Context.Get("user").(*model.SysUser)
42
 	autoreply := model.TaAutoReply{}
43
 	autoreply := model.TaAutoReply{}
43
 	if err := c.ParseForm(&autoreply); err != nil {
44
 	if err := c.ParseForm(&autoreply); err != nil {
44
 		c.ResponseError(err)
45
 		c.ResponseError(err)
45
 	}
46
 	}
46
-	newAuto, err := c.dao.SaveAutoReply(autoreply)
47
+	newAuto, err := c.dao.SaveAutoReply(autoreply, user.OrgId)
47
 	if err != nil {
48
 	if err != nil {
48
 		c.ResponseError(err)
49
 		c.ResponseError(err)
49
 	}
50
 	}
57
 	}
58
 	}
58
 	c.ResponseJSON("删除成功")
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 View File

53
 	auto.CreateDate = time.Now()
53
 	auto.CreateDate = time.Now()
54
 	auto.Status = models.STATUS_NORMAL
54
 	auto.Status = models.STATUS_NORMAL
55
 	auto.AutoReplyId = utils.GetGUID()
55
 	auto.AutoReplyId = utils.GetGUID()
56
+	auto.IsUse = models.AUTOREPLY_IS_USE_ON
56
 	_, err := m.db.Insert(auto)
57
 	_, err := m.db.Insert(auto)
57
 	return &auto, err
58
 	return &auto, err
58
 }
59
 }
170
 	}
171
 	}
171
 	return nil, nil
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 View File

54
 	// 图文
54
 	// 图文
55
 	MESSAGE_TYPE_CONTENT = "content"
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 View File

16
 	CreateDate       time.Time `xorm:"DATETIME"`
16
 	CreateDate       time.Time `xorm:"DATETIME"`
17
 	Status           int       `xorm:"SMALLINT(6)"`
17
 	Status           int       `xorm:"SMALLINT(6)"`
18
 	OrgId            string    `xorm:"VARCHAR(64)"`
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 View File

27
 		// 登陆
27
 		// 登陆
28
 		beego.NSRouter("/user/login", &controllers.UserController{}, "post:Login"),
28
 		beego.NSRouter("/user/login", &controllers.UserController{}, "post:Login"),
29
 		beego.NSNamespace("/admin",
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
 			beego.NSRouter("/menu", &menu.MenuController{}, "get:GetMenuList"),
34
 			beego.NSRouter("/menu", &menu.MenuController{}, "get:GetMenuList"),
32
 			// 自动回复
35
 			// 自动回复
35
 			beego.NSRouter("/autoreply", &autoreply.AutoreplyController{}, "post:SaveAutoreply"),
38
 			beego.NSRouter("/autoreply", &autoreply.AutoreplyController{}, "post:SaveAutoreply"),
36
 			beego.NSRouter("/autoreply", &autoreply.AutoreplyController{}, "put:SaveAutoreply"),
39
 			beego.NSRouter("/autoreply", &autoreply.AutoreplyController{}, "put:SaveAutoreply"),
37
 			beego.NSRouter("/autoreply/:autoreplyId", &autoreply.AutoreplyController{}, "delete:DeleteAutoReply"),
40
 			beego.NSRouter("/autoreply/:autoreplyId", &autoreply.AutoreplyController{}, "delete:DeleteAutoReply"),
41
+			beego.NSRouter("/autoreply/isUse/:autoType/:isUse", &autoreply.AutoreplyController{}, "put:ChangeIsUse"),
38
 			// 图片资源
42
 			// 图片资源
39
 			beego.NSRouter("/wechatimg", &wechatimg.WechatImgController{}, "get:GetWechatImgList"),
43
 			beego.NSRouter("/wechatimg", &wechatimg.WechatImgController{}, "get:GetWechatImgList"),
40
 			beego.NSRouter("/wechatimg/sync", &wechatimg.WechatImgController{}, "put:SyncWechatImg"),
44
 			beego.NSRouter("/wechatimg/sync", &wechatimg.WechatImgController{}, "put:SyncWechatImg"),

+ 25
- 11
service/autoreply/autoreply.go View File

3
 import (
3
 import (
4
 	"errors"
4
 	"errors"
5
 	"strings"
5
 	"strings"
6
+	"wechat-conf/models"
6
 	"wechat-conf/models/autoreply"
7
 	"wechat-conf/models/autoreply"
7
 	"wechat-conf/models/model"
8
 	"wechat-conf/models/model"
8
 	"wechat-conf/service"
9
 	"wechat-conf/service"
53
 	return autoreply, nil
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
 	var newAutoreply *model.TaAutoReply
58
 	var newAutoreply *model.TaAutoReply
58
 	var err error
59
 	var err error
59
 	if autoreply.AutoReplyId == "" {
60
 	if autoreply.AutoReplyId == "" {
61
+		autoreply.OrgId = orgId
60
 		newAutoreply, err = s.dao.AddAutoReply(autoreply)
62
 		newAutoreply, err = s.dao.AddAutoReply(autoreply)
61
 	} else {
63
 	} else {
62
 		err = s.dao.DeleteKeywords(autoreply.AutoReplyId)
64
 		err = s.dao.DeleteKeywords(autoreply.AutoReplyId)
63
 		err = s.dao.UpdateAutoRelpy(autoreply)
65
 		err = s.dao.UpdateAutoRelpy(autoreply)
64
 		newAutoreply = &autoreply
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
 	return newAutoreply, nil
83
 	return newAutoreply, nil
79
 }
84
 }
80
 
85
 
107
 	}
112
 	}
108
 	return autoReplay, err
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
+}