智慧食堂
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

276 lignes
9.0 KiB

  1. package svc
  2. import (
  3. "applet/app/admin/md"
  4. md2 "applet/app/customer/md"
  5. "applet/app/db"
  6. "applet/app/db/model"
  7. "applet/app/enum"
  8. "applet/app/utils"
  9. "time"
  10. )
  11. func CalcByYearForNursingHome(uid int, buyPackageReq md2.NursingHomeBuyPackageReq) (totalPrice float64, data []*model.NursingHomeUserWithDay, err error) {
  12. sysCfgDb := db.SysCfgDb{}
  13. sysCfgDb.Set()
  14. cfg, err := sysCfgDb.SysCfgGetOne(enum.NursingHomeReserveMealTime)
  15. if err != nil {
  16. return
  17. }
  18. //1、查询出套餐基础设置
  19. NursingHomeWithSpec := db.NursingHomeWithSpec{}
  20. NursingHomeWithSpec.Set(buyPackageReq.EnterpriseId)
  21. NursingHomeWithSpecData, err := NursingHomeWithSpec.GetNursingHomeWithSpec()
  22. if err != nil {
  23. return
  24. }
  25. //2、查询出当前合适的package
  26. var m []model.NursingHomePackage
  27. now := time.Now()
  28. today, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local)
  29. err = db.Db.Where("enterprise_id =?", buyPackageReq.EnterpriseId).In("id", buyPackageReq.PackageIds).And("is_delete = 0").And("state = 1").Desc("end_date").Find(&m)
  30. if err != nil {
  31. return
  32. }
  33. NursingHomeReserveMealTime, _ := time.ParseInLocation("2006-01-02 15:04:05", now.Format("2006-01-02")+" "+cfg.Val+":00", time.Local)
  34. //3、循环拼接数据
  35. for _, v := range m {
  36. NursingHomePackageWithDayDb := db.NursingHomePackageWithDayDb{}
  37. NursingHomePackageWithDayDb.Set(v.Id)
  38. NursingHomePackageWithDay, err1 := NursingHomePackageWithDayDb.FindNursingHomePackageWithDay()
  39. if err1 != nil {
  40. return
  41. }
  42. for _, v1 := range *NursingHomePackageWithDay {
  43. //3.1、判断是否小于今天
  44. date, _ := time.ParseInLocation("2006-01-02", v1.Date, time.Local)
  45. if today.After(date) {
  46. continue
  47. }
  48. if today.Equal(date) {
  49. //2.2、判断是否过了今日可订餐时间
  50. if now.After(NursingHomeReserveMealTime) {
  51. continue
  52. }
  53. }
  54. //3.3、计算价格 && 组装数据
  55. if v1.IsOpenBreakfast == md.OpenBreakfast && buyPackageReq.IsBuyBreakfast == 1 {
  56. //早餐
  57. var amount = NursingHomeWithSpecData.BreakfastUnitPrice
  58. totalPrice += utils.StrToFloat64(amount)
  59. data = append(data, &model.NursingHomeUserWithDay{
  60. Uid: uid,
  61. IdentityId: buyPackageReq.UserIdentityId,
  62. Amount: amount,
  63. Kind: enum.NursingHomeUserWithDayKindForBreakfast,
  64. Date: v1.Date,
  65. State: enum.NursingHomeUserWithDayStateForWait,
  66. })
  67. }
  68. if v1.IsOpenLunch == md.OpenLunch && buyPackageReq.IsBuyLunch == 1 {
  69. var amount = NursingHomeWithSpecData.LunchUnitPrice
  70. totalPrice += utils.StrToFloat64(amount)
  71. data = append(data, &model.NursingHomeUserWithDay{
  72. Uid: uid,
  73. IdentityId: buyPackageReq.UserIdentityId,
  74. Amount: amount,
  75. Kind: enum.NursingHomeUserWithDayKindForLunch,
  76. Date: v1.Date,
  77. State: enum.NursingHomeUserWithDayStateForWait,
  78. })
  79. }
  80. if v1.IsOpenDinner == md.OpenDinner && buyPackageReq.IsBuyDinner == 1 {
  81. var amount = NursingHomeWithSpecData.DinnerUnitPrice
  82. totalPrice += utils.StrToFloat64(amount)
  83. data = append(data, &model.NursingHomeUserWithDay{
  84. Uid: uid,
  85. IdentityId: buyPackageReq.UserIdentityId,
  86. Kind: enum.NursingHomeUserWithDayKindForDinner,
  87. Date: v1.Date,
  88. Amount: amount,
  89. State: enum.NursingHomeUserWithDayStateForWait,
  90. })
  91. }
  92. }
  93. }
  94. return
  95. }
  96. func CalcByMonthForNursingHome(uid int, buyPackageReq md2.NursingHomeBuyPackageReq) (totalPrice float64, data []*model.NursingHomeUserWithDay, err error) {
  97. sysCfgDb := db.SysCfgDb{}
  98. sysCfgDb.Set()
  99. cfg, err := sysCfgDb.SysCfgGetOne(enum.NursingHomeReserveMealTime)
  100. if err != nil {
  101. return
  102. }
  103. //1、查询出套餐基础设置
  104. NursingHomeWithSpec := db.NursingHomeWithSpec{}
  105. NursingHomeWithSpec.Set(buyPackageReq.EnterpriseId)
  106. NursingHomeWithSpecData, err := NursingHomeWithSpec.GetNursingHomeWithSpec()
  107. if err != nil {
  108. return
  109. }
  110. //2、查询出当前合适的package
  111. var m []model.NursingHomePackage
  112. now := time.Now()
  113. today, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local)
  114. err = db.Db.Where("enterprise_id =?", buyPackageReq.EnterpriseId).And("id =?", buyPackageReq.PackageId).And("is_delete = 0").And("state = 1").Find(&m)
  115. if err != nil {
  116. return
  117. }
  118. NursingHomeReserveMealTime, _ := time.ParseInLocation("2006-01-02 15:04:05", now.Format("2006-01-02")+" "+cfg.Val+":00", time.Local)
  119. //3、循环拼接数据
  120. for _, v := range m {
  121. NursingHomePackageWithDayDb := db.NursingHomePackageWithDayDb{}
  122. NursingHomePackageWithDayDb.Set(v.Id)
  123. NursingHomePackageWithDay, err1 := NursingHomePackageWithDayDb.FindNursingHomePackageWithDay()
  124. if err1 != nil {
  125. return
  126. }
  127. for _, v1 := range *NursingHomePackageWithDay {
  128. //3.1、判断是否小于今天
  129. date, _ := time.ParseInLocation("2006-01-02", v1.Date, time.Local)
  130. if today.After(date) {
  131. continue
  132. }
  133. if today.Equal(date) {
  134. //2.2、判断是否过了今日可订餐时间
  135. if now.After(NursingHomeReserveMealTime) {
  136. continue
  137. }
  138. }
  139. //3.3、计算价格 && 组装数据
  140. if v1.IsOpenBreakfast == md.OpenBreakfast && buyPackageReq.IsBuyBreakfast == 1 {
  141. //早餐
  142. var amount = NursingHomeWithSpecData.BreakfastUnitPrice
  143. totalPrice += utils.StrToFloat64(amount)
  144. data = append(data, &model.NursingHomeUserWithDay{
  145. Uid: uid,
  146. IdentityId: buyPackageReq.UserIdentityId,
  147. Amount: amount,
  148. Kind: enum.NursingHomeUserWithDayKindForBreakfast,
  149. Date: v1.Date,
  150. State: enum.NursingHomeUserWithDayStateForWait,
  151. })
  152. }
  153. if v1.IsOpenLunch == md.OpenLunch && buyPackageReq.IsBuyLunch == 1 {
  154. var amount = NursingHomeWithSpecData.LunchUnitPrice
  155. totalPrice += utils.StrToFloat64(amount)
  156. data = append(data, &model.NursingHomeUserWithDay{
  157. Uid: uid,
  158. IdentityId: buyPackageReq.UserIdentityId,
  159. Amount: amount,
  160. Kind: enum.NursingHomeUserWithDayKindForLunch,
  161. Date: v1.Date,
  162. State: enum.NursingHomeUserWithDayStateForWait,
  163. })
  164. }
  165. if v1.IsOpenDinner == md.OpenDinner && buyPackageReq.IsBuyDinner == 1 {
  166. var amount = NursingHomeWithSpecData.DinnerUnitPrice
  167. totalPrice += utils.StrToFloat64(amount)
  168. data = append(data, &model.NursingHomeUserWithDay{
  169. Uid: uid,
  170. IdentityId: buyPackageReq.UserIdentityId,
  171. Kind: enum.NursingHomeUserWithDayKindForDinner,
  172. Amount: amount,
  173. Date: v1.Date,
  174. State: enum.NursingHomeUserWithDayStateForWait,
  175. })
  176. }
  177. }
  178. }
  179. return
  180. }
  181. func CalcByDayForNursingHome(uid int, buyPackageReq md2.NursingHomeBuyPackageReq) (totalPrice float64, data []*model.NursingHomeUserWithDay, err error) {
  182. sysCfgDb := db.SysCfgDb{}
  183. sysCfgDb.Set()
  184. cfg, err := sysCfgDb.SysCfgGetOne(enum.NursingHomeReserveMealTime)
  185. if err != nil {
  186. return
  187. }
  188. //1、查询出套餐基础设置
  189. NursingHomeWithSpec := db.NursingHomeWithSpec{}
  190. NursingHomeWithSpec.Set(buyPackageReq.EnterpriseId)
  191. NursingHomeWithSpecData, err := NursingHomeWithSpec.GetNursingHomeWithSpec()
  192. if err != nil {
  193. return
  194. }
  195. now := time.Now()
  196. today, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local)
  197. NursingHomeReserveMealTime, _ := time.ParseInLocation("2006-01-02 15:04:05", now.Format("2006-01-02")+" "+cfg.Val+":00", time.Local)
  198. //2、循环拼接数据
  199. for _, v1 := range buyPackageReq.WithDays {
  200. //2.1、判断是否小于今天
  201. date, _ := time.ParseInLocation("2006-01-02", v1.Date, time.Local)
  202. if today.After(date) {
  203. continue
  204. }
  205. if today.Equal(date) {
  206. //2.2、判断是否过了今日可订餐时间
  207. if now.After(NursingHomeReserveMealTime) {
  208. continue
  209. }
  210. }
  211. //2.3、计算价格 && 组装数据
  212. if v1.IsBuyBreakfast == 1 && buyPackageReq.IsBuyBreakfast == 1 {
  213. //早餐
  214. var amount = NursingHomeWithSpecData.BreakfastUnitPrice
  215. totalPrice += utils.StrToFloat64(amount)
  216. data = append(data, &model.NursingHomeUserWithDay{
  217. Uid: uid,
  218. IdentityId: buyPackageReq.UserIdentityId,
  219. Kind: enum.NursingHomeUserWithDayKindForBreakfast,
  220. Date: v1.Date,
  221. Amount: amount,
  222. State: enum.NursingHomeUserWithDayStateForWait,
  223. })
  224. }
  225. if v1.IsBuyLunch == 1 && buyPackageReq.IsBuyLunch == 1 {
  226. var amount = NursingHomeWithSpecData.LunchUnitPrice
  227. totalPrice += utils.StrToFloat64(amount)
  228. data = append(data, &model.NursingHomeUserWithDay{
  229. Uid: uid,
  230. IdentityId: buyPackageReq.UserIdentityId,
  231. Kind: enum.NursingHomeUserWithDayKindForLunch,
  232. Date: v1.Date,
  233. State: enum.NursingHomeUserWithDayStateForWait,
  234. Amount: amount,
  235. })
  236. }
  237. if v1.IsBuyDinner == 1 && buyPackageReq.IsBuyDinner == 1 {
  238. var amount = NursingHomeWithSpecData.DinnerUnitPrice
  239. totalPrice += utils.StrToFloat64(amount)
  240. data = append(data, &model.NursingHomeUserWithDay{
  241. Uid: uid,
  242. IdentityId: buyPackageReq.UserIdentityId,
  243. Kind: enum.NursingHomeUserWithDayKindForDinner,
  244. Amount: amount,
  245. Date: v1.Date,
  246. State: enum.NursingHomeUserWithDayStateForWait,
  247. })
  248. }
  249. }
  250. return
  251. }