Browse Source

添加机构信息模块

庄逸洲 4 years ago
parent
commit
da5166cc9f

+ 294 - 0
controllers/admin_user/org_controller.go View File

@@ -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
+}

+ 1 - 0
controllers/admin_user/router_collector.go View File

@@ -2,4 +2,5 @@ package admin_user
2 2
 
3 3
 func RegisterRouters() {
4 4
 	AdminCtlRegistRouters()
5
+	OrgInfoCtlRegistRouters()
5 6
 }

+ 26 - 0
controllers/global/district_controller.go View File

@@ -0,0 +1,26 @@
1
+package global
2
+
3
+import (
4
+	base_ctl "SCRM/controllers"
5
+	"SCRM/service/district_service"
6
+
7
+	"github.com/astaxie/beego"
8
+)
9
+
10
+type DistrictApiController struct {
11
+	base_ctl.BaseAPIController
12
+}
13
+
14
+func DistrictCtlRegistRouters() {
15
+	beego.Router("/api/district/getdistrictsbyupid", &DistrictApiController{}, "get:GetDistrictsByUpid")
16
+}
17
+
18
+func (c *DistrictApiController) GetDistrictsByUpid() {
19
+	id, _ := c.GetInt64("id", 0)
20
+	citys, _ := district_service.GetDistrictsByUpid(id)
21
+
22
+	c.ServeSuccessJSON(map[string]interface{}{
23
+		"citys": citys,
24
+	})
25
+	return
26
+}

+ 35 - 0
controllers/global/qiniu_controller.go View File

@@ -0,0 +1,35 @@
1
+package global
2
+
3
+import (
4
+	base_ctl "SCRM/controllers"
5
+	"SCRM/enums"
6
+	base_service "SCRM/service"
7
+	"fmt"
8
+
9
+	"github.com/astaxie/beego"
10
+)
11
+
12
+type QiNiuApiController struct {
13
+	base_ctl.BaseAPIController
14
+}
15
+
16
+func QiniuCtlRegistRouters() {
17
+	beego.Router("/api/qiniu/uptoken", &QiNiuApiController{}, "get:GetQNUpToken")
18
+}
19
+
20
+func (c *QiNiuApiController) GetQNUpToken() {
21
+	redisClient := base_service.RedisClient()
22
+	defer redisClient.Close()
23
+
24
+	token, err := redisClient.Get("qn_token").Result()
25
+	if err != nil {
26
+		defer fmt.Println(err)
27
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGetQiniuUpToken)
28
+		return
29
+	}
30
+
31
+	c.ServeSuccessJSON(map[string]interface{}{
32
+		"uptoken": token,
33
+	})
34
+	return
35
+}

+ 2 - 0
controllers/global/router_collector.go View File

@@ -2,4 +2,6 @@ package global
2 2
 
3 3
 func RegisterRouters() {
4 4
 	ErrorCtlRegistRouters()
5
+	DistrictCtlRegistRouters()
6
+	QiniuCtlRegistRouters()
5 7
 }

+ 6 - 6
controllers/login/login_controller.go View File

@@ -122,17 +122,17 @@ func (this *VerifyUserLoginAPIController) VerifyToken() {
122 122
 			}
123 123
 
124 124
 			orgApps := adminUserInfo.OrgApps[curOrg.Id]
125
-			didRegistedForSCRM := false
125
+			didRegistedForXT := false
126 126
 			didRegistedForMall := false
127 127
 			didRegistedForCDM := false
