jyq 4 vuotta sitten
vanhempi
commit
38bde0a2ab
9 muutettua tiedostoa jossa 787 lisäystä ja 0 poistoa
  1. 65 0
      controller/base.go
  2. 65 0
      controller/hrSensors.go
  3. 385 0
      controller/user.go
  4. 18 0
      errors/error.go
  5. 25 0
      service/base.go
  6. 41 0
      service/user.go
  7. 28 0
      utils/page.go
  8. 34 0
      utils/string.go
  9. 126 0
      utils/time.go

+ 65 - 0
controller/base.go

@@ -6,9 +6,13 @@
 package controller
 
 import (
+	"fmt"
 	"gframe/errors"
 	"gframe/model"
+	"gframe/utils"
 	"gitee.com/zr233/bsf"
+	"strconv"
+	"time"
 )
 
 type Controller interface {
@@ -38,3 +42,64 @@ func (b BaseController) getSession() *model.Session {
 	}
 	return nil
 }
+
+func (b *BaseController) postInt(key string) (value *int) {
+	valueStr := b.Ctx().PostForm(key)
+	if valueStr != "" {
+		valueInt, err := strconv.Atoi(valueStr)
+		if err != nil {
+			panic(errors.NewParamErr(err))
+		}
+		value = &valueInt
+	}
+
+	return
+}
+func (b *BaseController) postIntNecessary(key string) (value int) {
+	valueStr := b.Ctx().PostForm(key)
+	var err error
+	if valueStr != "" {
+		value, err = strconv.Atoi(valueStr)
+		if err != nil {
+			panic(errors.FromParamErr(key, err))
+		}
+	} else {
+		panic(errors.FromParamErr(key, fmt.Errorf("参数不能为空。")))
+	}
+	return
+}
+
+func (b *BaseController) postString(key string, necessary bool) string {
+	str := b.Ctx().PostForm(key)
+	if necessary && str == "" {
+		err := errors.FromParamErr(key, fmt.Errorf("参数不能为空。"))
+		panic(err)
+	}
+	return str
+}
+
+// 日期校验
+func (b *BaseController) getPostFromDate(key string) (value time.Time) {
+	valueStr := b.Ctx().PostForm(key)
+	value, e := time.Parse(utils.TimeFormatterDate(), valueStr)
+	if e != nil {
+		err := errors.FromParamErr(key, e)
+		panic(err)
+	}
+	return value
+}
+
+func (b *BaseController) postFloatToInt(key string, necessary bool) int {
+	str := b.Ctx().PostForm(key)
+	if necessary && str == "" {
+		err := errors.FromParamErr(key, fmt.Errorf("参数不能为空。"))
+		panic(err)
+	}
+	wt, err := strconv.ParseFloat(str, 32)
+	if err != nil {
+		err := errors.FromParamErr(key, err)
+		panic(err)
+	}
+	i := int(wt * 10) // 乘以10转int型,保留1位小数
+	return i
+}

+ 65 - 0
controller/hrSensors.go

