|
@@ -0,0 +1,294 @@
|
|
1
|
+package admin_user
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ base_ctl "SCRM/controllers"
|
|
5
|
+ "SCRM/enums"
|
|
6
|
+ "SCRM/models"
|
|
7
|
+ "SCRM/service/district_service"
|
|
8
|
+ "SCRM/service/org_service"
|
|
9
|
+ "SCRM/utils"
|
|
10
|
+ "encoding/json"
|
|
11
|
+ "reflect"
|
|
12
|
+ "time"
|
|
13
|
+
|
|
14
|
+ "github.com/astaxie/beego"
|
|
15
|
+)
|
|
16
|
+
|
|
17
|
+func OrgInfoCtlRegistRouters() {
|
|
18
|
+ beego.Router("/api/orginfo/getinfo", &OrgInfoApiController{}, "get:GetOrgInfo")
|
|
19
|
+ beego.Router("/api/orginfo/savegallery", &OrgInfoApiController{}, "post:SaveOrgGallery")
|
|
20
|
+ beego.Router("/api/orginfo/deletegallery", &OrgInfoApiController{}, "delete:DeleteOrgGallery")
|
|
21
|
+ beego.Router("/api/orginfo/edit", &OrgInfoApiController{}, "post:EditOrgInfo")
|
|
22
|
+}
|
|
23
|
+
|
|
24
|
+type OrgInfoApiController struct {
|
|
25
|
+ base_ctl.BaseAuthAPIController
|
|
26
|
+}
|
|
27
|
+
|
|
28
|
+func (c *OrgInfoApiController) GetOrgInfo() {
|
|
29
|
+
|
|
30
|
+ adminUserInfo := c.GetAdminUserInfo()
|
|
31
|
+
|
|
32
|
+ orgInfo := adminUserInfo.Orgs[adminUserInfo.CurrentOrgId]
|
|
33
|
+ provinces, _ := district_service.GetDistrictsByUpid(0)
|
|
34
|
+ var citys []*models.District
|
|
35
|
+ var districts []*models.District
|
|
36
|
+ if orgInfo.Province > 0 {
|
|
37
|
+ citys, _ = district_service.GetDistrictsByUpid(orgInfo.Province)
|
|
38
|
+ }
|
|
39
|
+ if orgInfo.City > 0 {
|
|
40
|
+ districts, _ = district_service.GetDistrictsByUpid(orgInfo.City)
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ orgtypes, _ := org_service.GetOrgTypes()
|
|
44
|
+
|
|
45
|
+ illness, _ := org_service.GetIllnessList()
|
|
46
|
+
|
|
47
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
48
|
+ "orginfo": orgInfo,
|
|
49
|
+ "provinces": provinces,
|
|
50
|
+ "citys": citys,
|
|
51
|
+ "districts": districts,
|
|
52
|
+ "orgtypes": orgtypes,
|
|
53
|
+ "illness": illness,
|
|
54
|
+ })
|
|
55
|
+ return
|
|
56
|
+}
|
|
57
|
+
|
|
58
|
+func (c *OrgInfoApiController) EditOrgInfo() {
|
|
59
|
+ adminUserInfo := c.GetAdminUserInfo()
|
|
60
|
+
|
|
61
|
+ if !adminUserInfo.AdminUser.IsSuperAdmin {
|
|
62
|
+ c.ServeFailJsonSend(enums.ErrorCodePermissionDenied, "权限不足")
|
|
63
|
+ return
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ dataBody := make(map[string]interface{}, 0)
|
|
67
|
+ err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
|
|
68
|
+ if err != nil {
|
|
69
|
+ utils.ErrorLog(err.Error())
|
|
70
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
71
|
+ return
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ orgInfo := adminUserInfo.Orgs[adminUserInfo.CurrentOrgId]
|
|
75
|
+ org := *orgInfo
|
|
76
|
+
|
|
77
|
+ if dataBody["org_name"] == nil || reflect.TypeOf(dataBody["org_name"]).String() != "string" {
|
|
78
|
+ c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:机构名称")
|
|
79
|
+ return
|
|
80
|
+ }
|
|
81
|
+ orgName, _ := dataBody["org_name"].(string)
|
|
82
|
+ if len(orgName) == 0 {
|
|
83
|
+ c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "机构名称不能为空")
|
|
84
|
+ return
|
|
85
|
+ }
|
|
86
|
+ org.OrgName = orgName
|
|
87
|
+
|
|
88
|
+ if dataBody["contact_name"] == nil || reflect.TypeOf(dataBody["contact_name"]).String() != "string" {
|
|
89
|
+ c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:联系人姓名")
|
|
90
|
+ return
|
|
91
|
+ }
|
|
92
|
+ contactName, _ := dataBody["contact_name"].(string)
|
|
93
|
+ if len(contactName) == 0 {
|
|
94
|
+ c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人姓名不能为空")
|
|
95
|
+ return
|
|
96
|
+ }
|
|
97
|
+ org.ContactName = contactName
|
|
98
|
+
|
|
99
|
+ // if dataBody["org_short_name"] == nil || reflect.TypeOf(dataBody["org_short_name"]).String() != "string" {
|
|
100
|
+ // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:商家简称")
|
|
101
|
+ // return
|
|
102
|
+ // }
|
|
103
|
+ // orgShortName, _ := dataBody["org_short_name"].(string)
|
|
104
|
+ // if len(orgShortName) == 0 {
|
|
105
|
+ // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "商家简称不能为空")
|
|
106
|
+ // return
|
|
107
|
+ // }
|
|
108
|
+ org.OrgShortName = orgName
|
|
109
|
+
|
|
110
|
+ if dataBody["org_introduction"] == nil || reflect.TypeOf(dataBody["org_introduction"]).String() != "string" {
|
|
111
|
+ c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:机构介绍")
|
|
112
|
+ return
|
|
113
|
+ }
|
|
114
|
+ orgIntroduction, _ := dataBody["org_introduction"].(string)
|
|
115
|
+ if len(orgIntroduction) == 0 {
|
|
116
|
+ c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "机构介绍不能为空")
|
|
117
|
+ return
|
|
118
|
+ }
|
|
119
|
+ org.OrgIntroduction = orgIntroduction
|
|
120
|
+
|
|
121
|
+ if dataBody["org_logo"] == nil || reflect.TypeOf(dataBody["org_logo"]).String() != "string" {
|
|
122
|
+ c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "缺少参数:机构头像")
|
|
123
|
+ return
|
|
124
|
+ }
|
|
125
|
+ orgLogo, _ := dataBody["org_logo"].(string)
|
|
126
|
+ if len(orgLogo) == 0 {
|
|
127
|
+ c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "机构头像不能为空")
|
|
128
|
+ return
|
|
129
|
+ }
|
|
130
|
+ org.OrgLogo = orgLogo
|
|
131
|
+
|
|
132
|
+ if dataBody["province"] != nil || reflect.TypeOf(dataBody["province"]).String() == "float64" {
|
|
133
|
+ province := int64(dataBody["province"].(float64))
|
|
134
|
+ org.Province = province
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ if dataBody["city"] != nil || reflect.TypeOf(dataBody["city"]).String() == "float64" {
|
|
138
|
+ city := int64(dataBody["city"].(float64))
|
|
139
|
+ org.City = city
|
|
140
|
+ }
|
|
141
|
+
|
|
142
|
+ if dataBody["district"] != nil || reflect.TypeOf(dataBody["district"]).String() == "float64" {
|
|
143
|
+ district := int64(dataBody["district"].(float64))
|
|
144
|
+ org.District = district
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ if dataBody["address"] != nil || reflect.TypeOf(dataBody["address"]).String() == "string" {
|
|
148
|
+ address, _ := dataBody["address"].(string)
|
|
149
|
+ org.Address = address
|
|
150
|
+ }
|
|
151
|
+
|
|
152
|
+ if dataBody["org_type"] != nil || reflect.TypeOf(dataBody["org_type"]).String() == "float64" {
|
|
153
|
+ orgType := int64(dataBody["org_type"].(float64))
|
|
154
|
+ org.OrgType = orgType
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ if dataBody["telephone"] != nil || reflect.TypeOf(dataBody["telephone"]).String() == "string" {
|
|
158
|
+ telephone, _ := dataBody["telephone"].(string)
|
|
159
|
+ org.Telephone = telephone
|
|
160
|
+ }
|
|
161
|
+
|
|
162
|
+ if dataBody["operating_state"] != nil || reflect.TypeOf(dataBody["operating_state"]).String() == "float64" {
|
|
163
|
+ operatingState := int64(dataBody["operating_state"].(float64))
|
|
164
|
+ org.OperatingState = operatingState
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+ if dataBody["business_week"] != nil || reflect.TypeOf(dataBody["business_week"]).String() == "string" {
|
|
168
|
+ businessWeek, _ := dataBody["business_week"].(string)
|
|
169
|
+ org.BusinessWeek = businessWeek
|
|
170
|
+ }
|
|
171
|
+
|
|
172
|
+ if dataBody["business_time"] != nil || reflect.TypeOf(dataBody["business_time"]).String() == "string" {
|
|
173
|
+ businessTime, _ := dataBody["business_time"].(string)
|
|
174
|
+ org.BusinessTime = businessTime
|
|
175
|
+ }
|
|
176
|
+ if dataBody["illness"] != nil || reflect.TypeOf(dataBody["illness"]).String() == "string" {
|
|
177
|
+ illness, _ := dataBody["illness"].(string)
|
|
178
|
+ org.Illness = illness
|
|
179
|
+ }
|
|
180
|
+
|
|
181
|
+ timeNow := time.Now().Unix()
|
|
182
|
+ org.ModifyTime = timeNow
|
|
183
|
+ org.OrgGallery = nil
|
|
184
|
+ err = org_service.UpdateOrgInfo(&org)
|
|
185
|
+ if err != nil {
|
|
186
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
187
|
+ return
|
|
188
|
+ }
|
|
189
|
+
|
|
190
|
+ orgInfo.OrgName = orgName
|
|
191
|
+ orgInfo.OrgShortName = orgName
|
|
192
|
+ orgInfo.OrgIntroduction = orgIntroduction
|
|
193
|
+ orgInfo.OrgLogo = orgLogo
|
|
194
|
+ orgInfo.Province = org.Province
|
|
195
|
+ orgInfo.District = org.District
|
|
196
|
+ orgInfo.City = org.City
|
|
197
|
+ orgInfo.OrgType = org.OrgType
|
|
198
|
+ orgInfo.Telephone = org.Telephone
|
|
199
|
+ orgInfo.OperatingState = org.OperatingState
|
|
200
|
+ orgInfo.BusinessWeek = org.BusinessWeek
|
|
201
|
+ orgInfo.BusinessTime = org.BusinessTime
|
|
202
|
+ orgInfo.Illness = org.Illness
|
|
203
|
+ orgInfo.ContactName = org.ContactName
|
|
204
|
+
|
|
205
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
206
|
+ "msg": "ok",
|
|
207
|
+ })
|
|
208
|
+ return
|
|
209
|
+}
|
|
210
|
+
|
|
211
|
+func (c *OrgInfoApiController) SaveOrgGallery() {
|
|
212
|
+ adminUserInfo := c.GetAdminUserInfo()
|
|
213
|
+
|
|
214
|
+ dataBody := make(map[string]interface{}, 0)
|
|
215
|
+ err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
|
|
216
|
+ if err != nil {
|
|
217
|
+ utils.ErrorLog(err.Error())
|
|
218
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
219
|
+ return
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ if dataBody["type"] == nil || reflect.TypeOf(dataBody["type"]).String() != "float64" {
|
|
223
|
+ utils.ErrorLog("type")
|
|
224
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
225
|
+ return
|
|
226
|
+ }
|
|
227
|
+ galleryType := int64(dataBody["type"].(float64))
|
|
228
|
+ if galleryType != 1 && galleryType != 2 {
|
|
229
|
+ utils.ErrorLog("galleryType != 1&&2")
|
|
230
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
231
|
+ return
|
|
232
|
+ }
|
|
233
|
+
|
|
234
|
+ if dataBody["url"] == nil || reflect.TypeOf(dataBody["url"]).String() != "string" {
|
|
235
|
+ utils.ErrorLog("url")
|
|
236
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
237
|
+ return
|
|
238
|
+ }
|
|
239
|
+ url, _ := dataBody["url"].(string)
|
|
240
|
+ if len(url) == 0 {
|
|
241
|
+ utils.ErrorLog("len(url) == 0")
|
|
242
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
243
|
+ return
|
|
244
|
+ }
|
|
245
|
+
|
|
246
|
+ timeNow := time.Now().Unix()
|
|
247
|
+ var gallery models.OrgGallery
|
|
248
|
+ gallery.Type = galleryType
|
|
249
|
+ gallery.Url = url
|
|
250
|
+ gallery.OrgId = adminUserInfo.CurrentOrgId
|
|
251
|
+ gallery.Status = 1
|
|
252
|
+ gallery.Ctime = timeNow
|
|
253
|
+ gallery.Mtime = timeNow
|
|
254
|
+ err = org_service.CreateOrgGalleryItem(&gallery)
|
|
255
|
+ if err != nil {
|
|
256
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
257
|
+ return
|
|
258
|
+ }
|
|
259
|
+
|
|
260
|
+ orgInfo := adminUserInfo.Orgs[adminUserInfo.CurrentOrgId]
|
|
261
|
+ orgInfo.OrgGallery = append(orgInfo.OrgGallery, &gallery)
|
|
262
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
263
|
+ "msg": "ok",
|
|
264
|
+ })
|
|
265
|
+ return
|
|
266
|
+
|
|
267
|
+}
|
|
268
|
+
|
|
269
|
+func (c *OrgInfoApiController) DeleteOrgGallery() {
|
|
270
|
+ adminUserInfo := c.GetAdminUserInfo()
|
|
271
|
+ id, _ := c.GetInt64("id", 0)
|
|
272
|
+ if id <= 0 {
|
|
273
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
274
|
+ return
|
|
275
|
+ }
|
|
276
|
+
|
|
277
|
+ err := org_service.DeleteOrgGalleryItem(id)
|
|
278
|
+ if err != nil {
|
|
279
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
280
|
+ return
|
|
281
|
+ }
|
|
282
|
+
|
|
283
|
+ orgInfo := adminUserInfo.Orgs[adminUserInfo.CurrentOrgId]
|
|
284
|
+ for index, item := range orgInfo.OrgGallery {
|
|
285
|
+ if item.ID == id {
|
|
286
|
+ orgInfo.OrgGallery = append(orgInfo.OrgGallery[:index], orgInfo.OrgGallery[index+1:]...)
|
|
287
|
+ }
|
|
288
|
+ }
|
|
289
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
290
|
+ "msg": "ok",
|
|
291
|
+ })
|
|
292
|
+ return
|
|
293
|
+
|
|
294
|
+}
|