liuxiaolong
2020-08-11 13a31b1caab8ffa0049dc8299cab8b8c4a31b6ed
service/userService.go
@@ -16,30 +16,30 @@
}
func (sv *UserService) Login(phoneNum, code string) (bool,*vo.UserInfo,error) {
func (sv *UserService) Login(phoneNum, code, cid string) (bool,*vo.UserInfo,error) {
   if verifyCode(phoneNum, code) {
      carSv := NewCarService()
      //先判断此手机号是否在海康平台中
      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("请联系停车场管理员")
      }
      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: hikPersonId,
            PhoneNum: phoneNum,
@@ -54,6 +54,13 @@
                  plateNos = append(plateNos, up.PlateNo)
               }
            }
            //客户端cid绑定别名
            if cid != "" {
               go func() {
                  bindR, bindE := BindAlias(cid, phoneNum)
                  fmt.Println("bind cid:",cid, "phoneNum:",phoneNum,"result:", bindR, "err:", bindE)
               }()
            }
            return true, &vo.UserInfo{
               UserId: u.Id,
               PhoneNum: phoneNum,
@@ -64,6 +71,10 @@
            return false, nil, errors.New("注册失败")
         }
      } else { //用户已存在
         if hikPersonId != tmpUser.Id {
            tmpUser.Id = hikPersonId
            tmpUser.SyncHikPersonId(tmpUser.PhoneNum, hikPersonId)
         }
         var plateNos = make([]string, 0)
         hikVehicles := carSv.GetVehicleListByPerson(tmpUser.Id)
@@ -72,6 +83,13 @@
               plateNos = append(plateNos, up.PlateNo)
            }
         }
         //客户端cid绑定别名
         if cid != "" {
            go func() {
               bindR, bindE := BindAlias(cid, phoneNum)
               fmt.Println("bind cid:",cid, "phoneNum:",phoneNum,"result:", bindR, "err:", bindE)
            }()
         }
         return true, &vo.UserInfo{
            UserId: tmpUser.Id,
            PhoneNum: phoneNum,