qryOPApply.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. }
  63. // 查询业务管理/点价应答
  64. type QryBusinessDjRsp struct {
  65. models.ErmcpOPApplyModel
  66. DjData
  67. }
  68. // QueryBusinessDj 企业风险管理合同操作查询
  69. // @Summary 查询业务管理(点价)(对应菜单:业务管理/点价)
  70. // @Produce json
  71. // @Security ApiKeyAuth
  72. // @Param UserId query int true "用户ID"
  73. // @Param relatedid query string false "现货合同ID, 不填则查所有"
  74. // @Success 200 {array} QryBusinessDjRsp
  75. // @Failure 500 {object} app.Response
  76. // @Router /Ermcp/QueryBusinessDj [get]
  77. // @Tags 企业风险管理(app)
  78. func QueryBusinessDj(c *gin.Context) {
  79. appG := app.Gin{C: c}
  80. var req QryOPApplyReq
  81. _ = c.ShouldBind(&req)
  82. m := models.ErmcpOPApplyModel{RELATEDID: req.RelatedId, USERID: req.UserId}
  83. if d, err := m.GetData(1); err == nil {
  84. //构建应答数据
  85. sData := make([]QryBusinessDjRsp, 0)
  86. for _, v := range d {
  87. var rsp QryBusinessDjRsp
  88. rsp.ErmcpOPApplyModel = v
  89. if len(rsp.DETAILJSON) > 0 {
  90. if err := json.Unmarshal([]byte(rsp.DETAILJSON), &rsp.DjData); err == nil {
  91. rsp.DjData.calc(rsp.PRICEMOVE)
  92. }
  93. sData = append(sData, rsp)
  94. }
  95. }
  96. appG.Response(http.StatusOK, e.SUCCESS, sData)
  97. } else {
  98. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  99. }
  100. }
  101. // 查询业务管理/结算响应
  102. type QryBussinessJsRsp struct {
  103. models.ErmcpOPApplyModel
  104. ReckonData
  105. }
  106. // QueryBusinessJs 企业风险管理合同操作查询
  107. // @Summary 查询业务管理(结算)(对应菜单:业务管理/结算)
  108. // @Produce json
  109. // @Security ApiKeyAuth
  110. // @Param UserId query int true "用户ID"
  111. // @Param relatedid query string false "现货合同ID, 不填则查所有"
  112. // @Param operateapplyid query string false "操作申请id"
  113. // @Success 200 {array} QryBussinessJsRsp
  114. // @Failure 500 {object} app.Response
  115. // @Router /Ermcp/QueryBusinessJs [get]
  116. // @Tags 企业风险管理(app)
  117. func QueryBusinessJs(c *gin.Context) {
  118. appG := app.Gin{C: c}
  119. var req QryOPApplyReq
  120. _ = c.ShouldBind(&req)
  121. m := models.ErmcpOPApplyModel{RELATEDID: req.RelatedId, USERID: req.UserId, OPERATEAPPLYID: req.OperateapplyId}
  122. if d, err := m.GetData(2); err == nil {
  123. //构建应答数据
  124. sData := make([]QryBussinessJsRsp, 0)
  125. for _, v := range d {
  126. var rsp QryBussinessJsRsp
  127. rsp.ErmcpOPApplyModel = v
  128. if len(rsp.DETAILJSON) > 0 {
  129. _ = json.Unmarshal([]byte(rsp.DETAILJSON), &rsp.ReckonData)
  130. }
  131. sData = append(sData, rsp)
  132. }
  133. appG.Response(http.StatusOK, e.SUCCESS, sData)
  134. } else {
  135. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  136. }
  137. }
  138. // 查询业务管理/结算响应(拆分字段)
  139. type QryBussinessJsExRsp struct {
  140. models.ErmcpOPApplyModel
  141. ReckonType string `json:"reckontype"` // 结算类型
  142. ReckonValue float64 `json:"reckonvalue"` // 值
  143. }
  144. // @Summary 查询业务管理(结算)(对应菜单:业务管理/结算[拆分记录])
  145. // @Produce json
  146. // @Security ApiKeyAuth
  147. // @Param UserId query int true "用户ID"
  148. // @Param relatedid query string false "现货合同ID, 不填则查所有"
  149. // @Success 200 {array} QryBussinessJsExRsp
  150. // @Failure 500 {object} app.Response
  151. // @Router /Ermcp/QueryBusinessJsEx [get]
  152. // @Tags 企业风险管理(app)
  153. func QueryBusinessJsEx(c *gin.Context) {
  154. appG := app.Gin{C: c}
  155. var req QryOPApplyReq
  156. _ = c.ShouldBind(&req)
  157. m := models.ErmcpOPApplyModel{RELATEDID: req.RelatedId, USERID: req.UserId}
  158. if d, err := m.GetData(2); err == nil {
  159. //构建应答数据
  160. sData := make([]QryBussinessJsExRsp, 0)
  161. for _, v := range d {
  162. var rsp QryBussinessJsExRsp
  163. var rd ReckonData
  164. rsp.ErmcpOPApplyModel = v
  165. if len(rsp.DETAILJSON) > 0 {
  166. if err := json.Unmarshal([]byte(rsp.DETAILJSON), &rd); err == nil {
  167. if rd.ReckonRealQty != nil {
  168. rsp.ReckonType = "确定量"
  169. rsp.ReckonValue = *rd.ReckonRealQty
  170. sData = append(sData, rsp)
  171. }
  172. if rd.ReckonOtherAmount != nil {
  173. rsp.ReckonType = "其它费用"
  174. rsp.ReckonValue = *rd.ReckonOtherAmount
  175. sData = append(sData, rsp)
  176. }
  177. if rd.ReckonAdjustAmount != nil {
  178. rsp.ReckonType = "调整金额"
  179. rsp.ReckonValue = *rd.ReckonAdjustAmount
  180. sData = append(sData, rsp)
  181. }
  182. if rd.AddMargin != nil {
  183. rsp.ReckonType = "追加保证金"
  184. rsp.ReckonValue = *rd.AddMargin
  185. sData = append(sData, rsp)
  186. }
  187. if rd.DecMargin != nil {
  188. rsp.ReckonType = "退还保证金"
  189. rsp.ReckonValue = *rd.DecMargin
  190. sData = append(sData, rsp)
  191. }
  192. if rd.ReckonOsAmount != nil {
  193. rsp.ReckonType = "溢短金额"
  194. rsp.ReckonValue = *rd.ReckonOsAmount
  195. sData = append(sData, rsp)
  196. }
  197. }
  198. }
  199. }
  200. appG.Response(http.StatusOK, e.SUCCESS, sData)
  201. } else {
  202. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  203. }
  204. }
  205. // 查询业务管理/款项响应
  206. type QryBussinessKxRsp struct {
  207. models.ErmcpOPApplyModel
  208. KxData
  209. }
  210. // QueryBusinessKx 企业风险管理合同操作查询
  211. // @Summary 查询财务管理(款项)(对应菜单:财务管理/款项)
  212. // @Produce json
  213. // @Security ApiKeyAuth
  214. // @Param UserId query int true "用户ID"
  215. // @Param relatedid query string false "现货合同ID, 不填则查所有"
  216. // @Success 200 {array} QryBussinessKxRsp
  217. // @Failure 500 {object} app.Response
  218. // @Router /Ermcp/QueryBusinessKx [get]
  219. // @Tags 企业风险管理(app)
  220. func QueryBusinessKx(c *gin.Context) {
  221. appG := app.Gin{C: c}
  222. var req QryOPApplyReq
  223. _ = c.ShouldBind(&req)
  224. m := models.ErmcpOPApplyModel{RELATEDID: req.RelatedId, USERID: req.UserId}
  225. if d, err := m.GetData(3); err == nil {
  226. //构建应答数据
  227. sData := make([]QryBussinessKxRsp, 0)
  228. for _, v := range d {
  229. var rsp QryBussinessKxRsp
  230. rsp.ErmcpOPApplyModel = v
  231. if len(rsp.DETAILJSON) > 0 {
  232. if err := json.Unmarshal([]byte(rsp.DETAILJSON), &rsp.KxData); err == nil {
  233. rsp.KxData.CalcKxType()
  234. sData = append(sData, rsp)
  235. }
  236. }
  237. }
  238. appG.Response(http.StatusOK, e.SUCCESS, sData)
  239. } else {
  240. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  241. }
  242. }
  243. // 查询业务管理/款项响应
  244. type QryBussinessFpRsp struct {
  245. models.ErmcpOPApplyModel
  246. KpData
  247. }
  248. // QueryBusinessFp 企业风险管理合同操作查询
  249. // @Summary 查询财务管理(发票)(对应菜单:财务管理/发票)
  250. // @Produce json
  251. // @Security ApiKeyAuth
  252. // @Param UserId query int true "用户ID"
  253. // @Param relatedid query string false "现货合同ID, 不填则查所有"
  254. // @Success 200 {array} QryBussinessFpRsp
  255. // @Failure 500 {object} app.Response
  256. // @Router /Ermcp/QueryBusinessFp [get]
  257. // @Tags 企业风险管理(app)
  258. func QueryBusinessFp(c *gin.Context) {
  259. appG := app.Gin{C: c}
  260. var req QryOPApplyReq
  261. _ = c.ShouldBind(&req)
  262. m := models.ErmcpOPApplyModel{RELATEDID: req.RelatedId, USERID: req.UserId}
  263. if d, err := m.GetData(4); err == nil {
  264. //构建应答数据
  265. sData := make([]QryBussinessFpRsp, 0)
  266. for _, v := range d {
  267. var rsp QryBussinessFpRsp
  268. rsp.ErmcpOPApplyModel = v
  269. if len(rsp.DETAILJSON) > 0 {
  270. _ = json.Unmarshal([]byte(rsp.DETAILJSON), &rsp.KpData)
  271. }
  272. sData = append(sData, rsp)
  273. }
  274. appG.Response(http.StatusOK, e.SUCCESS, sData)
  275. } else {
  276. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  277. }
  278. }