@@ -0,0 +1,65 @@
+/**
+ * @ File:
+ * @ Date: 2021/1/25 16:15
+ * @ Author: JYQ
+ * @ Description:
+ */
+package controller
+
+type HrSensors struct {
+	BaseController
+}
+
+// AddHrSensors godoc
+// @Summary 添加商家公共心率设备
+// @tags HrSensors
+// @Description 添加商家公共心率设备
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param shopId formData int true "商家ID"
+// @Param sn formData int true "心率带Sn"
+// @Param venueNo formData string false "场馆内编号  01 02"
+// @Success 200 {object} controller.ResponseBase
+// @Router /HrSensors/AddHrSensors [post]
+func (h *HrSensors) AddHrSensors() (err error) {
+	//sess := h.Ctx().PostForm("Token")
+	//sn := h.postString("sn", true)
+	//venueNo := h.Ctx().PostForm("venueNo")
+	//shopId := h.postIntNecessary("shopId")
+	//
+	//logInfo, err := service.HrSensors{}.AddHrSensors(sess, sn, venueNo, shopId)
+	//if err != nil {
+	//	return
+	//}
+	//h.saveOptLogInfo(logInfo)
+	//h.json(newResponseBase())
+	return
+}
+
+// AddPvtHrSensors godoc
+// @Summary 添加会员私有心率设备
+// @tags HrSensors
+// @Description 添加会员私有心率设备
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param shopId formData int true "商家ID"
+// @Param sn formData int true "心率带Sn"
+// @Param userId formData int true "用户ID"
+// @Success 200 {object} controller.ResponseBase
+// @Router /HrSensors/AddPvtHrSensors [post]
+func (h *HrSensors) AddPvtHrSensors() (err error) {
+	//sess := h.Ctx().PostForm("Token")
+	//sn := h.postString("sn", true)
+	//shopId := h.postIntNecessary("shopId")
+	//userId := h.postIntNecessary("userId")
+	//
+	//logInfo, err := service.HrSensors{}.AddPvtHrSensors(sess, sn, userId, shopId)
+	//if err != nil {
+	//	return
+	//}
+	//h.saveOptLogInfo(logInfo)
+	//h.json(newResponseBase())
+	return
+}

+ 385 - 0
controller/user.go

