1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package service
- import (
- "sfis/db"
- "sfis/model"
- "sfis/utils"
- "strconv"
- "strings"
- "time"
- )
- func CallLog(appid, productId, startTime, endTime string) ([]map[string]interface{}, error) {
- key := []string{}
- param := []interface{}{}
- datas := []map[string]interface{}{}
- if startTime != "" {
- key = append(key, "create_at >= ?")
- param = append(param, startTime+" 00:00:00")
- }
- if endTime != "" {
- key = append(key, "create_at <= ?")
- param = append(param, endTime+" 23:59:59")
- } else {
- key = append(key, "create_at <= ?")
- param = append(param, time.Now().Local().Format("2006-01-02 15:04:05"))
- }
- if productId != "" {
- productIds, _ := strconv.Atoi(productId)
- key = append(key, "product_id = ?")
- param = append(param, productIds)
- }
- whereSql := strings.Join(key, " and ")
- userCallRecord := []model.UserCallRecord{}
- err := db.GetSFISDB().Where(whereSql, param...).Where("app_id = ? ", appid).Order("create_at desc").Find(&userCallRecord).Error
- if err != nil {
- return nil, err
- } else {
- for _, v := range userCallRecord {
- productname := ""
- if product, ok := utils.ProductCaches.Map.Load(v.ProductId); ok {
- productname = product.(*model.Product).Name
- }
- dataMap := map[string]interface{}{
- "app_id": v.AppID,
- "invok_time": v.CreateAt.Local().Format("2006-01-02 15:04:05"),
- "ip": v.Ip,
- "name": productname,
- }
- datas = append(datas, dataMap)
- }
- }
- return datas, nil
- }
|