广告平台(媒体使用)
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

165 行
5.7 KiB

  1. package svc
  2. import (
  3. "applet/app/e"
  4. "applet/app/md"
  5. "applet/app/utils"
  6. db "code.fnuoos.com/zhimeng/model.git/src"
  7. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  8. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  9. "encoding/json"
  10. "github.com/gin-gonic/gin"
  11. "time"
  12. )
  13. func SettleCenterList(c *gin.Context, req md.SettleCenterDataReq) md.SettleCenterDataRes {
  14. user := GetUser(c)
  15. engine := db.Db
  16. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  17. MediumList, total, _ := NewMediumSettlementDb.FindMediumSettlementList(c.GetString("mid"), utils.IntToStr(user.MediumId), "", "", "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  18. data := make([]md.SettleCenterDataData, 0)
  19. if len(MediumList) > 0 {
  20. NewUserAppDomainDb := implement.NewUserAppDomainDb(db.Db)
  21. domain, _ := NewUserAppDomainDb.GetUserAppDomainByPlatform(utils.StrToInt(c.GetString("mid")), "medium")
  22. host := c.Request.Host
  23. if domain != nil {
  24. host = domain.Domain
  25. }
  26. for _, v := range MediumList {
  27. var tmp = md.SettleCenterDataData{
  28. Id: utils.IntToStr(v.Id),
  29. AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100),
  30. MediumIncome: utils.Float64ToStr(float64(v.BasicIncome) / 100),
  31. OtherIncome: utils.Float64ToStr(float64(v.OtherIncome) / 100),
  32. TimeStr: v.StartDate,
  33. SettleType: utils.IntToStr(v.Kind),
  34. PayState: utils.IntToStr(v.PayState),
  35. State: utils.IntToStr(v.State),
  36. Label: "预估",
  37. SettleFile: v.SettleFile,
  38. }
  39. tmp.DownUrl = "http://" + host + "/api/settle/file/down?id=" + utils.IntToStr(v.Id)
  40. if v.EndDate != "" && v.EndDate != "0000-00-00" {
  41. if v.EndDate != v.StartDate {
  42. tmp.TimeStr += "~" + v.EndDate
  43. }
  44. tmp.Label = ""
  45. }
  46. data = append(data, tmp)
  47. }
  48. }
  49. res := md.SettleCenterDataRes{
  50. List: data,
  51. Total: total,
  52. SettleType: md.AccountSettleState,
  53. BusinessKind: md.BusinessKind,
  54. SettlePayState: md.SettlePayState,
  55. SettleState: md.SettleState,
  56. }
  57. return res
  58. }
  59. func SettleCenterDetail(c *gin.Context, req md.CommDetailReq) md.SettleCenterDataDetailRes {
  60. engine := db.Db
  61. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  62. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  63. file := make([]md.InvoiceFile, 0)
  64. invoice := md.Invoice{
  65. Type: "0",
  66. Time: "",
  67. Count: "0",
  68. File: file,
  69. }
  70. //发票
  71. NewMediumInvoiceDb := implement.NewMediumInvoiceDb(engine)
  72. invoiceData, _ := NewMediumInvoiceDb.GetMediumInvoice(data.Id)
  73. if invoiceData != nil {
  74. invoice.Type = utils.IntToStr(invoiceData.Type)
  75. invoice.Time = invoiceData.UpdateAt
  76. invoice.Count = utils.IntToStr(invoiceData.Count)
  77. json.Unmarshal([]byte(invoiceData.File), &file)
  78. invoice.File = file
  79. }
  80. tmp := md.SettleCenterDataDetail{
  81. SettleFile: data.SettleFile,
  82. Invoice: invoice,
  83. AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100),
  84. MediumIncome: utils.Float64ToStr(float64(data.BasicIncome) / 100),
  85. OtherIncome: utils.Float64ToStr(float64(data.OtherIncome) / 100),
  86. TimeStr: data.StartDate,
  87. PayState: utils.IntToStr(data.PayState),
  88. State: utils.IntToStr(data.State),
  89. BusinessKind: utils.IntToStr(data.BusinessKind),
  90. }
  91. if data.EndDate != "" && data.EndDate != "0000-00-00" {
  92. if data.EndDate != data.StartDate {
  93. tmp.TimeStr += "~" + data.EndDate
  94. }
  95. }
  96. NewUserAppDomainDb := implement.NewUserAppDomainDb(db.Db)
  97. domain, _ := NewUserAppDomainDb.GetUserAppDomainByPlatform(utils.StrToInt(c.GetString("mid")), "medium")
  98. host := c.Request.Host
  99. if domain != nil {
  100. host = domain.Domain
  101. }
  102. tmp.DownUrl = "http://" + host + "/api/settle/file/down?id=" + utils.IntToStr(data.Id)
  103. res := md.SettleCenterDataDetailRes{
  104. Data: tmp,
  105. InvoiceCate: md.InvoiceCate,
  106. SettleType: md.AccountSettleState,
  107. BusinessKind: md.BusinessKind,
  108. SettlePayState: md.SettlePayState,
  109. SettleState: md.SettleState,
  110. InvoiceState: md.InvoiceState,
  111. }
  112. return res
  113. }
  114. func SettleCenterSettleFileSave(c *gin.Context, req md.SettleFileReq) {
  115. engine := db.Db
  116. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  117. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  118. if data.State == 3 {
  119. e.OutErr(c, 400, e.NewErr(400, "已完成签订,不能再调整"))
  120. return
  121. }
  122. data.State = 3
  123. data.PayState = 1
  124. data.SettleFile = req.File
  125. engine.Where("id=?", data.Id).Cols("state,settle_file,pay_state").Update(data)
  126. e.OutSuc(c, "success", nil)
  127. return
  128. }
  129. func SettleCenterInvoiceSave(c *gin.Context, req md.InvoiceReq) {
  130. engine := db.Db
  131. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  132. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  133. if data.PayState > 3 {
  134. e.OutErr(c, 400, e.NewErr(400, "已完成审核,不能再调整"))
  135. return
  136. }
  137. data.PayState = 2
  138. engine.Where("id=?", data.Id).Cols("pay_state").Update(data)
  139. NewMediumInvoiceDb := implement.NewMediumInvoiceDb(engine)
  140. invoice, _ := NewMediumInvoiceDb.GetMediumInvoice(data.Id)
  141. if invoice == nil {
  142. invoice = &model.MediumInvoice{
  143. SettlementId: data.Id,
  144. Uuid: utils.StrToInt(c.GetString("mid")),
  145. MediumId: data.MediumId,
  146. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  147. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  148. }
  149. engine.Insert(invoice)
  150. }
  151. for k := range req.File {
  152. req.File[k].State = "0"
  153. }
  154. invoice.File = utils.SerializeStr(req.File)
  155. invoice.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  156. invoice.State = 0
  157. invoice.Type = utils.StrToInt(req.Type)
  158. invoice.Count = len(req.File)
  159. engine.Where("id=?", invoice.Id).AllCols().Update(invoice)
  160. e.OutSuc(c, "success", nil)
  161. return
  162. }