paymentinfoService.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package paymentinfo
  2. import (
  3. . "dashoo.cn/backend/api/mydb"
  4. "github.com/go-xorm/xorm"
  5. "strconv"
  6. . "dashoo.cn/utils/db"
  7. )
  8. type PaymentService struct {
  9. MyServiceBase
  10. }
  11. func GetPaymentService(xormEngine *xorm.Engine) *PaymentService {
  12. s := new(PaymentService)
  13. s.DBE = xormEngine
  14. return s
  15. }
  16. func (s *PaymentService) GetPaymentinfoList(pageIndex, itemsPerPage int64, order string, asc string, entitiesPtr interface{}, where string) (total int64) {
  17. var err error
  18. var resultsSlice []map[string][]byte
  19. sqlconunt := "SELECT count(*) " +
  20. "FROM OilPaymentInfo p " +
  21. "LEFT JOIN OilSupplier s ON p.SupplierId = s.Id " +
  22. "LEFT JOIN OilSupplierCert c ON p.SupplierCertId = c.Id " +
  23. "WHERE "+ where
  24. sql := "SELECT c.SupplierTypeCode,c.SupplierTypeName,s.SupplierName,s.CommercialNo,p.* " +
  25. "FROM OilPaymentInfo p " +
  26. "LEFT JOIN OilSupplier s ON p.SupplierId = s.Id " +
  27. "LEFT JOIN OilSupplierCert c ON p.SupplierCertId = c.Id " +
  28. "WHERE "+ where +
  29. " Order By " + order + asc + " Limit " + strconv.Itoa(int(itemsPerPage)) +" OFFSET " + strconv.Itoa((int(pageIndex)-1)*int(itemsPerPage))
  30. resultsSlice, err = s.DBE.Query(sqlconunt)
  31. err = s.DBE.SQL(sql).Find(entitiesPtr)
  32. LogError(err)
  33. if len(resultsSlice) > 0 {
  34. results := resultsSlice[0]
  35. for _, value := range results {
  36. total, err = strconv.ParseInt(string(value), 10, 64)
  37. LogError(err)
  38. break
  39. }
  40. }
  41. return total
  42. }
  43. func (s *PaymentService) GetPaymentinfoById(Id string, entitiesPtr interface{}) (err error) {
  44. sql := "SELECT c.SupplierTypeCode,c.SupplierTypeName,s.SupplierName,p.* " +
  45. "FROM OilPaymentInfo p " +
  46. "LEFT JOIN OilSupplier s ON p.SupplierId = s.Id " +
  47. "LEFT JOIN OilSupplierCert c ON p.SupplierCertId = c.Id " +
  48. "WHERE p.Id="+ Id
  49. err = s.DBE.SQL(sql).Find(entitiesPtr)
  50. LogError(err)
  51. return err
  52. }
  53. // Amount 交费金额 PayType 缴费类型 1 准入缴费 2 年审缴费
  54. func (s *PaymentService) AddPaymentinfo(SupplierId int, SupplierCertId int, Amount float64, PayType string)(err error){
  55. //var err error
  56. sql := "INSERT INTO OilPaymentInfo (SupplierId, SupplierCertId, Amount, PayType) VALUES" +
  57. "(? ,? , ?, ?)"
  58. _,err = s.DBE.Exec(sql, SupplierId, SupplierCertId, Amount, PayType)
  59. return err
  60. }