123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- 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
- }
|