智慧食堂
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

170 řádky
6.0 KiB

  1. package hdl
  2. import (
  3. "applet/app/customer/svc"
  4. svc2 "applet/app/customer/svc/order"
  5. "applet/app/db"
  6. "applet/app/db/model"
  7. "applet/app/e"
  8. "applet/app/enum"
  9. "applet/app/utils"
  10. "github.com/gin-gonic/gin"
  11. "time"
  12. )
  13. func UserInfo(c *gin.Context) {
  14. //1、获取用户信息
  15. userInfo := svc.GetUser(c)
  16. //2、获取用户身份信息
  17. userIdentityDb := db.UserIdentityDb{}
  18. userIdentityDb.Set(userInfo.Id)
  19. identity, err := userIdentityDb.FindUserIdentity()
  20. if err != nil {
  21. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  22. return
  23. }
  24. var identityList []map[string]interface{}
  25. classWithUserDb := db.ClassWithUserDb{}
  26. classWithUserDb.Set()
  27. for _, v := range *identity {
  28. var tmp = map[string]interface{}{
  29. "identity": v.UserIdentity,
  30. "enterprise": v.Enterprise,
  31. "grade": nil,
  32. "class": nil,
  33. }
  34. if v.UserIdentity.Identity == enum.UserIdentityForCentralKitchenForStudent || v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForStudent {
  35. //央厨学生 or 自营学生
  36. data, err1 := classWithUserDb.GetInfoByUserIdentityId(v.UserIdentity.Id)
  37. if err1 != nil {
  38. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  39. return
  40. }
  41. if data != nil {
  42. tmp["grade"] = data.Grade
  43. tmp["class"] = data.Class
  44. }
  45. }
  46. now := time.Now()
  47. if v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForStudent || v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForTeacher {
  48. //TODO:: 自营-学生 or 自营-教职员工
  49. sMDate := utils.GetFirstDateOfMonth(now).Format("2006-01-02 15:04:05")
  50. eMDate := utils.GetLastDateOfMonth(now).Format("2006-01-02 15:04:05")
  51. sTDate, eTDate := utils.GetDateTimeRangeStr("today")
  52. monthStatistic, err2 := svc2.SupportUserIdentityOrderStatistic(v.UserIdentity.Id, sMDate, eMDate)
  53. if err2 != nil {
  54. e.OutErr(c, e.ERR, err2.Error())
  55. return
  56. }
  57. dayStatistic, err2 := svc2.SupportUserIdentityOrderStatistic(v.UserIdentity.Id, sTDate, eTDate)
  58. if err2 != nil {
  59. e.OutErr(c, e.ERR, err2.Error())
  60. return
  61. }
  62. tmp["month_statistic"] = monthStatistic
  63. tmp["day_statistic"] = dayStatistic
  64. //统计是否存在欠费
  65. arrearsStatistic, err2 := svc2.SupportUserIdentityOrderStatisticForArrears(v.UserIdentity.Id)
  66. if err2 != nil {
  67. e.OutErr(c, e.ERR, err2.Error())
  68. return
  69. }
  70. tmp["arrears_statistic"] = arrearsStatistic
  71. //查询支付宝扣款账户
  72. selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
  73. selfSupportForUserFaceInfoDb.Set(v.UserIdentity.Id)
  74. info, err2 := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo()
  75. if err2 != nil {
  76. e.OutErr(c, e.ERR, err2.Error())
  77. return
  78. }
  79. if info == nil {
  80. selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{}
  81. selfSupportForSchoolInfoDb.Set(v.UserIdentity.EnterpriseId)
  82. selfSupportForSchoolInfo, err1 := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo()
  83. if err1 != nil {
  84. return
  85. }
  86. if selfSupportForSchoolInfo == nil {
  87. e.OutErr(c, e.ERR, "当前学校暂未完成《一脸通行入驻》")
  88. return
  89. }
  90. info = &model.SelfSupportForUserFaceInfo{
  91. EnterpriseId: v.UserIdentity.EnterpriseId,
  92. UserIdentityId: v.UserIdentity.Id,
  93. CollectFaceType: 1, //默认个采
  94. SchoolCode: selfSupportForSchoolInfo.SchoolCode,
  95. SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode,
  96. ParentUserId: "",
  97. ParentLogonId: "",
  98. UserId: "",
  99. SchoolFacePassStatus: "CLOSE",
  100. SchoolFacePaymentStatus: "CLOSE",
  101. ConcentrateSchoolFacePassStatus: 1,
  102. CreateAt: now.Format("2006-01-02 15:04:05"),
  103. UpdateAt: now.Format("2006-01-02 15:04:05"),
  104. }
  105. _, err3 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(info)
  106. if err3 != nil {
  107. e.OutErr(c, e.ERR, err3.Error())
  108. return
  109. }
  110. }
  111. tmp["parent_logon_id"] = info.ParentLogonId
  112. tmp["collect_face_type"] = info.CollectFaceType
  113. tmp["concentrate_school_face_pass_status"] = info.ConcentrateSchoolFacePassStatus
  114. }
  115. if v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForWorker {
  116. selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
  117. selfSupportForUserFaceInfoDb.Set(0)
  118. tmp["school_face_pass_num"], _ = selfSupportForUserFaceInfoDb.CountSchoolFacePassStatus(v.EnterpriseId, "open")
  119. tmp["school_face_payment_num"], _ = selfSupportForUserFaceInfoDb.CountSchoolFacePaymentStatus(v.EnterpriseId, "open")
  120. tmp["concentrate_school_face_pass_num"], _ = selfSupportForUserFaceInfoDb.CountCollectFaceType(v.EnterpriseId, 2)
  121. tmp["single_school_face_pass_num"], _ = selfSupportForUserFaceInfoDb.CountCollectFaceType(v.EnterpriseId, 1)
  122. }
  123. identityList = append(identityList, tmp)
  124. }
  125. utils.FilePutContents("user_info", utils.SerializeStr(map[string]interface{}{
  126. "user_info": userInfo,
  127. "user_identity": identityList,
  128. }))
  129. e.OutSuc(c, map[string]interface{}{
  130. "user_info": userInfo,
  131. "user_identity": identityList,
  132. "user_identity_kind_list": []map[string]interface{}{
  133. {
  134. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent),
  135. "value": enum.UserIdentityForCentralKitchenForStudent,
  136. },
  137. {
  138. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher),
  139. "value": enum.UserIdentityForCentralKitchenForTeacher,
  140. },
  141. {
  142. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker),
  143. "value": enum.UserIdentityForCentralKitchenForWorker,
  144. },
  145. {
  146. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent),
  147. "value": enum.UserIdentityForSelfSupportForStudent,
  148. },
  149. {
  150. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher),
  151. "value": enum.UserIdentityForSelfSupportForTeacher,
  152. },
  153. {
  154. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker),
  155. "value": enum.UserIdentityForSelfSupportForWorker,
  156. },
  157. },
  158. }, nil)
  159. return
  160. }