123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package match
- import (
- "fmt"
- /*"strconv"
- "strings"*/
- "time"
- "zhiyuan/models"
- "zhiyuan/pkg/db"
- adminParam "zhiyuan/pkg/param/admin"
- /*"zhiyuan/services/admin"
- "zhiyuan/services/dept"*/
- "github.com/gin-gonic/gin"
- )
- type MatchOrder struct {
- ID int64 `json:"id" prop:"add:false"`
- AdminId int64 `json:"adminId" type:"int" prop:"add" search:"="`
- Halfs int64 `json:"halfs" type:"int" default:"0" search:"="`
- Content string `json:"content" type:"string" prop:"add"`
- Path string `json:"path" type:"string" prop:"add"`
- DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
- CreatedAt int64 `json:"created_at" prop:"add:false"`
- UpdatedAt int64 `json:"updated_at" prop:"add:false"`
- AdminName string `json:"admin_name" prop:"select:admin.username" search:"like"`
- db.BaseModel
- }
- func (MatchOrder) TableName() string {
- return "zy_match_order"
- }
- func (model MatchOrder) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
- /*if !admin.IsSuperAdmin(c.GetInt("adminID")) {
- var adminInfo *models.Admin
- admin.GetInfoByID(c.GetInt("adminID"), nil, &adminInfo)
- if adminInfo == nil {
- return false
- }
- adminRole := false
- roleSlice := strings.Split(adminInfo.RoleIds, ",")
- for _, v := range roleSlice {
- if role, err := strconv.Atoi(v); err == nil && (role == adminParam.AdminRoleId) {
- adminRole = true
- break
- }
- }
- if !adminRole {
- s.Where = append(s.Where, fmt.Sprintf("`admin`.`dept_id` IN %s", s.Param(dept.GetSubDeptIds(adminInfo.DeptID, []int{adminInfo.DeptID}))))
- }
- }*/
- return true
- }
- func (MatchOrder) OnePrivilege(c *gin.Context, id int64) bool {
- return true
- }
- func (model MatchOrder) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
- return []db.JoinModel{
- {
- Model: models.Admin{},
- As: "admin",
- On: []string{
- "`admin`.`id` = " + model.TableName() + ".`adminId`",
- },
- },
- }
- }
- func (MatchOrder) Page() bool {
- return false
- }
- func (MatchOrder) Count() bool {
- return true
- }
- type MatchStatist struct {
- ID int `json:"id"`
- Username string `json:"username" search:"like"`
- Phone string `json:"phone"`
- RoleIds string `json:"role_ids" search:"find_in_set"`
- LastTime int64 `json:"lasttime" prop:"select:order.created_at"`
- Halfs int64 `json:"halfs" prop:"select:order.halfs"`
- State int64 `json:"state" label:"状态" type:"int" prop:"select:if(isnull(order.id),0,if(order.halfs=0,1,2))" search:"="`
- db.BaseModel
- }
- func (MatchStatist) TableName() string {
- return "zy_admin"
- }
- func (model MatchStatist) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
- s.Where = append(s.Where, fmt.Sprintf("find_in_set('%d', `%s`.`role_ids`)", adminParam.DivisionDirectorRoleId, model.TableName()))
- return true
- }
- func (model MatchStatist) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
- tt := time.Now()
- if t, ok := data["time"]; ok {
- if ti, ok := db.ToInt64(t); ok {
- tt = time.Unix(ti, 0)
- }
- }
- offset := int(time.Monday - tt.Weekday())
- if offset > 0 {
- offset -= 7
- }
- starttime := time.Date(tt.Year(), tt.Month(), tt.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset).Unix()
- endtime := starttime + (5*24+12)*3600
- return []db.JoinModel{
- {
- Model: MatchOrder{},
- As: "order",
- On: []string{
- fmt.Sprintf("`order`.`id` in (select max(id) from zy_match_order where `zy_match_order`.`adminId` = "+model.TableName()+".`id` and `zy_match_order`.`created_at` >= %s and `zy_match_order`.`created_at` < %s group by `zy_match_order`.`adminId`)", s.Param(starttime), s.Param(endtime)),
- },
- },
- }
- }
- func (MatchStatist) Page() bool {
- return false
- }
- func (MatchStatist) Count() bool {
- return true
- }
|