XMLWAN 3 lat temu
rodzic
commit
c66f416ece

+ 137 - 0
controllers/xcx_mobile_api_controller.go/xcx_api_controller.go Wyświetl plik

@@ -0,0 +1,137 @@
1
+package xcx_mobile_api_controller_go
2
+
3
+import (
4
+	"Xcx_New/controllers"
5
+	"Xcx_New/enums"
6
+	"Xcx_New/models"
7
+	"Xcx_New/service"
8
+	"Xcx_New/utils"
9
+	"fmt"
10
+	"github.com/astaxie/beego"
11
+	"github.com/jinzhu/gorm"
12
+	"time"
13
+)
14
+
15
+func XcxApiControllersRegisterRouters() {
16
+
17
+	//传送codeinit
18
+	beego.Router("/m/api/code", &XcxApiController{}, "Get:GetCodeInit")
19
+	//获取验证码
20
+	beego.Router("/xcx/api/mobile/code", &XcxApiController{}, "Get:GetCodeInfo")
21
+	//用户绑定
22
+	beego.Router("/xcx/api/mobile/register", &XcxApiController{}, "Get:GetUserRegister")
23
+	//登录
24
+	beego.Router("/xcx/api/mobile/register", &XcxApiController{}, "Get:GetLoginInfor")
25
+}
26
+
27
+type XcxApiController struct {
28
+	controllers.BaseAuthAPIController
29
+}
30
+
31
+func (this *XcxApiController) GetCodeInit() {
32
+	redisClient := service.RedisClient()
33
+	defer redisClient.Close()
34
+	req := this.Ctx.Request
35
+	addr := utils.GetIP(req)
36
+	cur_time := time.Now().Format("2006-01-02")
37
+	_, err := redisClient.Get("ip:host_" + cur_time + "_" + addr).Result()
38
+	if err != nil {
39
+		redisClient.Set("ip:host_"+cur_time+"_"+addr, 0, time.Second*24*60*60)
40
+	}
41
+	//将客户端的ip加密传给前端,作为短信验证的密钥,来验证短信发送的IP地址
42
+	aespass := utils.AESEncrypt(addr)
43
+
44
+	fmt.Println("hhhhhhh3223323232332", aespass)
45
+	this.ServeSuccessJSON(map[string]interface{}{
46
+		"aespass": aespass,
47
+	})
48
+
49
+}
50
+
51
+func (this *XcxApiController) GetUserRegister() {
52
+
53
+	//用户绑定
54
+	name := this.GetString("name")
55
+	id_card_no := this.GetString("id_card_no")
56
+	mobile := this.GetString("mobile")
57
+	code := this.GetString("code")
58
+
59
+	role := models.XcxAdminUserRole{
60
+		PatientName: name,
61
+		IdCardNo:    id_card_no,
62
+		Mobile:      mobile,
63
+		Code:        code,
64
+		PatientId:   0,
65
+		UserOrgId:   0,
66
+		Status:      0,
67
+		Ctime:       0,
68
+		Mtime:       0,
69
+		Appid:       "",
70
+		Appsecret:   "",
71
+		SessionKey:  "",
72
+	}
73
+
74
+	//查找该电话号码是否存在
75
+	_, errcode := service.GetXcxMobileInformation(mobile)
76
+	if errcode == gorm.ErrRecordNotFound {
77
+
78
+		err := service.CreateXcxAdminUser(role)
79
+		if err == nil {
80
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
81
+			return
82
+		}
83
+		this.ServeSuccessJSON(map[string]interface{}{
84
+			"role": role,
85
+		})
86
+	} else if errcode == nil {
87
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
88
+		return
89
+	}
90
+
91
+	fmt.Println("roler", role)
92
+}
93
+
94
+func (this *XcxApiController) GetCodeInfo() {
95
+
96
+	mobile := this.GetString("phone")
97
+	aespass := this.GetString("aespass")
98
+	utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
99
+	if utils.CellPhoneRegexp().MatchString(mobile) == false {
100
+		this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
101
+		this.ServeJSON()
102
+		return
103
+	}
104
+
105
+	adminUser, _ := service.GetValidAdminUserByMobileReturnErr(mobile)
106
+	if adminUser != nil {
107
+		this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRegisterExist)
108
+		this.ServeJSON()
109
+		return
110
+	}
111
+
112
+	if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
113
+		this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
114
+		this.ServeJSON()
115
+	} else {
116
+		this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
117
+			"msg": "短信发送成功,有效期为10分钟",
118
+		})
119
+		this.ServeJSON()
120
+	}
121
+}
122
+
123
+func (this *XcxApiController) GetLoginInfor() {
124
+
125
+	mobile := this.GetString("mobile")
126
+
127
+	role, err := service.GetLoginInfor(mobile)
128
+
129
+	if err == nil {
130
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
131
+		return
132
+	}
133
+
134
+	this.ServeSuccessJSON(map[string]interface{}{
135
+		"role": role,
136
+	})
137
+}

