Пример #1
0
func PassengerFindDriver(hs *routing.HTTPSession) routing.HResult {
	var uid int64
	var startTime int64
	var sLat float64
	var sLng float64
	var eLat float64
	var eLng float64
	var sCity string
	var eCity string
	t := time.Now()
	err := hs.ValidCheckVal(`
		uid,R|I,R:0;
		startTime,R|I,R:0;
		sLat,R|F,R:0;
		sLng,R|F,R:0;
		eLat,R|F,R:0;
		eLng,R|F,R:0;
		sCity,R|S,L:0;
		eCity,R|S,L:0;
		`, &uid, &startTime, &sLat, &sLng, &eLat, &eLng, &sCity, &eCity)
	if err != nil {
		return hs.MsgResErr(100, "config error", err)
	} else if t.Unix()-startTime < 1800 {
		return hs.MsgResE(1, "invalid startTime , need > 30min from now")
	} else {
		s, err := db.FindDriverRoute(uid, startTime, sLat, sLng, eLat, eLng, sCity, eCity)
		if err != nil {
			return hs.MsgResErr2(1, "", err)
		} else {
			return hs.MsgRes(s)
		}
	}

}
Пример #2
0
func Register(hs *routing.HTTPSession) routing.HResult {
	var userName string
	hobby := ""
	var mobile string
	head := ""
	var gender int64
	gender = 1
	err := hs.ValidCheckVal(`
		userName,R|S,L:0;
		hobby,O|S,L:0;
		mobile,R|S,L:0;
		head,O|S,L:0;
		gender,O|I,R:-1~2;
		`, &userName, &hobby, &mobile, &head, &gender)
	if err != nil {
		return hs.MsgResErr(100, "config error", err)
	} else {
		s, err := db.Register(userName, mobile, hobby, head, gender)
		if err != nil {
			return hs.MsgResErr2(1, "", err)
		} else {
			return hs.MsgRes(s)
		}
	}
}
Пример #3
0
func RecF(hs *routing.HTTPSession) routing.HResult {
	_, sha, _, err := hs.RecF2("file", "/tmp/")
	if err == nil {
		fmt.Println("receive file:", sha)
		return hs.MsgRes(sha)
	} else {
		fmt.Println("receive file err:", err.Error())
		return hs.MsgResErr2(1, "arg-err", err)
	}
}
Пример #4
0
func ListBook(hs *routing.HTTPSession) routing.HResult {
	is := []Item{}
	for i := 0; i < 10; i++ {
		it := Item{}
		it.Id = i
		it.Name = fmt.Sprintf("bk-%d", i)
		is = append(is, it)
	}
	return hs.MsgRes(is)
}
Пример #5
0
func DeleteUserByMobile(hs *routing.HTTPSession) routing.HResult {
	var mobile string
	err := hs.ValidCheckVal(`
		mobile,R|S,L:0
		`, &mobile)
	if err != nil {
		return hs.MsgResErr(100, "config error", err)
	} else {
		s, err := db.DeleteUserByMobile(mobile)
		if err != nil {
			return hs.MsgResErr2(1, "", err)
		}
		return hs.MsgRes(s)
	}
}
Пример #6
0
func DeleteUserById(hs *routing.HTTPSession) routing.HResult {
	var uid int64
	err := hs.ValidCheckVal(`
		uid,R|I,R:0
		`, &uid)
	if err != nil {
		return hs.MsgResErr(100, "config error", err)
	} else {
		s, err := db.DeleteUser(uid)
		if err != nil {
			return hs.MsgResErr2(1, "", err)
		}
		return hs.MsgRes(s)
	}
}
Пример #7
0
func Login(hs *routing.HTTPSession) routing.HResult {
	var mobile string
	err := hs.ValidCheckVal(`
		mobile,R|S,L:0;
		`, &mobile)
	if err != nil {
		return hs.MsgResErr(100, "config error", err)
	} else {
		s, err := db.Login(mobile)
		if err != nil {
			return hs.MsgResErr2(1, "", err)
		} else {
			return hs.MsgRes(s)
		}
	}
}
Пример #8
0
func ListChapter(hs *routing.HTTPSession) routing.HResult {
	var id int64 = 0
	err := hs.ValidRVal(`
		id,R|I,R:-1~10
		`, &id)
	if err != nil {
		return hs.MsgResE(1, err.Error())
	}
	is := []Item{}
	for i := 0; i < 10; i++ {
		it := Item{}
		it.Id = i
		it.Name = fmt.Sprintf("ch-%d-%d", id, i)
		is = append(is, it)
	}
	return hs.MsgRes(is)
}
Пример #9
0
func ChargeBalance(hs *routing.HTTPSession) routing.HResult {
	var uid int64
	var money float64
	err := hs.ValidCheckVal(`
		uid,R|I,R:0;
		money,R|F,R:0;
		`, &uid, &money)
	if err != nil {
		return hs.MsgResErr(100, "config error", err)
	} else {
		s, err := db.ChargeBalance(uid, money)
		if err != nil {
			return hs.MsgResErr2(1, "", err)
		} else {
			return hs.MsgRes(s)
		}
	}
}
Пример #10
0
func GetAnswerRecord(hs *routing.HTTPSession) routing.HResult {
	var aId int64
	err := hs.ValidCheckVal(`
		aId,R|I,R:0;
		`, &aId)
	if err != nil {
		log.E("GetAnswerRecord arg error:%v", err)
		return hs.MsgResE(1, fmt.Sprintf("%s:%s", common_.ARG_ERROR, err.Error()))
	}
	conn := dbMgr.DbConn()
	var content sql.NullString
	if err := conn.QueryRow("select content from ebs_answer where tid=?", aId).Scan(&content); err != nil {
		if err != sql.ErrNoRows {
			return hs.MsgResE(2, err.Error())
		}
	}
	return hs.MsgRes(content.String)
}
Пример #11
0
func GetPassengerOrderList(hs *routing.HTTPSession) routing.HResult {
	var uid int64
	var page int64
	var pageCount int64
	err := hs.ValidCheckVal(`
		uid,R|I,R:0;
		page,O|I,R:0;
		pageCount,O|I,R:0;
		`, &uid, &page, &pageCount)
	if err != nil {
		return hs.MsgResErr(100, "config error", err)
	} else {
		s, err := db.GetPassengerOrderList(uid, page, pageCount)
		if err != nil {
			return hs.MsgResErr2(1, "", err)
		} else {
			return hs.MsgRes(s)
		}
	}
}
Пример #12
0
func PassengerCancelOrder(hs *routing.HTTPSession) routing.HResult {
	var uid int64
	var oid int64
	var drid int64
	err := hs.ValidCheckVal(`
		uid,R|I,R:0;
		oid,R|I,R:0;
		drid,R|I,R:0;
		`, &uid, &oid, &drid)
	if err != nil {
		return hs.MsgResErr(100, "config error", err)
	} else {
		s, err := db.PassengerCancelOrder(uid, oid, drid)
		if err != nil {
			return hs.MsgResErr2(1, "", err)
		} else {
			return hs.MsgRes(s)
		}
	}
}
Пример #13
0
func FillInfo(hs *routing.HTTPSession) routing.HResult {
	var userName string
	var hobby string
	var head string
	var gender int64
	var uid int64
	err := hs.ValidCheckVal(`
		userName,R|S,L:0;
		hobby,R|S,L:0;
		head,R|S,L:0;
		gender,R|I,R:-1~2;
		uid,R|I,R:0
		`, &userName, &hobby, &head, &gender, &uid)
	if err != nil {
		return hs.MsgResErr(100, "config error", err)
	} else {
		s, err := db.FillInfo(userName, hobby, head, gender, uid)
		if err != nil {
			return hs.MsgResErr2(1, "", err)
		} else {
			return hs.MsgRes(s)
		}
	}
}
Пример #14
0
func SaveAnswer(hs *routing.HTTPSession) routing.HResult {
	var aId int64
	var a string
	err := hs.ValidCheckVal(`
		aId,R|I,R:0;
		a,R|S,L:0;
		`, &aId, &a)
	if err != nil {
		log.E("SaveAnswer arg error:%v", err)
		return hs.MsgResE(1, fmt.Sprintf("%s:%s", common_.ARG_ERROR, err.Error()))
	}
	aParse := []ANSWER2{}
	if err := json.Unmarshal([]byte(a), &aParse); err != nil {
		log.E("%v", err)
		return hs.MsgResE(1, fmt.Sprintf("%s:作答内容格式错误,%s", common_.ARG_ERROR, err.Error()))
	}
	sql_ := `update ebs_answer set content=? where tid=?`
	conn := dbMgr.DbConn()
	if _, err := conn.Exec(sql_, a, aId); err != nil {
		log.E("SaveAnswer db error:%v,sql:%s,args:%v", err, sql_, a)
		return hs.MsgResE(2, fmt.Sprintf("%s:%s", common_.DB_ERROR, err.Error()))
	}
	return hs.MsgRes("success")
}
Пример #15
0
func TestMethod(hs *routing.HTTPSession) routing.HResult {
	balance, err := db.Method()
	fmt.Println(balance, err)
	return hs.MsgRes(balance)
}
Пример #16
0
func exit(hs *routing.HTTPSession) routing.HResult {
	log.D("receiving exit command...")
	StopSrv()
	return hs.MsgRes("SUCCESS")
}