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

svc_settle_center.go 5.0 KiB

3 月之前
3 月之前
3 月之前
3 月之前
3 月之前
3 月之前
3 月之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. invoice.File = file
  72. }
  73. tmp := md.SettleCenterDataDetail{
  74. SettleFile: data.SettleFile,
  75. Invoice: invoice,
  76. AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100),
  77. MediumIncome: utils.Float64ToStr(float64(data.BasicIncome) / 100),
  78. OtherIncome: utils.Float64ToStr(float64(data.OtherIncome) / 100),
  79. TimeStr: data.StartDate,
  80. PayState: utils.IntToStr(data.PayState),
  81. State: utils.IntToStr(data.State),
  82. BusinessKind: utils.IntToStr(data.BusinessKind),
  83. }
  84. if data.EndDate != "" && data.EndDate != "0000-00-00" {
  85. if data.EndDate != data.StartDate {
  86. tmp.TimeStr += "~" + data.EndDate
  87. }
  88. }
  89. res := md.SettleCenterDataDetailRes{
  90. Data: tmp,
  91. InvoiceCate: md.InvoiceCate,
  92. SettleType: md.AccountSettleState,
  93. BusinessKind: md.BusinessKind,
  94. SettlePayState: md.SettlePayState,
  95. SettleState: md.SettleState,
  96. InvoiceState: md.InvoiceState,
  97. }
  98. return res
  99. }
  100. func SettleCenterSettleFileSave(c *gin.Context, req md.SettleFileReq) {
  101. engine := db.Db
  102. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  103. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  104. if data.State == 3 {
  105. e.OutErr(c, 400, e.NewErr(400, "已完成签订,不能再调整"))
  106. return
  107. }
  108. data.State = 3
  109. data.PayState = 1
  110. data.SettleFile = req.File
  111. engine.Where("id=?", data.Id).Cols("state,settle_file,pay_state").Update(data)
  112. e.OutSuc(c, "success", nil)
  113. return
  114. }
  115. func SettleCenterInvoiceSave(c *gin.Context, req md.InvoiceReq) {
  116. engine := db.Db
  117. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  118. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  119. if data.PayState > 3 {
  120. e.OutErr(c, 400, e.NewErr(400, "已完成审核,不能再调整"))
  121. return
  122. }
  123. data.PayState = 2
  124. engine.Where("id=?", data.Id).Cols("pay_state").Update(data)
  125. NewMediumInvoiceDb := implement.NewMediumInvoiceDb(engine)
  126. invoice, _ := NewMediumInvoiceDb.GetMediumInvoice(data.Id)
  127. if invoice == nil {
  128. invoice = &model.MediumInvoice{
  129. SettlementId: data.Id,
  130. Uuid: utils.StrToInt(c.GetString("mid")),
  131. MediumId: data.MediumId,
  132. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  133. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  134. }
  135. engine.Insert(invoice)
  136. }
  137. for k := range req.File {
  138. req.File[k].State = "0"
  139. }
  140. invoice.File = utils.SerializeStr(req.File)
  141. invoice.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  142. invoice.State = 0
  143. invoice.Type = utils.StrToInt(req.Type)
  144. invoice.Count = len(req.File)
  145. engine.Where("id=?", invoice.Id).AllCols().Update(invoice)
  146. e.OutSuc(c, "success", nil)
  147. return
  148. }