广告平台(站长使用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

518 lines
18 KiB

  1. package svc
  2. import (
  3. "applet/app/e"
  4. "applet/app/enum"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "applet/app/utils/cache"
  8. db "code.fnuoos.com/zhimeng/model.git/src"
  9. implement2 "code.fnuoos.com/zhimeng/model.git/src/implement"
  10. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  11. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  12. "errors"
  13. "fmt"
  14. "github.com/gin-gonic/gin"
  15. "github.com/jinzhu/copier"
  16. "time"
  17. )
  18. func DataCenterIncomeDataListForOpen(c *gin.Context, req md.DataCenterGenerateDataForOpenReq) md.DataCenterIncomeDataRes {
  19. engine := db.Db
  20. NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine)
  21. mediumId := req.MediumId
  22. MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataListMedium(c.GetString("mid"), "", mediumId, "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  23. data := make([]md.DataCenterIncomeDataData, 0)
  24. if len(MediumList) > 0 {
  25. for _, v := range MediumList {
  26. var tmp = md.DataCenterIncomeDataData{
  27. AgreementSharing: utils.Float64ToStr(float64(v.AgreementSharing) / 100),
  28. AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
  29. Id: utils.IntToStr(v.Id),
  30. ExposureCount: utils.IntToStr(v.ExposureCount),
  31. ClickCount: utils.IntToStr(v.ClickCount),
  32. ClickRate: v.ClickRate,
  33. Ecpm: utils.Float64ToStr(utils.StrToFloat64(v.Ecpm) / 100),
  34. Date: v.Date,
  35. MediaRevenue: utils.Float64ToStr(float64(v.MediaRevenue) / 100),
  36. SettleAmount: utils.Float64ToStr(float64(v.MediaRevenue+v.AgentRevenue+v.AgreementSharing) / 100),
  37. }
  38. tmpApplet := GetAppletInfo(c, v.AppId)
  39. if tmpApplet["platform"] != "" {
  40. tmp.Platform = tmpApplet["platform"]
  41. }
  42. if tmpApplet["name"] != "" {
  43. tmp.Name = tmpApplet["name"]
  44. }
  45. tmpSlot := GetSlotInfo(c, v.SlotId)
  46. if tmpSlot["state"] != "" {
  47. tmp.State = tmpSlot["state"]
  48. }
  49. if tmpSlot["name"] != "" {
  50. tmp.AdvName = tmpSlot["name"]
  51. }
  52. data = append(data, tmp)
  53. }
  54. }
  55. res := md.DataCenterIncomeDataRes{
  56. List: data,
  57. Total: total,
  58. State: md.AdState,
  59. Platform: md.AdPlatform,
  60. }
  61. return res
  62. }
  63. func DataCenterIncomeDataList(c *gin.Context, req md.DataCenterGenerateDataReq) md.DataCenterIncomeDataRes {
  64. engine := db.Db
  65. NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine)
  66. user := GetUser(c)
  67. appId := GetAppletId(c, req.Name, req.Platform, req.AppId)
  68. mediumId := GetMediumIdStr(c, user.AdmId, "", "")
  69. slotId := GetSlotId(c, req.State)
  70. MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataListMedium(c.GetString("mid"), appId, mediumId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  71. data := make([]md.DataCenterIncomeDataData, 0)
  72. if len(MediumList) > 0 {
  73. for _, v := range MediumList {
  74. var tmp = md.DataCenterIncomeDataData{
  75. AgreementSharing: utils.Float64ToStr(float64(v.AgreementSharing) / 100),
  76. AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
  77. Id: utils.IntToStr(v.Id),
  78. ExposureCount: utils.IntToStr(v.ExposureCount),
  79. ClickCount: utils.IntToStr(v.ClickCount),
  80. ClickRate: v.ClickRate,
  81. Ecpm: utils.Float64ToStr(utils.StrToFloat64(v.Ecpm) / 100),
  82. Date: v.Date,
  83. MediaRevenue: utils.Float64ToStr(float64(v.MediaRevenue) / 100),
  84. SettleAmount: utils.Float64ToStr(float64(v.MediaRevenue+v.AgentRevenue+v.AgreementSharing) / 100),
  85. }
  86. tmpApplet := GetAppletInfo(c, v.AppId)
  87. if tmpApplet["platform"] != "" {
  88. tmp.Platform = tmpApplet["platform"]
  89. }
  90. if tmpApplet["name"] != "" {
  91. tmp.Name = tmpApplet["name"]
  92. }
  93. tmpSlot := GetSlotInfo(c, v.SlotId)
  94. if tmpSlot["state"] != "" {
  95. tmp.State = tmpSlot["state"]
  96. }
  97. if tmpSlot["name"] != "" {
  98. tmp.AdvName = tmpSlot["name"]
  99. }
  100. data = append(data, tmp)
  101. }
  102. }
  103. res := md.DataCenterIncomeDataRes{
  104. List: data,
  105. Total: total,
  106. State: md.AdState,
  107. Platform: md.AdPlatform,
  108. }
  109. return res
  110. }
  111. func DataCenterIncomeDataListOutput(c *gin.Context, req md.DataCenterGenerateDataReq) {
  112. engine := db.Db
  113. NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine)
  114. user := GetUser(c)
  115. appId := GetAppletId(c, req.Name, req.Platform, req.AppId)
  116. mediumId := GetMediumIdStr(c, user.AdmId, "", "")
  117. slotId := GetSlotId(c, req.State)
  118. req.Limit = "3000"
  119. MediumList, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataListMediumAll(c.GetString("mid"), appId, mediumId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  120. data := map[string]string{
  121. "A1": "名称",
  122. "B1": "日期",
  123. "C1": "广告位",
  124. "D1": "曝光量",
  125. "E1": "点击率(%)",
  126. "F1": "点击量",
  127. "G1": "结算平台",
  128. "H1": "媒体-ECPM",
  129. "I1": "媒体收益(元)",
  130. "J1": "代理收益(元)",
  131. "K1": "平台收益(元)",
  132. }
  133. name := "运营报表第" + req.Page + "页"
  134. if len(MediumList) > 0 {
  135. for k, v := range MediumList {
  136. var tmp = md.DataCenterIncomeDataData{
  137. AgreementSharing: utils.Float64ToStr(float64(v.AgreementSharing) / 100),
  138. AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
  139. Id: utils.IntToStr(v.Id),
  140. ExposureCount: utils.IntToStr(v.ExposureCount),
  141. ClickCount: utils.IntToStr(v.ClickCount),
  142. ClickRate: v.ClickRate,
  143. Ecpm: utils.Float64ToStr(utils.StrToFloat64(v.Ecpm) / 100),
  144. Date: v.Date,
  145. MediaRevenue: utils.Float64ToStr(float64(v.MediaRevenue) / 100),
  146. SettleAmount: utils.Float64ToStr(float64(v.MediaRevenue+v.AgentRevenue+v.AgreementSharing) / 100),
  147. }
  148. tmpApplet := GetAppletInfo(c, v.AppId)
  149. if tmpApplet["platform"] != "" {
  150. tmp.Platform = md.AdPlatformMap[tmpApplet["platform"]]
  151. }
  152. if tmpApplet["name"] != "" {
  153. tmp.Name = tmpApplet["name"]
  154. }
  155. tmpSlot := GetSlotInfo(c, v.SlotId)
  156. if tmpSlot["state"] != "" {
  157. tmp.State = tmpSlot["state"]
  158. }
  159. if tmpSlot["name"] != "" {
  160. tmp.AdvName = tmpSlot["name"]
  161. }
  162. i := utils.IntToStr(k + 2)
  163. data["A"+i] = tmp.Name
  164. data["B"+i] = tmp.Date
  165. data["C"+i] = tmp.AdvName
  166. data["D"+i] = tmp.ExposureCount
  167. data["E"+i] = tmp.ClickRate
  168. data["F"+i] = tmp.ClickCount
  169. data["G"+i] = tmp.Platform
  170. data["H"+i] = tmp.Ecpm
  171. data["I"+i] = tmp.MediaRevenue
  172. data["J"+i] = tmp.AgentRevenue
  173. data["K"+i] = tmp.AgreementSharing
  174. }
  175. }
  176. file := utils.Output(c, name, data)
  177. filename := name + ".xlsx"
  178. r := map[string]string{
  179. "file": file,
  180. "filename": filename,
  181. }
  182. e.OutSuc(c, r, nil)
  183. return
  184. }
  185. func DataCenterIncomeDataDetail(c *gin.Context, req md.DataCenterGenerateDataCommReq) {
  186. NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db)
  187. data, _ := NewGenerateWxAdDataDb.GetGenerateWxAdData(utils.StrToInt(req.Id))
  188. if data == nil {
  189. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  190. return
  191. }
  192. agentReward := make([]md.DataCenterGenerateDataDetailAgentRewardSecond, 0)
  193. NewGenerateWxAdDataWithAgentFlowDb := implement.NewGenerateWxAdDataWithAgentFlowDb(db.Db)
  194. agent, _ := NewGenerateWxAdDataWithAgentFlowDb.FindGenerateWxAdDataWithAgentFlowByStrategyId(data.Id)
  195. if agent != nil {
  196. for _, v := range *agent {
  197. tmp := md.DataCenterGenerateDataDetailAgentRewardSecond{
  198. Name: "",
  199. Account: "",
  200. AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
  201. AgentRevenueRate: utils.IntToStr(data.AgentRevenueRate),
  202. }
  203. tmpApplet := GetAgentInfo(c, v.AgentId)
  204. if tmpApplet["name"] != "" {
  205. tmp.Name = tmpApplet["name"]
  206. }
  207. if tmpApplet["account"] != "" {
  208. tmp.Account = tmpApplet["account"]
  209. }
  210. agentReward = append(agentReward, tmp)
  211. }
  212. }
  213. res := md.DataCenterIncomeDataDetail{
  214. MediaRevenue: utils.Float64ToStr(float64(data.MediaRevenue) / 100),
  215. AgreementSharing: utils.Float64ToStr(float64(data.AgreementSharing) / 100),
  216. AgentRevenue: utils.Float64ToStr(float64(data.AgentRevenue) / 100),
  217. DataSource: "手动同步",
  218. CreateAt: data.CreateAt,
  219. UpdateAt: data.UpdateAt,
  220. MediaRevenueRate: utils.IntToStr(data.MediaRevenueRate),
  221. AgentRevenueRate: utils.IntToStr(data.AgentRevenueRate),
  222. AgreementSharingRate: utils.IntToStr(data.AgreementSharingRate),
  223. AgentReward: agentReward,
  224. }
  225. tmpApplet := GetAppletInfo(c, data.AppId)
  226. if tmpApplet["platform"] != "" {
  227. res.Platform = tmpApplet["platform"]
  228. }
  229. NewAppletApplicationDb := implement2.NewAppletApplicationDb(MasterDb(c))
  230. app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(data.AppId)
  231. tmp := GetMediumInfo(c, app.MediumId)
  232. if tmp["name"] != "" {
  233. res.MediumName = tmp["name"]
  234. if tmp["account"] != "" {
  235. res.MediumName += "(" + tmp["account"] + ")"
  236. }
  237. }
  238. e.OutSuc(c, res, nil)
  239. return
  240. }
  241. func DataCenterGenerateDataList(c *gin.Context, req md.DataCenterGenerateDataReq) md.DataCenterGenerateDataRes {
  242. engine := db.Db
  243. NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine)
  244. user := GetUser(c)
  245. appId := GetAppletId(c, req.Name, req.Platform, req.AppId)
  246. mediumId := GetMediumIdStr(c, user.AdmId, "", "")
  247. slotId := GetSlotId(c, req.State)
  248. MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataList(c.GetString("mid"), appId, mediumId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  249. data := make([]md.DataCenterGenerateDataData, 0)
  250. if len(MediumList) > 0 {
  251. NewOriginalWxAdDataDb := implement.NewOriginalWxAdDataDb(engine)
  252. for _, v := range MediumList {
  253. wxData, _ := NewOriginalWxAdDataDb.GetOriginalWxAdData(v.OriginalDataId)
  254. var tmp = md.DataCenterGenerateDataData{
  255. Id: utils.IntToStr(v.Id),
  256. ExposureCount: utils.IntToStr(v.ExposureCount),
  257. ClickCount: utils.IntToStr(v.ClickCount),
  258. ClickRate: v.ClickRate,
  259. Ecpm: utils.Float64ToStr(utils.StrToFloat64(v.Ecpm) / 100),
  260. IsGenerateReport: utils.IntToStr(v.IsGenerateReport),
  261. Date: v.Date,
  262. PlatformRetention: utils.Float64ToStr(float64(v.PlatformRetention) / 100),
  263. CommissionRetention: utils.Float64ToStr(float64(v.CommissionRetention) / 100),
  264. PriceAdjustmentRetention: utils.Float64ToStr(float64(v.PriceAdjustmentRetention) / 100),
  265. MediaRevenue: utils.Float64ToStr(float64(v.MediaRevenue) / 100),
  266. AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
  267. ExtraRevenue: utils.Float64ToStr(float64(v.ExtraRevenue) / 100),
  268. AgreementSharing: utils.Float64ToStr(float64(v.AgreementSharing) / 100),
  269. AgreementSharingTotal: utils.Float64ToStr(float64(v.AgreementSharingTotal) / 100),
  270. }
  271. if wxData != nil {
  272. tmp.OldClickRate = wxData.ClickRate
  273. tmp.OldClickCount = utils.IntToStr(wxData.ClickCount)
  274. tmp.OldEcpm = utils.Float64ToStr(utils.StrToFloat64(wxData.Ecpm) / 100)
  275. tmp.OldExposureCount = utils.IntToStr(wxData.ExposureCount)
  276. }
  277. tmpApplet := GetAppletInfo(c, v.AppId)
  278. if tmpApplet["platform"] != "" {
  279. tmp.Platform = tmpApplet["platform"]
  280. }
  281. if tmpApplet["name"] != "" {
  282. tmp.Name = tmpApplet["name"]
  283. }
  284. tmpSlot := GetSlotInfo(c, v.SlotId)
  285. if tmpSlot["state"] != "" {
  286. tmp.State = tmpSlot["state"]
  287. }
  288. if tmpSlot["name"] != "" {
  289. tmp.AdvName = tmpSlot["name"]
  290. }
  291. data = append(data, tmp)
  292. }
  293. }
  294. res := md.DataCenterGenerateDataRes{
  295. List: data,
  296. Total: total,
  297. State: md.AdState,
  298. Platform: md.AdPlatform,
  299. }
  300. return res
  301. }
  302. func DataCenterGenerateDataDel(c *gin.Context, req md.DataCenterGenerateDataCommReq) error {
  303. NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db)
  304. data, _ := NewGenerateWxAdDataDb.GetGenerateWxAdData(utils.StrToInt(req.Id))
  305. if data == nil {
  306. return errors.New("记录不存在")
  307. }
  308. if data.IsGenerateReport == 1 {
  309. return errors.New("记录已应用,不能删除")
  310. }
  311. // 1、删除 generate_wx_ad_data 数据
  312. _, err := db.Db.Where("id=?", req.Id).Delete(&model.GenerateWxAdData{})
  313. if err != nil {
  314. return err
  315. }
  316. // 2、删除 generate_wx_ad_data_with_agent_flow 数据
  317. _, err = db.Db.Where("generate_data_id=?", req.Id).Delete(&model.GenerateWxAdDataWithAgentFlow{})
  318. if err != nil {
  319. return err
  320. }
  321. // 3、修改 original_wx_ad_data 状态值
  322. db.Db.Where("id=?", data.OriginalDataId).Cols("is_apply").Update(&model.OriginalWxAdData{IsApply: 0})
  323. return nil
  324. }
  325. func DataCenterGenerateDataDetail(c *gin.Context, req md.DataCenterGenerateDataCommReq) {
  326. NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db)
  327. data, _ := NewGenerateWxAdDataDb.GetGenerateWxAdData(utils.StrToInt(req.Id))
  328. if data == nil {
  329. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  330. return
  331. }
  332. agentReward := make([]md.DataCenterGenerateDataDetailAgentReward, 0)
  333. NewGenerateWxAdDataWithAgentFlowDb := implement.NewGenerateWxAdDataWithAgentFlowDb(db.Db)
  334. agent, _ := NewGenerateWxAdDataWithAgentFlowDb.FindGenerateWxAdDataWithAgentFlowByStrategyId(data.Id)
  335. if agent != nil {
  336. for _, v := range *agent {
  337. tmp := md.DataCenterGenerateDataDetailAgentReward{
  338. Name: "",
  339. Account: "",
  340. AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
  341. AgentRevenueRate: utils.IntToStr(data.AgentRevenueRate),
  342. ExtraRevenue: utils.Float64ToStr(float64(v.ExtraRevenue) / 100),
  343. ExtraRevenueRate: utils.IntToStr(data.ExtraRevenueRate),
  344. }
  345. tmpApplet := GetAgentInfo(c, v.AgentId)
  346. if tmpApplet["name"] != "" {
  347. tmp.Name = tmpApplet["name"]
  348. }
  349. if tmpApplet["account"] != "" {
  350. tmp.Account = tmpApplet["account"]
  351. }
  352. agentReward = append(agentReward, tmp)
  353. }
  354. }
  355. res := md.DataCenterGenerateDataDetailData{
  356. PlatformRetentionRate: utils.IntToStr(data.PlatformRetentionRate),
  357. CommissionRetentionRate: utils.IntToStr(data.CommissionRetentionRate),
  358. MediaRevenueRate: utils.IntToStr(data.MediaRevenueRate),
  359. AgentRevenueRate: utils.IntToStr(data.AgentRevenueRate),
  360. ExtraRevenueRate: utils.IntToStr(data.ExtraRevenueRate),
  361. AgreementSharingRate: utils.IntToStr(data.AgreementSharingRate),
  362. AgentReward: agentReward,
  363. }
  364. e.OutSuc(c, res, nil)
  365. return
  366. }
  367. func DataCenterGenerateDataDoing(c *gin.Context, req md.DataCenterGenerateDataCommReq) error {
  368. NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db)
  369. data, _ := NewGenerateWxAdDataDb.GetGenerateWxAdData(utils.StrToInt(req.Id))
  370. if data == nil {
  371. return e.NewErr(400, "记录不存在")
  372. }
  373. if data.IsGenerateReport == 1 {
  374. return e.NewErr(400, "该记录已完成操作")
  375. }
  376. // 加锁 防止并发提取
  377. mutexKey := fmt.Sprintf("%s:DataCenterGenerateDataDoing:%s", c.GetString("mid"), req.Id)
  378. withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 5, "NX")
  379. if err != nil {
  380. return err
  381. }
  382. if withdrawAvailable != "OK" {
  383. return e.NewErr(400000, "请求过于频繁,请稍后再试")
  384. }
  385. args := md.SettlementWxAdData{
  386. GenerateDataId: utils.StrToInt(req.Id),
  387. }
  388. err = SettlementWxAdData(args)
  389. if err != nil {
  390. return err
  391. }
  392. return nil
  393. }
  394. func DataCenterSelectData(c *gin.Context) {
  395. NewAppletApplicationDb := implement2.NewAppletApplicationDb(MasterDb(c))
  396. appList, _ := NewAppletApplicationDb.FindAllAppletApplicationList()
  397. appMap := make(map[string][]map[string]interface{})
  398. user := GetUser(c)
  399. NewAdminBindMediumDb := implement2.NewAdminBindMediumDb(MasterDb(c))
  400. list := NewAdminBindMediumDb.FindAll(user.AdmId)
  401. ids := make([]string, 0)
  402. for _, v := range list {
  403. ids = append(ids, utils.IntToStr(v.MediumId))
  404. }
  405. for _, v := range appList {
  406. if utils.InArr(utils.IntToStr(v.MediumId), ids) == false {
  407. continue
  408. }
  409. _, ok := appMap[v.Platform]
  410. if ok == false {
  411. appMap[v.Platform] = make([]map[string]interface{}, 0)
  412. }
  413. tmp := map[string]interface{}{
  414. "name": v.Name,
  415. "app_id": v.AppId,
  416. "ad_type": enum.AdTypeList,
  417. }
  418. appMap[v.Platform] = append(appMap[v.Platform], tmp)
  419. }
  420. platform := []map[string]interface{}{
  421. {
  422. "name": "微信小程序",
  423. "platform": "wx_applet",
  424. "app_list": appMap["wx_applet"],
  425. },
  426. }
  427. e.OutSuc(c, platform, nil)
  428. return
  429. }
  430. func DataCenterTable(c *gin.Context, req md.DataCenterTableReq) md.DataCenterTableRes {
  431. var req1 md.DataCenterRecordReq
  432. copier.Copy(&req1, &req)
  433. nativeString, _ := comm(c, 0, req1)
  434. list := make([]md.DataCenterTableData, 0)
  435. tmpMap := make(map[string]md.DataCenterTableData)
  436. for _, v := range nativeString {
  437. tmp := md.DataCenterTableData{
  438. Date: v["date"],
  439. ExposureCount: v["exposure_count"],
  440. MediaRevenue: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100),
  441. Ecpm: v["ecpm"],
  442. }
  443. tmpMap[v["date"]] = tmp
  444. }
  445. day := (utils.TimeStdParseUnix(req.EndDate+" 00:00:00") - utils.TimeStdParseUnix(req.StartDate+" 00:00:00")) / 86400
  446. for i := day; i >= 0; i-- {
  447. date := utils.TimeStdParseUnix(req.EndDate+" 00:00:00") - i*86400
  448. tmp, ok := tmpMap[time.Unix(date, 0).Format("2006-01-02")]
  449. if ok == false {
  450. tmp = md.DataCenterTableData{
  451. Date: time.Unix(date, 0).Format("2006-01-02"),
  452. ExposureCount: "0",
  453. MediaRevenue: "0",
  454. Ecpm: "0",
  455. }
  456. }
  457. list = append(list, tmp)
  458. }
  459. res := md.DataCenterTableRes{
  460. List: list,
  461. }
  462. return res
  463. }
  464. func comm(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[string]string, int64) {
  465. appId := GetAppletId(c, req.Name, req.Platform, req.AppId)
  466. sql := `
  467. SELECT
  468. %s
  469. FROM generate_wx_ad_data
  470. where %s %s
  471. `
  472. where := "is_generate_report=1 and uuid=" + c.GetString("mid")
  473. if req.AppId != "" || req.Platform != "" {
  474. where += " and app_id in('" + appId + "')"
  475. }
  476. if req.AdType != "" {
  477. where += " and ad_slot='" + req.AdType + "'"
  478. }
  479. if req.StartDate != "" {
  480. where += " and date>='" + req.StartDate + "'"
  481. }
  482. if req.EndDate != "" {
  483. where += " and date<='" + req.EndDate + "'"
  484. }
  485. field := `*`
  486. start := (utils.StrToInt(req.Page) - 1) * utils.StrToInt(req.Limit)
  487. groupBy := " order by date desc,id desc"
  488. if req.Page != "" {
  489. groupBy += " limit " + utils.IntToStr(start) + "," + req.Limit
  490. } else {
  491. groupBy = " order by date asc,id asc"
  492. }
  493. sql1 := fmt.Sprintf(sql, field, where, groupBy)
  494. nativeString, _ := db.QueryNativeString(db.Db, sql1)
  495. var total int64 = 0
  496. if isTotal == 1 {
  497. sqlTotal := fmt.Sprintf(sql, "COUNT(*) as count ", where, "")
  498. nativeStringTotal, _ := db.QueryNativeString(db.Db, sqlTotal)
  499. for _, v := range nativeStringTotal {
  500. total = utils.StrToInt64(v["count"])
  501. }
  502. }
  503. return nativeString, total
  504. }