智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
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. tmp["period"] = data.Period
  45. }
  46. }
  47. now := time.Now()
  48. if v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForStudent || v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForTeacher {
  49. //TODO:: 自营-学生 or 自营-教职员工
  50. sMDate := utils.GetFirstDateOfMonth(now).Format("2006-01-02 15:04:05")
  51. eMDate := utils.GetLastDateOfMonth(now).Format("2006-01-02 15:04:05")
  52. sTDate, eTDate := utils.GetDateTimeRangeStr("today")
  53. monthStatistic, err2 := svc2.SupportUserIdentityOrderStatistic(v.UserIdentity.Id, sMDate, eMDate)
  54. if err2 != nil {
  55. e.OutErr(c, e.ERR, err2.Error())
  56. return
  57. }
  58. dayStatistic, err2 := svc2.SupportUserIdentityOrderStatistic(v.UserIdentity.Id, sTDate, eTDate)
  59. if err2 != nil {
  60. e.OutErr(c, e.ERR, err2.Error())
  61. return
  62. }
  63. tmp["month_statistic"] = monthStatistic
  64. tmp["day_statistic"] = dayStatistic
  65. //统计是否存在欠费
  66. arrearsStatistic, err2 := svc2.SupportUserIdentityOrderStatisticForArrears(v.UserIdentity.Id)
  67. if err2 != nil {
  68. e.OutErr(c, e.ERR, err2.Error())
  69. return
  70. }
  71. tmp["arrears_statistic"] = arrearsStatistic
  72. //查询支付宝扣款账户
  73. selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
  74. selfSupportForUserFaceInfoDb.Set(v.UserIdentity.Id)
  75. info, err2 := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo()
  76. if err2 != nil {
  77. e.OutErr(c, e.ERR, err2.Error())
  78. return
  79. }
  80. if info == nil {
  81. selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{}
  82. selfSupportForSchoolInfoDb.Set(v.UserIdentity.EnterpriseId)
  83. selfSupportForSchoolInfo, err1 := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo()
  84. if err1 != nil {
  85. return
  86. }
  87. if selfSupportForSchoolInfo == nil {
  88. e.OutErr(c, e.ERR, "当前学校暂未完成《一脸通行入驻》")
  89. return
  90. }
  91. info = &model.SelfSupportForUserFaceInfo{
  92. EnterpriseId: v.UserIdentity.EnterpriseId,
  93. UserIdentityId: v.UserIdentity.Id,
  94. CollectFaceType: 1, //默认个采
  95. SchoolCode: selfSupportForSchoolInfo.SchoolCode,
  96. SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode,
  97. ParentUserId: "",
  98. ParentLogonId: "",
  99. UserId: "",
  100. SchoolFacePassStatus: "CLOSE",
  101. SchoolFacePaymentStatus: "CLOSE",
  102. ConcentrateSchoolFacePassStatus: 1,
  103. CreateAt: now.Format("2006-01-02 15:04:05"),
  104. UpdateAt: now.Format("2006-01-02 15:04:05"),
  105. }
  106. _, err3 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(info)
  107. if err3 != nil {
  108. e.OutErr(c, e.ERR, err3.Error())
  109. return
  110. }
  111. }
  112. tmp["parent_logon_id"] = info.ParentLogonId
  113. tmp["collect_face_type"] = info.CollectFaceType
  114. tmp["concentrate_school_face_pass_status"] = info.ConcentrateSchoolFacePassStatus
  115. }
  116. if v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForWorker {
  117. selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
  118. selfSupportForUserFaceInfoDb.Set(0)
  119. tmp["school_face_pass_num"], _ = selfSupportForUserFaceInfoDb.CountSchoolFacePassStatus(v.EnterpriseId, "open")
  120. tmp["school_face_payment_num"], _ = selfSupportForUserFaceInfoDb.CountSchoolFacePaymentStatus(v.EnterpriseId, "open")
  121. tmp["concentrate_school_face_pass_num"], _ = selfSupportForUserFaceInfoDb.CountCollectFaceType(v.EnterpriseId, 2)
  122. tmp["single_school_face_pass_num"], _ = selfSupportForUserFaceInfoDb.CountCollectFaceType(v.EnterpriseId, 1)
  123. }
  124. identityList = append(identityList, tmp)
  125. }
  126. utils.FilePutContents("user_info", utils.SerializeStr(map[string]interface{}{
  127. "user_info": userInfo,
  128. "user_identity": identityList,
  129. }))
  130. e.OutSuc(c, map[string]interface{}{
  131. "user_info": userInfo,
  132. "user_identity": identityList,
  133. "user_identity_kind_list": []map[string]interface{}{
  134. {
  135. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent),
  136. "value": enum.UserIdentityForCentralKitchenForStudent,
  137. },
  138. {
  139. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher),
  140. "value": enum.UserIdentityForCentralKitchenForTeacher,
  141. },
  142. {
  143. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker),
  144. "value": enum.UserIdentityForCentralKitchenForWorker,
  145. },
  146. {
  147. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent),
  148. "value": enum.UserIdentityForSelfSupportForStudent,
  149. },
  150. {
  151. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher),
  152. "value": enum.UserIdentityForSelfSupportForTeacher,
  153. },
  154. {
  155. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker),
  156. "value": enum.UserIdentityForSelfSupportForWorker,
  157. },
  158. },
  159. }, nil)
  160. return
  161. }