From 85f9175b3064094a09dbe9f71ba37b2f11f38e5f Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期三, 29 七月 2020 14:21:16 +0800
Subject: [PATCH] use sqlite, spaceNo add isMine

---
 service/userService.go |   66 ++++++++++++++++++++++++++-------
 1 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/service/userService.go b/service/userService.go
index 1fe7435..a3e643f 100644
--- a/service/userService.go
+++ b/service/userService.go
@@ -18,31 +18,57 @@
 
 func (sv *UserService) Login(phoneNum, code string) (bool,*vo.UserInfo,error) {
 	if verifyCode(phoneNum, code) {
+		carSv := NewCarService()
+
 		var tmpUser models.User
 		err := tmpUser.SelectByPhoneNum(phoneNum)
 		fmt.Println("login err:", err)
 		if err != nil { //鐢ㄦ埛涓嶅瓨鍦�,鍒欐柊澧�
+			//鍏堝垽鏂鎵嬫満鍙锋槸鍚﹀湪娴峰悍骞冲彴涓�
+			hikPersons := carSv.GetHikPersonList()
+			found := false
+			hikPersonId := ""
+			if hikPersons != nil {
+				for _,hikP := range hikPersons {
+					if hikP.PhoneNo == phoneNum {
+						found = true
+						hikPersonId = hikP.PersonId
+					}
+				}
+			}
+			if !found {
+				return false, nil, errors.New("璇疯仈绯诲仠杞﹀満绠$悊鍛�")
+			}
+
 			u := models.User{
-				Id: uuid.NewV4().String(),
+				Id: hikPersonId,
 				PhoneNum: phoneNum,
 				IsDelete: false,
 			}
 			if _, e := u.Insert();e ==nil {
+				var plateNos = make([]string, 0)
+				hikVehicles := carSv.GetVehicleListByPerson(u.Id)
+
+				if hikVehicles != nil {
+					for _,up := range hikVehicles {
+						plateNos = append(plateNos, up.PlateNo)
+					}
+				}
 				return true, &vo.UserInfo{
 					UserId: u.Id,
 					PhoneNum: phoneNum,
-					PlateNos: []string{},
+					PlateNos: plateNos,
 				}, nil
 			} else {
 				fmt.Println("u.Insert err:", e)
 				return false, nil, errors.New("娉ㄥ唽澶辫触")
 			}
 		} else { //鐢ㄦ埛宸插瓨鍦�
-			var userCar models.UserCar
-			var plateNos []string
-			all, e := userCar.GetByUserId(tmpUser.Id)
-			if e == nil && all != nil {
-				for _,up := range all {
+			var plateNos = make([]string, 0)
+			hikVehicles := carSv.GetVehicleListByPerson(tmpUser.Id)
+
+			if hikVehicles != nil {
+				for _,up := range hikVehicles {
 					plateNos = append(plateNos, up.PlateNo)
 				}
 			}
@@ -58,6 +84,19 @@
 }
 
 func (sv *UserService) AddPlateNo(userId, plateNo string) bool {
+	var uc models.UserCar
+	if uc.Exist(userId, plateNo) {
+		return true
+	}
+	tmp := models.UserCar{
+		Id: uuid.NewV4().String(),
+		UserId: userId,
+		PlateNo: plateNo,
+	}
+	_, err := tmp.Insert()
+	if err == nil {
+		return true
+	}
 	return false
 }
 
@@ -88,13 +127,12 @@
 }
 
 func verifyCode(phoneNum string, cod string) bool {
-	return true
-	//if b,r := existCode(phoneNum);b && r == cod {
-	//	return true
-	//} else {
-	//	fmt.Println("verifyCode false,cod:",cod, "r:",r,"b:",b)
-	//}
-	//return false
+	if b,r := existCode(phoneNum);b && r == cod {
+		return true
+	} else {
+		fmt.Println("verifyCode false,cod:",cod, "r:",r,"b:",b)
+	}
+	return false
 }
 
 func add2Cache(phoneNum string, code string) {

--
Gitblit v1.8.0