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

203 lines
6.5 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 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 FinanceCenterAgentCheckSave(c *gin.Context, req md.CommDetailReq) {
  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.State = 2
  83. engine.Where("id=?", data.Id).Cols("state").Update(data)
  84. e.OutSuc(c, "success", nil)
  85. return
  86. }
  87. func FinanceCenterAgentOtherIncomeSave(c *gin.Context, req md.OtherIncomeReq) {
  88. engine := db.Db
  89. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  90. data, _ := NewAgentSettlementDb.GetAgentSettlementById(utils.StrToInt(req.Id))
  91. if data.State >= 2 {
  92. e.OutErr(c, 400, e.NewErr(400, "已推送给代理,不能再调整"))
  93. return
  94. }
  95. data.OtherIncome = int(utils.StrToFloat64(req.Amount) * 100)
  96. engine.Where("id=?", data.Id).Cols("other_income").Update(data)
  97. e.OutSuc(c, "success", nil)
  98. return
  99. }
  100. func FinanceCenterAgentDetail(c *gin.Context, req md.CommDetailReq) md.FinanceCenterDataAgentDetailRes {
  101. engine := db.Db
  102. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  103. data, _ := NewAgentSettlementDb.GetAgentSettlementById(utils.StrToInt(req.Id))
  104. file := make([]md.InvoiceFile, 0)
  105. invoice := md.Invoice{
  106. Type: "0",
  107. Time: "",
  108. Count: "0",
  109. File: file,
  110. }
  111. //发票
  112. NewAgentInvoiceDb := implement.NewAgentInvoiceDb(engine)
  113. invoiceData, _ := NewAgentInvoiceDb.GetAgentInvoice(data.Id)
  114. if invoiceData != nil {
  115. invoice.Type = utils.IntToStr(invoiceData.Type)
  116. invoice.Time = invoiceData.UpdateAt
  117. invoice.Count = utils.IntToStr(invoiceData.Count)
  118. json.Unmarshal([]byte(invoiceData.File), &file)
  119. invoice.File = file
  120. }
  121. tmp := md.FinanceCenterDataAgentDetail{
  122. Source: "手动导入",
  123. SettleFile: data.SettleFile,
  124. Invoice: invoice,
  125. AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100),
  126. Income: utils.Float64ToStr(float64(data.BasicIncome) / 100),
  127. OtherIncome: utils.Float64ToStr(float64(data.OtherIncome) / 100),
  128. TimeStr: data.StartDate,
  129. PayState: utils.IntToStr(data.PayState),
  130. State: utils.IntToStr(data.State),
  131. }
  132. if data.EndDate != "" && data.EndDate != "0000-00-00" {
  133. if data.EndDate != data.StartDate {
  134. tmp.TimeStr += "~" + data.EndDate
  135. }
  136. }
  137. tmpAgent := GetAgentInfo(c, data.AgentId)
  138. if tmpAgent["name"] != "" {
  139. tmp.Name = tmpAgent["name"]
  140. }
  141. if tmpAgent["account"] != "" {
  142. tmp.Account = tmpAgent["account"]
  143. }
  144. tmp.DownUrl = "http://" + c.Request.Host + "/api/medium/settle/file/down?id=" + utils.IntToStr(data.Id)
  145. res := md.FinanceCenterDataAgentDetailRes{
  146. Data: tmp,
  147. InvoiceCate: md.InvoiceCate,
  148. SettleType: md.AccountSettleState,
  149. BusinessKind: md.BusinessKind,
  150. SettlePayState: md.SettlePayState,
  151. SettleState: md.SettleState,
  152. InvoiceState: md.InvoiceState,
  153. }
  154. return res
  155. }
  156. func FinanceCenterAgentList(c *gin.Context, req md.FinanceCenterDataReq) md.FinanceCenterDataAgentRes {
  157. engine := db.Db
  158. NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
  159. AgentList, total, _ := NewAgentSettlementDb.FindAgentSettlementList(c.GetString("mid"), "", "", req.PayState, "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  160. data := make([]md.FinanceCenterDataAgentData, 0)
  161. if len(AgentList) > 0 {
  162. for _, v := range AgentList {
  163. var tmp = md.FinanceCenterDataAgentData{
  164. Id: utils.IntToStr(v.Id),
  165. Name: "",
  166. AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100),
  167. Income: utils.Float64ToStr(float64(v.BasicIncome) / 100),
  168. OtherIncome: utils.Float64ToStr(float64(v.OtherIncome) / 100),
  169. TimeStr: v.StartDate,
  170. SettleType: utils.IntToStr(v.Kind),
  171. PayState: utils.IntToStr(v.PayState),
  172. State: utils.IntToStr(v.State),
  173. Label: "预估",
  174. }
  175. tmpAgent := GetAgentInfo(c, v.AgentId)
  176. if tmpAgent["name"] != "" {
  177. tmp.Name = tmpAgent["name"]
  178. }
  179. if v.EndDate != "" && v.EndDate != "0000-00-00" {
  180. if v.EndDate != v.StartDate {
  181. tmp.TimeStr += "~" + v.EndDate
  182. }
  183. tmp.Label = ""
  184. }
  185. data = append(data, tmp)
  186. }
  187. }
  188. res := md.FinanceCenterDataAgentRes{
  189. List: data,
  190. Total: total,
  191. SettleType: md.AccountSettleState,
  192. BusinessKind: md.BusinessKind,
  193. SettlePayState: md.SettlePayState,
  194. SettleState: md.SettleState,
  195. }
  196. return res
  197. }