work.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. package worker
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. "zhiyuan/models"
  7. "zhiyuan/models/final"
  8. "zhiyuan/pkg/app"
  9. "zhiyuan/pkg/db"
  10. "zhiyuan/pkg/utils"
  11. "zhiyuan/services/form"
  12. "zhiyuan/services/role"
  13. "zhiyuan/services/user"
  14. "zhiyuan/services/work/worker"
  15. "zhiyuan/services/work/worksiteclock"
  16. "github.com/gin-gonic/gin"
  17. "github.com/gogf/gf/v2/os/gtime"
  18. "github.com/gogf/gf/v2/util/gconv"
  19. )
  20. func WorkSiteList(c *gin.Context) {
  21. page := app.HandlePageNums(c)
  22. where := map[string]string{
  23. "where": "`zy_work_site`.`id`>0 AND `zy_work_site`.`deleted_at`=0",
  24. "_group_by": "`zy_work_site`.`id`",
  25. "_order_by": "`zy_work_site`.`id` desc",
  26. }
  27. if page.PageSize != 0 {
  28. where["_page_size"] = utils.ToStr(page.PageSize)
  29. where["_page_num"] = utils.ToStr(page.PageNum)
  30. }
  31. param := make(map[string]interface{})
  32. username := c.Query("username")
  33. if username != "" {
  34. where["where"] = where["where"] + " AND `zy_work_site`.`username` LIKE {{username}}"
  35. param["username"] = "%" + username + "%"
  36. }
  37. phone := c.Query("phone")
  38. if phone != "" {
  39. where["where"] = where["where"] + " AND `zy_work_site`.`phone` LIKE {{phone}}"
  40. param["phone"] = "%" + phone + "%"
  41. }
  42. village := c.Query("village")
  43. if village != "" {
  44. where["where"] = where["where"] + " AND `zy_work_site`.`village` LIKE {{village}}"
  45. param["village"] = "%" + village + "%"
  46. }
  47. address := c.Query("address")
  48. if address != "" {
  49. where["where"] = where["where"] + " AND `zy_work_site`.`address` LIKE {{address}}"
  50. param["address"] = "%" + address + "%"
  51. }
  52. room_no := c.Query("room_no")
  53. if room_no != "" {
  54. where["where"] = where["where"] + " AND `zy_work_site`.`room_no` LIKE {{room_no}}"
  55. param["room_no"] = "%" + room_no + "%"
  56. }
  57. area := c.Query("area")
  58. if area != "" {
  59. where["where"] = where["where"] + " AND `zy_work_site`.`area` LIKE {{area}}"
  60. param["area"] = "%" + area + "%"
  61. }
  62. state := utils.ToInt(c.Query("state"))
  63. if state != 0 {
  64. where["where"] = where["where"] + " AND `zy_work_site`.`state`={{state}}"
  65. param["state"] = state
  66. }
  67. userInfo, err := user.GetInfoByID(c.GetInt("userID"), nil, nil)
  68. if userInfo == nil || err != nil {
  69. app.ErrorMsg(c, err.Error(), nil)
  70. return
  71. }
  72. where["where"] = where["where"] + " AND `zy_work_site_node`.`worker_id` = {{worker_id}}"
  73. param["worker_id"] = c.GetInt("workerID")
  74. 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)
  75. if err != nil {
  76. app.Error(c, err.Error())
  77. return
  78. }
  79. total := utils.ToInt64(res["count"])
  80. type WorksiteList struct {
  81. ID int `json:"id"`
  82. Username string `json:"username"`
  83. Phone string `json:"phone"`
  84. Village string `json:"village"`
  85. Address string `json:"address"`
  86. RoomNo string `json:"room_no"`
  87. Area string `json:"area"`
  88. Longitude string `json:"longitude"`
  89. Latitude string `json:"latitude"`
  90. ManagerId int `json:"manager_id"`
  91. DesignerId int `json:"designer_id"`
  92. CreatedId int `json:"created_id"`
  93. AdminIds string `json:"admin_ids"`
  94. StartTime int `json:"starttime"`
  95. EndTime int `json:"endtime"`
  96. State int `json:"state"`
  97. CreatedAt int `json:"created_at"`
  98. UpdatedAt int `json:"updated_at"`
  99. ManagerName string `json:"manager_name"`
  100. ManagerPhone string `json:"manager_phone"`
  101. DesignerName string `json:"designer_name"`
  102. DesignerPhone string `json:"designer_phone"`
  103. CreatedName string `json:"created_name"`
  104. AdminNames string `json:"admin_names"`
  105. }
  106. 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` "
  107. worksiteList := make([]WorksiteList, 0)
  108. if err = db.GetMultiRaw(field, where, param, &worksiteList); err != nil {
  109. app.Error(c, err.Error())
  110. return
  111. }
  112. data := gin.H{
  113. "list": worksiteList,
  114. "total": total,
  115. "limit": page.PageSize,
  116. }
  117. app.Success(c, data)
  118. }
  119. func WorkSiteClockList(c *gin.Context) {
  120. page := app.HandlePageNum(c)
  121. where := map[string]string{
  122. "where": "`zy_work_site_clock`.`id`>0 AND `zy_work_site_clock`.`deleted_at`=0",
  123. "_order_by": "`zy_work_site_clock`.`id` desc",
  124. }
  125. if page.PageSize != 0 {
  126. where["_page_size"] = utils.ToStr(page.PageSize)
  127. where["_page_num"] = utils.ToStr(page.PageNum)
  128. }
  129. param := make(map[string]interface{})
  130. if c.GetInt("workerID") != 0 {
  131. where["where"] = where["where"] + " AND `zy_work_site_clock`.`staff_type`=0 AND `zy_work_site_clock`.`staff_id`={{staff_id}}"
  132. param["staff_id"] = c.GetInt("workerID")
  133. }
  134. site_id := utils.ToInt(c.Query("site_id"))
  135. if site_id != 0 {
  136. where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_id`={{site_id}}"
  137. param["site_id"] = site_id
  138. }
  139. site_node_id := utils.ToInt(c.Query("site_node_id"))
  140. if site_node_id != 0 {
  141. where["where"] = where["where"] + " AND `zy_work_site_clock`.`site_node_id`={{site_node_id}}"
  142. param["site_node_id"] = site_node_id
  143. }
  144. state := utils.ToInt(c.Query("state"))
  145. if state != 0 {
  146. where["where"] = where["where"] + " AND `zy_work_site_clock`.`state`={{state}}"
  147. param["state"] = state
  148. }
  149. starttime := utils.ToInt(c.Query("starttime"))
  150. if starttime != 0 {
  151. where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` >= {{starttime}}"
  152. param["starttime"] = starttime
  153. }
  154. endtime := utils.ToInt(c.Query("endtime"))
  155. if endtime != 0 {
  156. where["where"] = where["where"] + " AND `zy_work_site_clock`.`created_at` <= {{endtime}}"
  157. param["endtime"] = endtime
  158. }
  159. total, err := worksiteclock.CountRaw(where["where"], param)
  160. if err != nil {
  161. app.Error(c, err.Error())
  162. return
  163. }
  164. type WorkSiteClockList struct {
  165. ID int `json:"id"`
  166. SiteId int `json:"site_id"`
  167. SiteNodeId int `json:"site_node_id"`
  168. StaffType int `json:"staff_type"`
  169. StaffId int `json:"staff_id"`
  170. Pictures string `json:"pictures"`
  171. Content string `json:"content"`
  172. Type int `json:"type"`
  173. CreatedAt int `json:"created_at"`
  174. UpdatedAt int `json:"updated_at"`
  175. StaffName string `json:"staff_name"`
  176. StaffPhone string `json:"staff_phone"`
  177. NodeName string `json:"node_name"`
  178. }
  179. workSiteClockList := make([]WorkSiteClockList, 0)
  180. if err = worksiteclock.GetWorkSiteClocksRaw(where, param, &workSiteClockList); err != nil {
  181. app.Error(c, err.Error())
  182. return
  183. }
  184. data := gin.H{
  185. "list": workSiteClockList,
  186. "total": total,
  187. "limit": page.PageSize,
  188. }
  189. app.Success(c, data)
  190. }
  191. func WorkSiteClockAdd(c *gin.Context) {
  192. var addForm form.WorkSiteClockAdd
  193. if app.Bind(c, &addForm) != nil {
  194. return
  195. }
  196. id, err := worksiteclock.AddWorker(addForm, c.GetInt("workerID"))
  197. if err != nil {
  198. app.Error(c, err.Error())
  199. return
  200. }
  201. app.Success(c, gin.H{"id": id})
  202. }
  203. func WorkSiteClockEdit(c *gin.Context) {
  204. id := utils.ToInt(c.Param("id"))
  205. if id <= 0 {
  206. app.ErrorMsg(c, "id must be a number", nil)
  207. return
  208. }
  209. var editForm form.WorkSiteClockEdit
  210. if app.Bind(c, &editForm) != nil {
  211. return
  212. }
  213. err := worksiteclock.EditByIDWorker(editForm, id, c.GetInt("workerID"))
  214. if err != nil {
  215. app.ErrorMsg(c, err.Error(), nil)
  216. return
  217. }
  218. app.Success(c, nil)
  219. }
  220. /*
  221. * 工人套餐子项列表
  222. */
  223. func MatPickWork(c *gin.Context) {
  224. siteId := utils.ToInt(c.Param("site_id"))
  225. roomType := utils.ToInt(c.Param("room_type"))
  226. if siteId <= 0 {
  227. app.ErrorMsg(c, "id must be a number", nil)
  228. return
  229. }
  230. list, err := worker.GetWorkerItems(siteId, roomType, c.GetInt("workerID"))
  231. if err != nil {
  232. app.ErrorMsg(c, err.Error(), nil)
  233. return
  234. }
  235. app.Success(c, list)
  236. }
  237. /*
  238. * 工人开工
  239. */
  240. func MatPickWorkStart(c *gin.Context) {
  241. pickId := utils.ToInt(c.Param("pick_id"))
  242. if pickId <= 0 {
  243. app.ErrorMsg(c, "id must be a number", nil)
  244. return
  245. }
  246. err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
  247. "id": pickId,
  248. "worker_id": c.GetInt("workerID"),
  249. }, map[string]interface{}{
  250. "worker_start_at": time.Now().Unix(), //工人开始工作时间
  251. })
  252. if err != nil {
  253. app.ErrorMsg(c, err.Error(), nil)
  254. return
  255. }
  256. app.Success(c, nil)
  257. }
  258. /*
  259. * 工人完成
  260. */
  261. func MatPickWorkCompleted(c *gin.Context) {
  262. pickId := utils.ToInt(c.Param("pick_id"))
  263. var form form.Workcompleted
  264. if app.Bind(c, &form) != nil {
  265. return
  266. }
  267. //fmt.Println("工人确认节点", form.Pictures)
  268. if pickId <= 0 {
  269. app.ErrorMsg(c, "id must be a number", nil)
  270. return
  271. }
  272. err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
  273. "id": pickId,
  274. "worker_id": c.GetInt("workerID"),
  275. }, map[string]interface{}{
  276. "worker_status": 1, //工人已确认状态
  277. "worker_confirm_at": time.Now().Unix(), //工人完成工作确认时间
  278. //"pictures": form.Pictures,
  279. //"content": form.Content,
  280. })
  281. if err != nil {
  282. app.ErrorMsg(c, err.Error(), nil)
  283. return
  284. }
  285. //存入工人提交记录表
  286. //_, err = db.InsertModel(db.Type(models.WorkAcceptanceLog{}), map[string]interface{}{
  287. // "type": 2, //1项目经理 2工人 3客服
  288. // "work_id": pickId,
  289. // "context": form.Content,
  290. // "pictures": form.Pictures,
  291. // "created_id": c.GetInt("workerID"),
  292. //})
  293. if err != nil {
  294. app.ErrorMsg(c, err.Error(), nil)
  295. return
  296. }
  297. app.Success(c, nil)
  298. }
  299. /*
  300. * 项目经理完成节点
  301. */
  302. func ManagerConfirmMatPickWork(c *gin.Context) {
  303. workId := gconv.Int(c.Param("work_id"))
  304. if workId < 0 {
  305. app.ErrorMsg(c, "id must be a number", nil)
  306. return
  307. }
  308. var form form.Workcompleted
  309. if app.Bind(c, &form) != nil {
  310. return
  311. }
  312. //判断是否超时完成
  313. var pickwork *final.MatPickWork
  314. db.GetModel(map[string]interface{}{
  315. "id": workId,
  316. }, &pickwork)
  317. if pickwork == nil {
  318. app.ErrorMsg(c, "找不到工作节点", nil)
  319. return
  320. }
  321. //找工地
  322. var site final.FinalSite
  323. db.GetModel(map[string]interface{}{"id": pickwork.SiteId,
  324. "deleted_at": 0}, &site)
  325. if site.ID == 0 {
  326. app.ErrorMsg(c, "工地不存在", nil)
  327. return
  328. }
  329. if site.ManagerId != c.GetInt64("adminID") {
  330. fmt.Println("workId", workId)
  331. fmt.Println("work项目经理Id", site.ManagerId)
  332. fmt.Println("登录的adminId", c.GetInt("adminID"))
  333. //todo上线打开
  334. //app.ErrorMsg(c, "请登录项目经理账号提交", nil)
  335. //return
  336. }
  337. //判断是否审核中
  338. if pickwork.ItemStatus == 1 {
  339. app.ErrorMsg(c, "改节点已完成", nil)
  340. return
  341. }
  342. if pickwork.ItemStatus == 2 {
  343. app.ErrorMsg(c, "审核中,请等待", nil)
  344. return
  345. }
  346. var itemStatus int
  347. //0:"待提交",
  348. //1:"已完成",
  349. //2:"审核中",
  350. //3:"验收不通过",
  351. //正常节点确认完成 绿色
  352. //条件:现在时间> 开始时间 ,现在时间 < 结束时间,并且已确认
  353. if gtime.Now().Unix() > gtime.New(pickwork.Starttime).Unix() && gtime.Now().Unix() < gtime.New(pickwork.ExampleAt).Unix() {
  354. //itemStatus = 0
  355. }
  356. //超时完成 黄色
  357. //条件:确认时间 > 结束时间 并且工人已确认
  358. if gtime.Now().Unix() > gtime.New(pickwork.ExampleAt).Unix() {
  359. //itemStatus = 0
  360. }
  361. itemStatus = 2
  362. err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
  363. "id": workId,
  364. }, map[string]interface{}{
  365. "manager_status": itemStatus, //已确认
  366. "manager_confirm_at": time.Now().Unix(), //确认时间
  367. "item_status": itemStatus,
  368. })
  369. if err != nil {
  370. app.ErrorMsg(c, err.Error(), nil)
  371. return
  372. }
  373. _, err = db.InsertModel(db.Type(models.TaskSubmission{}), map[string]interface{}{
  374. "site_id": site.ID,
  375. "work_id": workId,
  376. "pictures": form.Pictures,
  377. "content": form.Content,
  378. "created_at": time.Now().Unix(),
  379. "review_status": 0, //待审核
  380. "created_id": c.GetInt64("adminID"),
  381. })
  382. if err != nil {
  383. app.ErrorMsg(c, err.Error(), nil)
  384. return
  385. }
  386. app.Success(c, nil)
  387. }
  388. /*
  389. * 队长验收通过
  390. */
  391. func ManagerAcceptancePassed(c *gin.Context) {
  392. workId := gconv.Int(c.Param("work_id"))
  393. if workId < 0 {
  394. app.ErrorMsg(c, "id must be a number", nil)
  395. return
  396. }
  397. var form form.ReviewOktruct
  398. if app.Bind(c, &form) != nil {
  399. return
  400. }
  401. //判断是否超时完成
  402. var pickwork *final.MatPickWork
  403. db.GetModel(map[string]interface{}{
  404. "id": workId,
  405. }, &pickwork)
  406. if pickwork == nil {
  407. app.ErrorMsg(c, "找不到工作节点", nil)
  408. return
  409. }
  410. //找工地
  411. var site final.FinalSite
  412. db.GetModel(map[string]interface{}{"id": pickwork.SiteId,
  413. "deleted_at": 0}, &site)
  414. if site.ID == 0 {
  415. app.ErrorMsg(c, "工地不存在", nil)
  416. return
  417. }
  418. if site.ProjectLeaderId != c.GetInt64("adminID") {
  419. fmt.Println("workId", workId)
  420. fmt.Println("work项目经理Id", site.ManagerId)
  421. fmt.Println("登录的adminId", c.GetInt("adminID"))
  422. //todo上线打开
  423. //app.ErrorMsg(c, "请登录项目经理账号提交", nil)
  424. //return
  425. }
  426. //0:"待提交",
  427. //1:"已完成",
  428. //2:"审核中",
  429. //3:"验收不通过",
  430. err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
  431. "id": workId,
  432. }, map[string]interface{}{
  433. "item_status": 1, //完成
  434. })
  435. if err != nil {
  436. fmt.Println("errrr", err)
  437. app.ErrorMsg(c, err.Error(), nil)
  438. return
  439. }
  440. //更新提交记录
  441. UpdateTaskSubmission(form.LogId, 1, "")
  442. app.Success(c, nil)
  443. }
  444. /*
  445. * 队长验收不通过
  446. */
  447. func ManagerAcceptanceFailed(c *gin.Context) {
  448. workId := gconv.Int(c.Param("work_id"))
  449. fmt.Println("dispatch ,ManagerAcceptanceFailed")
  450. if workId < 0 {
  451. app.ErrorMsg(c, "id must be a number", nil)
  452. return
  453. }
  454. var form form.Reviewstruct
  455. if app.Bind(c, &form) != nil {
  456. return
  457. }
  458. var pickwork *final.MatPickWork
  459. db.GetModel(map[string]interface{}{
  460. "id": workId,
  461. }, &pickwork)
  462. fmt.Println("workId", workId)
  463. fmt.Println("pickwork", pickwork)
  464. if pickwork == nil {
  465. app.ErrorMsg(c, "找不到工作节点", nil)
  466. return
  467. }
  468. //找工地
  469. var site final.FinalSite
  470. db.GetModel(map[string]interface{}{"id": pickwork.SiteId,
  471. "deleted_at": 0}, &site)
  472. if site.ID == 0 {
  473. app.ErrorMsg(c, "工地不存在", nil)
  474. return
  475. }
  476. if site.ProjectLeaderId != c.GetInt64("adminID") {
  477. fmt.Println("workId", workId)
  478. fmt.Println("work项目经理Id", site.ManagerId)
  479. fmt.Println("登录的adminId", c.GetInt("adminID"))
  480. //todo上线打开
  481. //app.ErrorMsg(c, "请登录项目经理账号提交", nil)
  482. //return
  483. }
  484. //0:"待提交",
  485. //1:"已完成",
  486. //2:"审核中",
  487. //3:"验收不通过",
  488. err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
  489. "id": workId,
  490. }, map[string]interface{}{
  491. "item_status": 3,
  492. })
  493. if err != nil {
  494. fmt.Println("errrr", err)
  495. app.ErrorMsg(c, err.Error(), nil)
  496. return
  497. }
  498. //更新提交记录
  499. UpdateTaskSubmission(form.LogId, 2, form.Content)
  500. app.Success(c, nil)
  501. }
  502. /*
  503. * 节点添加留言
  504. */
  505. func AddMsg(c *gin.Context) {
  506. workId := gconv.Int(c.Param("work_id"))
  507. if workId < 0 {
  508. app.ErrorMsg(c, "id must be a number", nil)
  509. return
  510. }
  511. var form form.MsgTruct
  512. if app.Bind(c, &form) != nil {
  513. return
  514. }
  515. var pickwork *final.MatPickWork
  516. db.GetModel(map[string]interface{}{
  517. "id": workId,
  518. }, &pickwork)
  519. if pickwork == nil {
  520. app.ErrorMsg(c, "找不到工作节点", nil)
  521. return
  522. }
  523. //找工地
  524. var site final.FinalSite
  525. db.GetModel(map[string]interface{}{"id": pickwork.SiteId,
  526. "deleted_at": 0}, &site)
  527. if site.ID == 0 {
  528. app.ErrorMsg(c, "工地不存在", nil)
  529. return
  530. }
  531. adminId := c.GetInt("adminID")
  532. var admin *models.Admin
  533. db.GetModel(map[string]interface{}{
  534. "id": adminId,
  535. }, &admin)
  536. roleListMap := make(map[int]string)
  537. if roleList, err := role.GetList(nil, []string{"id, name"}, app.Page{}, nil); err == nil {
  538. for _, v := range roleList {
  539. roleListMap[v.ID] = v.Name
  540. }
  541. }
  542. roleNames := ""
  543. roleSlice := strings.Split(admin.RoleIds, ",")
  544. for _, vv := range roleSlice {
  545. roleNames += "," + roleListMap[utils.ToInt(vv)]
  546. }
  547. RoleNames := strings.TrimLeft(roleNames, ",")
  548. _, err := db.InsertModel(db.Type(models.TaskComments{}), map[string]interface{}{
  549. "site_id": site.ID,
  550. "work_id": workId,
  551. "commenter_id": adminId,
  552. "commenter_role": admin.Username + fmt.Sprintf("(%s)", RoleNames),
  553. "content": form.Content,
  554. "created_at": time.Now().Unix(),
  555. })
  556. if err != nil {
  557. app.ErrorMsg(c, err.Error(), nil)
  558. return
  559. }
  560. app.Success(c, nil)
  561. }
  562. /*
  563. * 延期申请
  564. */
  565. func ExtensionRequest(c *gin.Context) {
  566. pickId := utils.ToInt(c.Param("pick_id"))
  567. if pickId <= 0 {
  568. app.ErrorMsg(c, "id must be a number", nil)
  569. return
  570. }
  571. var form form.ExtensionRequestFailed
  572. if app.Bind(c, &form) != nil {
  573. return
  574. }
  575. //验证此节点是否有延期申请
  576. var workExtension *final.WorkExtension
  577. err := db.GetOne(final.WorkExtension{}.TableName(), map[string]interface{}{
  578. "work_id": pickId, //工作id
  579. }, nil, &workExtension)
  580. if workExtension != nil && workExtension.Id != 0 && workExtension.AuditState == 0 {
  581. app.ErrorMsg(c, "请勿重复申请", nil)
  582. return
  583. }
  584. _, err = db.InsertModel(db.Type(final.WorkExtension{}), map[string]interface{}{
  585. "work_id": pickId, //工作id
  586. "duration": form.Duration, //延期天数
  587. "manager_id": c.GetInt("adminID"), //申请人
  588. "content": form.Content, //申请人
  589. "pictures": form.Pictures,
  590. "type": form.Type,
  591. "created_at": time.Now().Unix(),
  592. })
  593. if err != nil {
  594. return
  595. }
  596. fmt.Println("pickId", pickId)
  597. fmt.Println("项目经理postdata", form)
  598. fmt.Println("adminId", c.GetInt("adminID"))
  599. app.Success(c, nil)
  600. }
  601. /*
  602. *
  603. 考勤打卡
  604. */
  605. func PutAttendance(c *gin.Context) {
  606. var failed form.AttendanceRequestFailed
  607. if app.Bind(c, &failed) != nil {
  608. return
  609. }
  610. workerId := c.GetInt("workerID")
  611. // 检查用户今天的打卡次数
  612. count, err := final.GetTodayAttendanceCount(workerId, failed.SiteId, failed.RoomType)
  613. if err != nil {
  614. app.ErrorMsg(c, err.Error(), nil)
  615. return
  616. }
  617. if count >= 2 {
  618. app.ErrorMsg(c, "当前节点已打两次卡", nil)
  619. return
  620. }
  621. //开启开工- 检查这个工地的roomtype 是否有打卡记录,没有则说明是开工
  622. var model *final.WorkerAttendance
  623. db.GetModel(map[string]interface{}{
  624. "site_id": failed.SiteId,
  625. "room_type": failed.RoomType,
  626. "worker_id": workerId,
  627. }, &model)
  628. //如果没有记录,则说明开工了
  629. if model == nil {
  630. err = db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
  631. "site_id": failed.SiteId,
  632. "room_type": failed.RoomType,
  633. "worker_id": workerId,
  634. }, map[string]interface{}{
  635. "worker_start_at": time.Now().Unix(),
  636. })
  637. if err != nil {
  638. app.ErrorMsg(c, err.Error(), nil)
  639. return
  640. }
  641. }
  642. // 记录打卡时间
  643. nowTime := time.Now().Unix()
  644. _, err = db.InsertModel(db.Type(final.WorkerAttendance{}), map[string]interface{}{
  645. "worker_id": workerId, //申请人
  646. "pictures": failed.Pictures,
  647. "site_id": failed.SiteId,
  648. "room_type": failed.RoomType,
  649. "clock_time": nowTime,
  650. "created_at": nowTime,
  651. })
  652. if err != nil {
  653. app.ErrorMsg(c, err.Error(), nil)
  654. return
  655. }
  656. app.Success(c, nil)
  657. }
  658. // 获取打卡记录
  659. func GetAttendanceList(c *gin.Context) {
  660. where := map[string]string{
  661. "_order_by": "a.id desc",
  662. }
  663. param := make(map[string]interface{})
  664. page := app.HandlePageNum(c)
  665. attendanceList := make([]form.AttendanceList, 0)
  666. err := worker.GetListWidthAttendance(where, param, page, &attendanceList)
  667. if err != nil {
  668. app.Error(c, err.Error())
  669. return
  670. }
  671. app.Success(c, attendanceList)
  672. }
  673. func SelectWorkList(c *gin.Context) {
  674. var post map[string]interface{}
  675. if err := c.ShouldBindJSON(&post); err != nil {
  676. }
  677. model := final.MatPickWorkClient{}
  678. where := make(map[string]interface{})
  679. s := db.ModelQuery(db.Type(model), post, false)
  680. s.Select = map[string]string{
  681. "id": "`zy_mat_pick_work`.`id`",
  682. "site_id": "`zy_mat_pick_work`.`site_id`",
  683. "site_name": "`site`.`village`",
  684. "username": "`site`.`username`",
  685. "village": "`site`.`village`",
  686. "address": "`site`.`address`",
  687. "room_no": "`site`.`room_no`",
  688. "pkg_id": "`zy_mat_pick_work`.`pkg_id`",
  689. "pick_id": "`zy_mat_pick_work`.`pick_id`",
  690. "worker_id": "`zy_mat_pick_work`.`worker_id`",
  691. "manager_name": "`manager`.`username`",
  692. "manager_phone": "`manager`.`phone`",
  693. "worker_name": "`worker`.`name`",
  694. "room_type": "`zy_mat_pick_work`.`room_type`",
  695. "order_status": "`zy_mat_pick_work`.`order_status`",
  696. "worker_start_at": "`zy_mat_pick_work`.`worker_start_at`",
  697. "item_status": "`zy_mat_pick_work`.`item_status`",
  698. "cycle": "`zy_mat_pick_work`.`cycle`",
  699. "order_acceptance_at": "`zy_mat_pick_work`.`order_acceptance_at`",
  700. "manager_confirm_at": "`zy_mat_pick_work`.`manager_confirm_at`",
  701. "worker_confirm_at": "`zy_mat_pick_work`.`worker_confirm_at`",
  702. "worker_status": "`zy_mat_pick_work`.`worker_status`",
  703. "manager_status": "`zy_mat_pick_work`.`manager_status`",
  704. }
  705. db.WhereParse(&s, where)
  706. deleted := model.DeletedField()
  707. if deleted != "" {
  708. s.Where = append(s.Where, fmt.Sprintf("`%s`.`%s` = 0", model.TableName(), deleted))
  709. }
  710. s.Where = append(s.Where, fmt.Sprintf("`zy_mat_pick_work`.`worker_id` = %d", c.GetInt("workerID")))
  711. if post["state"] != "" {
  712. s.Where = append(s.Where, fmt.Sprintf("`zy_mat_pick_work`.`order_status` = %s", utils.ToStr(post["state"])))
  713. }
  714. s.GroupBy = "`zy_mat_pick_work`.`site_id`,`zy_mat_pick_work`.`room_type`"
  715. s.OrderBy = "`zy_mat_pick_work`.`pick_id` asc"
  716. // join查询
  717. s.LeftJoin = []db.Join{
  718. {
  719. TableName: "zy_final_site",
  720. As: "site",
  721. On: []string{"`site`.`id` = " + model.TableName() + ".`site_id`"},
  722. },
  723. {
  724. TableName: "zy_worker",
  725. As: "worker",
  726. On: []string{"`worker`.`id` = " + model.TableName() + ".`worker_id`"},
  727. },
  728. {
  729. TableName: "zy_admin",
  730. As: "manager",
  731. On: []string{"`manager`.`id` = " + model.TableName() + ".`manager_id`"},
  732. },
  733. }
  734. query, params := s.Query()
  735. list, err := db.QueryMap(query, params, model.DB())
  736. if err != nil {
  737. app.ErrorMsg(c, err.Error(), nil)
  738. return
  739. }
  740. if list == nil {
  741. list = make([]map[string]interface{}, 0)
  742. }
  743. workIds := make([]int, 0)
  744. for _, v := range list {
  745. workIds = append(workIds, gconv.Int(v["site_id"]))
  746. }
  747. //找到考勤记录表
  748. var workerAttendance []final.WorkerAttendance
  749. db.GetModel(map[string]interface{}{
  750. "site_id in": workIds,
  751. "worker_id": c.GetInt("workerID"),
  752. }, &workerAttendance)
  753. workerAttendanceMap := map[string][]final.WorkerAttendance{}
  754. for _, item := range workerAttendance {
  755. workerAttendanceMap[gconv.String(item.SiteId)+gconv.String(item.RoomType)] = append(workerAttendanceMap[gconv.String(item.SiteId)+gconv.String(item.RoomType)], item)
  756. }
  757. for _, v := range list {
  758. if workerAttendanceMap[gconv.String(v["site_id"])+gconv.String(v["room_type"])] != nil {
  759. v["workerAttendance"] = workerAttendanceMap[gconv.String(v["site_id"])+gconv.String(v["room_type"])]
  760. }
  761. }
  762. data := gin.H{
  763. "list": list,
  764. "aaaaaaaaaaaa": workIds,
  765. "workAcceptanceLog": workerAttendanceMap,
  766. }
  767. if model.Count() {
  768. count, err := db.GetCount(s, model.DB())
  769. if err != nil {
  770. app.ErrorMsg(c, err.Error(), nil)
  771. return
  772. }
  773. data["count"] = count
  774. }
  775. app.Success(c, data)
  776. }
  777. func SelectWorkEdit(c *gin.Context) {
  778. siteId := utils.ToInt(c.Param("id"))
  779. if siteId <= 0 {
  780. app.ErrorMsg(c, "id must be a number", nil)
  781. return
  782. }
  783. var post map[string]interface{}
  784. if err := c.ShouldBindJSON(&post); err != nil {
  785. }
  786. err := db.UpdateModels(db.Type(final.MatPickWork{}), map[string]interface{}{
  787. "site_id": siteId,
  788. "room_type": gconv.Int(post["room_type"]),
  789. }, map[string]interface{}{
  790. "order_status": post["status"],
  791. "order_acceptance_at": time.Now().Unix(),
  792. })
  793. if err != nil {
  794. app.ErrorMsg(c, err.Error(), nil)
  795. return
  796. }
  797. app.Success(c, nil)
  798. }
  799. func UpdateTaskSubmission(logId, state int, msg string) error {
  800. fmt.Println(logId)
  801. fmt.Println(msg)
  802. err := db.UpdateModels(db.Type(models.TaskSubmission{}), map[string]interface{}{
  803. "id": logId,
  804. }, map[string]interface{}{
  805. "review_comments": msg,
  806. "review_status": state,
  807. "review_time": time.Now().Unix(),
  808. })
  809. if err != nil {
  810. return err
  811. }
  812. return nil
  813. }