| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /**
- * @Author: zou.yingbin
- * @Create : 2020/12/2 9:17
- * @Modify : 2020/12/2 9:17
- */
- // 查询待审核的合同
- package models
- import (
- "fmt"
- "mtp2_if/db"
- "mtp2_if/logger"
- )
- // 待审核合同(普通合同)
- type AuditContractModel struct {
- SpotContractId string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'" binding:"required"` // 合同ID
- MatchCustomerName string `json:"matchcustomername" xorm:"'MATCHCUSTOMERNAME'" binding:"required"` // 销售方ID
- MatchAccountId string `json:"matchaccountid" xorm:"'MATCHACCOUNTID'"` // 业务员ID
- AccountId string `json:"accountid" xorm:"'ACCOUNTID'"` // 交易员ID
- CustomerName string `json:"customername" xorm:"'CUSTOMERNAME'"` // 采购方ID
- ApplyStatus uint32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 状态
- EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
- DetailJSON string `json:"detailjson" xorm:"'DETAILJSON'"` // 合同明细
- }
- // 组装查询普通待审核合同Sql
- func (r *AuditContractModel) buildSql(accountId uint64, contractType int32) string {
- str := "select to_char(s.spotcontractid) spotcontractid," +
- " u.customername," +
- " s.accountid," +
- " u2.customername matchcustomername," +
- " s.customeraccountid matchaccountid," +
- " s.signdate," +
- " s.applystatus," +
- " to_char(s.DETAILJSON) DETAILJSON" +
- " from ERMS3_SpotContractApply s" +
- " left join userinfo u" +
- " on u.userid = s.areauserid" +
- " left join userinfo u2" +
- " on u2.userid = s.customeruserid" +
- " where s.contracttype = %v" +
- " and s.applystatus in(0,2)" +
- " and s.accountid = %v"
- return fmt.Sprintf(str, contractType, accountId)
- }
- // 获取待审核的合同
- func (r *AuditContractModel) GetData(accountId uint64, contractType int32) ([]AuditContractModel, error) {
- sAC := make([]AuditContractModel, 0)
- e := db.GetEngine()
- s := e.SQL(r.buildSql(accountId, contractType))
- if err := s.Find(&sAC); err != nil {
- logger.GetLogger().Errorf("query pending contract fail:%v", err)
- return sAC, err
- }
- return sAC, nil
- }
- // 待审核合同(回购)
- type AutditContractHGModel struct {
- SpotContractId string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'" binding:"required"` // 合同ID
- MatchCustomerName string `json:"matchcustomername" xorm:"'MATCHCUSTOMERNAME'" binding:"required"` // 销售方ID
- MatchAccountId string `json:"matchaccountid" xorm:"'MATCHACCOUNTID'"` // 业务员ID
- AccountId string `json:"accountid" xorm:"'ACCOUNTID'"` // 交易员ID
- CustomerName string `json:"customername" xorm:"'CUSTOMERNAME'"` // 采购方ID
- WrstandardName string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 商品名称
- Wrstandardcode string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 商品代码
- ApplyStatus uint32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 状态
- EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
- ContractQty float64 `json:"contractqty" xorm:"'CONTRACTQTY'"` // 合同量
- SignDate string `json:"signdate" xorm:"'SIGNDATE'"` // 签订日期
- }
- func (r *AutditContractHGModel) buildSql(accountId uint64) string {
- sqlId := "select to_char(t.wrrcontractid) spotcontractid," +
- " t.accountid," +
- " t.contractqty," +
- " to_char(t.signdate, 'yyyy-mm-dd') signdate," +
- " t.applystatus," +
- " w.wrstandardname," +
- " w.wrstandardcode," +
- " u.accountname customername," +
- " u2.accountname matchcustomername," +
- " t.customeraccountid matchaccountid," +
- " ec.enumdicname" +
- " from erms2_wrrapply t" +
- " left join wrstandard w" +
- " on t.wrstandardid = w.wrstandardid" +
- " left join useraccount u" +
- " on t.areauserid = u.userid" +
- " left join useraccount u2" +
- " on t.customeruserid = u2.userid" +
- " left join enumdicitem ec" +
- " on w.unitid = ec.enumitemname" +
- " and ec.enumdiccode = 'goodsunit'" +
- " where t.accountid = %v" +
- " and t.applystatus in (0, 2)"
- return fmt.Sprintf(sqlId, accountId)
- }
- func (r *AutditContractHGModel) GetData(accountId uint64) ([]AutditContractHGModel, error) {
- sAC := make([]AutditContractHGModel, 0)
- e := db.GetEngine()
- s := e.SQL(r.buildSql(accountId))
- if err := s.Find(&sAC); err != nil{
- logger.GetLogger().Errorf("query hg pending contract fail:%v", err)
- return sAC, err
- }
- return sAC, nil
- }
|