128 128
 			for _, app := range orgApps {
129
-				if app.AppType == 1 {
130
-					didRegistedForSCRM = true
129
+				if app.AppType == 3 && app.OpenStatus == 1 {
130
+					didRegistedForXT = true
131 131
 				}
132
-				if app.AppType == 4 {
132
+				if app.AppType == 4 && app.OpenStatus == 1 {
133 133
 					didRegistedForCDM = true
134 134
 				}
135
-				if app.AppType == 5 {
135
+				if app.AppType == 5 && app.OpenStatus == 1 {
136 136
 					didRegistedForMall = true
137 137
 				}
138 138
 			}
@@ -144,7 +144,7 @@ func (this *VerifyUserLoginAPIController) VerifyToken() {
144 144
 				"current_org_id":  adminUserInfo.CurrentOrgId,
145 145
 				"current_app_id":  adminUserInfo.CurrentAppId,
146 146
 				"subscibe":        subscibe,
147
-				"scrm_role_exist": didRegistedForSCRM,
147
+				"xt_role_exist":   didRegistedForXT,
148 148
 				"cdm_role_exist":  didRegistedForCDM,
149 149
 				"mall_role_exist": didRegistedForMall,
150 150
 			})

+ 18 - 0
models/district_models.go View File

@@ -0,0 +1,18 @@
1
+package models
2
+
3
+type District struct {
4
+	ID        int64  `gorm:"column:id" json:"id" form:"id"`
5
+	Name      string `gorm:"column:name" json:"name" form:"name"`
6
+	Level     int64  `gorm:"column:level" json:"level" form:"level"`
7
+	Upid      int64  `gorm:"column:upid" json:"upid" form:"upid"`
8
+	Path      string `gorm:"column:path" json:"path" form:"path"`
9
+	Namepath  string `gorm:"column:namepath" json:"namepath" form:"namepath"`
10
+	Initial   string `gorm:"column:initial" json:"initial" form:"initial"`
11
+	Longitude string `gorm:"column:longitude" json:"longitude" form:"longitude"`
12
+	Latitude  string `gorm:"column:latitude" json:"latitude" form:"latitude"`
13
+	Adcode    int64  `gorm:"column:adcode" json:"adcode" form:"adcode"`
14
+}
15
+
16
+func (District) TableName() string {
17
+	return "sgj_user_district"
18
+}

+ 54 - 0
models/org_models.go View File

@@ -15,17 +15,44 @@ type Org struct {
15 15
 	Status          int8   `json:"status"`                    // 状态 0.无效 1.有效 2.禁用
16 16
 	CreateTime      int64  `gorm:"column:ctime" json:"ctime"` // 创建时间
17 17
 	ModifyTime      int64  `gorm:"column:mtime" json:"mtime"` // 修改时间
18
+
19
+	OrgType        int64   `gorm:"column:org_type" json:"org_type"`
20
+	Evaluate       float64 `gorm:"column:evaluate" json:"evaluate"`
21
+	Comments       int64   `gorm:"column:comments" json:"comments"`
22
+	OperatingState int64   `gorm:"column:operating_state" json:"operating_state"`
23
+	Claim          int64   `gorm:"column:claim" json:"claim"`
24
+	Telephone      string  `gorm:"column:telephone" json:"telephone"`
25
+	BusinessWeek   string  `gorm:"column:business_week" json:"business_week"`
26
+	BusinessTime   string  `gorm:"column:business_time" json:"business_time"`
27
+	Gallery        string  `gorm:"column:gallery" json:"gallery"`
28
+	ContactName    string  `gorm:"column:contact_name" json:"contact_name"`
18 29
 }
19 30
 
20 31
 func (Org) TableName() string {
21 32
 	return "sgj_user_org"
22 33
 }
23 34
 
35
+type OrgGallery struct {
36
+	ID     int64  `gorm:"column:id" json:"id" form:"id"`
37
+	Url    string `gorm:"column:url" json:"url" form:"url"`
38
+	Type   int64  `gorm:"column:type" json:"type" form:"type"`
39
+	OrgId  int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
40
+	UserId int64  `gorm:"column:user_id" json:"user_id" form:"user_id"`
41
+	Status int64  `gorm:"column:status" json:"status" form:"status"`
42
+	Ctime  int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
43
+	Mtime  int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
44
+}
45
+
46
+func (OrgGallery) TableName() string {
47
+	return "sgj_user_org_gallery"
48
+}
49
+
24 50
 type OrgApp struct {
25 51
 	Id         int64 `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"` // ID
26 52
 	AppType    int   `gorm:"column:app_type" json:"app_type"`      // 应用类型 1.病友经营;2.科普号;3.血透经营;4.慢病管理
27 53
 	Creator    int   `json:"creator"`                              // 创建者,即管理员用户的 id
28 54
 	OrgId      int   `gorm:"column:org_id" json:"org_id"`
55
+	OpenStatus int   `gorm:"column:open_status" json:"open_status"`
29 56
 	Status     int8  `json:"status"`                    // 状态 0.无效 1.有效 2.禁用
30 57
 	CreateTime int64 `gorm:"column:ctime" json:"ctime"` // 创建时间
31 58
 	ModifyTime int64 `gorm:"column:mtime" json:"mtime"` // 修改时间
@@ -48,3 +75,30 @@ type OrgBan struct {
48 75
 func (OrgBan) TableName() string {
49 76
 	return "sgj_user_admin_org_ban"
50 77
 }
78
+
79
+type OrgType struct {
80
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
81
+	Name        string `gorm:"column:name" json:"name" form:"name"`
82
+	ShortName   string `gorm:"column:short_name" json:"short_name" form:"short_name"`
83
+	Pid         int64  `gorm:"column:pid" json:"pid" form:"pid"`
84
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
85
+	CreatedTime int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
86
+	UpdatedTime int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
87
+	SortNo      int64  `gorm:"column:sort_no" json:"sort_no" form:"sort_no"`
88
+}
89
+
90
+func (OrgType) TableName() string {
91
+	return "sgj_user_org_type"
92
+}
93
+
94
+type Illness struct {
95
+	ID          int64  `gorm:"column:id" json:"id"`
96
+	IllnessName string `gorm:"column:illness_name" json:"illness_name"`
97
+	Status      int64  `gorm:"column:status" json:"status"`
98
+	CreatedTime int64  `gorm:"column:created_time" json:"created_time"`
99
+	UpdatedTime int64  `gorm:"column:updated_time" json:"updated_time"`
100
+}
101
+
102
+func (Illness) TableName() string {
103
+	return "sgj_user_illness"
104
+}

+ 5 - 4
service/admin_service/verify_login_token_service.go View File

@@ -10,6 +10,7 @@ import (
10 10
 
11 11
 	"SCRM/models"
12 12
 	"SCRM/service"
13
+	"SCRM/service/org_service"
13 14
 	"SCRM/utils"
14 15
 
15 16
 	"github.com/astaxie/beego"
@@ -20,7 +21,7 @@ type AdminUserInfo struct {
20 21
 	CurrentOrgId int64                                `json:"current_org_id"`
21 22
 	CurrentAppId int64                                `json:"current_app_id"`
22 23
 	OrgIds       []int64                              `json:"org_ids"`
23
-	Orgs         map[int64]*models.Org                `json:"orgs"`
24
+	Orgs         map[int64]*org_service.Org           `json:"orgs"`
24 25
 	OrgAppIds    map[int64][]int64                    `json:"org_app_ids"`
25 26
 	OrgApps      map[int64](map[int64]*models.OrgApp) `json:"org_apps"`
26 27
 	App2OrgIds   map[int64]int64                      `json:"app_to_org_ids"`
@@ -204,12 +205,12 @@ func processOrgIds(data map[string]interface{}) []int64 {
204 205
 // 	1: { Org's json },
205 206
 // 	2: { Org's json },
206 207
 // },
207
-func processOrgs(data map[string]interface{}) map[int64]*models.Org {
208
+func processOrgs(data map[string]interface{}) map[int64]*org_service.Org {
208 209
 	orgJSONs := data["orgs"].(map[string]interface{})
209
-	orgs := make(map[int64]*models.Org)
210
+	orgs := make(map[int64]*org_service.Org)
210 211
 	for orgIdStr, orgJSON := range orgJSONs {
211 212
 		orgId, _ := strconv.Atoi(orgIdStr)
212
-		var org models.Org
213
+		var org org_service.Org
213 214
 		json.Unmarshal([]byte(orgJSON.(string)), &org)
214 215
 		orgs[int64(orgId)] = &org
215 216
 	}

+ 2 - 2
service/db.go View File

@@ -95,10 +95,10 @@ func ConnectDB() {
95 95
 	writeUserDb.LogMode(true)
96 96
 }
97 97
 
98
-func XTReadDB() *gorm.DB {
98
+func PatientReadDB() *gorm.DB {
99 99
 	return readDb
100 100
 }
101
-func XTWriteDB() *gorm.DB {
101
+func PatientWriteDB() *gorm.DB {
102 102
 	return writeDb
103 103
 }
104 104
 func UserReadDB() *gorm.DB {

+ 11 - 0
service/district_service/district_service.go View File

@@ -0,0 +1,11 @@
1
+package district_service
2
+
3
+import (
4
+	"SCRM/models"
5
+	"SCRM/service"
6
+)
7
+
8
+func GetDistrictsByUpid(id int64) (dis []*models.District, err error) {
9
+	err = service.UserReadDB().Model(&models.District{}).Where("upid=?", id).Find(&dis).Error
10
+	return
11
+}

+ 14 - 0
service/org_service/org_info_models.go View File

@@ -0,0 +1,14 @@
1
+package org_service
2
+
3
+import (
4
+	"SCRM/models"
5
+)
6
+
7
+type Org struct {
8
+	models.Org
9
+	OrgGallery []*models.OrgGallery `gorm:"ForeignKey:OrgId" json:"org_gallery"`
10
+}
11
+
12
+func (Org) TableName() string {
13
+	return "sgj_user_org"
14
+}

+ 32 - 0
service/org_service/org_info_service.go View File

@@ -0,0 +1,32 @@
1
+package org_service
2
+
3
+import (
4
+	"SCRM/models"
5
+	"SCRM/service"
6
+	"time"
7
+)
8
+
9
+func GetOrgTypes() (ots []*models.OrgType, err error) {
10
+	err = service.UserReadDB().Model(&models.OrgType{}).Where("status=1").Order("sort_no").Find(&ots).Error
11
+	return
12
+}
13
+
14
+func UpdateOrgInfo(org *Org) (err error) {
15
+	err = service.UserWriteDB().Model(&models.Org{}).Where("id=?", org.Id).Update(org).Error
16
+	return
17
+}
18
+
19
+func GetIllnessList() (ills []*models.Illness, err error) {
20
+	err = service.UserReadDB().Where("status=1").Find(&ills).Error
21
+	return
22
+}
23
+
24
+func CreateOrgGalleryItem(item *models.OrgGallery) (err error) {
25
+	err = service.UserWriteDB().Create(item).Error
26
+	return
27
+}
28
+
29
+func DeleteOrgGalleryItem(id int64) (err error) {
30
+	err = service.UserWriteDB().Model(&models.OrgGallery{}).Where("id=?", id).Update(map[string]interface{}{"Status": 0, "Mtime": time.Now().Unix()}).Error
31
+	return
32
+}