contractModel.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2020/12/2 9:17
  4. * @Modify : 2020/12/2 9:17
  5. */
  6. // 查询待审核的合同
  7. package models
  8. import (
  9. "fmt"
  10. "mtp2_if/db"
  11. "mtp2_if/logger"
  12. )
  13. // 待审核合同(普通合同)
  14. type AuditContractModel struct {
  15. SpotContractId string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'" binding:"required"` // 合同ID
  16. MatchCustomerName string `json:"matchcustomername" xorm:"'MATCHCUSTOMERNAME'" binding:"required"` // 销售方ID
  17. MatchAccountId string `json:"matchaccountid" xorm:"'MATCHACCOUNTID'"` // 业务员ID
  18. AccountId string `json:"accountid" xorm:"'ACCOUNTID'"` // 交易员ID
  19. CustomerName string `json:"customername" xorm:"'CUSTOMERNAME'"` // 采购方ID
  20. ApplyStatus uint32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 状态
  21. EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
  22. DetailJSON string `json:"detailjson" xorm:"'DETAILJSON'"` // 合同明细
  23. }
  24. // 组装查询普通待审核合同Sql
  25. func (r *AuditContractModel) buildSql(accountId uint64, contractType int32) string {
  26. str := "select to_char(s.spotcontractid) spotcontractid," +
  27. " u.customername," +
  28. " s.accountid," +
  29. " u2.customername matchcustomername," +
  30. " s.customeraccountid matchaccountid," +
  31. " s.signdate," +
  32. " s.applystatus," +
  33. " to_char(s.DETAILJSON) DETAILJSON" +
  34. " from ERMS3_SpotContractApply s" +
  35. " left join userinfo u" +
  36. " on u.userid = s.areauserid" +
  37. " left join userinfo u2" +
  38. " on u2.userid = s.customeruserid" +
  39. " where s.contracttype = %v" +
  40. " and s.applystatus in(0,2)" +
  41. " and s.accountid = %v"
  42. return fmt.Sprintf(str, contractType, accountId)
  43. }
  44. // 获取待审核的合同
  45. func (r *AuditContractModel) GetData(accountId uint64, contractType int32) ([]AuditContractModel, error) {
  46. sAC := make([]AuditContractModel, 0)
  47. e := db.GetEngine()
  48. s := e.SQL(r.buildSql(accountId, contractType))
  49. if err := s.Find(&sAC); err != nil {
  50. logger.GetLogger().Errorf("query pending contract fail:%v", err)
  51. return sAC, err
  52. }
  53. return sAC, nil
  54. }
  55. // 待审核合同(回购)
  56. type AutditContractHGModel struct {
  57. SpotContractId string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'" binding:"required"` // 合同ID
  58. MatchCustomerName string `json:"matchcustomername" xorm:"'MATCHCUSTOMERNAME'" binding:"required"` // 销售方ID
  59. MatchAccountId string `json:"matchaccountid" xorm:"'MATCHACCOUNTID'"` // 业务员ID
  60. AccountId string `json:"accountid" xorm:"'ACCOUNTID'"` // 交易员ID
  61. CustomerName string `json:"customername" xorm:"'CUSTOMERNAME'"` // 采购方ID
  62. WrstandardName string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 商品名称
  63. Wrstandardcode string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 商品代码
  64. ApplyStatus uint32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 状态
  65. EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
  66. ContractQty float64 `json:"contractqty" xorm:"'CONTRACTQTY'"` // 合同量
  67. SignDate string `json:"signdate" xorm:"'SIGNDATE'"` // 签订日期
  68. }
  69. func (r *AutditContractHGModel) buildSql(accountId uint64) string {
  70. sqlId := "select to_char(t.wrrcontractid) spotcontractid," +
  71. " t.accountid," +
  72. " t.contractqty," +
  73. " to_char(t.signdate, 'yyyy-mm-dd') signdate," +
  74. " t.applystatus," +
  75. " w.wrstandardname," +
  76. " w.wrstandardcode," +
  77. " u.accountname customername," +
  78. " u2.accountname matchcustomername," +
  79. " t.customeraccountid matchaccountid," +
  80. " ec.enumdicname" +
  81. " from erms2_wrrapply t" +
  82. " left join wrstandard w" +
  83. " on t.wrstandardid = w.wrstandardid" +
  84. " left join useraccount u" +
  85. " on t.areauserid = u.userid" +
  86. " left join useraccount u2" +
  87. " on t.customeruserid = u2.userid" +
  88. " left join enumdicitem ec" +
  89. " on w.unitid = ec.enumitemname" +
  90. " and ec.enumdiccode = 'goodsunit'" +
  91. " where t.accountid = %v" +
  92. " and t.applystatus in (0, 2)"
  93. return fmt.Sprintf(sqlId, accountId)
  94. }
  95. func (r *AutditContractHGModel) GetData(accountId uint64) ([]AutditContractHGModel, error) {
  96. sAC := make([]AutditContractHGModel, 0)
  97. e := db.GetEngine()
  98. s := e.SQL(r.buildSql(accountId))
  99. if err := s.Find(&sAC); err != nil{
  100. logger.GetLogger().Errorf("query hg pending contract fail:%v", err)
  101. return sAC, err
  102. }
  103. return sAC, nil
  104. }