123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package work
- import (
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/work/worksiteclock"
- "github.com/gin-gonic/gin"
- )
- func WorkSiteClockList(c *gin.Context) {
- page := app.HandlePageNums(c)
- where := map[string]string{
- "where": "`zy_work_site_clock`.`id`>0 AND `zy_work_site_clock`.`deleted_at`=0",
- "_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
- }
- state := utils.ToInt(c.Query("state"))
- if state != 0 {
- where["where"] = where["where"] + " AND `zy_work_site_clock`.`state`={{state}}"
- param["state"] = state
- }
- 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)
- }
- func WorkSiteClockVerify(c *gin.Context) {
- id := utils.ToInt(c.Param("id"))
- if id <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- err := worksiteclock.VerifyByID(id, c.GetInt("adminID"))
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
|