瀏覽代碼

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

zjxpcyc 6 年之前
父節點
當前提交
7ea7bf92e5

+ 10
- 0
controllers/file.go 查看文件

@@ -22,6 +22,16 @@ func (c *BaseController) FileUpload() {
22 22
 	})
23 23
 }
24 24
 
25
+func (c *BaseController) FileUploadMatrial() (string, error) {
26
+	file, err := c.uploadFileToOSS("media")
27
+	if err != nil {
28
+		utils.LogError("上传图片失败: " + err.Error())
29
+		return "", errors.New("上传图片失败")
30
+	}
31
+
32
+	return file, nil
33
+}
34
+
25 35
 func (c *BaseController) uploadFileToOSS(field string) (string, error) {
26 36
 	aliConf, ok := c.Configer[AliYunConf]
27 37
 	if !ok {

+ 8
- 1
controllers/wechatimg/wechatimt.go 查看文件

@@ -158,6 +158,12 @@ func (c *WechatImgController) AddNewImg() {
158 158
 	if err != nil {
159 159
 		c.ResponseError(err)
160 160
 	}
161
+	url, err := c.BaseController.FileUploadMatrial()
162
+	if err != nil {
163
+		c.ResponseError(err)
164
+	}
165
+	utils.LogInfo("↓↓↓↓_________________________↓↓↓↓ali OSS img url(upload)↓↓↓↓___________________↓↓↓↓")
166
+	utils.LogInfo(url)
161 167
 	user := c.Context.Get("user").(*model.SysUser)
162 168
 
163 169
 	appId, err := c.sdao.GetAppIdByOrgId(user.OrgId)
@@ -177,13 +183,14 @@ func (c *WechatImgController) AddNewImg() {
177 183
 		UpdateTime: time.Now(),
178 184
 		OrgId:      user.OrgId,
179 185
 	}
186
+	img.Url = url
180 187
 	err = c.dao.AddWechatImg(img)
181 188
 	if err != nil {
182 189
 		c.ResponseError(err)
183 190
 	}
184 191
 	c.ResponseJSON(map[string]interface{}{
185 192
 		"media_id": img.MediaId,
186
-		"url":      img.Url,
193
+		"url":      url,
187 194
 	})
188 195
 
189 196
 }

+ 12
- 0
controllers/wechatmenu/wechatmenu.go 查看文件

@@ -127,6 +127,12 @@ func (c *MenuController) GetMenuList() {
127 127
 			c.ResponseError(err)
128 128
 		}
129 129
 	}
130
+	utils.LogInfo("↓↓↓↓_________________________↓↓↓↓get menu(upload)↓↓↓↓___________________↓↓↓↓")
131
+	utils.LogInfo(menu)
132
+	utils.LogInfo("↓↓↓↓_________________________↓↓↓↓get keyList(upload)↓↓↓↓___________________↓↓↓↓")
133
+	utils.LogInfo(keyList)
134
+	utils.LogInfo("↓↓↓↓_________________________↓↓↓↓get imgList(upload)↓↓↓↓___________________↓↓↓↓")
135
+	utils.LogInfo(imgList)
130 136
 	c.ResponseJSON(map[string]interface{}{
131 137
 		"menu":    menu,
132 138
 		"keyList": keyList,
@@ -153,6 +159,8 @@ func (c *MenuController) RefreshMenu() {
153 159
 	}
154 160
 	wechatmenu := menu.Menu.Button
155 161
 	beego.Error(wechatmenu)
162
+	utils.LogInfo("↓↓↓↓_________________________↓↓↓↓wechamenu from front(upload)↓↓↓↓___________________↓↓↓↓")
163
+	utils.LogInfo(wechatmenu)
156 164
 	for i := 0; i < len(wechatmenu); i++ {
157 165
 		if wechatmenu[i].Type == "text" {
158 166
 			wechatmenu[i].Type = "click"
@@ -186,6 +194,8 @@ func (c *MenuController) RefreshMenu() {
186 194
 		}
187 195
 	}
188 196
 	beego.Error(wechatmenu)
197
+	utils.LogInfo("↓↓↓↓_________________________↓↓↓↓wechamenu after process(upload)↓↓↓↓___________________↓↓↓↓")
198
+	utils.LogInfo(wechatmenu)
189 199
 	var upwechat WechatMenu
190 200
 	upwechat.Button = wechatmenu
191 201
 	menuData, err := json.Marshal(upwechat)
@@ -193,6 +203,8 @@ func (c *MenuController) RefreshMenu() {
193 203
 		c.ResponseError(err)
194 204
 	}
195 205
 	beego.Error(string(menuData))
206
+	utils.LogInfo("↓↓↓↓_________________________↓↓↓↓wechamenu when upload(upload)↓↓↓↓___________________↓↓↓↓")
207
+	utils.LogInfo(string(menuData))
196 208
 	err = c.dao.UpdateWechatMenu(string(menuData), user.OrgId)
197 209
 	if err != nil {
198 210
 		c.ResponseError(err)

+ 10
- 0
models/sysorg/sysorg.go 查看文件

@@ -79,3 +79,13 @@ func (m *SysorgDAO) UnAutoOrg(confid string) error {
79 79
 	_, err := m.db.Cols(cols...).Where("wechat_id = ?", confid).Update(org)
80 80
 	return err
81 81
 }
82
+
83
+func (m *SysorgDAO) IsOrgBinded(orgId string) (bool, error) {
84
+	var user []model.SysUser
85
+	sql := `select * from sys_user WHERE org_id = '` + orgId + `'`
86
+	err := m.db.Sql(sql).Find(&user)
87
+	if len(user) > 0 {
88
+		return false, err
89
+	}
90
+	return true, err
91
+}

+ 5
- 0
models/wechatimg/wechatimg.go 查看文件

@@ -68,3 +68,8 @@ func (m *WechatImgDAO) DeleteBatchByOrgId(orgId string) error {
68 68
 	_, err := m.db.Delete(&model.TaWechatImg{OrgId: orgId})
69 69
 	return err
70 70
 }
71
+func (m *WechatImgDAO) IsExist(mediaId string) (bool, error) {
72
+	flag, err := m.db.Exist(model.TaWechatImg{MediaId: mediaId})
73
+	return flag, err
74
+
75
+}

+ 18
- 5
service/sysuser/sysuser.go 查看文件

@@ -3,6 +3,7 @@ package sysuser
3 3
 import (
4 4
 	"errors"
5 5
 	"wechat-conf/models/model"
6
+	"wechat-conf/models/sysorg"
6 7
 	"wechat-conf/models/sysuser"
7 8
 	"wechat-conf/service"
8 9
 	"wechat-conf/utils"
@@ -12,15 +13,17 @@ import (
12 13
 
13 14
 // SysuserServ 用户
14 15
 type SysuserServ struct {
15
-	ctx *utils.Context
16
-	dao *sysuser.SysuserDAO
16
+	ctx    *utils.Context
17
+	dao    *sysuser.SysuserDAO
18
+	orgdao *sysorg.SysorgDAO
17 19
 }
18 20
 
19 21
 // NewSysuserServ 初始化
20 22
 func NewSysuserServ(ctx *utils.Context) *SysuserServ {
21 23
 	return &SysuserServ{
22
-		ctx: ctx,
23
-		dao: sysuser.NewSysuserDAO(ctx),
24
+		ctx:    ctx,
25
+		dao:    sysuser.NewSysuserDAO(ctx),
26
+		orgdao: sysorg.NewSysorgDAO(ctx),
24 27
 	}
25 28
 }
26 29
 
@@ -80,11 +83,21 @@ func (s *SysuserServ) SaveUser(user model.SysUser) (*model.SysUser, error) {
80 83
 	return newUser, nil
81 84
 }
82 85
 func (s *SysuserServ) BindUser(userId, orgId string) error {
83
-	err := s.dao.BindUserToOrg(userId, orgId)
86
+	flag, err := s.orgdao.IsOrgBinded(orgId)
84 87
 	if err != nil {
85 88
 		utils.LogError("綁定用户失败: " + err.Error())
86 89
 		return errors.New("綁定用户失败")
87 90
 	}
91
+	if flag {
92
+		err := s.dao.BindUserToOrg(userId, orgId)
93
+		if err != nil {
94
+			utils.LogError("綁定用户失败: " + err.Error())
95
+			return errors.New("綁定用户失败")
96
+		}
97
+	} else {
98
+		return errors.New("该项目已绑定用户")
99
+	}
100
+
88 101
 	return nil
89 102
 
90 103
 }

+ 14
- 7
service/wechatimg/wechatimg.go 查看文件

@@ -36,11 +36,11 @@ func (s *WechatImgServ) AddWechatImg(img model.TaWechatImg) error {
36 36
 }
37 37
 
38 38
 func (s *WechatImgServ) SyncWechatImg(data interface{}, orgId string) error {
39
-	err := s.dao.DeleteBatchByOrgId(orgId)
40
-	if err != nil {
41
-		utils.LogError("同步图片失败: " + err.Error())
42
-		return errors.New("同步图片失败")
43
-	}
39
+	// err := s.dao.DeleteBatchByOrgId(orgId)
40
+	// if err != nil {
41
+	// 	utils.LogError("同步图片失败: " + err.Error())
42
+	// 	return errors.New("同步图片失败")
43
+	// }
44 44
 
45 45
 	imgs := data.([]interface{})
46 46
 	var wechatimgs []model.TaWechatImg
@@ -55,10 +55,17 @@ func (s *WechatImgServ) SyncWechatImg(data interface{}, orgId string) error {
55 55
 		// wechat.UpdateTime = val["update_time"]
56 56
 		wechat.Status = models.STATUS_NORMAL
57 57
 		wechat.CreateDate = time.Now()
58
-		wechatimgs = append(wechatimgs, wechat)
58
+		flag, err := s.dao.IsExist(wechat.MediaId)
59
+		if err != nil {
60
+			utils.LogError("同步图片失败: " + err.Error())
61
+			return errors.New("同步图片失败")
62
+		}
63
+		if !flag {
64
+			wechatimgs = append(wechatimgs, wechat)
65
+		}
59 66
 	}
60 67
 
61
-	err = s.dao.AddWechatImgs(wechatimgs)
68
+	err := s.dao.AddWechatImgs(wechatimgs)
62 69
 	if err != nil {
63 70
 		utils.LogError("同步图片失败: " + err.Error())
64 71
 		return errors.New("同步图片失败")