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

195 lines
6.3 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. "encoding/json"
  9. "github.com/gin-gonic/gin"
  10. )
  11. func FinanceCenterMediumInvoiceSave(c *gin.Context, req md.InvoiceReq) {
  12. engine := db.Db
  13. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  14. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  15. if data.State != 3 {
  16. e.OutErr(c, 400, e.NewErr(400, "媒体未完成签订"))
  17. return
  18. }
  19. if data.PayState == 5 {
  20. e.OutErr(c, 400, e.NewErr(400, "结算单已付款,不能调整"))
  21. return
  22. }
  23. NewMediumInvoiceDb := implement.NewMediumInvoiceDb(engine)
  24. invoice, _ := NewMediumInvoiceDb.GetMediumInvoice(data.Id)
  25. if req.State == "1" {
  26. data.PayState = 4
  27. invoice.State = 1
  28. for k := range req.File {
  29. req.File[k].State = "1"
  30. }
  31. }
  32. if req.State == "2" {
  33. invoice.State = 2
  34. data.PayState = 3
  35. for k, v := range req.File {
  36. if v.State == "0" {
  37. req.File[k].State = "1"
  38. }
  39. }
  40. }
  41. invoice.File = utils.SerializeStr(req.File)
  42. engine.Where("id=?", data.Id).Cols("pay_state").Update(data)
  43. engine.Where("id=?", invoice.Id).Cols("state,file").Update(invoice)
  44. e.OutSuc(c, "success", nil)
  45. return
  46. }
  47. func FinanceCenterMediumSettleFileSave(c *gin.Context, req md.SettleFileReq) {
  48. engine := db.Db
  49. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  50. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  51. if data.State >= 2 {
  52. e.OutErr(c, 400, e.NewErr(400, "已推送给媒体,不能再调整"))
  53. return
  54. }
  55. data.State = 2
  56. data.SettleFile = req.File
  57. engine.Where("id=?", data.Id).Cols("state,settle_file").Update(data)
  58. e.OutSuc(c, "success", nil)
  59. return
  60. }
  61. func FinanceCenterMediumPaySave(c *gin.Context, req md.CommDetailReq) {
  62. engine := db.Db
  63. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  64. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  65. if data.PayState < 4 {
  66. e.OutErr(c, 400, e.NewErr(400, "不能再调整"))
  67. return
  68. }
  69. data.PayState = 5
  70. engine.Where("id=?", data.Id).Cols("pay_state").Update(data)
  71. e.OutSuc(c, "success", nil)
  72. return
  73. }
  74. func FinanceCenterMediumOtherIncomeSave(c *gin.Context, req md.OtherIncomeReq) {
  75. engine := db.Db
  76. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  77. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  78. if data.State >= 2 {
  79. e.OutErr(c, 400, e.NewErr(400, "已推送给媒体,不能再调整"))
  80. return
  81. }
  82. data.OtherIncome = int(utils.StrToFloat64(req.Amount) * 100)
  83. engine.Where("id=?", data.Id).Cols("other_income").Update(data)
  84. e.OutSuc(c, "success", nil)
  85. return
  86. }
  87. func FinanceCenterMediumDetail(c *gin.Context, req md.CommDetailReq) md.FinanceCenterDataDetailRes {
  88. engine := db.Db
  89. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  90. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  91. file := make([]md.InvoiceFile, 0)
  92. invoice := md.Invoice{
  93. Type: "0",
  94. Time: "",
  95. Count: "0",
  96. File: file,
  97. }
  98. //发票
  99. NewMediumInvoiceDb := implement.NewMediumInvoiceDb(engine)
  100. invoiceData, _ := NewMediumInvoiceDb.GetMediumInvoice(data.Id)
  101. if invoiceData != nil {
  102. invoice.Type = utils.IntToStr(invoiceData.Type)
  103. invoice.Time = invoiceData.UpdateAt
  104. invoice.Count = utils.IntToStr(invoiceData.Count)
  105. json.Unmarshal([]byte(invoiceData.File), &file)
  106. }
  107. tmp := md.FinanceCenterDataDetail{
  108. Source: "手动导入",
  109. SettleFile: data.SettleFile,
  110. Invoice: invoice,
  111. AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100),
  112. TopIncome: "",
  113. CommissionIncome: "",
  114. PlatformIncome: "",
  115. ChangeIncome: "",
  116. MediumIncome: utils.Float64ToStr(float64(data.BasicIncome) / 100),
  117. OtherIncome: utils.Float64ToStr(float64(data.OtherIncome) / 100),
  118. TimeStr: data.StartDate,
  119. PayState: utils.IntToStr(data.PayState),
  120. State: utils.IntToStr(data.State),
  121. }
  122. if data.EndDate != "" && data.EndDate != "0000-00-00" {
  123. if data.EndDate != data.StartDate {
  124. tmp.TimeStr += "~" + data.EndDate
  125. }
  126. }
  127. tmpMedium := GetMediumInfo(c, data.MediumId)
  128. if tmpMedium["name"] != "" {
  129. tmp.Name = tmpMedium["name"]
  130. }
  131. if tmpMedium["account"] != "" {
  132. tmp.Account = tmpMedium["account"]
  133. }
  134. res := md.FinanceCenterDataDetailRes{
  135. Data: tmp,
  136. InvoiceCate: md.InvoiceCate,
  137. SettleType: md.AccountSettleState,
  138. BusinessKind: md.BusinessKind,
  139. SettlePayState: md.SettlePayState,
  140. SettleState: md.SettleState,
  141. InvoiceState: md.InvoiceState,
  142. }
  143. return res
  144. }
  145. func FinanceCenterMediumList(c *gin.Context, req md.FinanceCenterDataReq) md.FinanceCenterDataRes {
  146. engine := db.Db
  147. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  148. MediumList, total, _ := NewMediumSettlementDb.FindMediumSettlementList(c.GetString("mid"), "", "", req.PayState, "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  149. data := make([]md.FinanceCenterDataData, 0)
  150. if len(MediumList) > 0 {
  151. for _, v := range MediumList {
  152. var tmp = md.FinanceCenterDataData{
  153. Id: utils.IntToStr(v.Id),
  154. Name: "",
  155. AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100),
  156. TopIncome: "",
  157. CommissionIncome: "",
  158. PlatformIncome: "",
  159. ChangeIncome: "",
  160. MediumIncome: utils.Float64ToStr(float64(v.BasicIncome) / 100),
  161. OtherIncome: utils.Float64ToStr(float64(v.OtherIncome) / 100),
  162. TimeStr: v.StartDate,
  163. SettleType: utils.IntToStr(v.Kind),
  164. PayState: utils.IntToStr(v.PayState),
  165. State: utils.IntToStr(v.State),
  166. Label: "预估",
  167. }
  168. tmpMedium := GetMediumInfo(c, v.MediumId)
  169. if tmpMedium["name"] != "" {
  170. tmp.Name = tmpMedium["name"]
  171. }
  172. if v.EndDate != "" && v.EndDate != "0000-00-00" {
  173. if v.EndDate != v.StartDate {
  174. tmp.TimeStr += "~" + v.EndDate
  175. }
  176. tmp.Label = ""
  177. }
  178. data = append(data, tmp)
  179. }
  180. }
  181. res := md.FinanceCenterDataRes{
  182. List: data,
  183. Total: total,
  184. SettleType: md.AccountSettleState,
  185. BusinessKind: md.BusinessKind,
  186. SettlePayState: md.SettlePayState,
  187. SettleState: md.SettleState,
  188. }
  189. return res
  190. }