package models import ( orm "go-admin/common/global" "go-admin/logger" ) type Store struct { Model Name string `json:"name"` // 门店名称 Img string `json:"img"` // 门面图 Tel string `json:"tel" gorm:"type:varchar(20)"` // 电话 Province string `json:"province" gorm:"type:varchar(100)"` // 省 City string `json:"city" gorm:"type:varchar(100)"` // 市 District string `json:"district" gorm:"type:varchar(100)"` // 区 Address string `json:"address" gorm:"type:varchar(100)"` // 详细地址 Longitude float64 `json:"longitude" gorm:"column:longitude"` // 经度 Latitude float64 `json:"latitude" gorm:"column:latitude"` // 纬度 IsOnline uint32 `json:"is_online"` // 在线 CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` // 合作商id CooperativeName string `json:"cooperative_name"` // 合作商名称 DebitCardServiceState uint32 `json:"debit_card_service_state"` // 借卡服务状态:1-未开启 2-开启 //CooperativeAssistantMemberDeduct *CooperativeAssistantMemberDeduct `json:"cooperative_assistant_member_deduct" gorm:"-"` } func (*Store) TableName() string { return "store" } type GetCooperativeStoreReq struct { Name string `json:"name"` CooperativeBusinessId uint32 `json:"cooperative_business_id"` // 合作商id CooperativeName string `json:"cooperative_name"` // 合作商名称 //SysType uint32 `json:"sys_type"` // 1-管理系统 2-合作商系统 SysUid string `json:"sys_uid"` Page int `json:"pageIndex"` PageSize int `json:"pageSize"` } func (m *Store) Add() error { err := orm.Eloquent.Create(m).Error if err != nil { logger.Errorf("err:", err) return err } return nil } func (m *Store) Modify() error { para := m.getModifyPara() if len(para) > 0 { err := orm.Eloquent.Table(m.TableName()).Unscoped().Where("id", m.ID).Updates(para).Error if err != nil { logger.Errorf("err:", err) return err } } return nil } func (m *Store) getModifyPara() map[string]interface{} { paraMap := make(map[string]interface{}, 0) if m.Name != "" { paraMap["name"] = m.Name } if m.Img != "" { paraMap["img"] = m.Img } if m.Tel != "" { paraMap["tel"] = m.Tel } if m.Province != "" { paraMap["province"] = m.Province } if m.City != "" { paraMap["city"] = m.City } if m.District != "" { paraMap["district"] = m.District } if m.Address != "" { paraMap["address"] = m.Address } if m.Longitude != 0 { paraMap["longitude"] = m.Longitude } if m.Latitude != 0 { paraMap["latitude"] = m.Latitude } return paraMap } func (m *Store) MDel(ids []uint32) error { err := orm.Eloquent.Table(m.TableName()).Unscoped().Where("id in (?)", ids).Delete(m).Error if err != nil { logger.Errorf("err:", err) return err } return nil } func GetStore(id uint32) (*Store, error) { var store Store err := orm.Eloquent.Table("store").Where("id=?", id).Find(&store).Error if err != nil { logger.Errorf("err:", err) return &store, err } return &store, nil } func GetStoreIdsByCooperativeBusinessId(id uint32) ([]uint32, error) { ids := make([]uint32, 0) var stores []Store err := orm.Eloquent.Table("store").Where("cooperative_business_id=?", id).Find(&stores).Error if err != nil { logger.Errorf("err:", err) return ids, err } for i, _ := range stores { ids = append(ids, stores[i].ID) } return ids, nil }