package service import ( "sfis/db" "sfis/model" "sfis/utils" "strconv" "strings" "time" ) func CallLog(appid, productId, startTime, endTime string, isSelf bool) ([]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("id 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 } if isSelf { interfaceOrder := model.InterfaceOrder{} err := db.GetSFISDB().First(&interfaceOrder, &model.InterfaceOrder{AppID: v.AppID, OrderCode: v.OrderCode}).Error if err == nil { 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, "param": v.Param, "order_code": v.OrderCode, "before": interfaceOrder.Before, "after": interfaceOrder.After, "cost_model": interfaceOrder.CostModel, "trade_num": interfaceOrder.TradeNum, } datas = append(datas, dataMap) } } else { 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, "param": v.Param, } datas = append(datas, dataMap) } } } return datas, nil }