From 8849dda9c4fd92467e2c05c15ea483abae6af8e5 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期三, 12 八月 2020 11:25:39 +0800
Subject: [PATCH] add testPush

---
 routers/router.go    |    1 +
 models/userClient.go |    4 ++--
 controllers/car.go   |   21 +++++++++++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/controllers/car.go b/controllers/car.go
index a22189f..732fcff 100644
--- a/controllers/car.go
+++ b/controllers/car.go
@@ -160,6 +160,27 @@
 	c.ServeJSON()
 }
 
+// @router /testPush [get]
+func (c *CarController) TestPush() {
+	left := getSpaceLeft()
+	message := fmt.Sprintf("%s 鍓╀綑杞︿綅锛�%d涓�", time.Now().Format("2006-01-02 15:04:05"), left)
+	b, e := service.PushByAlias("鑲茶嫳涓鍋滆溅", message)
+
+	fmt.Println("b:", b,"e:",e, "message:", message)
+	resp := code.Code{}
+	if b {
+		resp.Success = true
+		resp.Status = http.StatusOK
+		resp.Data = "鎺ㄩ�佹垚鍔�"
+	} else {
+		resp.Success = false
+		resp.Status = http.StatusInternalServerError
+		resp.Data = e.Error()
+	}
+	c.Data["json"] = resp
+	c.ServeJSON()
+}
+
 // @router /crossRecord [get]
 func (c *CarController) CrossRecord() {
 	sv := service.NewCarService()
diff --git a/models/userClient.go b/models/userClient.go
index fafebeb..208a77c 100644
--- a/models/userClient.go
+++ b/models/userClient.go
@@ -25,7 +25,7 @@
 func (uc *UserClient) Exist(phoneNum string) bool {
 	var list []UserClient
 	o := orm.NewOrm()
-	o.Raw("select * from ? where phoneNum=?", uc.TableName(), phoneNum).QueryRows(&list)
+	o.QueryTable(uc.TableName()).Filter("phoneNum", phoneNum).All(&list)
 	if len(list) >0 {
 		return true
 	}
@@ -35,7 +35,7 @@
 func (uc *UserClient) ExistByCid(phoneNum string, cid string) bool {
 	var list []UserClient
 	o := orm.NewOrm()
-	o.Raw("select * from ? where phoneNum=? and clientId=?", uc.TableName(), phoneNum, cid).QueryRows(&list)
+	o.QueryTable(uc.TableName()).Filter("phoneNum", phoneNum).Filter("clientId", cid).All(&list)
 	if len(list) >0 {
 		return true
 	}
diff --git a/routers/router.go b/routers/router.go
index 4fd8880..fa29e7c 100644
--- a/routers/router.go
+++ b/routers/router.go
@@ -59,4 +59,5 @@
 	beego.Router(preApi+"/user/sync", &controllers.UserController{}, "*:Sync")
 
 	beego.Router(preApi+"/car/crossRecord", &controllers.CarController{}, "*:CrossRecord")
+	beego.Router(preApi+"/car/testPush", &controllers.CarController{}, "*:TestPush")
 }

--
Gitblit v1.8.0