123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package mysqlLy
- import (
- orm "duoduo/database"
- "github.com/shopspring/decimal"
- "time"
- )
- type Pets struct {
- ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
- UserID int64 `gorm:"column:user_id;type:bigint(20)" json:"user_id"`
- Name string `gorm:"column:name;type:varchar(64)" json:"name"`
- Pet string `gorm:"column:pet;type:varchar(64)" json:"pet"`
- Age string `gorm:"column:age;type:varchar(16)" json:"age"`
- Sex string `gorm:"column:sex;type:varchar(4)" json:"sex"`
- PetStatus int `gorm:"column:pet_status;type:tinyint(4)" json:"pet_status"`
- PetDes string `gorm:"column:pet_des;type:varchar(16)" json:"pet_des"`
- IsSterilization int `gorm:"column:is_sterilization;type:tinyint(4)" json:"is_sterilization"`
- IsExpellingParasite int `gorm:"column:is_expelling_parasite;type:tinyint(4)" json:"is_expelling_parasite"`
- IsImmune int `gorm:"column:is_immune;type:tinyint(4)" json:"is_immune"`
- IsFee int `gorm:"column:is_fee;type:tinyint(4)" json:"is_fee"`
- Deposit decimal.Decimal `gorm:"column:deposit;type:decimal(10,2)" json:"deposit"`
- DepositDate time.Time `gorm:"column:deposit_date;type:date;default:null" json:"deposit_date"`
- Amount decimal.Decimal `gorm:"column:amount;type:decimal(10,2)" json:"amount"`
- Province string `gorm:"column:province;type:varchar(16)" json:"province"`
- City string `gorm:"column:city;type:varchar(16)" json:"city"`
- Area string `gorm:"column:area;type:varchar(16)" json:"area"`
- PetInfo string `gorm:"column:pet_info;type:text" json:"pet_info"`
- AdoptInfo string `gorm:"column:adopt_info;type:text" json:"adopt_info"`
- Pictures string `gorm:"column:pictures;type:json" json:"pictures"`
- Status int `gorm:"column:status;type:tinyint(4)" json:"status"`
- CreateTime time.Time `gorm:"column:create_time;type:datetime" json:"create_time"`
- UpdateTime time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
- OpenId string `gorm:"column:open_id;type:varchar(255)" json:"open_id"`
- }
- func (m *Pets) TableName() string {
- return "pets"
- }
- func (m *Pets) Create() (Pets, error) {
- var doc Pets
- result := orm.LyMysql.Table(m.TableName()).Create(&m)
- if result.Error != nil {
- err := result.Error
- return doc, err
- }
- doc = *m
- return doc, nil
- }
- func (m *Pets) GetPetsList(pageSize int, pageIndex int) ([]Pets, int, error) {
- var doc []Pets
- table := orm.LyMysql.Table(m.TableName())
- if m.OpenId != "" {
- table = table.Where("open_id = ? ", m.OpenId)
- }
- if m.Pet != "" {
- table = table.Where("pet = ? ", m.Pet)
- }
- if m.City != "" {
- table = table.Where("city = ?", m.City)
- }
- if m.Status != 0 {
- table = table.Where("status = ?", m.Status)
- }
- if m.IsFee == 1 || m.IsFee == 2 {
- table = table.Where("is_fee in (1,2)")
- } else if m.IsFee == 3 {
- table = table.Where("is_fee = 3")
- }
- var count int
- if err := table.Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
- return nil, 0, err
- }
- table.Count(&count)
- return doc, count, nil
- }
- func (m *Pets) Get() (Pets, error) {
- var doc Pets
- err := orm.LyMysql.Where("id = ? ", m.ID).Table(m.TableName()).First(&doc).Error
- if err != nil {
- return doc, err
- }
- return doc, nil
- }
|