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

3 months ago
1 month ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
1 month ago
3 months ago
1 month ago
3 months ago
3 months ago
3 months ago
1 month ago
3 months ago
3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 FinanceCenterMediumCheckSave(c *gin.Context, req md.CommDetailReq) {
  75. engine := db.Db
  76. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  77. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id))
  78. if data.State > 1 {
  79. e.OutErr(c, 400, e.NewErr(400, "不能再调整"))
  80. return
  81. }
  82. data.State = 1
  83. engine.Where("id=?", data.Id).Cols("state").Update(data)
  84. e.OutSuc(c, "success", nil)
  85. return
  86. }
  87. func FinanceCenterMediumOtherIncomeSave(c *gin.Context, req md.OtherIncomeReq) {
  88. engine := db.Db
  89. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  90. data, _ := NewMediumSettlementDb.GetMediumSettlementById(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 FinanceCenterMediumDetail(c *gin.Context, req md.CommDetailReq) md.FinanceCenterDataDetailRes {
  101. engine := db.Db
  102. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  103. data, _ := NewMediumSettlementDb.GetMediumSettlementById(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. NewMediumInvoiceDb := implement.NewMediumInvoiceDb(engine)
  113. invoiceData, _ := NewMediumInvoiceDb.GetMediumInvoice(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.FinanceCenterDataDetail{
  122. Source: "手动导入",
  123. SettleFile: data.SettleFile,
  124. Invoice: invoice,
  125. AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100),
  126. TopIncome: utils.Float64ToStr(float64(data.OriginalIncome) / 100),
  127. CommissionIncome: utils.Float64ToStr(float64(data.CommissionRetention) / 100),
  128. PlatformIncome: utils.Float64ToStr(float64(data.PlatformRetention) / 100),
  129. ChangeIncome: utils.Float64ToStr(float64(data.PriceAdjustmentRetention) / 100),
  130. MediumIncome: utils.Float64ToStr(float64(data.BasicIncome) / 100),
  131. OtherIncome: utils.Float64ToStr(float64(data.OtherIncome) / 100),
  132. TimeStr: data.StartDate,
  133. PayState: utils.IntToStr(data.PayState),
  134. State: utils.IntToStr(data.State),
  135. }
  136. if data.EndDate != "" && data.EndDate != "0000-00-00" {
  137. if data.EndDate != data.StartDate {
  138. tmp.TimeStr += "~" + data.EndDate
  139. }
  140. }
  141. tmpMedium := GetMediumInfo(c, data.MediumId)
  142. if tmpMedium["name"] != "" {
  143. tmp.Name = tmpMedium["name"]
  144. }
  145. if tmpMedium["account"] != "" {
  146. tmp.Account = tmpMedium["account"]
  147. }
  148. NewUserAppDomainDb := implement.NewUserAppDomainDb(db.Db)
  149. domain, _ := NewUserAppDomainDb.GetUserAppDomainByPlatform(utils.StrToInt(c.GetString("mid")), "admin")
  150. host := c.Request.Host
  151. if domain != nil {
  152. host = domain.Domain
  153. }
  154. tmp.DownUrl = "http://" + host + "/api/medium/settle/file/down?id=" + utils.IntToStr(data.Id)
  155. res := md.FinanceCenterDataDetailRes{
  156. Data: tmp,
  157. InvoiceCate: md.InvoiceCate,
  158. SettleType: md.AccountSettleState,
  159. BusinessKind: md.BusinessKind,
  160. SettlePayState: md.SettlePayState,
  161. SettleState: md.SettleState,
  162. InvoiceState: md.InvoiceState,
  163. }
  164. return res
  165. }
  166. func FinanceCenterMediumList(c *gin.Context, req md.FinanceCenterDataReq) md.FinanceCenterDataRes {
  167. engine := db.Db
  168. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  169. MediumList, total, _ := NewMediumSettlementDb.FindMediumSettlementList(c.GetString("mid"), "", "", req.PayState, "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  170. data := make([]md.FinanceCenterDataData, 0)
  171. if len(MediumList) > 0 {
  172. for _, v := range MediumList {
  173. var tmp = md.FinanceCenterDataData{
  174. Id: utils.IntToStr(v.Id),
  175. Name: "",
  176. Account: "",
  177. AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100),
  178. TopIncome: utils.Float64ToStr(float64(v.OriginalIncome) / 100),
  179. CommissionIncome: utils.Float64ToStr(float64(v.CommissionRetention) / 100),
  180. PlatformIncome: utils.Float64ToStr(float64(v.PlatformRetention) / 100),
  181. ChangeIncome: utils.Float64ToStr(float64(v.PriceAdjustmentRetention) / 100),
  182. MediumIncome: utils.Float64ToStr(float64(v.BasicIncome) / 100),
  183. OtherIncome: utils.Float64ToStr(float64(v.OtherIncome) / 100),
  184. TimeStr: v.StartDate,
  185. SettleType: utils.IntToStr(v.Kind),
  186. PayState: utils.IntToStr(v.PayState),
  187. State: utils.IntToStr(v.State),
  188. Label: "预估",
  189. }
  190. tmpMedium := GetMediumInfo(c, v.MediumId)
  191. if tmpMedium["name"] != "" {
  192. tmp.Name = tmpMedium["name"]
  193. tmp.Account = tmpMedium["account"]
  194. }
  195. if v.EndDate != "" && v.EndDate != "0000-00-00" {
  196. if v.EndDate != v.StartDate {
  197. tmp.TimeStr += "~" + v.EndDate
  198. }
  199. tmp.Label = ""
  200. }
  201. data = append(data, tmp)
  202. }
  203. }
  204. res := md.FinanceCenterDataRes{
  205. List: data,
  206. Total: total,
  207. SettleType: md.AccountSettleState,
  208. BusinessKind: md.BusinessKind,
  209. SettlePayState: md.SettlePayState,
  210. SettleState: md.SettleState,
  211. }
  212. return res
  213. }
  214. func FinanceCenterPlatformList(c *gin.Context, req md.FinanceCenterPlatformDataReq) md.FinanceCenterPlatformDataRes {
  215. engine := db.Db
  216. NewPlatformSettlementDb := implement.NewPlatformSettlementDb(engine)
  217. MediumList, total, _ := NewPlatformSettlementDb.FindPlatformSettlementList(c.GetString("mid"), req.Date, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  218. data := make([]md.FinanceCenterPlatformDataData, 0)
  219. if len(MediumList) > 0 {
  220. for _, v := range MediumList {
  221. var tmp = md.FinanceCenterPlatformDataData{
  222. Id: utils.IntToStr(v.Id),
  223. TopIncome: utils.Float64ToStr(float64(v.OriginalIncome) / 100),
  224. CommissionIncome: utils.Float64ToStr(float64(v.CommissionRetention) / 100),
  225. PlatformIncome: utils.Float64ToStr(float64(v.PlatformRetention) / 100),
  226. ChangeIncome: utils.Float64ToStr(float64(v.PriceAdjustmentRetention) / 100),
  227. MediumIncome: utils.Float64ToStr(float64(v.MediumIncome) / 100),
  228. AgentIncome: utils.Float64ToStr(float64(v.AgentIncome) / 100),
  229. TimeStr: v.StartDate,
  230. UpdateAt: v.UpdateAt,
  231. }
  232. data = append(data, tmp)
  233. }
  234. }
  235. res := md.FinanceCenterPlatformDataRes{
  236. List: data,
  237. Total: total,
  238. }
  239. return res
  240. }