Browse Source

Merge branch 'master' of http://git.shengws.com/csx/XT_Admin_Api

xiaoming_global 5 years ago
parent
commit
8c9f60d566

+ 7 - 0
controllers/admin_api_controllers/admin_api_router_register.go View File

@@ -13,4 +13,11 @@ func AdminAPIControllersRegisterRouters() {
13 13
 	beego.Router("/admin/api/dialysis/analysis", &AnalysisAPIController{}, "get:DialysisAnalysis")
14 14
 	beego.Router("/admin/api/monitor/analysis", &AnalysisAPIController{}, "get:MonitorAnalysis")
15 15
 	beego.Router("/admin/api/patient/analysis", &AnalysisAPIController{}, "get:PatientAnalysis")
16
+	beego.Router("/admin/api/home/statistics", &AnalysisAPIController{}, "get:HomeStatistics")
17
+	beego.Router("/admin/api/getdistrictsbyupid", &OrgAPIController{}, "get:GetDistrictsByUpid")
18
+	beego.Router("/admin/api/org/initdata", &OrgAPIController{}, "get:GetInitData")
19
+
20
+
21
+
22
+
16 23
 }

+ 100 - 0
controllers/admin_api_controllers/analysis_api_controller.go View File

@@ -2,6 +2,7 @@ package admin_api_controllers
2 2
 
3 3
 import (
4 4
 	"XT_Admin_Api/models"
5
+	"XT_Admin_Api/models/admin_models"
5 6
 	"XT_Admin_Api/service"
6 7
 	"XT_Admin_Api/utils"
7 8
 	"time"
@@ -464,3 +465,102 @@ func (this *AnalysisAPIController) PatientAnalysis() {
464 465
 		"age_counts": ageDistribution,
465 466
 	})
466 467
 }
468
+
469
+func (this *AnalysisAPIController) HomeStatistics() {
470
+	range_data := this.GetString("range_data")
471
+	range_type, _ := this.GetInt64("range_type")
472
+
473
+	var rangeDate *time.Time
474
+	var parseDateErr error
475
+	var rangeTimeStamp int64
476
+
477
+	if len(range_data) > 0 {
478
+		rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
479
+		if parseDateErr != nil {
480
+			this.ErrorLog("日期(%v)解析错误:%v", range_data, parseDateErr)
481
+			return
482
+		}
483
+		rangeTimeStamp = rangeDate.Unix()
484
+	} else {
485
+		rangeTimeStamp = 0
486
+	}
487
+	now := time.Now().Unix()
488
+
489
+	newOrgCount, _ := service.GetRegistedOrgCount(rangeTimeStamp, now)
490
+	totalOrg, _ := service.GetTotalOrgCount()
491
+
492
+	activeOrgCount, _ := service.GetActiveOrgCount(rangeTimeStamp, now)
493
+	totalActiveOrg, _ := service.GetActiveOrgTotalCount()
494
+
495
+	activeAdminCount, _ := service.GetActiveAdminUserCount(rangeTimeStamp, now)
496
+	adminTotalCount, _ := service.GetAdminUserTotalCount()
497
+
498
+	patientCount, _ :=service.GetNewPatientCount(rangeTimeStamp, now)
499
+	patientTotalCount, _ := service.GetPatientTotalCount()
500
+
501
+	var orgRegisterStatistics []*admin_models.Statistics
502
+	var newPatientStatistics []*admin_models.Statistics
503
+	var orgActiveAdminStatistics []*admin_models.Statistics
504
+	var orgActiveStatistics []*admin_models.Statistics
505
+
506
+	switch range_type {
507
+	case 3:
508
+		orgRegisterStatistics, _ = service.GetWeekRegistedOrgCount()
509
+		newPatientStatistics, _ = service.GetWeekNewPatientCount()
510
+		orgActiveAdminStatistics, _ = service.GetWeekActiveAdminUserCount()
511
+		orgActiveStatistics,_ = service.GetWeekActiveOrgCount()
512
+
513
+		//newOrgCount, _ = service.GetWeekRegistedOrgTotalCount()
514
+		//activeOrgCount, _ = service.GetWeekRegistedOrgTotalCount()
515
+		//activeAdminCount, _ = service.GetWeekRegistedOrgTotalCount()
516
+		//activeAdminCount, _ = service.GetWeekRegistedOrgTotalCount()
517
+		//
518
+		//
519
+
520
+		break
521
+	case 4:
522
+		orgRegisterStatistics, _ = service.GetMonthRegistedOrgCount()
523
+		newPatientStatistics, _ = service.GetMonthNewPatientCount()
524
+		orgActiveAdminStatistics, _ = service.GetMonthActiveAdminUserCount()
525
+		orgActiveStatistics,_ = service.GetMonthActiveOrgCount()
526
+
527
+		break
528
+	case 5:
529
+		orgRegisterStatistics, _ = service.GetThreeMonthRegistedOrgCount()
530
+		newPatientStatistics, _ = service.GetThreeMonthNewPatientCount()
531
+		orgActiveAdminStatistics, _ = service.GetThreeMonthActiveAdminUserCount()
532
+		orgActiveStatistics,_ = service.GetThreeMonthActiveOrgCount()
533
+
534
+		break
535
+	case 6:
536
+		orgRegisterStatistics, _ = service.GetSixMonthRegistedOrgCount()
537
+		newPatientStatistics, _ = service.GetSixMonthNewPatientCount()
538
+		orgActiveAdminStatistics, _ = service.GetSixMonthActiveAdminUserCount()
539
+		orgActiveStatistics,_ = service.GetSixMonthActiveOrgCount()
540
+
541
+		break
542
+	case 7:
543
+		orgRegisterStatistics, _ = service.GetYearRegistedOrgCount()
544
+		newPatientStatistics, _ = service.GetYearNewPatientCount()
545
+		orgActiveAdminStatistics, _ = service.GetYearActiveAdminUserCount()
546
+		orgActiveStatistics,_ = service.GetYearActiveOrgCount()
547
+
548
+		break
549
+	}
550
+
551
+	this.ServeSuccessJSON(map[string]interface{}{
552
+		"org_count":  newOrgCount,
553
+		"org_total_count":   totalOrg,
554
+		"active_org_count":  activeOrgCount,
555
+		"active_org_total_count": totalActiveOrg,
556
+		"active_admin_count":   activeAdminCount,
557
+		"active_admin_total_count": adminTotalCount,
558
+		"patient_count":  patientCount,
559
+		"patient_total_count":  patientTotalCount,
560
+		"org_count_list": orgRegisterStatistics,
561
+		"patient_count_list": newPatientStatistics,
562
+		"active_count_list": orgActiveAdminStatistics,
563
+		"active_org_list": orgActiveStatistics,
564
+	})
565
+
566
+}

