From dbc843d0b37f786fb816131bcc7ebca86dbe72e9 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期四, 06 八月 2020 09:58:46 +0800 Subject: [PATCH] add crossRecord --- controllers/user.go | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 105 insertions(+), 8 deletions(-) diff --git a/controllers/user.go b/controllers/user.go index 05a46fa..2025f12 100644 --- a/controllers/user.go +++ b/controllers/user.go @@ -4,6 +4,9 @@ "car-service/extend/code" "car-service/models" "car-service/service" + "car-service/vo" + "encoding/json" + "fmt" "github.com/astaxie/beego" "net/http" ) @@ -60,18 +63,27 @@ func (u *UserController) Login() { phoneNum := u.GetString("phoneNum") cod := u.GetString("code") - var sv service.UserService - b, info, e := sv.Login(phoneNum, cod) resp := code.Code{} - if b { - resp.Success= true - resp.Status= http.StatusOK - resp.Data= *info - } else { + fmt.Println("phoneNum:", phoneNum, "code:", cod) + if phoneNum == "" || cod == "" { resp.Success= false resp.Status= http.StatusBadRequest - resp.Data= e.Error() + resp.Data= "鍙傛暟鏈夎" + } else { + var sv service.UserService + b, info, e := sv.Login(phoneNum, cod) + + if b { + resp.Success= true + resp.Status= http.StatusOK + resp.Data= *info + } else { + resp.Success= false + resp.Status= http.StatusBadRequest + resp.Data= e.Error() + } } + u.Data["json"] = resp u.ServeJSON() } @@ -89,3 +101,88 @@ u.ServeJSON() } +// @Param reqBody body vo.AddPlateNoVo true "缁戝畾杞︾墝鍙峰弬鏁�" +// @router /addPlateNo [post] +func (u *UserController) AddPlateNo() { + var reqBody vo.AddPlateNoVo + body := u.Ctx.Input.RequestBody + err := json.Unmarshal(body, &reqBody) + resp := code.Code{} + if err != nil { + resp.Success = false + resp.Status = http.StatusBadRequest + resp.Data = "鍙傛暟鏈夎" + } else { + var sv service.UserService + if sv.AddPlateNo(reqBody.UserId, reqBody.PlateNo) { + resp.Success = true + resp.Status = http.StatusOK + resp.Data = "娣诲姞鎴愬姛" + } else { + resp.Success = false + resp.Status = http.StatusBadRequest + resp.Data = "娣诲姞澶辫触" + } + } + u.Data["json"] = resp + u.ServeJSON() +} + +// @router /myPlateNos [get] +func (u *UserController) MyPlateNos() { + userId := u.GetString("userId") + fmt.Println("MyPlateNos userId", userId) + sv := service.NewCarService() + vehicleList := sv.GetVehicleListByPerson(userId) + var nos = make([]string, 0) + if vehicleList != nil { + for _,p := range vehicleList { + nos = append(nos, p.PlateNo) + } + } + resp := code.Code{ + Success: true, + Status: http.StatusOK, + Data: nos, + } + u.Data["json"] = resp + u.ServeJSON() +} + +// @router /delPlateNo [delete] +func (u *UserController) DelPlateNo() { + userId := u.GetString("userId") + plateNo := u.GetString("plateNo") + resp := code.Code{} + var uc models.UserCar + i,e := uc.Delete(userId, plateNo) + fmt.Println("delPlateNo i:",i, "e:", e) + if e ==nil && i >0 { + resp.Success = true + resp.Status = http.StatusOK + resp.Data = "鍒犻櫎鎴愬姛" + } else { + resp.Success = false + resp.Status = http.StatusInternalServerError + resp.Data = "鍒犻櫎澶辫触" + } + u.Data["json"] = resp + u.ServeJSON() +} + +// @router /all [get] +func (u *UserController) GetUserAll() { + resp := code.Code{} + sv := service.NewCarService() + personAll := sv.GetHikPersonList() + if personAll != nil { + resp.Success = true + resp.Status = http.StatusOK + resp.Data = personAll + } + u.Data["json"] = resp + u.ServeJSON() +} + + + -- Gitblit v1.8.0