智慧食堂
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

316 строки
9.9 KiB

  1. package hdl
  2. import (
  3. "applet/app/admin/lib/validate"
  4. "applet/app/admin/md"
  5. svc "applet/app/admin/svc/enterprise_manage"
  6. svc2 "applet/app/admin/svc/order"
  7. "applet/app/db"
  8. "applet/app/e"
  9. "applet/app/enum"
  10. "applet/app/utils"
  11. "applet/app/utils/logx"
  12. "errors"
  13. "github.com/gin-gonic/gin"
  14. )
  15. func CentralKitchenForSchoolOrderRefundList(c *gin.Context) {
  16. var req md.CentralKitchenForSchoolOrderRefundListReq
  17. err := c.ShouldBindJSON(&req)
  18. if err != nil {
  19. err = validate.HandleValidateErr(err)
  20. err1 := err.(e.E)
  21. e.OutErr(c, err1.Code, err1.Error())
  22. return
  23. }
  24. list, total, err := svc2.CentralKitchenForSchoolOrderRefundList(req)
  25. if err != nil {
  26. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  27. return
  28. }
  29. e.OutSuc(c, map[string]interface{}{
  30. "list": list,
  31. "total": total,
  32. "audit_kind_list": []map[string]interface{}{
  33. {
  34. "name": "同意",
  35. "value": 1,
  36. },
  37. {
  38. "name": "拒绝",
  39. "value": 2,
  40. },
  41. },
  42. "kind_list": []map[string]interface{}{
  43. {
  44. "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast),
  45. "value": enum.CentralKitchenForSchoolUserWithDayKindForBreakfast,
  46. },
  47. {
  48. "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch),
  49. "value": enum.CentralKitchenForSchoolUserWithDayKindForLunch,
  50. },
  51. {
  52. "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner),
  53. "value": enum.CentralKitchenForSchoolUserWithDayKindForDinner,
  54. },
  55. },
  56. "state_list": []map[string]interface{}{
  57. {
  58. "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditing),
  59. "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditing,
  60. },
  61. {
  62. "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass),
  63. "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass,
  64. },
  65. {
  66. "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject),
  67. "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject,
  68. },
  69. {
  70. "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete),
  71. "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete,
  72. },
  73. },
  74. "user_identity_kind_list": []map[string]interface{}{
  75. {
  76. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent),
  77. "value": enum.UserIdentityForCentralKitchenForStudent,
  78. },
  79. {
  80. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher),
  81. "value": enum.UserIdentityForCentralKitchenForTeacher,
  82. },
  83. {
  84. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker),
  85. "value": enum.UserIdentityForCentralKitchenForWorker,
  86. },
  87. {
  88. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent),
  89. "value": enum.UserIdentityForSelfSupportForStudent,
  90. },
  91. {
  92. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher),
  93. "value": enum.UserIdentityForSelfSupportForTeacher,
  94. },
  95. {
  96. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker),
  97. "value": enum.UserIdentityForSelfSupportForWorker,
  98. },
  99. },
  100. }, nil)
  101. return
  102. }
  103. func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context) {
  104. var req md.CentralKitchenForSchoolOrderRefundAuditReq
  105. err := c.ShouldBindJSON(&req)
  106. if err != nil {
  107. err = validate.HandleValidateErr(err)
  108. err1 := err.(e.E)
  109. e.OutErr(c, err1.Code, err1.Error())
  110. return
  111. }
  112. //限制500条
  113. if len(req.Ids) > 500 {
  114. e.OutErr(c, e.ERR, errors.New("受理数据过长,请分批次处理"))
  115. return
  116. }
  117. //TODO::先将所有申请单改成 审核通过 状态
  118. session := db.Db.NewSession()
  119. defer session.Close()
  120. session.Begin()
  121. centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
  122. centralKitchenForSchoolUserRefundDayDb.Set(0)
  123. centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{}
  124. centralKitchenForSchoolUserWithDayDb.Set(0)
  125. for _, v := range req.Ids {
  126. returnDay, err1 := centralKitchenForSchoolUserRefundDayDb.GetCentralKitchenForSchoolUserRefundDay(utils.StrToInt(v))
  127. if err1 != nil {
  128. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  129. return
  130. }
  131. if returnDay.State != enum.CentralKitchenForSchoolUserRefundDayStateForAuditing {
  132. _ = session.Rollback()
  133. e.OutErr(c, e.ERR, "请勿重复审核申请单!")
  134. return
  135. }
  136. //1、更新状态
  137. if req.State == 1 {
  138. returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass
  139. } else {
  140. userWithDay, err3 := centralKitchenForSchoolUserWithDayDb.GetCentralKitchenForSchoolUserWithDay(returnDay.RecordsId)
  141. if err3 != nil {
  142. _ = session.Rollback()
  143. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  144. return
  145. }
  146. returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject
  147. userWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForWait
  148. updateAck1, err4 := centralKitchenForSchoolUserWithDayDb.CentralKitchenForSchoolUserWithDayUpdate(userWithDay.Id, userWithDay, "state")
  149. if err4 != nil {
  150. _ = session.Rollback()
  151. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  152. return
  153. }
  154. if updateAck1 <= 0 {
  155. _ = session.Rollback()
  156. e.OutErr(c, e.ERR_DB_ORM, errors.New("更新退款就餐记录状态失败2"))
  157. return
  158. }
  159. //2、处理订单状态
  160. err5 := svc.JudgePackageOrdOrdState(returnDay.OutTradeNo)
  161. if err5 != nil {
  162. _ = session.Rollback()
  163. e.OutErr(c, e.ERR, err5.Error())
  164. return
  165. }
  166. }
  167. returnDay.Memo = req.Memo
  168. updateAck, err2 := centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayUpdate(returnDay.Id, returnDay, "state", "memo")
  169. if err2 != nil {
  170. _ = session.Rollback()
  171. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  172. return
  173. }
  174. if updateAck <= 0 {
  175. _ = session.Rollback()
  176. e.OutErr(c, e.ERR_DB_ORM, errors.New("更新退款订单记录状态失败1"))
  177. return
  178. }
  179. }
  180. err = session.Commit()
  181. if err != nil {
  182. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  183. return
  184. }
  185. go func() {
  186. err1 := svc2.CentralKitchenForSchoolOrderRefundAudit(c, req)
  187. if err1 != nil {
  188. logx.Error(err1)
  189. println("<<<<CentralKitchenForSchoolOrderRefundAudit>>>>>Error:::", err1.Error())
  190. }
  191. }()
  192. e.OutSuc(c, "success", nil)
  193. return
  194. }
  195. func NursingHomeOrderRefundList(c *gin.Context) {
  196. var req md.NursingHomeOrderRefundListReq
  197. err := c.ShouldBindJSON(&req)
  198. if err != nil {
  199. err = validate.HandleValidateErr(err)
  200. err1 := err.(e.E)
  201. e.OutErr(c, err1.Code, err1.Error())
  202. return
  203. }
  204. list, total, err := svc2.NursingHomeOrderRefundList(req)
  205. if err != nil {
  206. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  207. return
  208. }
  209. e.OutSuc(c, map[string]interface{}{
  210. "list": list,
  211. "total": total,
  212. "audit_kind_list": []map[string]interface{}{
  213. {
  214. "name": "同意",
  215. "value": 1,
  216. },
  217. {
  218. "name": "拒绝",
  219. "value": 2,
  220. },
  221. },
  222. "kind_list": []map[string]interface{}{
  223. {
  224. "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast),
  225. "value": enum.CentralKitchenForSchoolUserWithDayKindForBreakfast,
  226. },
  227. {
  228. "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch),
  229. "value": enum.CentralKitchenForSchoolUserWithDayKindForLunch,
  230. },
  231. {
  232. "name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner),
  233. "value": enum.CentralKitchenForSchoolUserWithDayKindForDinner,
  234. },
  235. },
  236. "state_list": []map[string]interface{}{
  237. {
  238. "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditing),
  239. "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditing,
  240. },
  241. {
  242. "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass),
  243. "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass,
  244. },
  245. {
  246. "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject),
  247. "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject,
  248. },
  249. {
  250. "name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete),
  251. "value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete,
  252. },
  253. },
  254. "user_identity_kind_list": []map[string]interface{}{
  255. {
  256. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent),
  257. "value": enum.UserIdentityForCentralKitchenForStudent,
  258. },
  259. {
  260. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher),
  261. "value": enum.UserIdentityForCentralKitchenForTeacher,
  262. },
  263. {
  264. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker),
  265. "value": enum.UserIdentityForCentralKitchenForWorker,
  266. },
  267. {
  268. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent),
  269. "value": enum.UserIdentityForSelfSupportForStudent,
  270. },
  271. {
  272. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher),
  273. "value": enum.UserIdentityForSelfSupportForTeacher,
  274. },
  275. {
  276. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker),
  277. "value": enum.UserIdentityForSelfSupportForWorker,
  278. },
  279. },
  280. }, nil)
  281. return
  282. }
  283. func NursingHomeOrderRefundAudit(c *gin.Context) {
  284. var req md.NursingHomeOrderRefundAuditReq
  285. err := c.ShouldBindJSON(&req)
  286. if err != nil {
  287. err = validate.HandleValidateErr(err)
  288. err1 := err.(e.E)
  289. e.OutErr(c, err1.Code, err1.Error())
  290. return
  291. }
  292. err = svc2.NursingHomeOrderRefundAudit(req)
  293. if err != nil {
  294. e.OutErr(c, e.ERR, err.Error())
  295. return
  296. }
  297. e.OutSuc(c, "success", nil)
  298. return
  299. }