user_repair.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package frontc
  2. import (
  3. "wuyebaoxiuapi/models/frontm"
  4. "wuyebaoxiuapi/models/backgroundm"
  5. "time"
  6. )
  7. // 用户维修控制器
  8. type UserRepairController struct {
  9. BaseController
  10. }
  11. // 用户报修数量
  12. func (this *UserRepairController)UserRepairCount() {
  13. if this.userInfo.Types != 0 {
  14. this.Data["json"] = map[string]interface{}{"code": 0, "message": "登录过期"}
  15. this.ServeJSON()
  16. }
  17. repair := frontm.NewRepair()
  18. count := repair.FindRepairUserRepairCount(this.userInfo.Id)
  19. result := make(map[string]interface{})
  20. result["count"] = count
  21. this.ajaxMsg(MSG_OK,"",result)
  22. }
  23. // 报修用户报修列表
  24. func (this *UserRepairController)RepairUserRepairs() {
  25. userid := this.userInfo.Id
  26. page, err := this.GetInt("page")
  27. if err != nil {
  28. page = 1
  29. }
  30. limit, err := this.GetInt("limit")
  31. if err != nil {
  32. limit = 30
  33. }
  34. repair := frontm.NewRepair()
  35. repairs,total := repair.FindRepairUserRepairs(userid,page,limit)
  36. outReRepairs := make([]*frontm.OutReRepair,0)
  37. for _, v := range repairs {
  38. outReRepair := new(frontm.OutReRepair)
  39. this.fmtOutReRepair(v,outReRepair)
  40. outReRepairs = append(outReRepairs,outReRepair)
  41. }
  42. this.ajaxList(MSG_OK,"",total,outReRepairs)
  43. }
  44. func (this *UserRepairController)fmtOutReRepair(repair *frontm.Repair,outReRepair *frontm.OutReRepair) {
  45. repairUserPicture := frontm.NewRepairUserPicture()
  46. outReRepair.Id = repair.Id
  47. outReRepair.School = repair.School
  48. outReRepair.Position = repair.Position
  49. outReRepair.ApplicantName = repair.ApplicantName
  50. outReRepair.ApplicantPhone = repair.ApplicantPhone
  51. outReRepair.ApplicantUserId = repair.ApplicantUserId
  52. outReRepair.CreateTime = repair.CreateTime
  53. outReRepair.RepairUserId = repair.RepairUserId
  54. outReRepair.Status = repair.Status
  55. outReRepair.RepairTime = repair.RepairTime
  56. outReRepair.ApplicantContent = repair.ApplicantContent
  57. outReRepair.Address = repair.Address
  58. // 查找维修图片
  59. images := repairUserPicture.FindPictureByUserIdAndReparId(repair.ApplicantUserId,repair.Id)
  60. outReRepair.RepairImages = images
  61. // 查找维修图片
  62. outReRepair.ServiceImages = repairUserPicture.FindPictureByUserIdAndReparId(repair.RepairUserId,repair.Id)
  63. }
  64. // 维修用户维修数量
  65. func (this *UserRepairController)RepairUserRepairCount() {
  66. if this.userInfo.Types != 0 {
  67. this.Data["json"] = map[string]interface{}{"code": 0, "message": "登录过期"}
  68. this.ServeJSON()
  69. }
  70. repair := frontm.NewRepair()
  71. result := make(map[string]interface{})
  72. // 待维修数量
  73. result["WRepairCount"] = repair.FindServiceUserWRepairCount(this.userInfo.Id)
  74. // 已维修数量
  75. result["HRepairCount"] = repair.FindServiceUserHRepairCount(this.userInfo.Id)
  76. this.ajaxMsg(MSG_OK,"",result)
  77. }
  78. // 管理员维修数量
  79. func (this *UserRepairController)AdminRepairCount() {
  80. repair := frontm.NewRepair()
  81. admin := new(backgroundm.Admin)
  82. result := make(map[string]interface{})
  83. // 待维修数量
  84. result["WRepairCount"] = repair.FindAdminWRepairCount(0)
  85. // 已维修数量
  86. result["HRepairCount"] = repair.FindAdminHRepairCount(0)
  87. // 查找维修工人数量
  88. result["RepairWorkerCount"] = admin.FindRepairWorkerCount()
  89. this.ajaxMsg(MSG_OK,"",result)
  90. }
  91. // 维修工人列表
  92. func (this *UserRepairController)RepairWorkers() {
  93. repairWorkers,total := this.findRepairWorkers(false)
  94. this.ajaxList(MSG_OK,"",total,repairWorkers)
  95. }
  96. // 维修工人维修列表
  97. func (this *UserRepairController)RepairWorkerRepairs() {
  98. id, _ := this.GetInt("id")
  99. page, err := this.GetInt("page")
  100. if err != nil {
  101. page = 1
  102. }
  103. limit, err := this.GetInt("limit")
  104. if err != nil {
  105. limit = 30
  106. }
  107. repair := frontm.NewRepair()
  108. repairs,total := repair.FindRepairsByUserId(id,page,limit)
  109. this.ajaxList(MSG_OK,"",total,repairs)
  110. }
  111. // 管理员待维修列表
  112. func (this *UserRepairController)AdminWRepairs() {
  113. page, err := this.GetInt("page")
  114. if err != nil {
  115. page = 1
  116. }
  117. limit, err := this.GetInt("limit")
  118. if err != nil {
  119. limit = 30
  120. }
  121. repair := frontm.NewRepair()
  122. repairs,total :=repair.FindAdminWRepairs(page,limit)
  123. outReRepairs := make([]*frontm.OutReRepair,0)
  124. for _, v := range repairs {
  125. outReRepair := new(frontm.OutReRepair)
  126. this.fmtOutReRepair(v,outReRepair)
  127. outReRepairs = append(outReRepairs,outReRepair)
  128. }
  129. this.ajaxList(MSG_OK,"",total,outReRepairs)
  130. }
  131. // 管理员已维修列表
  132. func (this *UserRepairController)AdminHRepairs() {
  133. page, err := this.GetInt("page")
  134. if err != nil {
  135. page = 1
  136. }
  137. limit, err := this.GetInt("limit")
  138. if err != nil {
  139. limit = 30
  140. }
  141. repair := frontm.NewRepair()
  142. repairs,total :=repair.FindAdminHRepairs(page,limit)
  143. outReRepairs := make([]*frontm.OutReRepair,0)
  144. for _, v := range repairs {
  145. outReRepair := new(frontm.OutReRepair)
  146. this.fmtOutReRepair(v,outReRepair)
  147. outReRepairs = append(outReRepairs,outReRepair)
  148. }
  149. this.ajaxList(MSG_OK,"",total,outReRepairs)
  150. }
  151. // 指派维修工人列表
  152. func (this *UserRepairController)AssignRepairWorkers() {
  153. repairWorkers,total := this.findRepairWorkers(true)
  154. this.ajaxList(MSG_OK,"",total,repairWorkers)
  155. }
  156. // 指派维修任务
  157. func (this *UserRepairController)AssignRepairTask(){
  158. id, _ := this.GetInt("id")
  159. repairUserId, _ := this.GetInt("repair_user_id")
  160. if id <= 0 {
  161. this.ajaxMsg(MSG_ERR,"请选择维修任务",nil)
  162. }
  163. if repairUserId <= 0 {
  164. this.ajaxMsg(MSG_ERR,"请指派维修工人",nil)
  165. }
  166. repair := frontm.NewRepair()
  167. if _,err := repair.AssignRepairTask(id,repairUserId); err != nil {
  168. this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
  169. }
  170. this.ajaxMsg(MSG_OK,"指派成功",nil)
  171. }
  172. // 查找维修工人列表
  173. func (this *UserRepairController)findRepairWorkers(isAssign bool)([]*backgroundm.RepairWorker,
  174. int64) {
  175. page, err := this.GetInt("page")
  176. if err != nil {
  177. page = 1
  178. }
  179. limit, err := this.GetInt("limit")
  180. if err != nil {
  181. limit = 30
  182. }
  183. repairWorkers := make([]*backgroundm.RepairWorker,0)
  184. admin := new(backgroundm.Admin)
  185. repair := frontm.NewRepair()
  186. admins,total := admin.FindRepairWorkers(page,limit)
  187. for _, v := range admins {
  188. repairWorker := new(backgroundm.RepairWorker)
  189. repairWorker.Id = v.Id
  190. repairWorker.LoginName = v.LoginName
  191. repairWorker.Phone = v.Phone
  192. repairWorker.NickName = v.NickName
  193. repairWorker.AvatarUrl = v.AvatarUrl
  194. // 查找维修用户待维修数量
  195. repairWorker.WRepairCount = repair.FindServiceUserWRepairCount(v.Id)
  196. if isAssign == false {
  197. // 查找维修用户已维修数量
  198. repairWorker.HRepairCount = repair.FindServiceUserHRepairCount(v.Id)
  199. }else{
  200. // 查找维修用户已维修数量
  201. repairWorker.HRepairCount = 0
  202. }
  203. repairWorkers = append(repairWorkers, repairWorker)
  204. }
  205. return repairWorkers,total
  206. }
  207. // 查找维修用户待维修列表
  208. func (this *UserRepairController)ServiceUserWRepairs()() {
  209. page, err := this.GetInt("page")
  210. if err != nil {
  211. page = 1
  212. }
  213. limit, err := this.GetInt("limit")
  214. if err != nil {
  215. limit = 30
  216. }
  217. repair := frontm.NewRepair()
  218. repairs,total :=repair.FindServiceUserWRepairs(this.userInfo.Id,page,limit)
  219. outReRepairs := make([]*frontm.OutReRepair,0)
  220. for _, v := range repairs {
  221. outReRepair := new(frontm.OutReRepair)
  222. this.fmtOutReRepair(v,outReRepair)
  223. outReRepairs = append(outReRepairs,outReRepair)
  224. }
  225. this.ajaxList(MSG_OK,"",total,outReRepairs)
  226. }
  227. // 查找维修用户待维修列表
  228. func (this *UserRepairController)ServiceUserHRepairs()() {
  229. page, err := this.GetInt("page")
  230. if err != nil {
  231. page = 1
  232. }
  233. limit, err := this.GetInt("limit")
  234. if err != nil {
  235. limit = 30
  236. }
  237. repair := frontm.NewRepair()
  238. repairs,total :=repair.FindServiceUserHRepairs(this.userInfo.Id,page,limit)
  239. outReRepairs := make([]*frontm.OutReRepair,0)
  240. for _, v := range repairs {
  241. outReRepair := new(frontm.OutReRepair)
  242. this.fmtOutReRepair(v,outReRepair)
  243. outReRepairs = append(outReRepairs,outReRepair)
  244. }
  245. this.ajaxList(MSG_OK,"",total,outReRepairs)
  246. }
  247. // 确认维修
  248. func (this *UserRepairController)ConfirmRepair()() {
  249. repair := frontm.NewRepair()
  250. repair.Id, _ = this.GetInt("id")
  251. image := this.GetString("image")
  252. if repair.Id <= 0 {
  253. this.ajaxMsg(MSG_ERR,"请选择要确认维修的任务",nil)
  254. }
  255. repair.RepairUserId = this.userInfo.Id
  256. repair.RepairTime = int(time.Now().Unix())
  257. if _,err := repair.ConfirmRepair(); err != nil {
  258. this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil)
  259. }
  260. data := make(map[string]interface{})
  261. data["image"] = image
  262. data["repairId"] = repair.Id
  263. this.addPicture(data)
  264. this.ajaxMsg(MSG_OK,"维修成功",nil)
  265. }