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