Browse Source

体积小

XMLWAN 3 years ago
parent
commit
9221052ebf

+ 53 - 27
controllers/xcx_mobile_api_controller.go/xcx_api_controller.go View File

@@ -27,6 +27,9 @@ func XcxApiControllersRegisterRouters() {
27 27
 
28 28
 	//获取登录后的信息
29 29
 	beego.Router("/xcx/api/mobile/getdatainfo", &XcxApiController{}, "Get:GetDataInfo")
30
+
31
+	//获取排班数据
32
+	beego.Router("/xcx/api/mobile/schedule", &XcxApiController{}, "Get:GetScheduleInfo")
30 33
 }
31 34
 
32 35
 type XcxApiController struct {
@@ -61,39 +64,50 @@ func (this *XcxApiController) GetUserRegister() {
61 64
 	mobile := this.GetString("mobile")
62 65
 	code := this.GetString("code")
63 66
 
64
-	role := models.XcxAdminUserRole{
65
-		PatientName: name,
66
-		IdCardNo:    id_card_no,
67
-		Mobile:      mobile,
68
-		Code:        code,
69
-		PatientId:   0,
70
-		UserOrgId:   0,
71
-		Status:      0,
72
-		Ctime:       0,
73
-		Mtime:       0,
74
-		Appid:       "",
75
-		Appsecret:   "",
76
-		SessionKey:  "",
77
-	}
78
-
79
-	//查找该电话号码是否存在
80
-	_, errcode := service.GetXcxMobileInformation(mobile)
81
-	if errcode == gorm.ErrRecordNotFound {
67
+	patient, errcodes := service.GetMobilePatient(id_card_no)
68
+	if errcodes == gorm.ErrRecordNotFound {
69
+		role := models.XcxAdminUserRole{
70
+			PatientName: name,
71
+			IdCardNo:    id_card_no,
72
+			Mobile:      mobile,
73
+			Code:        code,
74
+			PatientId:   patient.ID,
75
+			UserOrgId:   patient.UserOrgId,
76
+			Status:      1,
77
+			Ctime:       time.Now().Unix(),
78
+			Mtime:       0,
79
+			Appid:       "",
80
+			Appsecret:   "",
81
+			SessionKey:  "",
82
+		}
82 83
 
83
-		err := service.CreateXcxAdminUser(role)
84
-		if err == nil {
85
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
86
-			return
84
+		//查找该电话号码是否存在
85
+		_, errcode := service.GetMobilePatient(mobile)
86
+		if errcode == gorm.ErrRecordNotFound {
87
+			err := service.CreateXcxAdminUser(role)
88
+			if err == nil {
89
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
90
+				return
91
+			}
92
+			this.ServeSuccessJSON(map[string]interface{}{
93
+				"role": role,
94
+			})
95
+		} else if errcode == nil {
96
+			mobilePatient, _ := service.GetMobilePatient(id_card_no)
97
+			this.ServeSuccessJSON(map[string]interface{}{
98
+				"is_bind": true,
99
+				"patient": mobilePatient,
100
+			})
87 101
 		}
102
+
103
+		fmt.Println("roler", role)
104
+	} else if errcodes == nil {
88 105
 		this.ServeSuccessJSON(map[string]interface{}{
89
-			"role": role,
106
+			"is_bind": false,
107
+			"patient": patient,
90 108
 		})
91
-	} else if errcode == nil {
92
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
93
-		return
94 109
 	}
95 110
 
96
-	fmt.Println("roler", role)
97 111
 }
98 112
 
99 113
 func (this *XcxApiController) GetCodeInfo() {
@@ -202,3 +216,15 @@ func (this *XcxApiController) GetDataInfo() {
202 216
 		"list": list,
203 217
 	})
204 218
 }
219
+
220
+func (this *XcxApiController) GetScheduleInfo() {
221
+	thisWeekMonday := service.GetFirstDateOfWeek()
222
+
223
+	TimeMonday, _ := time.Parse("2006-01-02", thisWeekMonday)
224
+	lastWeekMonday := TimeMonday.AddDate(0, 0, -7)
225
+	nextWeekMonday := TimeMonday.AddDate(0, 0, +7)
226
+	var weekMonday = lastWeekMonday.Format("2006-01-02")
227
+	var weekDay = nextWeekMonday.Format("2006-01-02")
228
+	fmt.Println("weekmodonday", weekMonday)
229
+	fmt.Println("nextweeekday", weekDay)
230
+}

+ 30 - 0
service/xcx_mobile_api_service.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"errors"
10 10
 	"github.com/jinzhu/gorm"
11 11
 	"strings"
12
+	"time"
12 13
 )
13 14
 
14 15
 func GetXcxMobileInformation(mobile string) (*models.XcxAdminUserRole, error) {
@@ -105,3 +106,32 @@ func AesDecrypt(crypted, key, iv []byte) ([]byte, error) {
105 106
 	return origData[:(length - unp)], nil
106 107
 
107 108
 }
109
+
110
+func GetFirstDateOfWeek() (weekMonday string) {
111
+	now := time.Now()
112
+
113
+	offset := int(time.Monday - now.Weekday())
114
+	if offset > 0 {
115
+		offset = -6
116
+	}
117
+
118
+	weekStartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
119
+	weekMonday = weekStartDate.Format("2006-01-02")
120
+	return
121
+}
122
+
123
+func GetMobilePatient(mobile string) (*models.XcxPatients, error) {
124
+
125
+	patient := models.XcxPatients{}
126
+
127
+	err := UserReadDB().Model(&patient).Where("id_card_no = ? and status = 1", mobile).Find(&patient).Error
128
+	if err == gorm.ErrRecordNotFound {
129
+		return nil, err
130
+	}
131
+
132
+	if err != nil {
133
+		return nil, err
134
+	}
135
+	return &patient, nil
136
+
137
+}