provider.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package model
  2. import (
  3. "github.com/jinzhu/gorm"
  4. "time"
  5. "fmt"
  6. )
  7. type TProvider struct {
  8. Id int64 `gorm:"column:ID" json:"id" form:"id"`
  9. Name string `gorm:"column:Name" json:"name" form:"name"`
  10. SocialCode string `gorm:"column:SocialCode" json:"social_code" form:"social_code"`
  11. LegalPerson string `gorm:"column:LegalPerson" json:"legal_person" form:"legal_person"`
  12. IdCert string `gorm:"column:IdCert" json:"id_cert" form:"id_cert"`
  13. EnterpriseLocation int32 `gorm:"column:EnterpriseLocation" json:"enterprise_location" form:"enterprise_location"`
  14. BusinessLicense string `gorm:"column:BusinessLicense" json:"business_license" form:"business_license"`
  15. IntegrityManagementLetter string `gorm:"column:IntegrityManagementLetter" json:"integrity_management_letter" form:"integrity_management_letter"`
  16. LegalPersonLetter string `gorm:"column:LegalPersonLetter" json:"legal_person_letter" form:"legal_person_letter"`
  17. BusinessResponsibleLetter string `gorm:"column:BusinessResponsibleLetter" json:"business_responsible_letter" form:"business_responsible_letter"`
  18. UserName string `gorm:"column:UserName" json:"user_name" form:"user_name"`
  19. Passwd string `gorm:"column:Passwd" json:"passwd" form:"passwd"`
  20. BusinessContact string `gorm:"column:BusinessContact" json:"business_contact" form:"business_contact"`
  21. BusinessContactPhone string `gorm:"column:BusinessContactPhone" json:"business_contact_phone" form:"business_contact_phone"`
  22. BusinessResponsible string `gorm:"column:BusinessResponsible" json:"business_responsible" form:"business_responsible"`
  23. BusinessResponsiblePhone string `gorm:"column:BusinessResponsiblePhone" json:"business_responsible_phone" form:"business_responsible_phone"`
  24. EmergencyContact string `gorm:"column:EmergencyContact" json:"emergency_contact" form:"emergency_contact"`
  25. EmergencyContactPhone string `gorm:"column:EmergencyContactPhone" json:"emergency_contact_phone" form:"emergency_contact_phone"`
  26. Status int64 `gorm:"column:Status" json:"status" form:"status"`
  27. CreatedAt time.Time `gorm:"column:CreatedAt" json:"created_at" form:"created_at"`
  28. UpdatedAt time.Time `gorm:"column:UpdatedAt" json:"updated_at" form:"updated_at"`
  29. Feedback string `gorm:"column:Feedback"`
  30. ApproveTime time.Time `gorm:"column:ApproveTime"`
  31. Email string `gorm:"column:Email"`
  32. }
  33. func PublicityList(db *gorm.DB, provider string) ([]TProvider, int64, error) {
  34. sql := fmt.Sprintf("select t1.* from Provider as t1 where(select count(1) from ProviderDeviceTesting where ProviderId=t1.ID and Status = 1) > 0 and t1.Status = 1")
  35. countSql := fmt.Sprintf("select count(1) as count from Provider as t1 where(select count(1) from ProviderDeviceTesting where ProviderId=t1.id and Status = 1) > 0 ")
  36. type CountResult struct {
  37. Count int64
  38. }
  39. if provider != "" {
  40. sql = fmt.Sprintf("%s and t1.Name like '%%%s%%'", sql, provider)
  41. countSql = fmt.Sprintf("%s and t1.Name like '%%%s%%'", countSql, provider)
  42. }
  43. array := []CountResult{}
  44. err := db.Raw(countSql).Scan(&array).Error
  45. if err != nil {
  46. return nil, 0, err
  47. }
  48. total := array[0].Count
  49. if total == 0 {
  50. return nil, 0, nil
  51. }
  52. list := []TProvider{}
  53. err = db.Raw(sql).Scan(&list).Error
  54. if err != nil {
  55. return nil, 0, err
  56. }
  57. return list, total, nil
  58. }