@@ -0,0 +1,385 @@
+/**
+ * @ File:
+ * @ Date: 2021/1/25 9:54
+ * @ Author: JYQ
+ * @ Description:
+ */
+package controller
+
+type User struct {
+	BaseController
+}
+
+type ShopUserInfo struct {
+	ResponseBase
+	PageCount int64
+	Rs        string
+}
+
+// ShopUserListQuery godoc
+// @Summary 会员用户列表(带分页)
+// @tags User
+// @Description 会员用户列表(带分页)
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param phone formData string false "手机号"
+// @Param name formData string false "姓名"
+// @Param start formData string true "当前条"
+// @Param tableMax formData string true "每页条数"
+// @Success 200 {object} controller.ShopUserInfo
+// @Router /User/ShopUserListQuery [post]
+func (u *User) ShopUserListQuery() (err error) {
+	//sess := u.Ctx().PostForm("Token")
+	//phone := u.Ctx().PostForm("phone")
+	//name := u.Ctx().PostForm("name")
+	//start := u.postIntNecessary("start")
+	//tableMax := u.postIntNecessary("tableMax")
+	//pageIndex := start/tableMax + 1
+	//
+	//rs, pageCount, err := service.User{}.ShopUserListQuery(sess, phone, name, pageIndex, tableMax)
+	//
+	//rp := ShopUserInfo{
+	//	newResponseBase(),
+	//	pageCount,
+	//	rs,
+	//}
+	//u.Ctx().JSON(http.StatusOK, rp)
+
+	return
+}
+
+type ShopUserSimpleInfo struct {
+	ResponseBase
+	Rs string
+	//Rs []*gorm.ShopUserSimpleInfo
+}
+
+// ShopUserSimpleQuery godoc
+// @Summary 本店会员用户基本信息查询
+// @tags User
+// @Description 本店会员用户基本信息查询
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param shopId formData int false "商家ID"
+// @Success 200 {object} controller.ShopUserSimpleInfo
+// @Router /User/ShopUserSimpleQuery [post]
+func (u *User) ShopUserSimpleQuery() (err error) {
+
+	//shopId := u.postInt("shopId")
+	//
+	//sess := u.Ctx().PostForm("Token")
+	//rs, err := service.User{}.ShopUserSimpleQuery(sess, shopId)
+	//
+	//rp := ShopUserSimpleInfo{
+	//	newResponseBase(),
+	//	rs,
+	//}
+	//u.Ctx().JSON(http.StatusOK, rp)
+
+	return
+}
+
+// ShopUserAdd godoc
+// @Summary 会员用户添加
+// @tags User
+// @Description 会员用户添加
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param shopId formData int true "店铺ID"
+// @Param phone formData string true "登陆用户名也是手机号"
+// @Param name formData string true "姓名"
+// @Param sex formData int true "性别  1:男, 2:女"
+// @Param birthday formData string true "生日"
+// @Param height formData int true "身高"
+// @Param weight formData string true "体重 "
+// @Param staticHr formData int false "静态心率"
+// @Param head formData string false "头像"
+// @Param memo formData string false "备注"
+// @Success 200 {object} controller.ResponseBase
+// @Router /User/ShopUserAdd [post]
+func (u *User) ShopUserAdd() (err error) {
+	//usercode := u.postString("phone", true)
+	//name := u.postString("name", true)
+	//phone := u.postString("phone", true)
+	//memo := u.Ctx().PostForm("memo")
+	//
+	//sex := u.postIntNecessary("sex")
+	//birthday := u.getPostFromDate("birthday")
+	//
+	//height := u.postIntNecessary("height")
+	//staticHr := u.postInt("staticHr")
+	//head := u.Ctx().PostForm("head")
+	//w := u.postFloatToInt("weight", true)
+	//
+	//// 如果未传入静息心率,则通过生日计算年龄后获取此年龄段的平均静息心率
+	//if staticHr == nil {
+	//	age := utils.GetAgeByBirthday(birthday)
+	//	hr := utils.GetStaticHrByAge(age)
+	//
+	//	staticHr = &hr
+	//}
+	//
+	//
+	//sess := u.getSession()
+	//s := service.NewUserService()
+	//logInfo, err := s.ShopUserAdd(sess, usercode, name, phone, memo, sex, birthday, height, w, staticHr, head)
+	//if err != nil {
+	//
+	//	return
+	//}
+	//u.saveOptLogInfo(logInfo)
+	//
+	//u.Ctx().JSON(http.StatusOK, newResponseBase())
+	return
+}
+
+// ShopUserEdit godoc
+// @Summary 会员用户基本信息修改
+// @tags User
+// @Description 会员用户基本信息修改
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param userId formData int true "用户Id"
+// @Param phone formData string false "手机号"
+// @Param name formData string false "姓名"
+// @Param memo formData string false "备注"
+// @Param birthday formData string true "生日"
+// @Param height formData int true "身高"
+// @Param weight formData string true "体重"
+// @Param sex formData int true "性别  1:男, 2:女"
+// @Param staticHr formData int false "静态心率"
+// @Param head formData string false "头像URL"
+// @Success 200 {object} controller.ResponseBase
+// @Router /User/ShopUserEdit [post]
+func (u *User) ShopUserEdit() (err error) {
+	//userId := u.postIntNecessary("userId")
+	//name := u.Ctx().PostForm("name")
+	//phone := u.Ctx().PostForm("phone")
+	//memo := u.Ctx().PostForm("memo")
+	//
+	////ubId := u.postInt("ubId")
+	//height := u.postIntNecessary("height")
+	//w := u.postFloatToInt("weight", true)
+	//sex := u.postIntNecessary("sex")
+	//staticHr := u.postInt("staticHr")
+	//head := u.Ctx().PostForm("head")
+	//birthday := u.getPostFromDate("birthday")
+	//
+	//// 如果未传入静息心率,则通过生日计算年龄后获取此年龄段的平均静息心率
+	//if staticHr == nil {
+	//	age := utils.GetAgeByBirthday(birthday)
+	//	hr := utils.GetStaticHrByAge(age)
+	//	staticHr = &hr
+	//}
+	//
+	//sess := u.getSession()
+	//logInfo, err := service.User{}.ShopUserEdit(sess, userId, name, phone, memo, height, w, sex, staticHr, head, birthday)
+	//if err != nil {
+	//
+	//	return
+	//}
+	//u.saveOptLogInfo(logInfo)
+	//
+	//u.Ctx().JSON(http.StatusOK, newResponseBase())
+	return
+}
+
+// ShopUserStatusEdit godoc
+// @Summary 会员用户状态修改
+// @tags User
+// @Description 会员用户状态修改
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param userId formData int true "用户ID"
+// @Param status formData int true "状态  1:启用	 8:禁用  9:删除"
+// @Success 200 {object} controller.ResponseBase
+// @Router /User/ShopUserStatusEdit [post]
+func (u *User) ShopUserStatusEdit() (err error) {
+	//userId := u.postIntNecessary("userId")
+	//status := u.postIntNecessary("status")
+	//
+	//sess := u.getSession()
+	//logInfo, err := service.User{}.ShopUserStatusEdit(sess, userId, status)
+	//if err != nil {
+	//	return
+	//}
+	//u.saveOptLogInfo(logInfo)
+	//
+	//u.Ctx().JSON(http.StatusOK, newResponseBase())
+	return
+}
+
+// ShopCoachAdd godoc
+// @Summary 商家教练添加
+// @tags User
+// @Description 商家教练添加
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param shopId formData int true "店铺ID"
+// @Param phone formData string true "登陆用户名也是手机号"
+// @Param name formData string true "姓名"
+// @Param pwd formData string true "密码"
+// @Param sex formData int true "性别  1:男, 2:女"
+// @Param memo formData string false "备注"
+// @Success 200 {object} controller.ResponseBase
+// @Router /User/ShopCoachAdd [post]
+func (u *User) ShopCoachAdd() (err error) {
+	//usercode := u.postString("phone", true)
+	//name := u.postString("name", true)
+	//phone := u.postString("phone", true)
+	//pwd := u.postString("pwd", true)
+	//memo := u.Ctx().PostForm("memo")
+	//
+	//sex := u.postIntNecessary("sex")
+
+	//sess := u.getSession()
+	//s := service.NewUserService()
+	//logInfo, err := s.ShopCoachAdd(sess, usercode, name, phone, memo, sex, pwd)
+	//if err != nil {
+	//
+	//	return
+	//}
+	//u.saveOptLogInfo(logInfo)
+	//
+	//u.Ctx().JSON(http.StatusOK, newResponseBase())
+	return
+}
+
+// ShopCoachEdit godoc
+// @Summary 商家教练基本信息修改
+// @tags User
+// @Description 商家教练基本信息修改
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param ssId formData int true "教练ID"
+// @Param phone formData string false "手机号"
+// @Param pwd formData string false "密码"
+// @Param name formData string false "姓名"
+// @Param memo formData string false "备注"
+// @Param sex formData int true "性别  1:男, 2:女"
+// @Success 200 {object} controller.ResponseBase
+// @Router /User/ShopCoachEdit [post]
+func (u *User) ShopCoachEdit() (err error) {
+	//ssId := u.postIntNecessary("ssId")
+	//name := u.Ctx().PostForm("name")
+	//phone := u.Ctx().PostForm("phone")
+	//pwd := u.Ctx().PostForm("pwd")
+	//memo := u.Ctx().PostForm("memo")
+	//
+	//sex := u.postIntNecessary("sex")
+	//
+	//sess := u.getSession()
+	//logInfo, err := service.User{}.ShopCoachEdit(sess, ssId, name, phone, memo, sex, pwd)
+	//if err != nil {
+	//
+	//	return
+	//}
+	//u.saveOptLogInfo(logInfo)
+	//
+	//u.Ctx().JSON(http.StatusOK, newResponseBase())
+	return
+}
+
+// ShopCoachStatusEdit godoc
+// @Summary 商家教练状态修改
+// @tags User
+// @Description 商家教练状态修改
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param ssId formData int true "教练ID"
+// @Param status formData int true "状态  1:启用	 8:禁用  9:删除"
+// @Success 200 {object} controller.ResponseBase
+// @Router /User/ShopCoachStatusEdit [post]
+func (u *User) ShopCoachStatusEdit() (err error) {
+	//ssId := u.postIntNecessary("ssId")
+	//status := u.postIntNecessary("status")
+	//
+	//sess := u.getSession()
+	//logInfo, err := service.User{}.ShopCoachStatusEdit(sess, ssId, status)
+	//if err != nil {
+	//	return
+	//}
+	//u.saveOptLogInfo(logInfo)
+	//
+	//u.Ctx().JSON(http.StatusOK, newResponseBase())
+	return
+}
+
+type ShopCoachInfo struct {
+	ResponseBase
+	PageCount int64
+	Rs        string
+}
+
+// ShopCoachListQuery godoc
+// @Summary 会员用户列表(带分页)
+// @tags User
+// @Description 会员用户列表(带分页)
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param phone formData string false "手机号"
+// @Param name formData string false "姓名"
+// @Param start formData string true "当前条"
+// @Param tableMax formData string true "每页条数"
+// @Success 200 {object} controller.ShopUserInfo
+// @Router /User/ShopCoachListQuery [post]
+func (u *User) ShopCoachListQuery() (err error) {
+	//sess := u.Ctx().PostForm("Token")
+	//phone := u.Ctx().PostForm("phone")
+	//name := u.Ctx().PostForm("name")
+	//start := u.postIntNecessary("start")
+	//tableMax := u.postIntNecessary("tableMax")
+	//pageIndex := start/tableMax + 1
+	//
+	//rs, pageCount, err := service.User{}.ShopCoachListQuery(sess, phone, name, pageIndex, tableMax)
+	//
+	//rp := ShopCoachInfo{
+	//	newResponseBase(),
+	//	pageCount,
+	//	rs,
+	//}
+	//u.Ctx().JSON(http.StatusOK, rp)
+
+	return
+}
+
+type ShopCoachSimpleInfo struct {
+	ResponseBase
+	Rs string
+	//Rs []*gorm.ShopUserSimpleInfo
+}
+
+// ShopCoachSimpleQuery godoc
+// @Summary 本店会员用户基本信息查询
+// @tags User
+// @Description 本店会员用户基本信息查询
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Param token formData string true "Token"
+// @Param shopId formData int false "商家ID"
+// @Success 200 {object} controller.ShopCoachSimpleInfo
+// @Router /User/ShopCoachSimpleQuery [post]
+func (u *User) ShopCoachSimpleQuery() (err error) {
+
+	//shopId := u.postInt("shopId")
+	//
+	//sess := u.Ctx().PostForm("Token")
+	//rs, err := service.User{}.ShopCoachSimpleQuery(sess, shopId)
+	//
+	//rp := ShopCoachSimpleInfo{
+	//	newResponseBase(),
+	//	rs,
+	//}
+	//u.Ctx().JSON(http.StatusOK, rp)
+
+	return
+}

