广告平台(媒体使用)
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.
 
 
 
 
 
 

150 regels
5.0 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. for _, v := range MediumList {
  21. var tmp = md.SettleCenterDataData{
  22. Id: utils.IntToStr(v.Id),
  23. AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100),
  24. MediumIncome: utils.Float64ToStr(float64(v.BasicIncome) / 100),
  25. OtherIncome: utils.Float64ToStr(float64(v.OtherIncome) / 100),
  26. TimeStr: v.StartDate,
  27. SettleType: utils.IntToStr(v.Kind),
  28. PayState: utils.IntToStr(v.PayState),
  29. State: utils.IntToStr(v.State),
  30. Label: "预估",
  31. SettleFile: v.SettleFile,
  32. }
  33. if v.EndDate != "" && v.EndDate != "0000-00-00" {
  34. if v.EndDate != v.StartDate {
  35. tmp.TimeStr += "~" + v.EndDate
  36. }
  37. tmp.Label = ""
  38. }
  39. data = append(data, tmp)
  40. }
  41. }
  42. res := md.SettleCenterDataRes{
  43. List: data,
  44. Total: total,
  45. SettleType: md.AccountSettleState,
  46. BusinessKind: md.BusinessKind,
  47. SettlePayState: md.SettlePayState,
  48. SettleState: md.SettleState,
  49. }
  50. return res
  51. }
  52. func SettleCenterDetail(c *gin.Context, req md.CommDetailReq) md.SettleCenterDataDetailRes {
  53. engine := db.Db
  54. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  55. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  56. file := make([]md.InvoiceFile, 0)
  57. invoice := md.Invoice{
  58. Type: "0",
  59. Time: "",
  60. Count: "0",
  61. File: file,
  62. }
  63. //发票
  64. NewMediumInvoiceDb := implement.NewMediumInvoiceDb(engine)
  65. invoiceData, _ := NewMediumInvoiceDb.GetMediumInvoice(data.Id)
  66. if invoiceData != nil {
  67. invoice.Type = utils.IntToStr(invoiceData.Type)
  68. invoice.Time = invoiceData.UpdateAt
  69. invoice.Count = utils.IntToStr(invoiceData.Count)
  70. json.Unmarshal([]byte(invoiceData.File), &file)
  71. }
  72. tmp := md.SettleCenterDataDetail{
  73. SettleFile: data.SettleFile,
  74. Invoice: invoice,
  75. AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100),
  76. MediumIncome: utils.Float64ToStr(float64(data.BasicIncome) / 100),
  77. OtherIncome: utils.Float64ToStr(float64(data.OtherIncome) / 100),
  78. TimeStr: data.StartDate,
  79. PayState: utils.IntToStr(data.PayState),
  80. State: utils.IntToStr(data.State),
  81. BusinessKind: utils.IntToStr(data.BusinessKind),
  82. }
  83. if data.EndDate != "" && data.EndDate != "0000-00-00" {
  84. if data.EndDate != data.StartDate {
  85. tmp.TimeStr += "~" + data.EndDate
  86. }
  87. }
  88. res := md.SettleCenterDataDetailRes{
  89. Data: tmp,
  90. InvoiceCate: md.InvoiceCate,
  91. SettleType: md.AccountSettleState,
  92. BusinessKind: md.BusinessKind,
  93. SettlePayState: md.SettlePayState,
  94. SettleState: md.SettleState,
  95. InvoiceState: md.InvoiceState,
  96. }
  97. return res
  98. }
  99. func SettleCenterSettleFileSave(c *gin.Context, req md.SettleFileReq) {
  100. engine := db.Db
  101. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  102. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  103. if data.State == 3 {
  104. e.OutErr(c, 400, e.NewErr(400, "已完成签订,不能再调整"))
  105. return
  106. }
  107. data.State = 3
  108. data.PayState = 1
  109. data.SettleFile = req.File
  110. engine.Where("id=?", data.Id).Cols("state,settle_file,pay_state").Update(data)
  111. e.OutSuc(c, "success", nil)
  112. return
  113. }
  114. func SettleCenterInvoiceSave(c *gin.Context, req md.InvoiceReq) {
  115. engine := db.Db
  116. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  117. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  118. if data.PayState > 3 {
  119. e.OutErr(c, 400, e.NewErr(400, "已完成审核,不能再调整"))
  120. return
  121. }
  122. data.PayState = 2
  123. engine.Where("id=?", data.Id).Cols("pay_state").Update(data)
  124. NewMediumInvoiceDb := implement.NewMediumInvoiceDb(engine)
  125. invoice, _ := NewMediumInvoiceDb.GetMediumInvoice(data.Id)
  126. if invoice == nil {
  127. invoice = &model.MediumInvoice{
  128. SettlementId: data.Id,
  129. Uuid: utils.StrToInt(c.GetString("mid")),
  130. MediumId: data.MediumId,
  131. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  132. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  133. }
  134. engine.Insert(invoice)
  135. }
  136. for k := range req.File {
  137. req.File[k].State = "0"
  138. }
  139. invoice.File = utils.SerializeStr(req.File)
  140. invoice.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  141. invoice.State = 0
  142. invoice.Type = utils.StrToInt(req.Type)
  143. invoice.Count = len(req.File)
  144. engine.Where("id=?", invoice.Id).AllCols().Update(invoice)
  145. e.OutSuc(c, "success", nil)
  146. return
  147. }