package company import ( "fmt" "recook/internal/model/user" "recook/internal/v2/model/recook/manage" "time" "github.com/golangkit/formatime" "github.com/shopspring/decimal" "gorm.io/gorm" ) type State uint const ( Wait State = iota + 1 Pass Reject ) var stateMap = map[State]string{ Wait: "待审核", Pass: "已通过", Reject: "已驳回", } func (o State) Str() string { return stateMap[o] } type Status uint const ( Normal Status = iota + 1 Disable ) var statusMap = map[Status]string{ Normal: "正常", Disable: "禁用", } func (o Status) Str() string { return statusMap[o] } type Info struct { ID uint `json:"id"` ShopName string `json:"shop_name" ` Mobile string `json:"mobile"` ContractName string `json:"contract_name"` ContractMobile string `json:"contract_mobile"` ContractEmail string `json:"contract_email"` ProcessUserID uint `json:"-"` ProcessUserInfo manage.RecookManageUserInfoModel `json:"-" gorm:"foreignKey:process_user_id"` ProcessUserName string `json:"process_user_name" gorm:"-"` ProcessTime formatime.Second `json:"process_time"` ContractNo string `json:"contract_no"` ContractStart formatime.Second `json:"contract_start"` ContractEnd formatime.Second `json:"contract_end"` ContractAttach string `json:"contract_attach"` CompanyName string `json:"company_name"` RegisterAddress string `json:"register_address"` BusinessAddress string `json:"business_address"` BusinessStart formatime.Second `json:"business_start"` BusinessEnd formatime.Second `json:"business_end"` BusinessPhoto string `json:"business_photo"` BusinessPerson string `json:"business_person"` TaxType string `json:"tax_type" validate:"required,oneof=一般纳税人 小规模纳税人"` TaxBank string `json:"tax_bank"` TaxNumber string `json:"tax_number"` TaxAccount string `json:"tax_account"` TaxPhoto string `json:"tax_photo"` TaxProve string `json:"tax_prove"` CreatedAt formatime.Second `json:"created_at"` ApplyUserID uint `json:"-"` ApplyUserInfo manage.RecookManageUserInfoModel `json:"-" gorm:"foreignKey:apply_user_id"` ApplyUserName string `json:"apply_user_name" gorm:"-"` State State `json:"state"` StateStr string `json:"state_str" gorm:"-"` Status Status `json:"status"` StatusStr string `json:"status_str" gorm:"-"` Logs []Log `json:"log" gorm:"foreignKey:company_id"` Count int64 `json:"count" gorm:"-"` UserID uint `json:"-"` Password string `json:"password"` Tax decimal.Decimal `json:"tax"` TaxBillType string `json:"tax_bill_type"` } func (o *Info) TableName() string { return "jyy_company_info" } func (o *Info) AfterFind(tx *gorm.DB) error { fmt.Println(123) o.ProcessUserName = o.ProcessUserInfo.Name o.ApplyUserName = o.ApplyUserInfo.Name o.StateStr = o.State.Str() o.StatusStr = o.Status.Str() return nil } type Log struct { ID uint `json:"id"` Text string `json:"text"` UserID uint `json:"-"` ManageUserInfo manage.RecookManageUserInfoModel `json:"-" gorm:"references:user_id;foreignKey:id"` ManageUserName string `json:"manage_user_name" gorm:"-"` CreatedAt formatime.Second `json:"created_at"` CompanyID uint `json:"company_id"` } func (o Log) TableName() string { return "jyy_company_log" } func (o *Log) AfterFind(tx *gorm.DB) error { o.ManageUserName = o.ManageUserInfo.Name return nil } type Apply struct { ID int `json:"id" gorm:"primaryKey;autoIncrement"` UserID int `json:"-" ` Amount decimal.Decimal `json:"amount"` State int `json:"state"` CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"` Content string `json:"content" gorm:"<-:update"` Proof string `json:"proof" gorm:"<-:update"` Tax int `json:"tax" validate:"oneof=1 2"` LogisticsName string `json:"logistics_name"` WaybillCode string `json:"waybill_code"` ApplyUserID int `json:"-"` ApplyUser *manage.RecookManageUserInfoModel `json:"-" gorm:"foreignKey:ApplyUserID"` ApplyUserName string `json:"apply_user_name" gorm:"-"` ApplyTime *time.Time `json:"apply_time" gorm:"<-:update"` ProcessUserID int `json:"-"` ProcessUser *manage.RecookManageUserInfoModel `json:"-" gorm:"foreignKey:ProcessUserID"` ProcessUserName string `json:"process_user_name" gorm:"-"` ProcessTime *time.Time `json:"process_time" gorm:"<-:update"` CompanyID int `json:"-"` Company *Info `json:"-" gorm:"foreignKey:CompanyID"` Bank string `json:"bank" gorm:"-"` Code string `json:"code" gorm:"-"` CompanyName string `json:"comapny_name" gorm:"-"` User *user.Information `json:"-" gorm:"foreignKey:UserID"` Mobile string `json:"mobile" gorm:"-"` Nickname string `json:"nickname" gorm:"-"` } func (o Apply) TableName() string { return "jyy_company_apply" } func (o *Apply) AfterFind(db *gorm.DB) error { if o.ApplyUser != nil { o.ApplyUserName = o.ApplyUser.Name } if o.ProcessUser != nil { o.ProcessUserName = o.ProcessUser.Name } if o.Company != nil { o.Bank = o.Company.TaxBank o.Code = o.Company.TaxAccount o.CompanyName = o.Company.CompanyName } if o.User != nil { o.Mobile = o.User.Mobile o.Nickname = o.User.Nickname } return nil }