+ 18 - 0
errors/error.go

@@ -23,11 +23,19 @@ const (
 	CodePasswordErr         ErrorCode = 1006
 	CodeTokenErr            ErrorCode = 1010
 	CodeNoRecord            ErrorCode = 1014
+	BirthdayErr             ErrorCode = 1036
+	StaticHrErr             ErrorCode = 1037
+	CodeParamErr            ErrorCode = 5000
 	CodeDATABASE            ErrorCode = 9000
 	CodeREDIS               ErrorCode = 10000
 	CodeParam                         = ErrorCode(errors.CodeParam)
 )
 
+var (
+	ErrStaticHr = NewServiceErr(StaticHrErr, "会员年龄太小,请重新输入用户生日。")
+	ErrBirthday = NewServiceErr(BirthdayErr, "用户生日不得大于当前年份,请重新输入")
+)
+
 func (e ErrorCode) ShowMsg() string {
 	switch e {
 	case CodeSUCCESS:
@@ -52,3 +60,13 @@ func FromError(err error) (stdErr *errors.StandardError) {
 func NewFromError(err error, code ErrorCode) (stdErr *errors.StandardError) {
 	return errors.NewFromError(err, errors.ErrorCode(code))
 }
+
+func FromParamErr(paramName string, err error) (stdErr *errors.StandardError) {
+	err = fmt.Errorf("参数名: %s, %w", paramName, err)
+	return NewFromError(err, CodeParam)
+}
+
+func NewServiceErr(code ErrorCode, msg string) (stdErr *errors.StandardError) {
+	err := fmt.Errorf(msg)
+	return NewFromError(err, code)
+}

+ 25 - 0
service/base.go

@@ -0,0 +1,25 @@
+/**
+ * @ File:
+ * @ Date: 2021/1/25 10:06
+ * @ Author: JYQ
+ * @ Description:
+ */
+package service
+
+import "strings"
+
+type base struct {
+	restFulApiBase []string
+	restFulApi     []string
+	userId         int
+}
+
+func newBase(ApiBaseUrl string) (b *base) {
+	b = &base{}
+	if ApiBaseUrl == "" {
+		return
+	}
+
+	b.restFulApiBase = strings.Split(ApiBaseUrl, "/")
+	return
+}

+ 41 - 0
service/user.go

@@ -0,0 +1,41 @@
+/**
+ * @ File:
+ * @ Date: 2021/1/25 10:07
+ * @ Author: JYQ
+ * @ Description:
+ */
+package service
+
+type User struct {
+	base
+}
+
+//会员用户列表查询带分页
+func (u User) ShopUserListQuery(
+	sess string,
+	phone string,
+	name string,
+	pageIndex int,
+	tableMax int) (rs string, pageCount int64, err error) {
+	//offset := utils.PageIndex2RowOffset(pageIndex, tableMax)
+	//// todo 做session校验
+	//
+	//dao := u.getUserDao()
+	//userrs, allCount, err := dao.ShopUserListQuery(phone, name, vipType, user.ShopId, expDay, tableMax, offset)
+	//if err != nil {
+	//	return
+	//}
+	//
+	//pageCount = utils.CountPage(allCount, tableMax)
+
+	return
+}
+
+//会员用户基本信息查询
+func (u User) ShopUserSimpleQuery(sess string, classId *int) (rs string, err error) {
+	// todo 做session校验
+	//user := u.getUser(sess)
+	//dao := u.getUserDao()
+	//rs, err = dao.ShopUserSimpleQuery(classId, user.ShopId)
+	return
+}

+ 28 - 0
utils/page.go

@@ -0,0 +1,28 @@
+/*
+@Time : 2019-07-10 10:20
+@Author : zr
+*/
+package utils
+
+func CountPage(totalCount int64, onePageCount int) int64 {
+	if onePageCount == 0 {
+		return 0
+	}
+	page := totalCount / int64(onePageCount)
+	remain := totalCount % int64(onePageCount)
+	if remain > 0 {
+		page = page + 1
+	}
+
+	return page
+}
+
+func PageIndex2RowOffset(pageIndex int, onePageCount int) int {
+	if onePageCount == 0 {
+		return 0
+	}
+	pageIndex = pageIndex - 1
+	offset := pageIndex * onePageCount
+
+	return offset
+}

+ 34 - 0
utils/string.go

@@ -0,0 +1,34 @@
+/**
+ * @ File:
+ * @ Date: 2020/12/11 10:14
+ * @ Author: JYQ
+ * @ Description:
+ */
+package utils
+
+//import (
+//	"gframe/errors"
+//	"strconv"
+//	"strings"
+//	"time"
+//)
+
+// 分隔字符串
+//func StringSplit(str string, sep string) (newTime time.Time, err error) {
+//
+//	var idArr []string
+//	if str != "" {
+//		idArr = strings.Split(str, sep)
+//		for _, valueStr := range idArr {
+//			_, err_ := strconv.Atoi(valueStr)
+//			if err_ != nil {
+//				err = errors.ErrCommalistCode
+//				return
+//			}
+//		}
+//	} else {
+//		err = errors.ErrStrIsNIl
+//		return
+//	}
+//	return
+//}

+ 126 - 0
utils/time.go

@@ -0,0 +1,126 @@
+/*
+@Time : 2019-07-08 11:12
+@Author : zr
+*/
+package utils
+
+import (
+	"gframe/errors"
+	"math"
+	"math/rand"
+	"time"
+)
+
+func TimeFormatter() string {
+	return "2006-01-02 15:04:05"
+}
+func TimeFormatterDate() string {
+	return "2006-01-02"
+}
+
+func TimeStdQueryBegin(stdTimeStr string) (newTime time.Time, err error) {
+	if stdTimeStr == "" {
+		return time.Parse(TimeFormatter(), "2000-01-01 00:00:00")
+	}
+
+	newTime, err = time.Parse(TimeFormatter(), stdTimeStr)
+	if err != nil {
+		return newTime, err
+	}
+	newTimeStr := newTime.Format("2006-01-02") + " 00:00:00"
+
+	return time.Parse(TimeFormatter(), newTimeStr)
+}
+func TimeStdQueryEnd(stdTimeStr string) (newTime time.Time, err error) {
+	if stdTimeStr == "" {
+		newTime = time.Now()
+	} else {
+		newTime, err = time.Parse(TimeFormatter(), stdTimeStr)
+		if err != nil {
+			return newTime, err
+		}
+	}
+	newTimeStr := newTime.Format("2006-01-02") + " 23:59:59"
+	return time.Parse(TimeFormatter(), newTimeStr)
+}
+
+func TimeDayBegin(day time.Time) time.Time {
+	dayBeginStr := day.Format("2006-01-02") + " 00:00:00"
+	dayBegin, _ := time.Parse(TimeFormatter(), dayBeginStr)
+	return dayBegin
+}
+func TimeTodayBegin() time.Time {
+	timeNow := time.Now()
+	dayBeginStr := timeNow.Format("2006-01-02") + " 00:00:00"
+	dayBegin, _ := time.Parse(TimeFormatter(), dayBeginStr)
+	return dayBegin
+}
+
+func TimeDayEnd(day time.Time) time.Time {
+	dayStr := day.Format("2006-01-02") + " 23:59:59"
+	day, _ = time.Parse(TimeFormatter(), dayStr)
+	return day
+}
+func RandomInt(n int) int {
+	min := int(math.Pow(10, float64(n-1)))
+	max := min*9 - 1
+
+	rand1 := rand.New(rand.NewSource(time.Now().UnixNano()))
+	code := rand1.Intn(max) + min
+	return code
+}
+
+func GetAgeByBirthday(b time.Time) (age int) {
+	//b, err := time.Parse(TimeFormatter(), birthday)
+	//if err != nil {
+	//	return 0, err
+	//}
+	year := b.Year()
+	month := int(b.Month())
+	day := b.Day()
+
+	nowYear := time.Now().Year()
+	nowMonth := int(time.Now().Month())
+	nowDay := time.Now().Day()
+
+	if nowYear < year {
+		panic(errors.ErrBirthday)
+	}
+	age = nowYear - year
+	if month > nowMonth { // 当生日月份>当前月份的时候,年龄-1
+		age = age - 1
+	}
+	if month == nowMonth && day > nowDay {
+		age = age - 1 // 当生日月份与当前月份相等的时候,如果生日日期大于当天日期,则生日未到,年龄-1
+	}
+
+	return
+}
+
+func GetStaticHrByAge(age int) (staticHr int) {
+	switch age {
+	case 2:
+		staticHr = 80
+	case 3:
+		staticHr = 80
+	case 4:
+		staticHr = 80
+	case 5:
+		staticHr = 75
+	case 6:
+		staticHr = 75
+	case 7:
+		staticHr = 70
+	case 8:
+		staticHr = 70
+	case 9:
+		staticHr = 70
+	default:
+		if age >= 10 {
+			staticHr = 60
+		} else {
+			panic(errors.ErrStaticHr)
+		}
+	}
+	return
+}