123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936 |
- package worker
- import (
- "fmt"
- "strings"
- "time"
- "zhiyuan/models"
- "zhiyuan/models/final"
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/db"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/form"
- "zhiyuan/services/role"
- "zhiyuan/services/user"
- "zhiyuan/services/work/worker"
- "zhiyuan/services/work/worksiteclock"
- "github.com/gin-gonic/gin"
- "github.com/gogf/gf/v2/os/gtime"
- "github.com/gogf/gf/v2/util/gconv"
- )
- 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_node`.`worker_id` = {{worker_id}}"
- param["worker_id"] = c.GetInt("workerID")
- res, err := db.GetOneMapRaw("SELECT count(distinct `zy_work_site`.`id`) as count FROM `zy_work_site` left join `zy_work_site_node` on `zy_work_site_node`.`site_id` = `zy_work_site`.`id` WHERE "+where["where"], param)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- total := utils.ToInt64(res["count"])
- 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"`
- }
- field := "SELECT `zy_work_site`.*, `manager`.`username` as `manager_name`, `manager`.`phone` as `manager_phone`, `designer`.`username` as `designer_name`, `designer`.`phone` as `designer_phone`, `created`.`username` as `created_name`, group_concat(`zy_admin`.`username` separator ',') as `admin_names` FROM `zy_work_site` left join `zy_admin` as `manager` on `manager`.`id` = `zy_work_site`.`manager_id` left join `zy_admin` as `designer` on `designer`.`id` = `zy_work_site`.`designer_id` left join `zy_admin` as `created` on `created`.`id` = `zy_work_site`.`created_id` left join `zy_admin` on FIND_IN_SET(`zy_admin`.`id`, `zy_work_site`.`admin_ids`) left join `zy_work_site_node` on `zy_work_site_node`.`site_id` = `zy_work_site`.`id` "
- worksiteList := make([]WorksiteList, 0)
- if err = db.GetMultiRaw(field, 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",
- "_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{})
- if c.GetInt("workerID") != 0 {
- where["where"] = where["where"] + " AND `zy_work_site_clock`.`staff_type`=0 AND `zy_work_site_clock`.`staff_id`={{staff_id}}"
- param["staff_id"] = c.GetInt("workerID")
- }
- 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
- }
- 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"`
- 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 WorkSiteClockAdd(c *gin.Context) {
- var addForm form.WorkSiteClockAdd
- if app.Bind(c, &addForm) != nil {
- return
- }
- id, err := worksiteclock.AddWorker(addForm, c.GetInt("workerID"))
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, gin.H{"id": id})
- }
- func WorkSiteClockEdit(c *gin.Context) {
- id := utils.ToInt(c.Param("id"))
- if id <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- var editForm form.WorkSiteClockEdit
- if app.Bind(c, &editForm) != nil {
- return
- }
- err := worksiteclock.EditByIDWorker(editForm, id, c.GetInt("workerID"))
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
- /*
- * 工人套餐子项列表
- */
- func MatPickWork(c *gin.Context) {
- siteId := utils.ToInt(c.Param("site_id"))
- roomType := utils.ToInt(c.Param("room_type"))
- if siteId <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- list, err := worker.GetWorkerItems(siteId, roomType, c.GetInt("workerID"))
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, list)
- }
- /*
- * 工人开工
- */
- func MatPickWorkStart(c *gin.Context) {
- pickId := utils.ToInt(c.Param("pick_id"))
- if pickId <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
- "id": pickId,
- "worker_id": c.GetInt("workerID"),
- }, map[string]interface{}{
- "worker_start_at": time.Now().Unix(), //工人开始工作时间
- })
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
- /*
- * 工人完成
- */
- func MatPickWorkCompleted(c *gin.Context) {
- pickId := utils.ToInt(c.Param("pick_id"))
- var form form.Workcompleted
- if app.Bind(c, &form) != nil {
- return
- }
- //fmt.Println("工人确认节点", form.Pictures)
- if pickId <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
- "id": pickId,
- "worker_id": c.GetInt("workerID"),
- }, map[string]interface{}{
- "worker_status": 1, //工人已确认状态
- "worker_confirm_at": time.Now().Unix(), //工人完成工作确认时间
- //"pictures": form.Pictures,
- //"content": form.Content,
- })
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- //存入工人提交记录表
- //_, err = db.InsertModel(db.Type(models.WorkAcceptanceLog{}), map[string]interface{}{
- // "type": 2, //1项目经理 2工人 3客服
- // "work_id": pickId,
- // "context": form.Content,
- // "pictures": form.Pictures,
- // "created_id": c.GetInt("workerID"),
- //})
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
- /*
- * 项目经理完成节点
- */
- func ManagerConfirmMatPickWork(c *gin.Context) {
- workId := gconv.Int(c.Param("work_id"))
- if workId < 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- var form form.Workcompleted
- if app.Bind(c, &form) != nil {
- return
- }
- //判断是否超时完成
- var pickwork *final.MatPickWork
- db.GetModel(map[string]interface{}{
- "id": workId,
- }, &pickwork)
- if pickwork == nil {
- app.ErrorMsg(c, "找不到工作节点", nil)
- return
- }
- //找工地
- var site final.FinalSite
- db.GetModel(map[string]interface{}{"id": pickwork.SiteId,
- "deleted_at": 0}, &site)
- if site.ID == 0 {
- app.ErrorMsg(c, "工地不存在", nil)
- return
- }
- if site.ManagerId != c.GetInt64("adminID") {
- fmt.Println("workId", workId)
- fmt.Println("work项目经理Id", site.ManagerId)
- fmt.Println("登录的adminId", c.GetInt("adminID"))
- //todo上线打开
- //app.ErrorMsg(c, "请登录项目经理账号提交", nil)
- //return
- }
- //判断是否审核中
- if pickwork.ItemStatus == 1 {
- app.ErrorMsg(c, "改节点已完成", nil)
- return
- }
- if pickwork.ItemStatus == 2 {
- app.ErrorMsg(c, "审核中,请等待", nil)
- return
- }
- var itemStatus int
- //0:"待提交",
- //1:"已完成",
- //2:"审核中",
- //3:"验收不通过",
- //正常节点确认完成 绿色
- //条件:现在时间> 开始时间 ,现在时间 < 结束时间,并且已确认
- if gtime.Now().Unix() > gtime.New(pickwork.Starttime).Unix() && gtime.Now().Unix() < gtime.New(pickwork.ExampleAt).Unix() {
- //itemStatus = 0
- }
- //超时完成 黄色
- //条件:确认时间 > 结束时间 并且工人已确认
- if gtime.Now().Unix() > gtime.New(pickwork.ExampleAt).Unix() {
- //itemStatus = 0
- }
- itemStatus = 2
- err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
- "id": workId,
- }, map[string]interface{}{
- "manager_status": itemStatus, //已确认
- "manager_confirm_at": time.Now().Unix(), //确认时间
- "item_status": itemStatus,
- })
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- _, err = db.InsertModel(db.Type(models.TaskSubmission{}), map[string]interface{}{
- "site_id": site.ID,
- "work_id": workId,
- "pictures": form.Pictures,
- "content": form.Content,
- "created_at": time.Now().Unix(),
- "review_status": 0, //待审核
- "created_id": c.GetInt64("adminID"),
- })
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
- /*
- * 队长验收通过
- */
- func ManagerAcceptancePassed(c *gin.Context) {
- workId := gconv.Int(c.Param("work_id"))
- if workId < 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- var form form.ReviewOktruct
- if app.Bind(c, &form) != nil {
- return
- }
- //判断是否超时完成
- var pickwork *final.MatPickWork
- db.GetModel(map[string]interface{}{
- "id": workId,
- }, &pickwork)
- if pickwork == nil {
- app.ErrorMsg(c, "找不到工作节点", nil)
- return
- }
- //找工地
- var site final.FinalSite
- db.GetModel(map[string]interface{}{"id": pickwork.SiteId,
- "deleted_at": 0}, &site)
- if site.ID == 0 {
- app.ErrorMsg(c, "工地不存在", nil)
- return
- }
- if site.ProjectLeaderId != c.GetInt64("adminID") {
- fmt.Println("workId", workId)
- fmt.Println("work项目经理Id", site.ManagerId)
- fmt.Println("登录的adminId", c.GetInt("adminID"))
- //todo上线打开
- //app.ErrorMsg(c, "请登录项目经理账号提交", nil)
- //return
- }
- //0:"待提交",
- //1:"已完成",
- //2:"审核中",
- //3:"验收不通过",
- err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
- "id": workId,
- }, map[string]interface{}{
- "item_status": 1, //完成
- })
- if err != nil {
- fmt.Println("errrr", err)
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- //更新提交记录
- UpdateTaskSubmission(form.LogId, 1, "")
- app.Success(c, nil)
- }
- /*
- * 队长验收不通过
- */
- func ManagerAcceptanceFailed(c *gin.Context) {
- workId := gconv.Int(c.Param("work_id"))
- fmt.Println("dispatch ,ManagerAcceptanceFailed")
- if workId < 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- var form form.Reviewstruct
- if app.Bind(c, &form) != nil {
- return
- }
- var pickwork *final.MatPickWork
- db.GetModel(map[string]interface{}{
- "id": workId,
- }, &pickwork)
- fmt.Println("workId", workId)
- fmt.Println("pickwork", pickwork)
- if pickwork == nil {
- app.ErrorMsg(c, "找不到工作节点", nil)
- return
- }
- //找工地
- var site final.FinalSite
- db.GetModel(map[string]interface{}{"id": pickwork.SiteId,
- "deleted_at": 0}, &site)
- if site.ID == 0 {
- app.ErrorMsg(c, "工地不存在", nil)
- return
- }
- if site.ProjectLeaderId != c.GetInt64("adminID") {
- fmt.Println("workId", workId)
- fmt.Println("work项目经理Id", site.ManagerId)
- fmt.Println("登录的adminId", c.GetInt("adminID"))
- //todo上线打开
- //app.ErrorMsg(c, "请登录项目经理账号提交", nil)
- //return
- }
- //0:"待提交",
- //1:"已完成",
- //2:"审核中",
- //3:"验收不通过",
- err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
- "id": workId,
- }, map[string]interface{}{
- "item_status": 3,
- })
- if err != nil {
- fmt.Println("errrr", err)
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- //更新提交记录
- UpdateTaskSubmission(form.LogId, 2, form.Content)
- app.Success(c, nil)
- }
- /*
- * 节点添加留言
- */
- func AddMsg(c *gin.Context) {
- workId := gconv.Int(c.Param("work_id"))
- if workId < 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- var form form.MsgTruct
- if app.Bind(c, &form) != nil {
- return
- }
- var pickwork *final.MatPickWork
- db.GetModel(map[string]interface{}{
- "id": workId,
- }, &pickwork)
- if pickwork == nil {
- app.ErrorMsg(c, "找不到工作节点", nil)
- return
- }
- //找工地
- var site final.FinalSite
- db.GetModel(map[string]interface{}{"id": pickwork.SiteId,
- "deleted_at": 0}, &site)
- if site.ID == 0 {
- app.ErrorMsg(c, "工地不存在", nil)
- return
- }
- adminId := c.GetInt("adminID")
- var admin *models.Admin
- db.GetModel(map[string]interface{}{
- "id": adminId,
- }, &admin)
- roleListMap := make(map[int]string)
- if roleList, err := role.GetList(nil, []string{"id, name"}, app.Page{}, nil); err == nil {
- for _, v := range roleList {
- roleListMap[v.ID] = v.Name
- }
- }
- roleNames := ""
- roleSlice := strings.Split(admin.RoleIds, ",")
- for _, vv := range roleSlice {
- roleNames += "," + roleListMap[utils.ToInt(vv)]
- }
- RoleNames := strings.TrimLeft(roleNames, ",")
- _, err := db.InsertModel(db.Type(models.TaskComments{}), map[string]interface{}{
- "site_id": site.ID,
- "work_id": workId,
- "commenter_id": adminId,
- "commenter_role": admin.Username + fmt.Sprintf("(%s)", RoleNames),
- "content": form.Content,
- "created_at": time.Now().Unix(),
- })
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
- /*
- * 延期申请
- */
- func ExtensionRequest(c *gin.Context) {
- pickId := utils.ToInt(c.Param("pick_id"))
- if pickId <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- var form form.ExtensionRequestFailed
- if app.Bind(c, &form) != nil {
- return
- }
- //验证此节点是否有延期申请
- var workExtension *final.WorkExtension
- err := db.GetOne(final.WorkExtension{}.TableName(), map[string]interface{}{
- "work_id": pickId, //工作id
- }, nil, &workExtension)
- if workExtension != nil && workExtension.Id != 0 && workExtension.AuditState == 0 {
- app.ErrorMsg(c, "请勿重复申请", nil)
- return
- }
- _, err = db.InsertModel(db.Type(final.WorkExtension{}), map[string]interface{}{
- "work_id": pickId, //工作id
- "duration": form.Duration, //延期天数
- "manager_id": c.GetInt("adminID"), //申请人
- "content": form.Content, //申请人
- "pictures": form.Pictures,
- "type": form.Type,
- "created_at": time.Now().Unix(),
- })
- if err != nil {
- return
- }
- fmt.Println("pickId", pickId)
- fmt.Println("项目经理postdata", form)
- fmt.Println("adminId", c.GetInt("adminID"))
- app.Success(c, nil)
- }
- /*
- *
- 考勤打卡
- */
- func PutAttendance(c *gin.Context) {
- var failed form.AttendanceRequestFailed
- if app.Bind(c, &failed) != nil {
- return
- }
- workerId := c.GetInt("workerID")
- // 检查用户今天的打卡次数
- count, err := final.GetTodayAttendanceCount(workerId, failed.SiteId, failed.RoomType)
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- if count >= 2 {
- app.ErrorMsg(c, "当前节点已打两次卡", nil)
- return
- }
- //开启开工- 检查这个工地的roomtype 是否有打卡记录,没有则说明是开工
- var model *final.WorkerAttendance
- db.GetModel(map[string]interface{}{
- "site_id": failed.SiteId,
- "room_type": failed.RoomType,
- "worker_id": workerId,
- }, &model)
- //如果没有记录,则说明开工了
- if model == nil {
- err = db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
- "site_id": failed.SiteId,
- "room_type": failed.RoomType,
- "worker_id": workerId,
- }, map[string]interface{}{
- "worker_start_at": time.Now().Unix(),
- })
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- }
- // 记录打卡时间
- nowTime := time.Now().Unix()
- _, err = db.InsertModel(db.Type(final.WorkerAttendance{}), map[string]interface{}{
- "worker_id": workerId, //申请人
- "pictures": failed.Pictures,
- "site_id": failed.SiteId,
- "room_type": failed.RoomType,
- "clock_time": nowTime,
- "created_at": nowTime,
- })
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
- // 获取打卡记录
- func GetAttendanceList(c *gin.Context) {
- where := map[string]string{
- "_order_by": "a.id desc",
- }
- param := make(map[string]interface{})
- page := app.HandlePageNum(c)
- attendanceList := make([]form.AttendanceList, 0)
- err := worker.GetListWidthAttendance(where, param, page, &attendanceList)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, attendanceList)
- }
- func SelectWorkList(c *gin.Context) {
- var post map[string]interface{}
- if err := c.ShouldBindJSON(&post); err != nil {
- }
- model := final.MatPickWorkClient{}
- where := make(map[string]interface{})
- s := db.ModelQuery(db.Type(model), post, false)
- s.Select = map[string]string{
- "id": "`zy_mat_pick_work`.`id`",
- "site_id": "`zy_mat_pick_work`.`site_id`",
- "site_name": "`site`.`village`",
- "username": "`site`.`username`",
- "village": "`site`.`village`",
- "address": "`site`.`address`",
- "room_no": "`site`.`room_no`",
- "pkg_id": "`zy_mat_pick_work`.`pkg_id`",
- "pick_id": "`zy_mat_pick_work`.`pick_id`",
- "worker_id": "`zy_mat_pick_work`.`worker_id`",
- "manager_name": "`manager`.`username`",
- "manager_phone": "`manager`.`phone`",
- "worker_name": "`worker`.`name`",
- "room_type": "`zy_mat_pick_work`.`room_type`",
- "order_status": "`zy_mat_pick_work`.`order_status`",
- "worker_start_at": "`zy_mat_pick_work`.`worker_start_at`",
- "item_status": "`zy_mat_pick_work`.`item_status`",
- "cycle": "`zy_mat_pick_work`.`cycle`",
- "order_acceptance_at": "`zy_mat_pick_work`.`order_acceptance_at`",
- "manager_confirm_at": "`zy_mat_pick_work`.`manager_confirm_at`",
- "worker_confirm_at": "`zy_mat_pick_work`.`worker_confirm_at`",
- "worker_status": "`zy_mat_pick_work`.`worker_status`",
- "manager_status": "`zy_mat_pick_work`.`manager_status`",
- }
- db.WhereParse(&s, where)
- deleted := model.DeletedField()
- if deleted != "" {
- s.Where = append(s.Where, fmt.Sprintf("`%s`.`%s` = 0", model.TableName(), deleted))
- }
- s.Where = append(s.Where, fmt.Sprintf("`zy_mat_pick_work`.`worker_id` = %d", c.GetInt("workerID")))
- if post["state"] != "" {
- s.Where = append(s.Where, fmt.Sprintf("`zy_mat_pick_work`.`order_status` = %s", utils.ToStr(post["state"])))
- }
- s.GroupBy = "`zy_mat_pick_work`.`site_id`,`zy_mat_pick_work`.`room_type`"
- s.OrderBy = "`zy_mat_pick_work`.`pick_id` asc"
- // join查询
- s.LeftJoin = []db.Join{
- {
- TableName: "zy_final_site",
- As: "site",
- On: []string{"`site`.`id` = " + model.TableName() + ".`site_id`"},
- },
- {
- TableName: "zy_worker",
- As: "worker",
- On: []string{"`worker`.`id` = " + model.TableName() + ".`worker_id`"},
- },
- {
- TableName: "zy_admin",
- As: "manager",
- On: []string{"`manager`.`id` = " + model.TableName() + ".`manager_id`"},
- },
- }
- query, params := s.Query()
- list, err := db.QueryMap(query, params, model.DB())
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- if list == nil {
- list = make([]map[string]interface{}, 0)
- }
- workIds := make([]int, 0)
- for _, v := range list {
- workIds = append(workIds, gconv.Int(v["site_id"]))
- }
- //找到考勤记录表
- var workerAttendance []final.WorkerAttendance
- db.GetModel(map[string]interface{}{
- "site_id in": workIds,
- "worker_id": c.GetInt("workerID"),
- }, &workerAttendance)
- workerAttendanceMap := map[string][]final.WorkerAttendance{}
- for _, item := range workerAttendance {
- workerAttendanceMap[gconv.String(item.SiteId)+gconv.String(item.RoomType)] = append(workerAttendanceMap[gconv.String(item.SiteId)+gconv.String(item.RoomType)], item)
- }
- for _, v := range list {
- if workerAttendanceMap[gconv.String(v["site_id"])+gconv.String(v["room_type"])] != nil {
- v["workerAttendance"] = workerAttendanceMap[gconv.String(v["site_id"])+gconv.String(v["room_type"])]
- }
- }
- data := gin.H{
- "list": list,
- "aaaaaaaaaaaa": workIds,
- "workAcceptanceLog": workerAttendanceMap,
- }
- if model.Count() {
- count, err := db.GetCount(s, model.DB())
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- data["count"] = count
- }
- app.Success(c, data)
- }
- func SelectWorkEdit(c *gin.Context) {
- siteId := utils.ToInt(c.Param("id"))
- if siteId <= 0 {
- app.ErrorMsg(c, "id must be a number", nil)
- return
- }
- var post map[string]interface{}
- if err := c.ShouldBindJSON(&post); err != nil {
- }
- err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
- "site_id": siteId,
- "room_type": gconv.Int(post["room_type"]),
- }, map[string]interface{}{
- "order_status": post["status"],
- "order_acceptance_at": time.Now().Unix(),
- })
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
- func UpdateTaskSubmission(logId, state int, msg string) error {
- fmt.Println(logId)
- fmt.Println(msg)
- err := db.UpdateModels(db.Type(models.TaskSubmission{}), map[string]interface{}{
- "id": logId,
- }, map[string]interface{}{
- "review_comments": msg,
- "review_status": state,
- "review_time": time.Now().Unix(),
- })
- if err != nil {
- return err
- }
- return nil
- }
|