address_dao.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package dao
  2. import (
  3. "github.com/druidcaesa/gotool"
  4. "ulink-admin/frame"
  5. "ulink-admin/modules/system/models/model"
  6. "ulink-admin/modules/system/models/req"
  7. "ulink-admin/pkg/base"
  8. "ulink-admin/pkg/page"
  9. )
  10. type AddressDao struct {
  11. base.BaseDao
  12. }
  13. // Page 查询地址管理分页数据
  14. func (this AddressDao) Page(query *req.AddressQuery, list interface{}) int64 {
  15. session := this.GetSession().Table(model.Address{}.TableName())
  16. if query.Id > 0 {
  17. session.And("id = ?", query.Id)
  18. }
  19. if query.MemberId > 0 {
  20. session.And("member_id = ?", query.MemberId)
  21. }
  22. if !gotool.StrUtils.HasEmpty(query.Name) {
  23. session.And("name = ?", query.Name)
  24. }
  25. if !gotool.StrUtils.HasEmpty(query.Phone) {
  26. session.And("phone = ?", query.Phone)
  27. }
  28. if !gotool.StrUtils.HasEmpty(query.Province) {
  29. session.And("province = ?", query.Province)
  30. }
  31. if !gotool.StrUtils.HasEmpty(query.City) {
  32. session.And("city = ?", query.City)
  33. }
  34. if !gotool.StrUtils.HasEmpty(query.AreaCode) {
  35. session.And("area_code = ?", query.AreaCode)
  36. }
  37. if !gotool.StrUtils.HasEmpty(query.District) {
  38. session.And("district = ?", query.District)
  39. }
  40. if !gotool.StrUtils.HasEmpty(query.Detail) {
  41. session.And("detail = ?", query.Detail)
  42. }
  43. if !gotool.StrUtils.HasEmpty(query.PostCode) {
  44. session.And("post_code = ?", query.PostCode)
  45. }
  46. if !gotool.StrUtils.HasEmpty(query.Longitude) {
  47. session.And("longitude = ?", query.Longitude)
  48. }
  49. if !gotool.StrUtils.HasEmpty(query.Latitude) {
  50. session.And("latitude = ?", query.Latitude)
  51. }
  52. if query.IsDefault > 0 {
  53. session.And("is_default = ?", query.IsDefault)
  54. }
  55. if query.IsDel > 0 {
  56. session.And("is_del = ?", query.IsDel)
  57. }
  58. if !gotool.StrUtils.HasEmpty(query.BeginTime) {
  59. session.And("date_format(u.create_time,'%y%m%d') >= date_format(?,'%y%m%d')", query.BeginTime)
  60. }
  61. if !gotool.StrUtils.HasEmpty(query.EndTime) {
  62. session.And("date_format(u.create_time,'%y%m%d') <= date_format(?,'%y%m%d')", query.EndTime)
  63. }
  64. session.Desc("id")
  65. total, err := session.Limit(query.PageSize, page.StartSize(query.PageNum, query.PageSize)).FindAndCount(list)
  66. if err != nil {
  67. frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error())
  68. }
  69. return total
  70. }
  71. // List 查询地址管理分页数据
  72. func (this AddressDao) List(query *req.AddressQuery, list interface{}) {
  73. session := this.GetSession().Table(model.Address{}.TableName())
  74. if query.Id > 0 {
  75. session.And("id = ?", query.Id)
  76. }
  77. if query.MemberId > 0 {
  78. session.And("member_id = ?", query.MemberId)
  79. }
  80. if !gotool.StrUtils.HasEmpty(query.Name) {
  81. session.And("name = ?", query.Name)
  82. }
  83. if !gotool.StrUtils.HasEmpty(query.Phone) {
  84. session.And("phone = ?", query.Phone)
  85. }
  86. if !gotool.StrUtils.HasEmpty(query.Province) {
  87. session.And("province = ?", query.Province)
  88. }
  89. if !gotool.StrUtils.HasEmpty(query.City) {
  90. session.And("city = ?", query.City)
  91. }
  92. if !gotool.StrUtils.HasEmpty(query.AreaCode) {
  93. session.And("area_code = ?", query.AreaCode)
  94. }
  95. if !gotool.StrUtils.HasEmpty(query.District) {
  96. session.And("district = ?", query.District)
  97. }
  98. if !gotool.StrUtils.HasEmpty(query.Detail) {
  99. session.And("detail = ?", query.Detail)
  100. }
  101. if !gotool.StrUtils.HasEmpty(query.PostCode) {
  102. session.And("post_code = ?", query.PostCode)
  103. }
  104. if !gotool.StrUtils.HasEmpty(query.Longitude) {
  105. session.And("longitude = ?", query.Longitude)
  106. }
  107. if !gotool.StrUtils.HasEmpty(query.Latitude) {
  108. session.And("latitude = ?", query.Latitude)
  109. }
  110. if query.IsDefault > 0 {
  111. session.And("is_default = ?", query.IsDefault)
  112. }
  113. if query.IsDel > 0 {
  114. session.And("is_del = ?", query.IsDel)
  115. }
  116. if !gotool.StrUtils.HasEmpty(query.BeginTime) {
  117. session.And("date_format(u.create_time,'%y%m%d') >= date_format(?,'%y%m%d')", query.BeginTime)
  118. }
  119. if !gotool.StrUtils.HasEmpty(query.EndTime) {
  120. session.And("date_format(u.create_time,'%y%m%d') <= date_format(?,'%y%m%d')", query.EndTime)
  121. }
  122. session.Desc("id")
  123. err := session.Find(list)
  124. if err != nil {
  125. frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error())
  126. }
  127. }