广告平台(站长下代理使用)
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

641 righe
20 KiB

  1. package svc
  2. import (
  3. "applet/app/e"
  4. "applet/app/enum"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
  8. db "code.fnuoos.com/zhimeng/model.git/src"
  9. "code.fnuoos.com/zhimeng/model.git/src/implement"
  10. model2 "code.fnuoos.com/zhimeng/model.git/src/model"
  11. "fmt"
  12. "github.com/gin-gonic/gin"
  13. "github.com/jinzhu/copier"
  14. "strings"
  15. )
  16. func DataCenterRecordTotal(c *gin.Context, req md.DataCenterTableReq) md.DataCenterTotalData {
  17. appId := GetAppletId(c, req.AppId, req.Platform)
  18. sql := `
  19. SELECT
  20. SUM(exposure_count) as exposure_count,
  21. SUM(click_count) as click_count,
  22. SUM(click_count)/SUM(exposure_count)*100 as click_rate,
  23. SUM(ecpm) as ecpm,
  24. SUM(media_revenue) as media_revenue
  25. FROM generate_wx_ad_data
  26. where %s
  27. `
  28. mediumId := GetAgentMediumId(c)
  29. where := "uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")"
  30. if req.AppId != "" || req.Platform != "" {
  31. where += " and app_id in(" + appId + ")"
  32. }
  33. if req.AdType != "" {
  34. where += " and ad_slot='" + req.AdType + "'"
  35. }
  36. if req.StartDate != "" {
  37. where += " and date>='" + req.StartDate + "'"
  38. }
  39. if req.EndDate != "" {
  40. where += " and date<='" + req.EndDate + "'"
  41. }
  42. sql = fmt.Sprintf(sql, where)
  43. nativeString, _ := db.QueryNativeString(db.Db, sql)
  44. res := md.DataCenterTotalData{}
  45. for _, v := range nativeString {
  46. res = md.DataCenterTotalData{
  47. Date: "-",
  48. AppName: "-",
  49. PlatformName: "-",
  50. AdvName: "-",
  51. ExposureCount: v["exposure_count"],
  52. MediaRevenue: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100),
  53. Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100),
  54. ClickRate: utils.GetPrec(v["click_rate"], "2") + "%",
  55. ClickCount: v["click_count"],
  56. }
  57. }
  58. return res
  59. }
  60. func DataCenterRecordList(c *gin.Context, req md.DataCenterRecordReq) md.DataCenterRecordRes {
  61. nativeString, total := comm(c, 1, req)
  62. list := make([]md.DataCenterTotalData, 0)
  63. for _, v := range nativeString {
  64. NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
  65. app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(v["app_id"])
  66. platform := ""
  67. name := ""
  68. if app != nil {
  69. name = app.Name
  70. platform = app.Platform
  71. }
  72. NewAppletApplicationAdSpaceListDb := implement.NewAppletApplicationAdSpaceListDb(MasterDb(c))
  73. adData, _ := NewAppletApplicationAdSpaceListDb.GetAppletApplicationAdSpaceListByAdId(v["slot_id"])
  74. adName := enum.AdunitType(v["ad_slot"]).String()
  75. if adData != nil {
  76. adName = adData.Name
  77. }
  78. tmp := md.DataCenterTotalData{
  79. Date: v["date"],
  80. AppName: name,
  81. PlatformName: md.AppletPlatformMap[platform],
  82. AdvName: adName,
  83. ExposureCount: v["exposure_count"],
  84. MediaRevenue: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100),
  85. Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100),
  86. ClickRate: v["click_rate"] + "%",
  87. ClickCount: v["click_count"],
  88. }
  89. list = append(list, tmp)
  90. }
  91. res := md.DataCenterRecordRes{
  92. List: list,
  93. Total: total,
  94. }
  95. return res
  96. }
  97. func DataCenterRecordOutPut(c *gin.Context, req md.DataCenterRecordOutPutReq) {
  98. var req1 md.DataCenterRecordReq
  99. copier.Copy(&req1, &req)
  100. req.Limit = "10000"
  101. nativeString, _ := comm(c, 0, req1)
  102. appId := make([]string, 0)
  103. adId := make([]string, 0)
  104. for _, v := range nativeString {
  105. appId = append(appId, v["app_id"])
  106. adId = append(adId, v["slot_id"])
  107. }
  108. var app []model2.AppletApplication
  109. appMap := make(map[string]model2.AppletApplication)
  110. MasterDb(c).In("app_id=?", appId).Find(&app)
  111. for _, v := range app {
  112. appMap[v.AppId] = v
  113. }
  114. var ad []model2.AppletApplicationAdSpaceList
  115. adMap := make(map[string]model2.AppletApplicationAdSpaceList)
  116. MasterDb(c).In("ad_id=?", adId).Find(&adMap)
  117. for _, v := range ad {
  118. adMap[v.AdId] = v
  119. }
  120. name := req.StartDate + "~" + req.EndDate + "(第" + req.Page + "页 " + utils.IntToStr(len(nativeString)) + "条)"
  121. //写入数据
  122. data := map[string]string{
  123. "A1": "日期",
  124. "B1": "应用名称",
  125. "C1": "平台类型",
  126. "D1": "广告位",
  127. "E1": "曝光量",
  128. "F1": "点击量",
  129. "G1": "ECPM",
  130. "H1": "预估收益",
  131. }
  132. for k, v := range nativeString {
  133. i := utils.IntToStr(k + 2)
  134. data["A"+i] = v["date"]
  135. data["B"+i] = appMap[v["app_id"]].Name
  136. data["C"+i] = md.AppletPlatformMap[appMap[v["app_id"]].Platform]
  137. data["D"+i] = adMap[v["slot_id"]].Name
  138. data["E"+i] = v["exposure_count"]
  139. data["F"+i] = v["click_count"]
  140. data["G"+i] = utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100)
  141. data["H"+i] = utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100)
  142. }
  143. file := utils.Output(c, name, data)
  144. filename := name + ".xlsx"
  145. r := map[string]string{
  146. "file": file,
  147. "filename": filename,
  148. }
  149. e.OutSuc(c, r, nil)
  150. return
  151. }
  152. func DataCenterCommissionRecordTotal(c *gin.Context, req md.DataCenterTableReq) md.DataCenterCommissionTotalData {
  153. appId := GetAppletId(c, req.AppId, req.Platform)
  154. sql := `
  155. SELECT
  156. SUM(exposure_count) as exposure_count,
  157. SUM(click_count) as click_count,
  158. SUM(click_count)/SUM(exposure_count)*100 as click_rate,
  159. SUM(ecpm) as ecpm,
  160. SUM(media_revenue) as media_revenue
  161. FROM generate_wx_ad_data
  162. where %s
  163. `
  164. mediumId := GetAgentMediumId(c)
  165. where := "uuid=" + c.GetString("mid")
  166. if req.AppId != "" || req.Platform != "" {
  167. where += " and app_id in(" + appId + ")"
  168. }
  169. if req.AdType != "" {
  170. where += " and ad_slot='" + req.AdType + "'"
  171. }
  172. if req.StartDate != "" {
  173. where += " and date>='" + req.StartDate + "'"
  174. }
  175. if req.EndDate != "" {
  176. where += " and date<='" + req.EndDate + "'"
  177. }
  178. whereMedium := where + " and medium_id in(" + mediumId + ")"
  179. sql = fmt.Sprintf(sql, whereMedium)
  180. nativeString, _ := db.QueryNativeString(db.Db, sql)
  181. res := md.DataCenterCommissionTotalData{}
  182. for _, v := range nativeString {
  183. res = md.DataCenterCommissionTotalData{
  184. Date: "-",
  185. AppName: "-",
  186. PlatformName: "-",
  187. AdvName: "-",
  188. ExposureCount: v["exposure_count"],
  189. Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100),
  190. ClickRate: utils.GetPrec(v["click_rate"], "2") + "%",
  191. ClickCount: v["click_count"],
  192. AllCommission: "0",
  193. OtherCommission: "0",
  194. Commission: "0",
  195. }
  196. }
  197. sqlAgent := `
  198. SELECT
  199. SUM(agent_revenue) as agent_revenue,
  200. SUM(extra_revenue) as extra_revenue
  201. FROM generate_wx_ad_data_with_agent_flow
  202. where %s
  203. `
  204. user := GetUser(c)
  205. whereAgent := where + " and agent_id=" + utils.IntToStr(user.AgentId)
  206. sqlAgent = fmt.Sprintf(sqlAgent, whereAgent)
  207. nativeStringAgent, _ := db.QueryNativeString(db.Db, sqlAgent)
  208. for _, v := range nativeStringAgent {
  209. res.Commission = utils.Float64ToStr(utils.StrToFloat64(v["agent_revenue"]) / 100)
  210. res.OtherCommission = utils.Float64ToStr(utils.StrToFloat64(v["extra_revenue"]) / 100)
  211. res.AllCommission = utils.Float64ToStr(utils.StrToFloat64(res.Commission) + utils.StrToFloat64(res.OtherCommission))
  212. }
  213. return res
  214. }
  215. func DataCenterCommissionRecordList(c *gin.Context, req md.DataCenterRecordReq) md.DataCenterCommissionRecordRes {
  216. nativeString, total := commAgent(c, 1, req)
  217. list := make([]md.DataCenterCommissionTotalData, 0)
  218. for _, v := range nativeString {
  219. NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
  220. app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(v["app_id"])
  221. platform := ""
  222. name := ""
  223. if app != nil {
  224. name = app.Name
  225. platform = app.Platform
  226. }
  227. NewAppletApplicationAdSpaceListDb := implement.NewAppletApplicationAdSpaceListDb(MasterDb(c))
  228. adData, _ := NewAppletApplicationAdSpaceListDb.GetAppletApplicationAdSpaceListByAdId(v["slot_id"])
  229. adName := enum.AdunitType(v["ad_slot"]).String()
  230. if adData != nil {
  231. adName = adData.Name
  232. }
  233. tmp := md.DataCenterCommissionTotalData{
  234. Date: v["date"],
  235. AppName: name,
  236. PlatformName: md.AppletPlatformMap[platform],
  237. AdvName: adName,
  238. ExposureCount: v["exposure_count"],
  239. Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100),
  240. ClickRate: v["click_rate"] + "%",
  241. ClickCount: v["click_count"],
  242. AllCommission: v["all_commission"],
  243. OtherCommission: v["other_commission"],
  244. Commission: v["commission"],
  245. }
  246. list = append(list, tmp)
  247. }
  248. res := md.DataCenterCommissionRecordRes{
  249. List: list,
  250. Total: total,
  251. }
  252. return res
  253. }
  254. func DataCenterCommissionRecordOutPut(c *gin.Context, req md.DataCenterRecordOutPutReq) {
  255. var req1 md.DataCenterRecordReq
  256. copier.Copy(&req1, &req)
  257. req.Limit = "10000"
  258. nativeString, _ := commAgent(c, 0, req1)
  259. appId := make([]string, 0)
  260. adId := make([]string, 0)
  261. for _, v := range nativeString {
  262. appId = append(appId, v["app_id"])
  263. adId = append(adId, v["slot_id"])
  264. }
  265. var app []model2.AppletApplication
  266. appMap := make(map[string]model2.AppletApplication)
  267. MasterDb(c).In("app_id=?", appId).Find(&app)
  268. for _, v := range app {
  269. appMap[v.AppId] = v
  270. }
  271. var ad []model2.AppletApplicationAdSpaceList
  272. adMap := make(map[string]model2.AppletApplicationAdSpaceList)
  273. MasterDb(c).In("ad_id=?", adId).Find(&adMap)
  274. for _, v := range ad {
  275. adMap[v.AdId] = v
  276. }
  277. name := req.StartDate + "~" + req.EndDate + "(第" + req.Page + "页 " + utils.IntToStr(len(nativeString)) + "条)"
  278. //写入数据
  279. data := map[string]string{
  280. "A1": "日期",
  281. "B1": "应用名称",
  282. "C1": "平台类型",
  283. "D1": "广告位",
  284. "E1": "曝光量",
  285. "F1": "点击量",
  286. "G1": "ECPM",
  287. "H1": "预估佣金",
  288. "I1": "额外奖励",
  289. "J1": "预估总收益",
  290. }
  291. for k, v := range nativeString {
  292. i := utils.IntToStr(k + 2)
  293. data["A"+i] = v["date"]
  294. data["B"+i] = appMap[v["app_id"]].Name
  295. data["C"+i] = md.AppletPlatformMap[appMap[v["app_id"]].Platform]
  296. data["D"+i] = adMap[v["slot_id"]].Name
  297. data["E"+i] = v["exposure_count"]
  298. data["F"+i] = v["click_count"]
  299. data["G"+i] = utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100)
  300. data["H"+i] = v["commission"]
  301. data["I"+i] = v["other_commission"]
  302. data["J"+i] = v["all_commission"]
  303. }
  304. file := utils.Output(c, name, data)
  305. filename := name + ".xlsx"
  306. r := map[string]string{
  307. "file": file,
  308. "filename": filename,
  309. }
  310. e.OutSuc(c, r, nil)
  311. return
  312. }
  313. func DataCenterProfitRecordOutPut(c *gin.Context, req md.DataCenterProfitRecordOutPutReq) {
  314. var req1 md.DataCenterProfitRecordReq
  315. copier.Copy(&req1, &req)
  316. req.Limit = "10000"
  317. nativeString, _ := commAgentProfit(c, 0, req1)
  318. appId := make([]string, 0)
  319. for _, v := range nativeString {
  320. appId = append(appId, v["app_id"])
  321. }
  322. var app []model2.AppletApplication
  323. appMap := make(map[string]model2.AppletApplication)
  324. MasterDb(c).In("app_id=?", appId).Find(&app)
  325. for _, v := range app {
  326. appMap[v.AppId] = v
  327. }
  328. name := req.StartDate + "~" + req.EndDate + "(第" + req.Page + "页 " + utils.IntToStr(len(nativeString)) + "条)"
  329. //写入数据
  330. data := map[string]string{
  331. "A1": "日期",
  332. "B1": "应用名称",
  333. "C1": "平台类型",
  334. "D1": "预估佣金",
  335. "E1": "额外奖励",
  336. "F1": "预估总收益",
  337. }
  338. for k, v := range nativeString {
  339. i := utils.IntToStr(k + 2)
  340. data["A"+i] = v["date"]
  341. data["B"+i] = appMap[v["app_id"]].Name
  342. data["C"+i] = md.AppletPlatformMap[appMap[v["app_id"]].Platform]
  343. data["D"+i] = v["commission"]
  344. data["E"+i] = v["other_commission"]
  345. data["F"+i] = v["all_commission"]
  346. }
  347. file := utils.Output(c, name, data)
  348. filename := name + ".xlsx"
  349. r := map[string]string{
  350. "file": file,
  351. "filename": filename,
  352. }
  353. e.OutSuc(c, r, nil)
  354. return
  355. }
  356. func DataCenterProfitRecordList(c *gin.Context, req md.DataCenterProfitRecordReq) md.DataCenterProfitRecordRes {
  357. data, total := commAgentProfit(c, 1, req)
  358. list := make([]md.DataCenterProfitRecordData, 0)
  359. for _, v := range data {
  360. NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
  361. app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(v["app_id"])
  362. platform := ""
  363. name := ""
  364. if app != nil {
  365. name = app.Name
  366. platform = app.Platform
  367. }
  368. tmp := md.DataCenterProfitRecordData{
  369. Date: v["date"],
  370. AppName: name,
  371. PlatformName: md2.PlatformMap[platform],
  372. Commission: utils.Float64ToStr(utils.StrToFloat64(v["agent_revenue"]) / 100),
  373. OtherCommission: utils.Float64ToStr(utils.StrToFloat64(v["extra_revenue"]) / 100),
  374. }
  375. tmp.AllCommission = utils.Float64ToStr(utils.StrToFloat64(tmp.Commission) + utils.StrToFloat64(tmp.OtherCommission))
  376. list = append(list, tmp)
  377. }
  378. res := md.DataCenterProfitRecordRes{
  379. List: list,
  380. Total: total,
  381. }
  382. return res
  383. }
  384. func comm(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[string]string, int64) {
  385. appId := GetAppletId(c, req.AppId, req.Platform)
  386. sql := `
  387. SELECT
  388. %s
  389. FROM generate_wx_ad_data
  390. where %s %s
  391. `
  392. mediumId := GetAgentMediumId(c)
  393. where := "uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")"
  394. if req.AppId != "" || req.Platform != "" {
  395. where += " and app_id in(" + appId + ")"
  396. }
  397. if req.AdType != "" {
  398. where += " and ad_slot='" + req.AdType + "'"
  399. }
  400. if req.StartDate != "" {
  401. where += " and date>='" + req.StartDate + "'"
  402. }
  403. if req.EndDate != "" {
  404. where += " and date<='" + req.EndDate + "'"
  405. }
  406. field := `*`
  407. start := (utils.StrToInt(req.Page) - 1) * utils.StrToInt(req.Limit)
  408. groupBy := " order by date desc,id desc"
  409. if req.Page != "" {
  410. groupBy += " limit " + utils.IntToStr(start) + "," + req.Limit
  411. } else {
  412. groupBy = " order by date asc,id asc"
  413. }
  414. sql1 := fmt.Sprintf(sql, field, where, groupBy)
  415. nativeString, _ := db.QueryNativeString(db.Db, sql1)
  416. var total int64 = 0
  417. if isTotal == 1 {
  418. sqlTotal := fmt.Sprintf(sql, "COUNT(*) as count ", where, "")
  419. nativeStringTotal, _ := db.QueryNativeString(db.Db, sqlTotal)
  420. for _, v := range nativeStringTotal {
  421. total = utils.StrToInt64(v["count"])
  422. }
  423. }
  424. return nativeString, total
  425. }
  426. func commAgentProfit(c *gin.Context, isTotal int, req md.DataCenterProfitRecordReq) ([]map[string]string, int64) {
  427. appId := GetAppletId(c, req.AppId, req.Platform)
  428. sql := `
  429. SELECT
  430. %s
  431. FROM generate_wx_ad_data_with_agent_flow
  432. where %s %s
  433. `
  434. user := GetUser(c)
  435. where := "uuid=" + c.GetString("mid") + " and agent_id =" + utils.IntToStr(user.AgentId)
  436. if req.AppId != "" || req.Platform != "" {
  437. where += " and app_id in(" + appId + ")"
  438. }
  439. if req.StartDate != "" {
  440. where += " and date>='" + req.StartDate + "'"
  441. }
  442. if req.EndDate != "" {
  443. where += " and date<='" + req.EndDate + "'"
  444. }
  445. field := `%s,app_id,SUM(agent_revenue) as agent_revenue,SUM(extra_revenue) as extra_revenue`
  446. start := (utils.StrToInt(req.Page) - 1) * utils.StrToInt(req.Limit)
  447. groupBy := " group by %s,app_id order by date desc,id desc"
  448. if req.Page != "" {
  449. groupBy += " limit " + utils.IntToStr(start) + "," + req.Limit
  450. } else {
  451. groupBy = " group by %s,app_id order by date asc,id asc"
  452. }
  453. timeStr := "date"
  454. if req.Type == "1" {
  455. timeStr = "DATE_FORMAT(date, '%Y-%m')"
  456. }
  457. if req.Type == "2" {
  458. timeStr = "DATE_FORMAT(date, '%Y')"
  459. }
  460. field = fmt.Sprintf(field, timeStr)
  461. groupBy = fmt.Sprintf(groupBy, timeStr+" as date")
  462. sql1 := fmt.Sprintf(sql, field, where, groupBy)
  463. nativeString, _ := db.QueryNativeString(db.Db, sql1)
  464. var total int64 = 0
  465. if isTotal == 1 {
  466. sqlTotal := fmt.Sprintf(sql, field, where, "")
  467. sqlTotal1 := `select COUNT(*) as count from (%s) as tmp`
  468. sqlTotal1 = fmt.Sprintf(sqlTotal1, sqlTotal)
  469. nativeStringTotal, _ := db.QueryNativeString(db.Db, sqlTotal1)
  470. for _, v := range nativeStringTotal {
  471. total = utils.StrToInt64(v["count"])
  472. }
  473. }
  474. return nativeString, total
  475. }
  476. func commAgent(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[string]string, int64) {
  477. appId := GetAppletId(c, req.AppId, req.Platform)
  478. sql := `
  479. SELECT
  480. %s
  481. FROM generate_wx_ad_data
  482. where %s %s
  483. `
  484. mediumId := GetAgentMediumId(c)
  485. where := "uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")"
  486. if req.AppId != "" || req.Platform != "" {
  487. where += " and app_id in(" + appId + ")"
  488. }
  489. if req.AdType != "" {
  490. where += " and ad_slot='" + req.AdType + "'"
  491. }
  492. if req.StartDate != "" {
  493. where += " and date>='" + req.StartDate + "'"
  494. }
  495. if req.EndDate != "" {
  496. where += " and date<='" + req.EndDate + "'"
  497. }
  498. field := `*`
  499. start := (utils.StrToInt(req.Page) - 1) * utils.StrToInt(req.Limit)
  500. groupBy := " order by date desc,id desc"
  501. if req.Page != "" {
  502. groupBy += " limit " + utils.IntToStr(start) + "," + req.Limit
  503. } else {
  504. groupBy = " order by date asc,id asc"
  505. }
  506. sql1 := fmt.Sprintf(sql, field, where, groupBy)
  507. nativeString, _ := db.QueryNativeString(db.Db, sql1)
  508. var total int64 = 0
  509. if isTotal == 1 {
  510. sqlTotal := fmt.Sprintf(sql, "COUNT(*) as count ", where, "")
  511. nativeStringTotal, _ := db.QueryNativeString(db.Db, sqlTotal)
  512. for _, v := range nativeStringTotal {
  513. total = utils.StrToInt64(v["count"])
  514. }
  515. }
  516. var ids []string
  517. for _, v := range nativeString {
  518. ids = append(ids, v["id"])
  519. }
  520. if len(ids) > 0 {
  521. sqlAgent := `
  522. SELECT
  523. SUM(agent_revenue) as agent_revenue,
  524. SUM(extra_revenue) as extra_revenue
  525. FROM generate_wx_ad_data_with_agent_flow
  526. where %s
  527. `
  528. user := GetUser(c)
  529. whereAgent := "original_data_id in(" + strings.Join(ids, ",") + ") and agent_id=" + utils.IntToStr(user.AgentId)
  530. sqlAgent = fmt.Sprintf(sqlAgent, whereAgent)
  531. nativeStringAgent, _ := db.QueryNativeString(db.Db, sqlAgent)
  532. agentMap := make(map[string]map[string]string)
  533. for _, v := range nativeStringAgent {
  534. _, ok := agentMap[v["uid"]]
  535. if ok == false {
  536. agentMap[v["uid"]] = make(map[string]string)
  537. }
  538. agentMap[v["uid"]] = v
  539. }
  540. for k, v := range nativeString {
  541. _, ok := agentMap[v["uid"]]
  542. if ok {
  543. nativeString[k]["commission"] = utils.Float64ToStr(utils.StrToFloat64(v["agent_revenue"]) / 100)
  544. nativeString[k]["other_commission"] = utils.Float64ToStr(utils.StrToFloat64(v["extra_revenue"]) / 100)
  545. nativeString[k]["all_commission"] = utils.Float64ToStr(utils.StrToFloat64(nativeString[k]["commission"]) + utils.StrToFloat64(nativeString[k]["other_commission"]))
  546. } else {
  547. nativeString[k]["commission"] = "0"
  548. nativeString[k]["other_commission"] = "0"
  549. nativeString[k]["all_commission"] = "0"
  550. }
  551. }
  552. }
  553. return nativeString, total
  554. }
  555. func DataCenterSelectData(c *gin.Context) {
  556. NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
  557. appList, _ := NewAppletApplicationDb.FindAllAppletApplicationList()
  558. appMap := make(map[string][]map[string]interface{})
  559. mediumId := GetAgentMediumId(c)
  560. for _, v := range appList {
  561. if strings.Contains(","+mediumId+",", ","+utils.IntToStr(v.MediumId)+",") == false {
  562. continue
  563. }
  564. _, ok := appMap[v.Platform]
  565. if ok == false {
  566. appMap[v.Platform] = make([]map[string]interface{}, 0)
  567. }
  568. tmp := map[string]interface{}{
  569. "name": v.Name,
  570. "app_id": v.AppId,
  571. "ad_type": enum.AdTypeList,
  572. }
  573. appMap[v.Platform] = append(appMap[v.Platform], tmp)
  574. }
  575. platform := []map[string]interface{}{
  576. {
  577. "name": "微信小程序",
  578. "platform": "wx_applet",
  579. "app_list": appMap["wx_applet"],
  580. },
  581. }
  582. e.OutSuc(c, platform, nil)
  583. return
  584. }
  585. // 应用
  586. func GetAppletId(c *gin.Context, appId, platform string) string {
  587. mediumId := ""
  588. sess := MasterDb(c).Where("1=1")
  589. var ids = make([]string, 0)
  590. if appId != "" || platform != "" {
  591. ids = append(ids, "-1")
  592. }
  593. if platform != "" {
  594. var tmp []model2.AppletApplication
  595. if platform != "" {
  596. sess.And("platform = ? ", platform)
  597. }
  598. sess.Find(&tmp)
  599. for _, v := range tmp {
  600. ids = append(ids, utils.IntToStr(v.MediumId))
  601. }
  602. }
  603. if appId != "" {
  604. ids = []string{appId}
  605. }
  606. if appId != "" || platform != "" {
  607. mediumId = strings.Join(ids, ",")
  608. }
  609. return mediumId
  610. }
  611. func GetAppletInfo(c *gin.Context, id string) map[string]string {
  612. var res = map[string]string{
  613. "platform": "",
  614. "name": "",
  615. "logo": "",
  616. }
  617. NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
  618. data, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(id)
  619. if data != nil {
  620. res["platform"] = data.Platform
  621. res["name"] = data.Name
  622. res["logo"] = data.Logo
  623. }
  624. return res
  625. }