From df6d61cdad1b72e1b94e87902b39a09f36b8e044 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期一, 29 六月 2020 19:05:00 +0800 Subject: [PATCH] add addPlateNo --- controllers/user.go | 46 +++++++++++++++++++---- vo/car.go | 6 +++ models/userCar.go | 10 +++++ service/userService.go | 4 ++ controllers/car.go | 5 -- 5 files changed, 59 insertions(+), 12 deletions(-) diff --git a/controllers/car.go b/controllers/car.go index 0699395..a3e4209 100644 --- a/controllers/car.go +++ b/controllers/car.go @@ -107,11 +107,8 @@ c.ServeJSON() } + func (c *CarController) BindCarSpace() { - sv := service.NewCarService() - if sv.BindCarSpace() { - - } c.ServeJSON() } \ No newline at end of file diff --git a/controllers/user.go b/controllers/user.go index 05a46fa..9cf24da 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,21 @@ 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 { + + } + u.Data["json"] = resp + u.ServeJSON() +} + diff --git a/models/userCar.go b/models/userCar.go index 598e613..24eb587 100644 --- a/models/userCar.go +++ b/models/userCar.go @@ -26,6 +26,16 @@ return all,nil } +func (uc *UserCar) Exist(userId string, plateNo string) bool { + var list []UserCar + o := orm.NewOrm() + i,_ := o.Raw("select * from ? where userId=? and plateNo=?", uc.TableName(), userId, plateNo).QueryRows(&list) + if i > 0 && len(list) >0 { + return true + } + return false +} + func (uc *UserCar) DeleteByUserId(userId string) (int64, error) { o := orm.NewOrm() result, err := o.Raw("delete from ? where userId=?", uc.TableName(), userId).Exec() diff --git a/service/userService.go b/service/userService.go index d84db9b..24db8c1 100644 --- a/service/userService.go +++ b/service/userService.go @@ -54,6 +54,10 @@ } } +func (sv *UserService) AddPlateNo(userId, plateNo string) bool { + return false +} + func NewVerifyCode(phoneNum string) error { regionId := "cn-hangzhou" accessKeyId := "LTAIkHFaStA1JKk5" diff --git a/vo/car.go b/vo/car.go new file mode 100644 index 0000000..5583ef1 --- /dev/null +++ b/vo/car.go @@ -0,0 +1,6 @@ +package vo + +type AddPlateNoVo struct { + UserId string `json:"userId" binding:"required"` + PlateNo string `json:"plateNo" binding:"required"` +} -- Gitblit v1.8.0