+ 114 - 0
controllers/admin_api_controllers/org_api_controller.go View File

@@ -0,0 +1,114 @@
1
+package admin_api_controllers
2
+
3
+import (
4
+	"XT_Admin_Api/service"
5
+)
6
+
7
+type OrgAPIController struct {
8
+	AdminBaseAPIAuthController
9
+}
10
+
11
+func (this *OrgAPIController) GetOrgList() {
12
+	//active_status,_ := this.GetInt64("active_status")
13
+	//depth_active_status,_ := this.GetInt64("depth_active_status")
14
+	//start_time := this.GetString("start_time")
15
+	//end_time := this.GetString("end_time")
16
+	//province,_ := this.GetInt64("province")
17
+	//city,_ := this.GetInt64("city")
18
+	//district,_ := this.GetInt64("district")
19
+	//follow,_ := this.GetInt64("follow")
20
+	//keyword := this.GetString("keyword")
21
+	//page, _ := this.GetInt64("page", 0)
22
+	//limit, _ := this.GetInt64("limit", 0)
23
+	//
24
+	//if page <= 0 {
25
+	//	page = 1
26
+	//}
27
+	//if limit <= 0 {
28
+	//	limit = 10
29
+	//}
30
+	//adminInfo := this.GetAdminInfo()
31
+	//if adminInfo.Admin.IsSuperAdmin == 1 {
32
+	//	list, err, total := service.GetAllOrgList(active_status,depth_active_status,start_time,end_time,province,city,district,follow,keyword,page,limit)
33
+	//	if err != nil {
34
+	//
35
+	//	} else {
36
+	//		this.ServeSuccessJSON(map[string]interface{}{
37
+	//			"list": list,
38
+	//			"total":total,
39
+	//		})
40
+	//
41
+	//	}
42
+	//} else {
43
+	//
44
+	//
45
+	//
46
+	//}
47
+
48
+}
49
+
50
+
51
+func (this *OrgAPIController) GetOrgDetail() {
52
+	org_id, _:=this.GetInt64("org_id",0)
53
+	info, err := service.GetOrgDetailInfo(org_id)
54
+	if err != nil {
55
+
56
+	} else {
57
+		this.ServeSuccessJSON(map[string]interface{}{
58
+			"info": info,
59
+		})
60
+	}
61
+}
62
+
63
+
64
+
65
+func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
66
+	//org_id, _:=this.GetInt64("org_id",0)
67
+	//range_data := this.GetString("range_data")
68
+	//range_type, _ := this.GetInt64("range_type")
69
+	//statistics_type, _ := this.GetInt64("type")
70
+	//
71
+	//
72
+	//var rangeDate *time.Time
73
+	//var parseDateErr error
74
+	//var rangeTimeStamp int64
75
+	//
76
+	//if len(range_data) > 0 {
77
+	//	rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
78
+	//	if parseDateErr != nil {
79
+	//		this.ErrorLog("日期(%v)解析错误:%v", range_data, parseDateErr)
80
+	//		return
81
+	//	}
82
+	//	rangeTimeStamp = rangeDate.Unix()
83
+	//} else {
84
+	//	rangeTimeStamp = 0
85
+	//}
86
+	//now := time.Now().Unix()
87
+	//
88
+	//info, err := service.GetOrgNewPatientInfo(org_id)
89
+	//if err != nil {
90
+	//
91
+	//} else {
92
+	//	this.ServeSuccessJSON(map[string]interface{}{
93
+	//		"info": info,
94
+	//	})
95
+	//}
96
+}
97
+
98
+func (c *OrgAPIController) GetDistrictsByUpid() {
99
+	id, _ := c.GetInt64("id", 0)
100
+	citys, _ := service.GetDistrictsByUpid(id)
101
+
102
+	c.ServeSuccessJSON(map[string]interface{}{
103
+		"citys": citys,
104
+	})
105
+	return
106
+}
107
+
108
+
109
+func (this *OrgAPIController)GetInitData(){
110
+	provinces, _ := service.GetDistrictsByUpid(0)
111
+	this.ServeSuccessJSON(map[string]interface{}{
112
+		"provinces": provinces,
113
+	})
114
+}

