package models import ( "fmt" "zhiyuan/pkg/db" "github.com/gin-gonic/gin" ) type ASOrder struct { ID int `json:"id"` No int `json:"no"` MainType int `json:"main_type"` SubType int `json:"sub_type"` Origin int `json:"origin"` UserID int `json:"user_id"` CommentID int `json:"comment_id"` LinkName string `json:"link_name"` LinkPhone string `json:"link_phone"` RepairID int `json:"repair_id"` State int `json:"state"` ScheduledTime int `json:"scheduled_time"` InWarranty int `json:"in_warranty"` Leader int `json:"leader"` IsForce int `json:"is_force"` CreatedAt int `json:"created_at"` UpdatedAt int `json:"updated_at"` StartTime int64 `json:"start_time"` EndTime int64 `json:"end_time"` IncompleteCount int64 `json:"incomplete_count"` } func (ASOrder) TableName() string { return "zy_as_order" } func (o ASOrder) GetOne(where map[string]interface{}, fields []string, retVal interface{}) (*ASOrder, error) { if retVal == nil { var order *ASOrder err := db.GetOne(o.TableName(), where, fields, &order) return order, err } else { err := db.GetOne(o.TableName(), where, fields, retVal) return nil, err } } func (o ASOrder) GetMulti(where map[string]interface{}, fields []string, retVal interface{}) ([]*ASOrder, error) { if retVal == nil { var order []*ASOrder err := db.GetMulti(o.TableName(), where, fields, &order) return order, err } else { err := db.GetMulti(o.TableName(), where, fields, retVal) return nil, err } } type ASOrderStatist struct { Time int64 `json:"time" prop:"select:FROM_UNIXTIME(created_at,'%Y-%m')"` Counts int64 `json:"count" prop:"select:count(id)"` db.BaseModel } func (ASOrderStatist) TableName() string { return "zy_as_order" } func (model ASOrderStatist) GroupBy() string { return "FROM_UNIXTIME(created_at,'%Y-%m') DESC" } func (model ASOrderStatist) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } type ASOrderYear struct { Year string `json:"year" prop:"select:DATE_FORMAT(FROM_UNIXTIME(created_at),'%Y')"` Counts int64 `json:"count" prop:"select:count(id)"` EndCounts int64 `json:"end_count" prop:"select:count(if(state=90,id,NULL))"` db.BaseModel } func (ASOrderYear) TableName() string { return "zy_as_order" } func (model ASOrderYear) GroupBy() string { return fmt.Sprintf("DATE_FORMAT(FROM_UNIXTIME(`%s`.`created_at`), '%%Y')", model.TableName()) } func (model ASOrderYear) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } type ASOrderType struct { MainType int64 `json:"main_type" prop:"select:main_type"` SubType int64 `json:"sub_type" prop:"select:sub_type"` MainTypeName string `json:"main_type_name" prop:"select:mainastype.type_name"` SubTypeName string `json:"sub_type_name" prop:"select:subastype.type_name"` Counts int64 `json:"count" prop:"select:count(zy_as_order.id)"` db.BaseModel } func (ASOrderType) TableName() string { return "zy_as_order" } func (model ASOrderType) GroupBy() string { return fmt.Sprintf("`%s`.`sub_type`", model.TableName()) } func (model ASOrderType) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } func (model ASOrderType) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return []db.JoinModel{{ Model: JoinASType{}, As: "mainastype", On: []string{"`mainastype`.`id` = " + model.TableName() + ".`main_type`"}, }, { Model: JoinASType{}, As: "subastype", On: []string{"`subastype`.`id` = " + model.TableName() + ".`sub_type`"}, }} } type JoinASType struct { db.BaseModel } func (JoinASType) TableName() string { return "zy_as_type" } type ASOrderIncompleteStatic struct { Username string `json:"username" prop:"select:leader.username" search:"like"` Leader int64 `json:"leader" prop:"select:zy_as_order.leader"` IncompleteCount int64 `json:"incomplete_count" prop:"select:sum(zy_as_order.incomplete_count)"` db.BaseModel } func (ASOrderIncompleteStatic) TableName() string { return "zy_as_order" } func (model ASOrderIncompleteStatic) GroupBy() string { return fmt.Sprintf("`%s`.`leader`", model.TableName()) } func (model ASOrderIncompleteStatic) OrderBy() string { return "sum(zy_as_order.incomplete_count) desc" } func (model ASOrderIncompleteStatic) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } func (model ASOrderIncompleteStatic) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return []db.JoinModel{{ Model: Admin{}, As: "leader", On: []string{"`leader`.`id` = " + model.TableName() + ".`leader`"}, }} } func (ASOrderIncompleteStatic) Page() bool { return false } func (ASOrderIncompleteStatic) Count() bool { return true }