package user import ( "zhiyuan/pkg/app" "zhiyuan/pkg/utils" "zhiyuan/services/user" "zhiyuan/services/work/worksite" "zhiyuan/services/work/worksiteclock" "github.com/gin-gonic/gin" ) func WorkSiteList(c *gin.Context) { page := app.HandlePageNums(c) where := map[string]string{ "where": "`zy_work_site`.`id`>0 AND `zy_work_site`.`deleted_at`=0", "_group_by": "`zy_work_site`.`id`", "_order_by": "`zy_work_site`.`id` desc", } if page.PageSize != 0 { where["_page_size"] = utils.ToStr(page.PageSize) where["_page_num"] = utils.ToStr(page.PageNum) } param := make(map[string]interface{}) username := c.Query("username") if username != "" { where["where"] = where["where"] + " AND `zy_work_site`.`username` LIKE {{username}}" param["username"] = "%" + username + "%" } phone := c.Query("phone") if phone != "" { where["where"] = where["where"] + " AND `zy_work_site`.`phone` LIKE {{phone}}" param["phone"] = "%" + phone + "%" } village := c.Query("village") if village != "" { where["where"] = where["where"] + " AND `zy_work_site`.`village` LIKE {{village}}" param["village"] = "%" + village + "%" } address := c.Query("address") if address != "" { where["where"] = where["where"] + " AND `zy_work_site`.`address` LIKE {{address}}" param["address"] = "%" + address + "%" } room_no := c.Query("room_no") if room_no != "" { where["where"] = where["where"] + " AND `zy_work_site`.`room_no` LIKE {{room_no}}" param["room_no"] = "%" + room_no + "%" } area := c.Query("area") if area != "" { where["where"] = where["where"] + " AND `zy_work_site`.`area` LIKE {{area}}" param["area"] = "%" + area + "%" } state := utils.ToInt(c.Query("state")) if state != 0 { where["where"] = where["where"] + " AND `zy_work_site`.`state`={{state}}" param["state"] = state } userInfo, err := user.GetInfoByID(c.GetInt("userID"), nil, nil) if userInfo == nil || err != nil { app.ErrorMsg(c, err.Error(), nil) return } where["where"] = where["where"] + " AND `zy_work_site`.`phone` = {{phone}}" param["phone"] = userInfo.Phone total, err := worksite.CountRaw(where["where"], param) if err != nil { app.Error(c, err.Error()) return } type WorksiteList struct { ID int `json:"id"` Username string `json:"username"` Phone string `json:"phone"` Village string `json:"village"` Address string `json:"address"` RoomNo string `json:"room_no"` Area string `json:"area"` Longitude string `json:"longitude"` Latitude string `json:"latitude"` ManagerId int `json:"manager_id"` DesignerId int `json:"designer_id"` CreatedId int `json:"created_id"` AdminIds string `json:"admin_ids"` StartTime int `json:"starttime"` EndTime int `json:"endtime"` State int `json:"state"` CreatedAt int `json:"created_at"` UpdatedAt int `json:"updated_at"` ManagerName string `json:"manager_name"` ManagerPhone string `json:"manager_phone"` DesignerName string `json:"designer_name"` DesignerPhone string `json:"designer_phone"` CreatedName string `json:"created_name"` AdminNames string `json:"admin_names"` } worksiteList := make([]WorksiteList, 0) if err = worksite.GetWorkSitesRaw(where, param, &worksiteList); err != nil { app.Error(c, err.Error()) return } data := gin.H{ "list": worksiteList, "total": total, "limit": page.PageSize, } app.Success(c, data) } func WorkSiteClockList(c *gin.Context) { page := app.HandlePageNum(c) where := map[string]string{ "where": "`zy_work_site_clock`.`id`>0 AND `zy_work_site_clock`.`deleted_at`=0 AND `zy_work_site_clock`.`state`=1", "_order_by": "`zy_work_site_clock`.`id` desc", } if page.PageSize != 0 { where["_page_size"] = utils.ToStr(page.PageSize) where["_page_num"] = utils.ToStr(page.PageNum) } param := make(map[string]interface{}) site_id := utils.ToInt(c.Query("site_id")) if site_id != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_id`={{site_id}}" param["site_id"] = site_id } site_node_id := utils.ToInt(c.Query("site_node_id")) if site_node_id != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_node_id`={{site_node_id}}" param["site_node_id"] = site_node_id } staff_type := utils.ToInt(c.Query("staff_type")) if staff_type != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`staff_type`={{staff_type}}" param["staff_type"] = staff_type } staff_id := utils.ToInt(c.Query("staff_id")) if staff_id != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`staff_id`={{staff_id}}" param["staff_id"] = staff_id } starttime := utils.ToInt(c.Query("starttime")) if starttime != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` >= {{starttime}}" param["starttime"] = starttime } endtime := utils.ToInt(c.Query("endtime")) if endtime != 0 { where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` <= {{endtime}}" param["endtime"] = endtime } total, err := worksiteclock.CountRaw(where["where"], param) if err != nil { app.Error(c, err.Error()) return } type WorkSiteClockList struct { ID int `json:"id"` SiteId int `json:"site_id"` SiteNodeId int `json:"site_node_id"` StaffType int `json:"staff_type"` StaffId int `json:"staff_id"` Pictures string `json:"pictures"` Content string `json:"content"` Type int `json:"type"` State int `json:"state"` CreatedAt int `json:"created_at"` UpdatedAt int `json:"updated_at"` StaffName string `json:"staff_name"` StaffPhone string `json:"staff_phone"` NodeName string `json:"node_name"` } workSiteClockList := make([]WorkSiteClockList, 0) if err = worksiteclock.GetWorkSiteClocksRaw(where, param, &workSiteClockList); err != nil { app.Error(c, err.Error()) return } data := gin.H{ "list": workSiteClockList, "total": total, "limit": page.PageSize, } app.Success(c, data) }