1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package main
- import (
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/mongodb"
- "fmt"
- "github.com/gogf/gf/v2/util/gconv"
- "time"
- )
- func TimeStrcount(start, end string) int64 {
- timeFormat := "2006-01-02 15:04:05" // 定义时间格式
- // 两个时间字符串
- // 解析时间字符串为 Time 对象
- startTime, err := time.Parse(timeFormat, start)
- if err != nil {
- fmt.Println("Error parsing start time:", err)
- return 0
- }
- endTime, err := time.Parse(timeFormat, end)
- if err != nil {
- fmt.Println("Error parsing end time:", err)
- return 0
- }
- // 计算时间差
- diff := endTime.Sub(startTime)
- // 获取相差的天数
- days := int64(diff.Hours() / 24)
- fmt.Printf("相差的天数: %d 天\n", days)
- return days
- }
- // 用户信息转uid查询
- func GetUidToUserId(userId string, phone string) (string, string) {
- uId := ""
- query := map[string]interface{}{}
- if userId == "" {
- query["phone"] = phone
- userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
- if userInfo != nil && len(*userInfo) > 0 {
- uId = gconv.String((*userInfo)["uid"])
- userId = gconv.String((*userInfo)["userid"])
- }
- } else {
- if !mongodb.IsObjectIdHex(userId) {
- userMapping := TiDb.FindOne("data_service.user_system", map[string]interface{}{"position_id": userId}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- userId = common.ObjToString((*userMapping)["userid"])
- } else {
- return uId, userId
- }
- }
- query["userid"] = userId
- userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
- if userInfo != nil && len(*userInfo) > 0 {
- uId = common.ObjToString((*userInfo)["uid"])
- } else {
- return uId, userId
- }
- }
- return uId, userId
- }
- func getUserIdToUid(uid string) []string {
- personData := TiDb.SelectBySql(`SELECT
- IF(type=0,userid,position_id) as positionId
- FROM
- data_service.user_system
- WHERE
- uid = ? group by positionId `, uid)
- if personData == nil || len(*personData) == 0 {
- return []string{}
- }
- var personArr []string
- for _, v := range *personData {
- personArr = append(personArr, fmt.Sprintf(`"%s"`,
- gconv.String(v["positionId"])))
- }
- return personArr
- }
|