qryOPApply.go 10 KB

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