Browse Source

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

zjxpcyc 6 years ago
parent
commit
7ea7bf92e5

+ 10
- 0
controllers/file.go View File

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
 func (c *BaseController) uploadFileToOSS(field string) (string, error) {
35
 func (c *BaseController) uploadFileToOSS(field string) (string, error) {
26
 	aliConf, ok := c.Configer[AliYunConf]
36
 	aliConf, ok := c.Configer[AliYunConf]
27
 	if !ok {
37
 	if !ok {

+ 8
- 1
controllers/wechatimg/wechatimt.go View File

158
 	if err != nil {
158
 	if err != nil {
159
 		c.ResponseError(err)
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
 	user := c.Context.Get("user").(*model.SysUser)
167
 	user := c.Context.Get("user").(*model.SysUser)
162
 
168
 
163
 	appId, err := c.sdao.GetAppIdByOrgId(user.OrgId)
169
 	appId, err := c.sdao.GetAppIdByOrgId(user.OrgId)
177
 		UpdateTime: time.Now(),
183
 		UpdateTime: time.Now(),
178
 		OrgId:      user.OrgId,
184
 		OrgId:      user.OrgId,
179
 	}
185
 	}
186
+	img.Url = url
180
 	err = c.dao.AddWechatImg(img)
187
 	err = c.dao.AddWechatImg(img)
181
 	if err != nil {
188
 	if err != nil {
182
 		c.ResponseError(err)
189
 		c.ResponseError(err)
183
 	}
190
 	}
184
 	c.ResponseJSON(map[string]interface{}{
191
 	c.ResponseJSON(map[string]interface{}{
185
 		"media_id": img.MediaId,
192
 		"media_id": img.MediaId,
186
-		"url":      img.Url,
193
+		"url":      url,
187
 	})
194
 	})
188
 
195
 
189
 }
196
 }

+ 12
- 0
controllers/wechatmenu/wechatmenu.go View File

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

+ 10
- 0
models/sysorg/sysorg.go View File

79
 	_, err := m.db.Cols(cols...).Where("wechat_id = ?", confid).Update(org)
79
 	_, err := m.db.Cols(cols...).Where("wechat_id = ?", confid).Update(org)
80
 	return err
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 View File

68
 	_, err := m.db.Delete(&model.TaWechatImg{OrgId: orgId})
68
 	_, err := m.db.Delete(&model.TaWechatImg{OrgId: orgId})
69
 	return err
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 View File

3
 import (
3
 import (
4
 	"errors"
4
 	"errors"
5
 	"wechat-conf/models/model"
5
 	"wechat-conf/models/model"
6
+	"wechat-conf/models/sysorg"
6
 	"wechat-conf/models/sysuser"
7
 	"wechat-conf/models/sysuser"
7
 	"wechat-conf/service"
8
 	"wechat-conf/service"
8
 	"wechat-conf/utils"
9
 	"wechat-conf/utils"
12
 
13
 
13
 // SysuserServ 用户
14
 // SysuserServ 用户
14
 type SysuserServ struct {
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
 // NewSysuserServ 初始化
21
 // NewSysuserServ 初始化
20
 func NewSysuserServ(ctx *utils.Context) *SysuserServ {
22
 func NewSysuserServ(ctx *utils.Context) *SysuserServ {
21
 	return &SysuserServ{
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
 	return newUser, nil
83
 	return newUser, nil
81
 }
84
 }
82
 func (s *SysuserServ) BindUser(userId, orgId string) error {
85
 func (s *SysuserServ) BindUser(userId, orgId string) error {
83
-	err := s.dao.BindUserToOrg(userId, orgId)
86
+	flag, err := s.orgdao.IsOrgBinded(orgId)
84
 	if err != nil {
87
 	if err != nil {
85
 		utils.LogError("綁定用户失败: " + err.Error())
88
 		utils.LogError("綁定用户失败: " + err.Error())
86
 		return errors.New("綁定用户失败")
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
 	return nil
101
 	return nil
89
 
102
 
90
 }
103
 }

+ 14
- 7
service/wechatimg/wechatimg.go View File

36
 }
36
 }
37
 
37
 
38
 func (s *WechatImgServ) SyncWechatImg(data interface{}, orgId string) error {
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
 	imgs := data.([]interface{})
45
 	imgs := data.([]interface{})
46
 	var wechatimgs []model.TaWechatImg
46
 	var wechatimgs []model.TaWechatImg
55
 		// wechat.UpdateTime = val["update_time"]
55
 		// wechat.UpdateTime = val["update_time"]
56
 		wechat.Status = models.STATUS_NORMAL
56
 		wechat.Status = models.STATUS_NORMAL
57
 		wechat.CreateDate = time.Now()
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
 	if err != nil {
69
 	if err != nil {
63
 		utils.LogError("同步图片失败: " + err.Error())
70
 		utils.LogError("同步图片失败: " + err.Error())
64
 		return errors.New("同步图片失败")
71
 		return errors.New("同步图片失败")