广告平台(站长下代理使用)
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 6.5 KiB

пре 3 месеци
пре 3 месеци
пре 3 месеци
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 SettleCenterMediumList(c *gin.Context, req md.SettleCenterDataReq) md.SettleCenterMediumDataRes {
  14. engine := db.Db
  15. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  16. mediumId := GetAgentMediumId(c)
  17. MediumList, total, _ := NewMediumSettlementDb.FindMediumSettlementList(c.GetString("mid"), mediumId, "", "", "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  18. data := make([]md.SettleCenterMediumDataData, 0)
  19. if len(MediumList) > 0 {
  20. for _, v := range MediumList {
  21. medium := GetMediumInfo(c, v.MediumId)
  22. name := ""
  23. if medium != nil {
  24. name = medium["name"]
  25. }
  26. var tmp = md.SettleCenterMediumDataData{
  27. Id: utils.IntToStr(v.Id),
  28. Name: name,
  29. AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100),
  30. Income: 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. }
  38. if v.EndDate != "" && v.EndDate != "0000-00-00" {
  39. if v.EndDate != v.StartDate {
  40. tmp.TimeStr += "~" + v.EndDate
  41. }
  42. tmp.Label = ""
  43. }
  44. data = append(data, tmp)
  45. }
  46. }
  47. res := md.SettleCenterMediumDataRes{
  48. List: data,
  49. Total: total,
  50. SettleType: md.AccountSettleState,
  51. BusinessKind: md.BusinessKind,
  52. SettlePayState: md.SettlePayState,
  53. SettleState: md.SettleState,
  54. }
  55. return res
  56. }
  57. func SettleCenterList(c *gin.Context, req md.SettleCenterDataReq) md.SettleCenterDataRes {
  58. user := GetUser(c)
  59. engine := db.Db
  60. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  61. list, total, _ := NewAgentSettlementDb.FindAgentSettlementList(c.GetString("mid"), utils.IntToStr(user.AgentId), "", "", "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  62. data := make([]md.SettleCenterDataData, 0)
  63. if len(list) > 0 {
  64. for _, v := range list {
  65. var tmp = md.SettleCenterDataData{
  66. Id: utils.IntToStr(v.Id),
  67. AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100),
  68. Income: utils.Float64ToStr(float64(v.BasicIncome) / 100),
  69. OtherIncome: utils.Float64ToStr(float64(v.OtherIncome) / 100),
  70. TimeStr: v.StartDate,
  71. SettleType: utils.IntToStr(v.Kind),
  72. PayState: utils.IntToStr(v.PayState),
  73. State: utils.IntToStr(v.State),
  74. Label: "预估",
  75. SettleFile: v.SettleFile,
  76. }
  77. if v.EndDate != "" && v.EndDate != "0000-00-00" {
  78. if v.EndDate != v.StartDate {
  79. tmp.TimeStr += "~" + v.EndDate
  80. }
  81. tmp.Label = ""
  82. }
  83. data = append(data, tmp)
  84. }
  85. }
  86. res := md.SettleCenterDataRes{
  87. List: data,
  88. Total: total,
  89. SettleType: md.AccountSettleState,
  90. BusinessKind: md.BusinessKind,
  91. SettlePayState: md.SettlePayState,
  92. SettleState: md.SettleState,
  93. }
  94. return res
  95. }
  96. func SettleCenterDetail(c *gin.Context, req md.CommDetailReq) md.SettleCenterDataDetailRes {
  97. engine := db.Db
  98. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  99. data, _ := NewAgentSettlementDb.GetAgentSettlementById(utils.StrToInt(req.Id))
  100. file := make([]md.InvoiceFile, 0)
  101. invoice := md.Invoice{
  102. Type: "0",
  103. Time: "",
  104. Count: "0",
  105. File: file,
  106. }
  107. //发票
  108. NewAgentInvoiceDb := implement.NewAgentInvoiceDb(engine)
  109. invoiceData, _ := NewAgentInvoiceDb.GetAgentInvoice(data.Id)
  110. if invoiceData != nil {
  111. invoice.Type = utils.IntToStr(invoiceData.Type)
  112. invoice.Time = invoiceData.UpdateAt
  113. invoice.Count = utils.IntToStr(invoiceData.Count)
  114. json.Unmarshal([]byte(invoiceData.File), &file)
  115. }
  116. tmp := md.SettleCenterDataDetail{
  117. SettleFile: data.SettleFile,
  118. Invoice: invoice,
  119. AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100),
  120. MediumIncome: utils.Float64ToStr(float64(data.BasicIncome) / 100),
  121. OtherIncome: utils.Float64ToStr(float64(data.OtherIncome) / 100),
  122. TimeStr: data.StartDate,
  123. PayState: utils.IntToStr(data.PayState),
  124. State: utils.IntToStr(data.State),
  125. BusinessKind: utils.IntToStr(data.BusinessKind),
  126. }
  127. if data.EndDate != "" && data.EndDate != "0000-00-00" {
  128. if data.EndDate != data.StartDate {
  129. tmp.TimeStr += "~" + data.EndDate
  130. }
  131. }
  132. res := md.SettleCenterDataDetailRes{
  133. Data: tmp,
  134. InvoiceCate: md.InvoiceCate,
  135. SettleType: md.AccountSettleState,
  136. BusinessKind: md.BusinessKind,
  137. SettlePayState: md.SettlePayState,
  138. SettleState: md.SettleState,
  139. InvoiceState: md.InvoiceState,
  140. }
  141. return res
  142. }
  143. func SettleCenterSettleFileSave(c *gin.Context, req md.SettleFileReq) {
  144. engine := db.Db
  145. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  146. data, _ := NewAgentSettlementDb.GetAgentSettlementById(utils.StrToInt(req.Id))
  147. if data.State == 3 {
  148. e.OutErr(c, 400, e.NewErr(400, "已完成签订,不能再调整"))
  149. return
  150. }
  151. data.State = 3
  152. data.PayState = 1
  153. data.SettleFile = req.File
  154. engine.Where("id=?", data.Id).Cols("state,settle_file,pay_state").Update(data)
  155. e.OutSuc(c, "success", nil)
  156. return
  157. }
  158. func SettleCenterInvoiceSave(c *gin.Context, req md.InvoiceReq) {
  159. engine := db.Db
  160. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  161. data, _ := NewAgentSettlementDb.GetAgentSettlementById(utils.StrToInt(req.Id))
  162. if data.PayState > 3 {
  163. e.OutErr(c, 400, e.NewErr(400, "已完成审核,不能再调整"))
  164. return
  165. }
  166. data.PayState = 2
  167. engine.Where("id=?", data.Id).Cols("pay_sate").Update(data)
  168. NewAgentInvoiceDb := implement.NewAgentInvoiceDb(engine)
  169. invoice, _ := NewAgentInvoiceDb.GetAgentInvoice(data.Id)
  170. if invoice == nil {
  171. invoice = &model.AgentInvoice{
  172. SettlementId: data.Id,
  173. Uuid: utils.StrToInt(c.GetString("mid")),
  174. AgentId: data.AgentId,
  175. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  176. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  177. }
  178. engine.Insert(invoice)
  179. }
  180. for k := range req.File {
  181. req.File[k].State = "0"
  182. }
  183. invoice.File = utils.SerializeStr(req.File)
  184. invoice.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  185. invoice.State = 0
  186. invoice.Type = utils.StrToInt(req.Type)
  187. invoice.Count = len(req.File)
  188. engine.Where("id=?", invoice.Id).AllCols().Update(invoice)
  189. e.OutSuc(c, "success", nil)
  190. return
  191. }