+ 7 - 6
models/admin_models/admin_models.go View File

@@ -3,12 +3,13 @@
3 3
 package admin_models
4 4
 
5 5
 type AdminAccount struct {
6
-	Id         int    `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
7
-	Account    string `json:"account"`
8
-	Pwd        string `json:"-"`
9
-	Status     int8   `json:"-"`                     // 状态 0.无效 1.有效
10
-	CreateTime int64  `gorm:"column:ctime" json:"-"` // 创建时间
11
-	ModifyTime int64  `gorm:"column:mtime" json:"-"` // 修改时间
6
+	Id           int    `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
7
+	Account      string `json:"account"`
8
+	Pwd          string `json:"-"`
9
+	Status       int8   `json:"-"`                     // 状态 0.无效 1.有效
10
+	CreateTime   int64  `gorm:"column:ctime" json:"-"` // 创建时间
11
+	ModifyTime   int64  `gorm:"column:mtime" json:"-"` // 修改时间
12
+	IsSuperAdmin int64  `gorm:"column:is_super_admin" json:"is_super_admin"`
12 13
 }
13 14
 
14 15
 func (AdminAccount) TableName() string {

+ 13 - 0
models/admin_models/statistics_models.go View File

@@ -0,0 +1,13 @@
1
+package admin_models
2
+
3
+
4
+type Statistics struct {
5
+	Count int64
6
+	Times  string
7
+}
8
+
9
+
10
+
11
+type Count struct {
12
+	Count int64
13
+}

+ 43 - 26
models/org_models.go View File

@@ -1,32 +1,32 @@
1 1
 package models
2 2
 
3 3
 type Org struct {
4
-	Id              int64  `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"` // 机构 ID
5
-	Creator         int64  `json:"creator"`                              // 创建者,即管理员用户的 id
6
-	OrgName         string `gorm:"column:org_name" json:"org_name"`
7
-	OrgShortName    string `gorm:"column:org_short_name" json:"org_short_name"` // 简称
8
-	OrgLogo         string `gorm:"column:org_logo" json:"org_logo"`
9
-	OrgIntroduction string `gorm:"column:org_introduction" json:"org_introduction"`
10
-	Province        int64  `json:"province"` // 省,代号,下面的市、区也一样
11
-	City            int64  `json:"city"`
12
-	District        int64  `json:"district"`
13
-	Address         string `json:"address"`                   // 详细地址
14
-	Illness         string `json:"illness"`                   // 服务病种 多个并用“,”隔开
15
-	Status          int8   `json:"status"`                    // 状态 0.无效 1.有效 2.禁用
16
-	CreateTime      int64  `gorm:"column:ctime" json:"ctime"` // 创建时间
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"`
29
-	OrgGallery     []*OrgGallery `gorm:"ForeignKey:OrgId" json:"org_gallery"`
4
+	Id                int64             `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"` // 机构 ID
5
+	Creator           int64             `json:"creator"`                              // 创建者,即管理员用户的 id
6
+	OrgName           string            `gorm:"column:org_name" json:"org_name"`
7
+	OrgShortName      string            `gorm:"column:org_short_name" json:"org_short_name"` // 简称
8
+	OrgLogo           string            `gorm:"column:org_logo" json:"org_logo"`
9
+	OrgIntroduction   string            `gorm:"column:org_introduction" json:"org_introduction"`
10
+	Province          int64             `json:"province"` // 省,代号,下面的市、区也一样
11
+	City              int64             `json:"city"`
12
+	District          int64             `json:"district"`
13
+	Address           string            `json:"address"`                   // 详细地址
14
+	Illness           string            `json:"illness"`                   // 服务病种 多个并用“,”隔开
15
+	Status            int8              `json:"status"`                    // 状态 0.无效 1.有效 2.禁用
16
+	CreateTime        int64             `gorm:"column:ctime" json:"ctime"` // 创建时间
17
+	ModifyTime        int64             `gorm:"column:mtime" json:"mtime"` // 修改时间
18
+	OrgType           int64             `gorm:"column:org_type" json:"org_type"`
19
+	Evaluate          float64           `gorm:"column:evaluate" json:"evaluate"`
20
+	Comments          int64             `gorm:"column:comments" json:"comments"`
21
+	OperatingState    int64             `gorm:"column:operating_state" json:"operating_state"`
22
+	Claim             int64             `gorm:"column:claim" json:"claim"`
23
+	Telephone         string            `gorm:"column:telephone" json:"telephone"`
24
+	BusinessWeek      string            `gorm:"column:business_week" json:"business_week"`
25
+	BusinessTime      string            `gorm:"column:business_time" json:"business_time"`
26
+	Gallery           string            `gorm:"column:gallery" json:"gallery"`
27
+	ContactName       string            `gorm:"column:contact_name" json:"contact_name"`
28
+	OrgGallery        []*OrgGallery     `gorm:"ForeignKey:OrgId" json:"org_gallery"`
29
+	AdminUserLoginLog AdminUserLoginLog `gorm:"ForeignKey:OrgId" json:"log"`
30 30
 }
31 31
 
32 32
 func (Org) TableName() string {
@@ -105,3 +105,20 @@ func (Illness) TableName() string {
105 105
 }
106 106
 
107 107
 
108
+
109
+type District struct {
110
+	ID        int64  `gorm:"column:id" json:"id" form:"id"`
111
+	Name      string `gorm:"column:name" json:"name" form:"name"`
112
+	Level     int64  `gorm:"column:level" json:"level" form:"level"`
113
+	Upid      int64  `gorm:"column:upid" json:"upid" form:"upid"`
114
+	Path      string `gorm:"column:path" json:"path" form:"path"`
115
+	Namepath  string `gorm:"column:namepath" json:"namepath" form:"namepath"`
116
+	Initial   string `gorm:"column:initial" json:"initial" form:"initial"`
117
+	Longitude string `gorm:"column:longitude" json:"longitude" form:"longitude"`
118
+	Latitude  string `gorm:"column:latitude" json:"latitude" form:"latitude"`
119
+	Adcode    int64  `gorm:"column:adcode" json:"adcode" form:"adcode"`
120
+}
121
+
122
+func (District) TableName() string {
123
+	return "sgj_user_district"
124
+}

+ 1 - 0
routers/router.go View File

@@ -2,6 +2,7 @@ package routers
2 2
 
3 3
 import (
4 4
 	admin_api "XT_Admin_Api/controllers/admin_api_controllers"
5
+
5 6
 	"github.com/astaxie/beego"
6 7
 	"github.com/astaxie/beego/plugins/cors"
7 8
 )

+ 387 - 0
service/admin_service.go View File

@@ -351,3 +351,390 @@ func BatchSaveSpecialPermissionAdminUsers(users []*models.AdminUserSpecialPermis
351 351
 	}
352 352
 	return tx.Commit().Error
353 353
 }
354
+
355
+// 获取一段时间内新增病人数量
356
+func GetNewPatientCount(from int64, to int64) (int, error) {
357
+	var count int
358
+	rows, err := readDb.Raw("SELECT COUNT(DISTINCT id_card_no) AS count FROM xt_patients WHERE status > 0 AND created_time >= ? AND created_time <= ?", from, to).Rows()
359
+	if err != nil {
360
+		return 0, err
361
+	}
362
+	if rows.Next() {
363
+		rows.Scan(&count)
364
+	}
365
+	return count, nil
366
+}
367
+
368
+// 获取所有机构病人数量
369
+func GetPatientTotalCount() (int64, error) {
370
+
371
+	var count int64
372
+	rows, err := readDb.Raw("SELECT COUNT(DISTINCT id_card_no) AS count FROM xt_patients").Rows()
373
+	if err != nil {
374
+		return 0, err
375
+	}
376
+	if rows.Next() {
377
+		rows.Scan(&count)
378
+	}
379
+	return count, nil
380
+
381
+}
382
+
383
+// 获取一段时间内的活跃账户数
384
+func GetActiveAdminUserCount(from int64, to int64) (int64, error) {
385
+	var count int64
386
+	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ? AND operate_type = 1", from, to).Rows()
387
+	if err != nil {
388
+		return 0, err
389
+	}
390
+	if rows.Next() {
391
+		rows.Scan(&count)
392
+	}
393
+	return count, nil
394
+}
395
+
396
+// 获取所有机构账户数量
397
+func GetAdminUserTotalCount() (int64, error) {
398
+	var count int64
399
+	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM sgj_user_admin_login_log").Rows()
400
+	if err != nil {
401
+		return 0, err
402
+	}
403
+	if rows.Next() {
404
+		rows.Scan(&count)
405
+	}
406
+	return count, nil
407
+}
408
+
409
+// 获取一段时间内注册的机构数量
410
+func GetRegistedOrgCount(from int64, to int64) (int64, error) {
411
+	var count int64
412
+	err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ?", from, to).Count(&count).Error
413
+	if err != nil {
414
+		return 0, err
415
+	}
416
+	return count, nil
417
+}
418
+
419
+// 获取一段时间内的活跃机构数
420
+func GetActiveOrgCount(from int64, to int64) (int64, error) {
421
+	var count int64
422
+	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ?", from, to).Joins("JOIN sgj_xt.xt_dialysis_order as order ON sgj_user_admin_login_log.org_id = order.user_org_id").Rows()
423
+	if err != nil {
424
+		return 0, err
425
+	}
426
+	if rows.Next() {
427
+		rows.Scan(&count)
428
+	}
429
+	return count, nil
430
+}
431
+
432
+// 获取所有活跃机构数
433
+func GetActiveOrgTotalCount() (int64, error) {
434
+	var count int64
435
+	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log").Joins("JOIN sgj_xt.xt_dialysis_order as order ON sgj_user_admin_login_log.org_id = order.user_org_id").Rows()
436
+	if err != nil {
437
+		return 0, err
438
+	}
439
+	if rows.Next() {
440
+		rows.Scan(&count)
441
+	}
442
+	return count, nil
443
+}
444
+
445
+
446
+
447
+//获取近七天每天的注册机构总量
448
+func GetWeekRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
449
+	err = readUserDb.Raw("select count(id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times  from sgj_user_org  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime)) GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
450
+	return
451
+}
452
+
453
+//func GetWeekActiveOrgCount() (weekStatistics []*admin_models.WeekStatistics, err error) {
454
+//	err = readUserDb.Raw("select count(id) as count, date(from_unixtime(ctime)) as times  from sgj_user_org  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime)) GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
455
+//	return
456
+//}
457
+
458
+//获取近七天每天的机构活跃总量
459
+func GetWeekActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
460
+	db := readUserDb.Raw("select count(DISTINCT(org_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times  from sgj_user_admin_login_log   join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = sgj_user_admin_login_log.org_id AND  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d')  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime))  AND operate_type = 1 GROUP BY date(from_unixtime(ctime));")
461
+	err = db.Scan(&weekStatistics).Error
462
+	return
463
+}
464
+
465
+//获取近七天每天的机构活跃账号总量
466
+func GetWeekActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
467
+	err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times  from sgj_user_admin_login_log  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime))  AND operate_type = 1 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
468
+	return
469
+}
470
+
471
+//获取近七天每天的机构新增病人总量
472
+func GetWeekNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
473
+	err = readDb.Raw("select count(DISTINCT(id_card_no)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) GROUP BY date(from_unixtime(created_time));").Scan(&weekStatistics).Error
474
+	return
475
+}
476
+
477
+
478
+
479
+
480
+//获取近七天每天的注册机构总量
481
+func GetWeekRegistedOrgTotalCount() (int64,  error) {
482
+	var result admin_models.Count
483
+	var err error
484
+	err = readUserDb.Raw("select count(id) as count  from sgj_user_org  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime))").Scan(&result).Error
485
+	return result.Count,err
486
+}
487
+
488
+//获取近七天每天的机构活跃账号总量
489
+func GetWeekActiveAdminUserTotalCount() (int64,  error) {
490
+	var result admin_models.Count
491
+	var err error
492
+	err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count  from sgj_user_admin_login_log  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime))  AND operate_type = 1 ").Scan(&result).Error
493
+	return result.Count,err
494
+
495
+}
496
+
497
+//获取近七天新增病人总量
498
+func GetWeekPatientTotalCount() (int64,  error) {
499
+	var result admin_models.Count
500
+	var err error
501
+	err = readDb.Raw("select count(DISTINCT(id_card_no)) as count  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time))").Scan(&result).Error
502
+	return result.Count,err
503
+
504
+}
505
+
506
+
507
+
508
+
509
+
510
+
511
+//获取近30天每天的注册机构总量
512
+func GetMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
513
+	err = readUserDb.Raw("select count(id) as count,DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times  from sgj_user_org  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_org.ctime)) GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
514
+	return
515
+}
516
+
517
+
518
+//获取近30天每天的机构活跃总量
519
+func GetMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
520
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,count(DISTINCT(org_id)) as count From  (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 ) T  join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND  DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where  DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 1 month),'%Y-%m')  group by month").Scan(&weekStatistics).Error
521
+	return
522
+}
523
+
524
+
525
+//获取近30天每天的机构活跃账号总量
526
+func GetMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
527
+	err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d')as times  from sgj_user_admin_login_log  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime))  AND operate_type = 1 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
528
+	return
529
+}
530
+
531
+//获取近30天每天的机构新增病人总量
532
+func GetMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
533
+	err = readDb.Raw("select count(DISTINCT(id_card_no)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) GROUP BY date(from_unixtime(created_time));").Scan(&weekStatistics).Error
534
+	return
535
+}
536
+
537
+
538
+
539
+//获取近30天每天的注册机构总量
540
+func GetMonthRegistedOrgTotalCount() (int64,  error) {
541
+	var result admin_models.Count
542
+	var err error
543
+	err = readUserDb.Raw("select count(id) as count from sgj_user_org  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_org.ctime))").Scan(&result).Error
544
+	return result.Count,err
545
+}
546
+
547
+
548
+//获取近30天每天的机构活跃账号总量
549
+func GetMonthActiveAdminUserTotalCount() (int64,  error) {
550
+	var result admin_models.Count
551
+	var err error
552
+	err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime))  AND operate_type = 1 ").Scan(&result).Error
553
+	return result.Count,err
554
+}
555
+
556
+//获取近30天每天的机构新增病人总量
557
+func GetMonthNewPatientTotalCount() (int64,  error) {
558
+	var result admin_models.Count
559
+	var err error
560
+	err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) ").Scan(&result).Error
561
+	return result.Count,err
562
+}
563
+
564
+
565
+
566
+
567
+
568
+
569
+//获取近3个月每个月的注册机构总量
570
+func GetThreeMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
571
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
572
+	return
573
+}
574
+
575
+
576
+//获取近3个月每个月的机构活跃账号总量
577
+func GetThreeMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
578
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')  AND operate_type = 1 group by times").Scan(&weekStatistics).Error
579
+	return
580
+}
581
+
582
+//获取近3个月每个月的机构活跃总量
583
+func GetThreeMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
584
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,count(DISTINCT(org_id)) as count From  (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 ) T  join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND  DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where  DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')  group by month").Scan(&weekStatistics).Error
585
+	return
586
+}
587
+
588
+//获取近3个月每个月机构新增病人总量
589
+func GetThreeMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
590
+	err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where  DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
591
+	return
592
+}
593
+
594
+
595
+//获取近3个月每个月的注册机构总量
596
+func GetThreeMonthRegistedOrgTotalCount() (int64,  error) {
597
+	var result admin_models.Count
598
+	var err error
599
+	err = readUserDb.Raw("select count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')").Scan(&result).Error
600
+	return result.Count,err
601
+
602
+}
603
+
604
+
605
+//获取近3个月每个月的机构活跃账号总量
606
+func GetThreeMonthActiveAdminUserTotalCount() (int64,  error) {
607
+	var result admin_models.Count
608
+	var err error
609
+	err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')  AND operate_type = 1 ").Scan(&result).Error
610
+	return result.Count,err
611
+
612
+}
613
+
614
+
615
+//获取近3个月每个月机构新增病人总量
616
+func GetThreeMonthNewPatientTotalCount() (int64,  error) {
617
+	var result admin_models.Count
618
+	var err error
619
+	err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where  DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')").Scan(&result).Error
620
+	return result.Count,err
621
+
622
+}
623
+
624
+
625
+
626
+//获取近半年每个月的注册机构总量
627
+func GetSixMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
628
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
629
+	return
630
+}
631
+
632
+
633
+//获取近半年每个月的机构活跃账号总量
634
+func GetSixMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
635
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
636
+	return
637
+}
638
+
639
+
640
+//获取近半年每个月的机构活跃总量
641
+func GetSixMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
642
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,count(DISTINCT(org_id)) as count From  (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 ) T  join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND  DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where  DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')  group by month").Scan(&weekStatistics).Error
643
+	return
644
+}
645
+
646
+
647
+//获取近半年每个月机构新增病人总量
648
+func GetSixMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
649
+	err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where  DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
650
+	return
651
+}
652
+
653
+
654
+//获取近半年每个月的注册机构总量
655
+func GetSixMonthRegistedOrgTotalCount() (int64,  error) {
656
+	var result admin_models.Count
657
+	var err error
658
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
659
+	return result.Count, err
660
+}
661
+
662
+
663
+	//获取近半年每个月的机构活跃账号总量
664
+func GetSixMonthActiveAdminUserTotalCount() (int64,  error) {
665
+	var result admin_models.Count
666
+	var err error
667
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
668
+	return result.Count, err
669
+
670
+}
671
+
672
+
673
+//获取近半年每个月机构新增病人总量
674
+func GetSixMonthNewPatientTotalCount() (int64,  error) {
675
+	var result admin_models.Count
676
+	var err error
677
+	err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where  DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
678
+	return result.Count, err
679
+
680
+}
681
+
682
+
683
+
684
+
685
+//获取近1年每个月的注册机构总量
686
+func GetYearRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
687
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
688
+	return
689
+}
690
+
691
+
692
+//获取近1年每个月的机构活跃账号总量
693
+func GetYearActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
694
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
695
+	return
696
+}
697
+
698
+//获取近1年每个月的机构活跃总量
699
+func GetYearActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
700
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,count(DISTINCT(org_id)) as count From  (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 ) T  join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND  DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where  DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')  group by month").Scan(&weekStatistics).Error
701
+	return
702
+}
703
+
704
+//获取近1年每个月机构新增病人总量
705
+func GetYearNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
706
+	err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where  DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') AND status > 0 group by times").Scan(&weekStatistics).Error
707
+	return
708
+}
709
+
710
+
711
+//获取近1年每个月的注册机构总量
712
+func GetYearRegistedOrgTotalCount() (int64,  error) {
713
+	var result admin_models.Count
714
+	var err error
715
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')").Scan(&result).Error
716
+	return result.Count, err
717
+
718
+}
719
+
720
+
721
+//获取近1年每个月的机构活跃账号总量
722
+func GetYearActiveAdminUserTotalCount() (int64,  error) {
723
+	var result admin_models.Count
724
+	var err error
725
+	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')").Scan(&result).Error
726
+	return result.Count, err
727
+}
728
+
729
+
730
+//获取近1年每个月机构新增病人总量
731
+func GetYearNewPatientTotalCount() (int64,  error) {
732
+	var result admin_models.Count
733
+	var err error
734
+	err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where  DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') AND status > 0").Scan(&result).Error
735
+	return result.Count, err
736
+
737
+}
738
+
739
+
740
+