+ 22 - 0
models/xcx_user_models.go Wyświetl plik

@@ -0,0 +1,22 @@
1
+package models
2
+
3
+type XcxAdminUserRole struct {
4
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
5
+	PatientName string `gorm:"column:patient_name" json:"patient_name" form:"patient_name"`
6
+	IdCardNo    string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
7
+	Mobile      string `gorm:"column:mobile" json:"mobile" form:"mobile"`
8
+	Code        string `gorm:"column:code" json:"code" form:"code"`
9
+	PatientId   int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
10
+	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
11
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
12
+	Ctime       int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
13
+	Mtime       int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
14
+	Appid       string `gorm:"column:appid" json:"appid" form:"appid"`
15
+	Appsecret   string `gorm:"column:appsecret" json:"appsecret" form:"appsecret"`
16
+	SessionKey  string `gorm:"column:session_key" json:"session_key" form:"session_key"`
17
+}
18
+
19
+func (XcxAdminUserRole) TableName() string {
20
+
21
+	return "xcx_admin_user_role"
22
+}

+ 16 - 13
routers/router.go Wyświetl plik

@@ -6,6 +6,8 @@ import (
6 6
 	new_m_api "Xcx_New/controllers/new_mobile_api_controllers"
7 7
 	"github.com/astaxie/beego"
8 8
 	"github.com/astaxie/beego/plugins/cors"
9
+
10
+	xcx_m_api "Xcx_New/controllers/xcx_mobile_api_controller.go"
9 11
 )
10 12
 
11 13
 func init() {
@@ -62,18 +64,19 @@ func init() {
62 64
 	new_m_api.StatisticsAPIControllersRegisterRouters()
63 65
 
64 66
 	//admin_api.AdminAPIControllersRegisterRouters()
65
-	new_m_api.CommonApiControllersRegisterRouters()
66
-	new_m_api.NewCommonApiControllersRegisterRouters()
67
-	new_m_api.NewManageApiControllersRegisterRouters()
68
-	controllers.ManageRouters()
69
-	//controllers.PatientRouters()
70
-	controllers.DoctorScheduleRouters()
71
-	new_m_api.StaffScheduleApiControllersRegisterRouters()
72
-	controllers.DialysisPrameteRoutes()
73
-	new_m_api.DialysisParameterApiControllersRegisterRouters()
74
-	controllers.SelfDrugRouters()
75
-	//new_m_api.NewDrugApiControllersRegisterRouters()
76
-	controllers.HisProjectRouters()
77
-	controllers.GdybRegistRouters()
67
+	//new_m_api.CommonApiControllersRegisterRouters()
68
+	//new_m_api.NewCommonApiControllersRegisterRouters()
69
+	//new_m_api.NewManageApiControllersRegisterRouters()
70
+	//controllers.ManageRouters()
71
+	////controllers.PatientRouters()
72
+	//controllers.DoctorScheduleRouters()
73
+	//new_m_api.StaffScheduleApiControllersRegisterRouters()
74
+	//controllers.DialysisPrameteRoutes()
75
+	//new_m_api.DialysisParameterApiControllersRegisterRouters()
76
+	//controllers.SelfDrugRouters()
77
+	////new_m_api.NewDrugApiControllersRegisterRouters()
78
+	//controllers.HisProjectRouters()
79
+	//controllers.GdybRegistRouters()
78 80
 
81
+	xcx_m_api.XcxApiControllersRegisterRouters()
79 82
 }

+ 32 - 0
service/xcx_mobile_api_service.go Wyświetl plik

@@ -0,0 +1,32 @@
1
+package service
2
+
3
+import (
4
+	"Xcx_New/models"
5
+	"github.com/jinzhu/gorm"
6
+)
7
+
8
+func GetXcxMobileInformation(mobile string) (*models.XcxAdminUserRole, error) {
9
+	role := models.XcxAdminUserRole{}
10
+
11
+	err := XTReadDB().Model(&role).Where("mobile = ? and status = 1", mobile).Find(&role).Error
12
+	if err == gorm.ErrRecordNotFound {
13
+		return nil, err
14
+	}
15
+
16
+	if err != nil {
17
+		return nil, err
18
+	}
19
+	return &role, nil
20
+}
21
+
22
+func CreateXcxAdminUser(role models.XcxAdminUserRole) error {
23
+
24
+	err := XTWriteDB().Create(&role).Error
25
+	return err
26
+}
27
+
28
+func GetLoginInfor(mobile string) (models.XcxAdminUserRole, error) {
29
+	role := models.XcxAdminUserRole{}
30
+	err := XTReadDB().Model(&role).Where("mobile = ? and status = 1", mobile).Find(&role).Error
31
+	return role, err
32
+}