123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package model
- import (
- "github.com/jinzhu/gorm"
- "time"
- )
- type TCompany struct {
- Id int64 `gorm:"column:ID;primary_key" json:"id" form:"id"`
- Name string `gorm:"column:Name" json:"name" form:"name"`
- SocialCode string `gorm:"column:SocialCode" json:"social_code" form:"social_code"`
- LegalPerson string `gorm:"column:LegalPerson" json:"legal_person" form:"legal_person"`
- IdCert string `gorm:"column:IdCert" json:"id_cert" form:"id_cert"`
- BusinessLicense string `gorm:"column:BusinessLicense" json:"business_license" form:"business_license"`
- UserName string `gorm:"column:UserName" json:"user_name" form:"user_name"`
- Passwd string `gorm:"column:Passwd" json:"passwd" form:"passwd"`
- BusinessContact string `gorm:"column:BusinessContact" json:"business_contact" form:"business_contact"`
- BusinessContactPhone string `gorm:"column:BusinessContactPhone" json:"business_contact_phone" form:"business_contact_phone"`
- BusinessResponsible string `gorm:"column:BusinessResponsible" json:"business_responsible" form:"business_responsible"`
- BusinessResponsiblePhone string `gorm:"column:BusinessResponsiblePhone" json:"business_responsible_phone" form:"business_responsible_phone"`
- EmergencyContact string `gorm:"column:EmergencyContact" json:"emergency_contact" form:"emergency_contact"`
- EmergencyContactPhone string `gorm:"column:EmergencyContactPhone" json:"emergency_contact_phone" form:"emergency_contact_phone"`
- Province string `gorm:"column:Province" json:"province" form:"province"`
- City string `gorm:"column:City" json:"city" form:"city"`
- Zone string `gorm:"column:Zone" json:"zone" form:"zone"`
- Status int64 `gorm:"column:Status" json:"status" form:"status"`
- Feedback string `gorm:"column:Feedback"`
- ApproveTime time.Time `gorm:"column:ApproveTime"`
- Email string `gorm:"column:Email"`
- CreatedAt time.Time `gorm:"column:CreatedAt" json:"created_at" form:"created_at"`
- UpdatedAt time.Time `gorm:"column:UpdatedAt" json:"updated_at" form:"updated_at"`
- Reviewer string `gorm:"column:Reviewer"`
- }
- var PageSize = 10
- func (TCompany) TableName() string {
- return "Company"
- }
- func (p *TCompany) Insert(db *gorm.DB) error {
- return db.Table(p.TableName()).Create(p).Error
- }
- func (p *TCompany) Find(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) error {
- cond, val, err := whereBuildAndOr(where, or)
- if err != nil {
- return err
- }
- return db.Table(p.TableName()).Where(cond, val...).First(p).Error
- }
- func (p *TCompany) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- return db.Table(p.TableName()).Table(p.TableName()).Where(cond, val...).Updates(values).Error
- }
- func (p *TCompany) FindSort(db *gorm.DB, where map[string]interface{}, sort string) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- ps := []TCompany{}
- err = db.Table(p.TableName()).Where(cond, val...).Order(sort).Limit(1).Find(&ps).Error
- if err != nil {
- return err
- }
- if len(ps) > 0 {
- *p = ps[0]
- }
- return nil
- }
- func (p *TCompany) List(db *gorm.DB, where map[string]interface{}, page int) (list []TCompany, err error) {
- offset := (page - 1) *PageSize
- if len(where) > 0 {
- cond, val, err := whereBuild(where)
- if err != nil {
- return list, err
- }
- result := db.Table(p.TableName()).Where(cond, val...).Limit(PageSize).Offset(offset).Find(&list)
- return list, result.Error
- }
- result := db.Table(p.TableName()).Limit(10).Offset(page).Find(&list)
- return list, result.Error
- }
- func (p *TCompany) All(db *gorm.DB) (list []TCompany, err error) {
- result := db.Table(p.TableName()).Find(&list)
- return list, result.Error
- }
- func (p *TCompany) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
- if len(where) > 0 {
- cond, val, err := whereBuild(where)
- if err != nil {
- return 0, err
- }
- ret := int64(0)
- err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
- return ret, err
- }
- ret := int64(0)
- err := db.Table(p.TableName()).Count(&ret).Error
- return ret, err
- }
- func (p *TCompany) Del(db *gorm.DB, where map[string]interface{}) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
- }
|