+ 112 - 0
service/org_service.go View File

@@ -0,0 +1,112 @@
1
+package service
2
+
3
+import (
4
+	"XT_Admin_Api/models"
5
+	"XT_Admin_Api/utils"
6
+	"github.com/jinzhu/gorm"
7
+	"time"
8
+)
9
+
10
+func GetAllOrgList(active_status int64,depth_active_status int64,start_time int64,end_time int64,province int64,city int64,district int64,follow int64,keyword string,page int64, limit int64) (list []*models.Org, err error, total int64){
11
+	offset := (page - 1) * limit
12
+
13
+	db := readUserDb.Model(&models.Org{})
14
+	if len(keyword) > 0{
15
+		likeKey := "%" + keyword + "%"
16
+		db = db.Where("contact_name  LIKE ?",likeKey)
17
+	}else{
18
+
19
+		switch active_status {
20
+		case 1:
21
+			now := time.Now()
22
+			zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
23
+			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND sgj_user_admin_login_log.ctime >= ? AND sgj_user_admin_login_log.ctime <= ? AND sgj_user_admin_login_log.app_type = 3",zeroHourTimeOfToday.Unix(),now.Unix())
24
+			break
25
+		case 2:
26
+			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3")
27
+			break
28
+		case 3:
29
+			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3")
30
+			break
31
+		case 4:
32
+			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 Year) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3")
33
+			break
34
+		}
35
+
36
+		switch depth_active_status {
37
+		case 1:
38
+			now := time.Now()
39
+			zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
40
+			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND sgj_user_admin_login_log.ctime >= ? AND sgj_user_admin_login_log.ctime <= ? AND sgj_user_admin_login_log.app_type = 3",zeroHourTimeOfToday.Unix(),now.Unix())
41
+			db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') AND sgj_user_admin_login_log.app_type = 3",zeroHourTimeOfToday.Unix(),now.Unix())
42
+
43
+			break
44
+		case 2:
45
+			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3")
46
+			db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') AND sgj_user_admin_login_log.app_type = 3")
47
+
48
+			break
49
+		case 3:
50
+			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3")
51
+			db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') AND sgj_user_admin_login_log.app_type = 3")
52
+
53
+			break
54
+		case 4:
55
+			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 Year) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3")
56
+			db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') AND sgj_user_admin_login_log.app_type = 3")
57
+
58
+			break
59
+		}
60
+		if province > 0{
61
+			db = db.Where("sgj_user_org.province = ?",province)
62
+		}
63
+
64
+		if city > 0{
65
+			db = db.Where("sgj_user_org.province = ?",city)
66
+		}
67
+
68
+		if district > 0{
69
+			db = db.Where("sgj_user_org.province = ?",district)
70
+		}
71
+
72
+		if start_time != 0 {
73
+			db = db.Where("ctime>=?", start_time)
74
+		}
75
+		if end_time != 0 {
76
+			db = db.Where("ctime<=?", end_time)
77
+		}
78
+
79
+	}
80
+	err = db.Where("status = 1").Count(&total).Offset(offset).Limit(limit).Find(&list).Error
81
+	return
82
+}
83
+
84
+
85
+func GetOrgDetailInfo(org_id int64) (info models.Org, err error){
86
+	err = readUserDb.Model(&models.Org{}).Where("org_id = ? AND status = 1",org_id).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
87
+		return db.Model(&models.AdminUserLoginLog{}).Where("status = 1 AND id = (SELECT max(id))")
88
+	}).Find(&info).Error
89
+	return
90
+}
91
+
92
+
93
+
94
+func GetOrgNewPatientInfo(org_id int64, from int64,to int64) (count int64, err error){
95
+
96
+	var counts int64
97
+	rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_patients WHERE org_id = ? AND created_time >= ? AND created_time <= ?",org_id ,from, to).Rows()
98
+	if err != nil {
99
+		return 0, err
100
+	}
101
+	if rows.Next() {
102
+		rows.Scan(&counts)
103
+	}
104
+	return counts, nil
105
+}
106
+
107
+
108
+
109
+func GetDistrictsByUpid(id int64) (dis []*models.District, err error) {
110
+	err = readUserDb.Model(&models.District{}).Where("upid=?", id).Find(&dis).Error
111
+	return
112
+}