123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package dao
- import (
- "github.com/druidcaesa/gotool"
- "ulink-admin/frame"
- "ulink-admin/modules/system/models/model"
- "ulink-admin/modules/system/models/req"
- "ulink-admin/pkg/base"
- "ulink-admin/pkg/page"
- )
- type AddressDao struct {
- base.BaseDao
- }
- // Page 查询地址管理分页数据
- func (this AddressDao) Page(query *req.AddressQuery, list interface{}) int64 {
- session := this.GetSession().Table(model.Address{}.TableName())
- if query.Id > 0 {
- session.And("id = ?", query.Id)
- }
- if query.MemberId > 0 {
- session.And("member_id = ?", query.MemberId)
- }
- if !gotool.StrUtils.HasEmpty(query.Name) {
- session.And("name = ?", query.Name)
- }
- if !gotool.StrUtils.HasEmpty(query.Phone) {
- session.And("phone = ?", query.Phone)
- }
- if !gotool.StrUtils.HasEmpty(query.Province) {
- session.And("province = ?", query.Province)
- }
- if !gotool.StrUtils.HasEmpty(query.City) {
- session.And("city = ?", query.City)
- }
- if !gotool.StrUtils.HasEmpty(query.AreaCode) {
- session.And("area_code = ?", query.AreaCode)
- }
- if !gotool.StrUtils.HasEmpty(query.District) {
- session.And("district = ?", query.District)
- }
- if !gotool.StrUtils.HasEmpty(query.Detail) {
- session.And("detail = ?", query.Detail)
- }
- if !gotool.StrUtils.HasEmpty(query.PostCode) {
- session.And("post_code = ?", query.PostCode)
- }
- if !gotool.StrUtils.HasEmpty(query.Longitude) {
- session.And("longitude = ?", query.Longitude)
- }
- if !gotool.StrUtils.HasEmpty(query.Latitude) {
- session.And("latitude = ?", query.Latitude)
- }
- if query.IsDefault > 0 {
- session.And("is_default = ?", query.IsDefault)
- }
- if query.IsDel > 0 {
- session.And("is_del = ?", query.IsDel)
- }
- if !gotool.StrUtils.HasEmpty(query.BeginTime) {
- session.And("date_format(u.create_time,'%y%m%d') >= date_format(?,'%y%m%d')", query.BeginTime)
- }
- if !gotool.StrUtils.HasEmpty(query.EndTime) {
- session.And("date_format(u.create_time,'%y%m%d') <= date_format(?,'%y%m%d')", query.EndTime)
- }
- session.Desc("id")
- total, err := session.Limit(query.PageSize, page.StartSize(query.PageNum, query.PageSize)).FindAndCount(list)
- if err != nil {
- frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error())
- }
- return total
- }
- // List 查询地址管理分页数据
- func (this AddressDao) List(query *req.AddressQuery, list interface{}) {
- session := this.GetSession().Table(model.Address{}.TableName())
- if query.Id > 0 {
- session.And("id = ?", query.Id)
- }
- if query.MemberId > 0 {
- session.And("member_id = ?", query.MemberId)
- }
- if !gotool.StrUtils.HasEmpty(query.Name) {
- session.And("name = ?", query.Name)
- }
- if !gotool.StrUtils.HasEmpty(query.Phone) {
- session.And("phone = ?", query.Phone)
- }
- if !gotool.StrUtils.HasEmpty(query.Province) {
- session.And("province = ?", query.Province)
- }
- if !gotool.StrUtils.HasEmpty(query.City) {
- session.And("city = ?", query.City)
- }
- if !gotool.StrUtils.HasEmpty(query.AreaCode) {
- session.And("area_code = ?", query.AreaCode)
- }
- if !gotool.StrUtils.HasEmpty(query.District) {
- session.And("district = ?", query.District)
- }
- if !gotool.StrUtils.HasEmpty(query.Detail) {
- session.And("detail = ?", query.Detail)
- }
- if !gotool.StrUtils.HasEmpty(query.PostCode) {
- session.And("post_code = ?", query.PostCode)
- }
- if !gotool.StrUtils.HasEmpty(query.Longitude) {
- session.And("longitude = ?", query.Longitude)
- }
- if !gotool.StrUtils.HasEmpty(query.Latitude) {
- session.And("latitude = ?", query.Latitude)
- }
- if query.IsDefault > 0 {
- session.And("is_default = ?", query.IsDefault)
- }
- if query.IsDel > 0 {
- session.And("is_del = ?", query.IsDel)
- }
- if !gotool.StrUtils.HasEmpty(query.BeginTime) {
- session.And("date_format(u.create_time,'%y%m%d') >= date_format(?,'%y%m%d')", query.BeginTime)
- }
- if !gotool.StrUtils.HasEmpty(query.EndTime) {
- session.And("date_format(u.create_time,'%y%m%d') <= date_format(?,'%y%m%d')", query.EndTime)
- }
- session.Desc("id")
- err := session.Find(list)
- if err != nil {
- frame.Throw(frame.SQL_CODE, "数据查询错误"+err.Error())
- }
- }
|