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

svc_finance_center_agent.go 6.0 KiB

2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 FinanceCenterAgentInvoiceSave(c *gin.Context, req md.InvoiceReq) {
  12. engine := db.Db
  13. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  14. data, _ := NewAgentSettlementDb.GetAgentSettlementById(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. NewAgentInvoiceDb := implement.NewAgentInvoiceDb(engine)
  24. invoice, _ := NewAgentInvoiceDb.GetAgentInvoice(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 FinanceCenterAgentSettleFileSave(c *gin.Context, req md.SettleFileReq) {
  48. engine := db.Db
  49. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  50. data, _ := NewAgentSettlementDb.GetAgentSettlementById(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 FinanceCenterAgentPaySave(c *gin.Context, req md.CommDetailReq) {
  62. engine := db.Db
  63. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  64. data, _ := NewAgentSettlementDb.GetAgentSettlementById(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 FinanceCenterAgentOtherIncomeSave(c *gin.Context, req md.OtherIncomeReq) {
  75. engine := db.Db
  76. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  77. data, _ := NewAgentSettlementDb.GetAgentSettlementById(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 FinanceCenterAgentDetail(c *gin.Context, req md.CommDetailReq) md.FinanceCenterDataAgentDetailRes {
  88. engine := db.Db
  89. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  90. data, _ := NewAgentSettlementDb.GetAgentSettlementById(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. NewAgentInvoiceDb := implement.NewAgentInvoiceDb(engine)
  100. invoiceData, _ := NewAgentInvoiceDb.GetAgentInvoice(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. invoice.File = file
  107. }
  108. tmp := md.FinanceCenterDataAgentDetail{
  109. Source: "手动导入",
  110. SettleFile: data.SettleFile,
  111. Invoice: invoice,
  112. AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100),
  113. Income: utils.Float64ToStr(float64(data.BasicIncome) / 100),
  114. OtherIncome: utils.Float64ToStr(float64(data.OtherIncome) / 100),
  115. TimeStr: data.StartDate,
  116. PayState: utils.IntToStr(data.PayState),
  117. State: utils.IntToStr(data.State),
  118. }
  119. if data.EndDate != "" && data.EndDate != "0000-00-00" {
  120. if data.EndDate != data.StartDate {
  121. tmp.TimeStr += "~" + data.EndDate
  122. }
  123. }
  124. tmpAgent := GetAgentInfo(c, data.AgentId)
  125. if tmpAgent["name"] != "" {
  126. tmp.Name = tmpAgent["name"]
  127. }
  128. if tmpAgent["account"] != "" {
  129. tmp.Account = tmpAgent["account"]
  130. }
  131. res := md.FinanceCenterDataAgentDetailRes{
  132. Data: tmp,
  133. InvoiceCate: md.InvoiceCate,
  134. SettleType: md.AccountSettleState,
  135. BusinessKind: md.BusinessKind,
  136. SettlePayState: md.SettlePayState,
  137. SettleState: md.SettleState,
  138. InvoiceState: md.InvoiceState,
  139. }
  140. return res
  141. }
  142. func FinanceCenterAgentList(c *gin.Context, req md.FinanceCenterDataReq) md.FinanceCenterDataAgentRes {
  143. engine := db.Db
  144. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  145. AgentList, total, _ := NewAgentSettlementDb.FindAgentSettlementList(c.GetString("mid"), "", "", req.PayState, "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  146. data := make([]md.FinanceCenterDataAgentData, 0)
  147. if len(AgentList) > 0 {
  148. for _, v := range AgentList {
  149. var tmp = md.FinanceCenterDataAgentData{
  150. Id: utils.IntToStr(v.Id),
  151. Name: "",
  152. AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100),
  153. Income: utils.Float64ToStr(float64(v.BasicIncome) / 100),
  154. OtherIncome: utils.Float64ToStr(float64(v.OtherIncome) / 100),
  155. TimeStr: v.StartDate,
  156. SettleType: utils.IntToStr(v.Kind),
  157. PayState: utils.IntToStr(v.PayState),
  158. State: utils.IntToStr(v.State),
  159. Label: "预估",
  160. }
  161. tmpAgent := GetAgentInfo(c, v.AgentId)
  162. if tmpAgent["name"] != "" {
  163. tmp.Name = tmpAgent["name"]
  164. }
  165. if v.EndDate != "" && v.EndDate != "0000-00-00" {
  166. if v.EndDate != v.StartDate {
  167. tmp.TimeStr += "~" + v.EndDate
  168. }
  169. tmp.Label = ""
  170. }
  171. data = append(data, tmp)
  172. }
  173. }
  174. res := md.FinanceCenterDataAgentRes{
  175. List: data,
  176. Total: total,
  177. SettleType: md.AccountSettleState,
  178. BusinessKind: md.BusinessKind,
  179. SettlePayState: md.SettlePayState,
  180. SettleState: md.SettleState,
  181. }
  182. return res
  183. }