package models import ( "fmt" "zhiyuan/pkg/db" "github.com/gin-gonic/gin" ) type UserHouse struct { ID int `json:"id"` UserID int `json:"user_id"` District int `json:"district"` Area string `json:"area"` Address string `json:"address"` PkgID int `json:"pkg_id"` ShopID int `json:"shop_id"` Salesman int `json:"salesman"` ProjectManager int `json:"project_manager"` ProjectLeader int `json:"project_leader"` Designer string `json:"designer"` Supervisor int `json:"supervisor"` LinkName string `json:"link_name"` LinkPhone string `json:"link_phone"` WarrantyStart int `json:"warranty_start"` WarrantyEnd int `json:"warranty_end"` WarrantyMark string `json:"warranty_mark"` InWarranty int `json:"in_warranty"` WarrantyPeriodBase int `json:"warranty_period_base"` WarrantyPeriodMaterial int `json:"warranty_period_material"` WarrantyPeriodElectric int `json:"warranty_period_electric"` Mark string `json:"mark"` CreatedAt int `json:"created_at"` UpdatedAt int `json:"updated_at"` } func (UserHouse) TableName() string { return "zy_user_house" } func (u UserHouse) GetOne(where map[string]interface{}, fields []string, retVal interface{}) (*UserHouse, error) { if retVal == nil { var userHouse *UserHouse err := db.GetOne(u.TableName(), where, fields, &userHouse) return userHouse, err } else { err := db.GetOne(u.TableName(), where, fields, retVal) return nil, err } } func (u UserHouse) GetMulti(where map[string]interface{}, fields []string, retVal interface{}) ([]*UserHouse, error) { if retVal == nil { var userHouse []*UserHouse err := db.GetMulti(u.TableName(), where, fields, &userHouse) return userHouse, err } else { err := db.GetMulti(u.TableName(), where, fields, retVal) return nil, err } } type UserHouseStatist struct { District int64 `json:"district"` Counts int64 `json:"count" prop:"select:count(id)"` WorkCount int64 `json:"work_count" prop:"select:count(IF(project_end=0,id,NULL))"` WarrantyCount int64 `json:"warranty_count" prop:"select:count(IF((warranty_start!=0)and(date_add(from_unixtime(warranty_start),interval(warranty_period_electric)year)>=now()),id,NULL))"` db.BaseModel } func (UserHouseStatist) TableName() string { return "zy_user_house" } func (model UserHouseStatist) GroupBy() string { return fmt.Sprintf("`%s`.`district`", model.TableName()) } func (model UserHouseStatist) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } type UserHouseYear struct { Year string `json:"year" prop:"select:DATE_FORMAT(FROM_UNIXTIME(created_at),'%Y')"` Counts int64 `json:"count" prop:"select:count(id)"` WorkCount int64 `json:"work_count" prop:"select:count(IF(project_end=0,id,NULL))"` WarrantyCount int64 `json:"warranty_count" prop:"select:count(IF((warranty_start!=0)and(date_add(from_unixtime(warranty_start),interval(warranty_period_electric)year)>=now()),id,NULL))"` db.BaseModel } func (UserHouseYear) TableName() string { return "zy_user_house" } func (model UserHouseYear) GroupBy() string { return fmt.Sprintf("DATE_FORMAT(FROM_UNIXTIME(`%s`.`created_at`), '%%Y')", model.TableName()) } func (model UserHouseYear) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } type UserHouseJoin struct { db.BaseModel } func (UserHouseJoin) TableName() string { return "zy_user_house" } type UserHouseMonth struct { Date string `json:"date" prop:"select:month.date"` ElectricWarrantyCount int64 `json:"electric_warranty_count" prop:"select:count(IF((userhouse.warranty_start!=0)and(date_add(from_unixtime(userhouse.warranty_start),interval(userhouse.warranty_period_electric)year)>=STR_TO_DATE(month.date,'%Y-%m-%d')),id,NULL))"` MaterialWarrantyCount int64 `json:"material_warranty_count" prop:"select:count(IF((userhouse.warranty_start!=0)and(date_add(from_unixtime(userhouse.warranty_start),interval(userhouse.warranty_period_material)year)>=STR_TO_DATE(month.date,'%Y-%m-%d')),id,NULL))"` BaseWarrantyCount int64 `json:"base_warranty_count" prop:"select:count(IF((userhouse.warranty_start!=0)and(date_add(from_unixtime(userhouse.warranty_start),interval(userhouse.warranty_period_base)year)>=STR_TO_DATE(month.date,'%Y-%m-%d')),id,NULL))"` db.BaseModel } func (UserHouseMonth) TableName() string { return "((select DATE_FORMAT(CURDATE() - INTERVAL 11 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 10 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 9 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 8 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 7 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 6 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 5 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 4 MONTH,'%Y-%m')) union (select DATE_FORMAT(CURDATE() - INTERVAL 3 MONTH,'%Y-%m')) union (select DATE_FORMAT(CURDATE() - INTERVAL 2 MONTH,'%Y-%m')) union (select DATE_FORMAT(CURDATE() - INTERVAL 1 MONTH,'%Y-%m')) union (select DATE_FORMAT(CURDATE(),'%Y-%m'))) as month" } func (model UserHouseMonth) GroupBy() string { return "`month`.`date`" } func (model UserHouseMonth) DeletedField() string { return "" } func (model UserHouseMonth) OrderBy() string { return "`month`.`date` asc" } func (model UserHouseMonth) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } func (model UserHouseMonth) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return []db.JoinModel{{ Model: UserHouseJoin{}, As: "userhouse", On: []string{"1=1"}, }} }