qryOPApply.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/1/11 17:58
  4. * @Modify : 2021/1/11 17:58
  5. */
  6. package ermcp
  7. import (
  8. "encoding/json"
  9. "github.com/gin-gonic/gin"
  10. "mtp2_if/global/app"
  11. "mtp2_if/global/e"
  12. "mtp2_if/models"
  13. "net/http"
  14. )
  15. //点价数据
  16. type DjData struct {
  17. PricedPrice *float64 `json:"pricedPrice,omitempty"` //点价价格(非必填)
  18. PricedQty *float64 `json:"pricedQty,omitempty"` //点价数量(非必填)
  19. Amount *float64 `json:"amount,omitempty"` //点价金额=(点价价格+升贴水)*点价数量
  20. }
  21. //计算点价金额
  22. func (r *DjData) calc(priceMove float64) {
  23. if r.PricedPrice != nil && r.PricedQty != nil {
  24. r.Amount = new(float64)
  25. *r.Amount = (*r.PricedPrice + priceMove) * (*r.PricedQty)
  26. }
  27. }
  28. //结点登记数据
  29. type ReckonData struct {
  30. ReckonRealQty *float64 `json:"reckonrealqty,omitempty"` //结算实际数量(非必填)
  31. ReckonOsAmount *float64 `json:"reckonosamount,omitempty"` //结算溢短金额(非必填)
  32. ReckonOtherAmount *float64 `json:"reckonotheramount,omitempty"` //结算其他费用(非必填)
  33. ReckonAdjustAmount *float64 `json:"reckonadjustamount,omitempty"` //结算调整金额(非必填)
  34. AddMargin *float64 `json:"addmargin,omitempty"` //追加保证金(非必填)
  35. DecMargin *float64 `json:"decmargin,omitempty"` //减少保证金(非必填)
  36. }
  37. //款项操作
  38. type KxData struct {
  39. PayAmount *float64 `json:"payamount,omitempty"` //收付款(非必填)
  40. DeductAmount *float64 `json:"deductamount,omitempty"` //退款(非必填)
  41. KxType int32 `json:"kxtype,omitempty"` // 款项类型 1-收付款(PayAmount字段有值) 2-退款(DeductAmount字段有值) 3-收付款/退款(2个字段都有)
  42. }
  43. // 获取款项类型,1-收付款(PayAmount字段有值) 2-退款(DeductAmount字段有值) 3-收付款/退款(2个字段都有)
  44. func (r *KxData) CalcKxType() {
  45. if r.PayAmount != nil && r.DeductAmount != nil {
  46. r.KxType = 3
  47. } else if r.PayAmount != nil {
  48. r.KxType = 1
  49. } else if r.DeductAmount != nil {
  50. r.KxType = 2
  51. }
  52. }
  53. //开票操作数据
  54. type KpData struct {
  55. InvoiceAmount *float64 //已开收票金额(销售为开票,采购为收票)
  56. }
  57. // 查询合同操作请求
  58. type QryOPApplyReq struct {
  59. UserId int64 `form:"UserId" binding:"required"` //用户ID
  60. RelatedId string `form:"relatedid" binding:"required"` //现货合同ID, 不填则查所有
  61. OperateapplyId string `form:"operateapplyid"` //操作申请id
  62. Applystatus string `form:"applystatus"` // 申请状态 1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回
  63. }
  64. // 查询业务管理/点价应答
  65. type QryBusinessDjRsp struct {
  66. models.ErmcpOPApplyModel
  67. DjData
  68. }
  69. // QueryBusinessDj 企业风险管理合同操作查询
  70. func QueryBusinessDj(c *gin.Context) {
  71. appG := app.Gin{C: c}
  72. var req QryOPApplyReq
  73. _ = c.ShouldBind(&req)
  74. m := models.ErmcpOPApplyModel{RELATEDID: req.RelatedId, USERID: req.UserId, FilterAppStatus: req.Applystatus}
  75. if d, err := m.GetData(1); err == nil {
  76. //构建应答数据
  77. sData := make([]QryBusinessDjRsp, 0)
  78. for _, v := range d {
  79. var rsp QryBusinessDjRsp
  80. rsp.ErmcpOPApplyModel = v
  81. if len(rsp.DETAILJSON) > 0 {
  82. if err := json.Unmarshal([]byte(rsp.DETAILJSON), &rsp.DjData); err == nil {
  83. rsp.DjData.calc(rsp.PRICEMOVE)
  84. }
  85. sData = append(sData, rsp)
  86. }
  87. }
  88. appG.Response(http.StatusOK, e.SUCCESS, sData)
  89. } else {
  90. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  91. }
  92. }
  93. // 查询业务管理/结算响应
  94. type QryBussinessJsRsp struct {
  95. models.ErmcpOPApplyModel
  96. ReckonData
  97. }
  98. // QueryBusinessJs 企业风险管理合同操作查询
  99. func QueryBusinessJs(c *gin.Context) {
  100. appG := app.Gin{C: c}
  101. var req QryOPApplyReq
  102. _ = c.ShouldBind(&req)
  103. m := models.ErmcpOPApplyModel{RELATEDID: req.RelatedId, USERID: req.UserId, OPERATEAPPLYID: req.OperateapplyId, FilterAppStatus: req.Applystatus}
  104. if d, err := m.GetData(2); err == nil {
  105. //构建应答数据
  106. sData := make([]QryBussinessJsRsp, 0)
  107. for _, v := range d {
  108. var rsp QryBussinessJsRsp
  109. rsp.ErmcpOPApplyModel = v
  110. if len(rsp.DETAILJSON) > 0 {
  111. _ = json.Unmarshal([]byte(rsp.DETAILJSON), &rsp.ReckonData)
  112. }
  113. sData = append(sData, rsp)
  114. }
  115. appG.Response(http.StatusOK, e.SUCCESS, sData)
  116. } else {
  117. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  118. }
  119. }
  120. // 查询业务管理/结算响应(拆分字段)
  121. type QryBussinessJsExRsp struct {
  122. models.ErmcpOPApplyModel
  123. ReckonType string `json:"reckontype"` // 结算类型
  124. ReckonValue float64 `json:"reckonvalue"` // 值
  125. }
  126. // QueryBusinessJsEx 查询业务管理(结算)(对应菜单:业务管理/结算[拆分记录])
  127. func QueryBusinessJsEx(c *gin.Context) {
  128. appG := app.Gin{C: c}
  129. var req QryOPApplyReq
  130. _ = c.ShouldBind(&req)
  131. m := models.ErmcpOPApplyModel{RELATEDID: req.RelatedId, USERID: req.UserId, FilterAppStatus: req.Applystatus}
  132. if d, err := m.GetData(2); err == nil {
  133. //构建应答数据
  134. sData := make([]QryBussinessJsExRsp, 0)
  135. for _, v := range d {
  136. var rsp QryBussinessJsExRsp
  137. var rd ReckonData
  138. rsp.ErmcpOPApplyModel = v
  139. if len(rsp.DETAILJSON) > 0 {
  140. if err := json.Unmarshal([]byte(rsp.DETAILJSON), &rd); err == nil {
  141. if rd.ReckonRealQty != nil {
  142. rsp.ReckonType = "确定量"
  143. rsp.ReckonValue = *rd.ReckonRealQty
  144. sData = append(sData, rsp)
  145. }
  146. if rd.ReckonOtherAmount != nil {
  147. rsp.ReckonType = "其它费用"
  148. rsp.ReckonValue = *rd.ReckonOtherAmount
  149. sData = append(sData, rsp)
  150. }
  151. if rd.ReckonAdjustAmount != nil {
  152. rsp.ReckonType = "调整金额"
  153. rsp.ReckonValue = *rd.ReckonAdjustAmount
  154. sData = append(sData, rsp)
  155. }
  156. if rd.AddMargin != nil {
  157. rsp.ReckonType = "追加保证金"
  158. rsp.ReckonValue = *rd.AddMargin
  159. sData = append(sData, rsp)
  160. }
  161. if rd.DecMargin != nil {
  162. rsp.ReckonType = "退还保证金"
  163. rsp.ReckonValue = *rd.DecMargin
  164. sData = append(sData, rsp)
  165. }
  166. if rd.ReckonOsAmount != nil {
  167. rsp.ReckonType = "溢短金额"
  168. rsp.ReckonValue = *rd.ReckonOsAmount
  169. sData = append(sData, rsp)
  170. }
  171. }
  172. }
  173. }
  174. appG.Response(http.StatusOK, e.SUCCESS, sData)
  175. } else {
  176. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  177. }
  178. }
  179. // 查询业务管理/款项响应
  180. type QryBussinessKxRsp struct {
  181. models.ErmcpOPApplyModel
  182. KxData
  183. }
  184. // QueryBusinessKx 企业风险管理合同操作查询
  185. func QueryBusinessKx(c *gin.Context) {
  186. appG := app.Gin{C: c}
  187. var req QryOPApplyReq
  188. _ = c.ShouldBind(&req)
  189. m := models.ErmcpOPApplyModel{RELATEDID: req.RelatedId, USERID: req.UserId, FilterAppStatus: req.Applystatus}
  190. if d, err := m.GetData(3); err == nil {
  191. //构建应答数据
  192. sData := make([]QryBussinessKxRsp, 0)
  193. for _, v := range d {
  194. var rsp QryBussinessKxRsp
  195. rsp.ErmcpOPApplyModel = v
  196. if len(rsp.DETAILJSON) > 0 {
  197. if err := json.Unmarshal([]byte(rsp.DETAILJSON), &rsp.KxData); err == nil {
  198. rsp.KxData.CalcKxType()
  199. sData = append(sData, rsp)
  200. }
  201. }
  202. }
  203. appG.Response(http.StatusOK, e.SUCCESS, sData)
  204. } else {
  205. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  206. }
  207. }
  208. // 查询业务管理/款项响应
  209. type QryBussinessFpRsp struct {
  210. models.ErmcpOPApplyModel
  211. KpData
  212. }
  213. // QueryBusinessFp 企业风险管理合同操作查询
  214. func QueryBusinessFp(c *gin.Context) {
  215. appG := app.Gin{C: c}
  216. var req QryOPApplyReq
  217. _ = c.ShouldBind(&req)
  218. m := models.ErmcpOPApplyModel{RELATEDID: req.RelatedId, USERID: req.UserId, FilterAppStatus: req.Applystatus}
  219. if d, err := m.GetData(4); err == nil {
  220. //构建应答数据
  221. sData := make([]QryBussinessFpRsp, 0)
  222. for _, v := range d {
  223. var rsp QryBussinessFpRsp
  224. rsp.ErmcpOPApplyModel = v
  225. if len(rsp.DETAILJSON) > 0 {
  226. _ = json.Unmarshal([]byte(rsp.DETAILJSON), &rsp.KpData)
  227. }
  228. sData = append(sData, rsp)
  229. }
  230. appG.Response(http.StatusOK, e.SUCCESS, sData)
  231. } else {
  232. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  233. }
  234. }