智慧食堂
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.

hdl_nursing_home.go 21 KiB

1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. package hdl
  2. import (
  3. "applet/app/admin/lib/validate"
  4. "applet/app/admin/md"
  5. "applet/app/admin/svc"
  6. svc2 "applet/app/admin/svc/enterprise_manage"
  7. "applet/app/db"
  8. "applet/app/db/model"
  9. "applet/app/e"
  10. "applet/app/enum"
  11. "applet/app/utils"
  12. "github.com/gin-gonic/gin"
  13. "time"
  14. )
  15. func NursingHomeUserUpdate(c *gin.Context) {
  16. var req md.NursingHomeUserUpdateReq
  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. enterpriseDb := db.EnterpriseDb{}
  25. enterpriseDb.Set()
  26. enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId)
  27. if err != nil {
  28. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  29. return
  30. }
  31. if enterprise == nil {
  32. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  33. return
  34. }
  35. err = svc2.NursingHomeUserUpdate(req)
  36. if err != nil {
  37. e.OutErr(c, e.ERR, err.Error())
  38. return
  39. }
  40. e.OutSuc(c, "success", nil)
  41. return
  42. }
  43. func NursingHomeUserDelete(c *gin.Context) {
  44. var req md.NursingHomeUserDeleteReq
  45. err := c.ShouldBindJSON(&req)
  46. if err != nil {
  47. err = validate.HandleValidateErr(err)
  48. err1 := err.(e.E)
  49. e.OutErr(c, err1.Code, err1.Error())
  50. return
  51. }
  52. enterpriseDb := db.EnterpriseDb{}
  53. enterpriseDb.Set()
  54. enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId)
  55. if err != nil {
  56. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  57. return
  58. }
  59. if enterprise == nil {
  60. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  61. return
  62. }
  63. err = svc2.NursingHomeUserDelete(req)
  64. if err != nil {
  65. e.OutErr(c, e.ERR, err.Error())
  66. return
  67. }
  68. e.OutSuc(c, "success", nil)
  69. return
  70. }
  71. func GetNursingHomeWithSpec(c *gin.Context) {
  72. enterpriseId := utils.StrToInt(c.DefaultQuery("enterprise_id", "0"))
  73. nursingHomeWithSpec := db.NursingHomeWithSpec{}
  74. nursingHomeWithSpec.Set(enterpriseId)
  75. data, err := nursingHomeWithSpec.GetNursingHomeWithSpec()
  76. if err != nil {
  77. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  78. return
  79. }
  80. e.OutSuc(c, map[string]interface{}{
  81. "data": data,
  82. }, nil)
  83. return
  84. }
  85. func SetNursingHomeWithSpec(c *gin.Context) {
  86. var req md.SetNursingHomeWithSpecReq
  87. err := c.ShouldBindJSON(&req)
  88. if err != nil {
  89. err = validate.HandleValidateErr(err)
  90. err1 := err.(e.E)
  91. e.OutErr(c, err1.Code, err1.Error())
  92. return
  93. }
  94. nursingHomeWithSpec := db.NursingHomeWithSpec{}
  95. nursingHomeWithSpec.Set(req.EnterpriseId)
  96. spec, err := nursingHomeWithSpec.GetNursingHomeWithSpec()
  97. if err != nil {
  98. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  99. return
  100. }
  101. _, err = nursingHomeWithSpec.NursingHomeWithSpecDelete()
  102. if err != nil {
  103. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  104. return
  105. }
  106. now := time.Now()
  107. if spec != nil {
  108. insertConfirm, err1 := nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{
  109. IsOpenBreakfast: spec.IsOpenBreakfast,
  110. IsOpenLunch: spec.IsOpenLunch,
  111. IsOpenDinner: spec.IsOpenDinner,
  112. EnterpriseId: req.EnterpriseId,
  113. BreakfastUnitPrice: req.BreakfastUnitPrice,
  114. LunchUnitPrice: req.LunchUnitPrice,
  115. DinnerUnitPrice: req.DinnerUnitPrice,
  116. CreateAt: now.Format("2006-01-02 15:04:05"),
  117. UpdateAt: now.Format("2006-01-02 15:04:05"),
  118. })
  119. if err1 != nil {
  120. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  121. return
  122. }
  123. if insertConfirm <= 0 {
  124. e.OutErr(c, e.ERR_DB_ORM, "新增数据失败")
  125. return
  126. }
  127. } else {
  128. insertConfirm, err1 := nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{
  129. EnterpriseId: req.EnterpriseId,
  130. BreakfastUnitPrice: req.BreakfastUnitPrice,
  131. LunchUnitPrice: req.LunchUnitPrice,
  132. DinnerUnitPrice: req.DinnerUnitPrice,
  133. CreateAt: now.Format("2006-01-02 15:04:05"),
  134. UpdateAt: now.Format("2006-01-02 15:04:05"),
  135. })
  136. if err1 != nil {
  137. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  138. return
  139. }
  140. if insertConfirm <= 0 {
  141. e.OutErr(c, e.ERR_DB_ORM, "新增数据失败")
  142. return
  143. }
  144. }
  145. e.OutSuc(c, "success", nil)
  146. return
  147. }
  148. func ListNursingHomePackage(c *gin.Context) {
  149. var req md.ListNursingHomePackageReq
  150. err := c.ShouldBindJSON(&req)
  151. if err != nil {
  152. err = validate.HandleValidateErr(err)
  153. err1 := err.(e.E)
  154. e.OutErr(c, err1.Code, err1.Error())
  155. return
  156. }
  157. nursingHomePackageDb := db.NursingHomePackageDb{}
  158. nursingHomePackageDb.Set()
  159. list, total, err := nursingHomePackageDb.NursingHomePackageList(req)
  160. if err != nil {
  161. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  162. return
  163. }
  164. e.OutSuc(c, map[string]interface{}{
  165. "list": list,
  166. "total": total,
  167. "state_list": []map[string]interface{}{
  168. {
  169. "name": "可用",
  170. "value": 1,
  171. },
  172. {
  173. "name": "不可用",
  174. "value": 2,
  175. },
  176. },
  177. }, nil)
  178. return
  179. }
  180. func DetailNursingHomePackage(c *gin.Context) {
  181. packageId := utils.StrToInt(c.DefaultQuery("package_id", ""))
  182. nursingHomePackageDb := db.NursingHomePackageDb{}
  183. nursingHomePackageDb.Set()
  184. NursingHomePackage, err := nursingHomePackageDb.GetNursingHomePackage(packageId)
  185. if err != nil {
  186. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  187. return
  188. }
  189. if NursingHomePackage == nil {
  190. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  191. return
  192. }
  193. nursingHomePackageWithDayDb := db.NursingHomePackageWithDayDb{}
  194. nursingHomePackageWithDayDb.Set(packageId)
  195. nursingHomePackageWithDay, err := nursingHomePackageWithDayDb.FindNursingHomePackageWithDay()
  196. if err != nil {
  197. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  198. return
  199. }
  200. var resp = md.SaveNursingHomePackageReq{
  201. PackageId: NursingHomePackage.Id,
  202. EnterpriseId: NursingHomePackage.EnterpriseId,
  203. Year: NursingHomePackage.Year,
  204. Month: NursingHomePackage.Month,
  205. StartDate: NursingHomePackage.StartDate,
  206. EndDate: NursingHomePackage.EndDate,
  207. DateList: nil,
  208. }
  209. for _, v := range *nursingHomePackageWithDay {
  210. resp.DateList = append(resp.DateList, struct {
  211. Date string `json:"date"`
  212. IsOpenBreakfast int32 `json:"is_open_breakfast"`
  213. IsOpenLunch int32 `json:"is_open_lunch"`
  214. IsOpenDinner int32 `json:"is_open_dinner"`
  215. IsOpenReplenish int32 `json:"is_open_replenish"`
  216. }{Date: v.Date, IsOpenBreakfast: int32(v.IsOpenBreakfast), IsOpenLunch: int32(v.IsOpenLunch), IsOpenDinner: int32(v.IsOpenDinner), IsOpenReplenish: int32(v.IsOpenReplenish)})
  217. }
  218. e.OutSuc(c, resp, nil)
  219. return
  220. }
  221. func SaveNursingHomePackage(c *gin.Context) {
  222. var req md.SaveNursingHomePackageReq
  223. err := c.ShouldBindJSON(&req)
  224. if err != nil {
  225. err = validate.HandleValidateErr(err)
  226. err1 := err.(e.E)
  227. e.OutErr(c, err1.Code, err1.Error())
  228. return
  229. }
  230. //判断是新增 / 编辑
  231. if req.PackageId > 0 {
  232. err = svc.UpdateNursingHomePackage(req)
  233. if err != nil {
  234. e.OutErr(c, e.ERR, err.Error())
  235. return
  236. }
  237. } else {
  238. err = svc.AddNursingHomePackage(req)
  239. if err != nil {
  240. e.OutErr(c, e.ERR, err.Error())
  241. return
  242. }
  243. }
  244. e.OutSuc(c, "success", nil)
  245. return
  246. }
  247. func SetBasicNursingHome(c *gin.Context) {
  248. var req md.SetBasicNursingHomeReq
  249. err := c.ShouldBindJSON(&req)
  250. if err != nil {
  251. err = validate.HandleValidateErr(err)
  252. err1 := err.(e.E)
  253. e.OutErr(c, err1.Code, err1.Error())
  254. return
  255. }
  256. now := time.Now()
  257. //1、更新 nursing_home_set
  258. nursingHomeSetDb := db.NursingHomeSetDb{}
  259. nursingHomeSetDb.Set(req.EnterpriseId)
  260. set, err := nursingHomeSetDb.GetNursingHomeSet()
  261. if err != nil {
  262. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  263. return
  264. }
  265. if set != nil {
  266. set.IsOpenReportMealForYear = req.IsOpenReportMealForYear
  267. set.IsOpenReportMealForDay = req.IsOpenReportMealForDay
  268. set.IsOpenReportMealForMonth = req.IsOpenReportMealForMonth
  269. set.UpdateAt = now.Format("2006-01-02 15:04:05")
  270. _, err2 := nursingHomeSetDb.NursingHomeSetUpdate(set.Id, set, "is_open_report_meal_for_day", "is_open_report_meal_for_month", "is_open_report_meal_for_year", "update_at")
  271. if err2 != nil {
  272. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  273. return
  274. }
  275. } else {
  276. _, err2 := nursingHomeSetDb.NursingHomeSetInsert(&model.NursingHomeSet{
  277. EnterpriseId: req.EnterpriseId,
  278. IsOpenReportMealForYear: req.IsOpenReportMealForYear,
  279. IsOpenReportMealForDay: req.IsOpenReportMealForDay,
  280. IsOpenReportMealForMonth: req.IsOpenReportMealForMonth,
  281. CreateAt: now.Format("2006-01-02 15:04:05"),
  282. UpdateAt: now.Format("2006-01-02 15:04:05"),
  283. })
  284. if err2 != nil {
  285. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  286. return
  287. }
  288. }
  289. //2、更新 nursing_home_with_spec
  290. nursingHomeWithSpec := db.NursingHomeWithSpec{}
  291. nursingHomeWithSpec.Set(req.EnterpriseId)
  292. spec, err := nursingHomeWithSpec.GetNursingHomeWithSpec()
  293. if err != nil {
  294. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  295. return
  296. }
  297. if spec != nil {
  298. spec.IsOpenBreakfast = req.IsOpenBreakfast
  299. spec.IsOpenLunch = req.IsOpenLunch
  300. spec.IsOpenDinner = req.IsOpenDinner
  301. spec.UpdateAt = now.Format("2006-01-02 15:04:05")
  302. _, err2 := nursingHomeWithSpec.NursingHomeWithSpecUpdate(spec.Id, spec, "is_open_breakfast", "is_open_lunch", "is_open_dinner", "update_at")
  303. if err2 != nil {
  304. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  305. return
  306. }
  307. } else {
  308. _, err2 := nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{
  309. EnterpriseId: req.EnterpriseId,
  310. IsOpenBreakfast: req.IsOpenBreakfast,
  311. IsOpenLunch: req.IsOpenLunch,
  312. IsOpenDinner: req.IsOpenDinner,
  313. CreateAt: now.Format("2006-01-02 15:04:05"),
  314. UpdateAt: now.Format("2006-01-02 15:04:05"),
  315. })
  316. if err2 != nil {
  317. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  318. return
  319. }
  320. }
  321. //3、更新 `enterprise`
  322. enterpriseDb := db.EnterpriseDb{}
  323. enterpriseDb.Set()
  324. enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId)
  325. if err != nil {
  326. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  327. return
  328. }
  329. if enterprise == nil {
  330. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  331. return
  332. }
  333. enterprise.Name = req.Name
  334. enterprise.State = req.State
  335. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  336. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "state", "update_at")
  337. if err != nil {
  338. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  339. return
  340. }
  341. e.OutSuc(c, "success", nil)
  342. return
  343. }
  344. func GetBasicNursingHome(c *gin.Context) {
  345. enterpriseId := utils.StrToInt(c.DefaultQuery("enterprise_id", "0"))
  346. //1、获取 nursing_home_set
  347. nursingHomeSetDb := db.NursingHomeSetDb{}
  348. nursingHomeSetDb.Set(enterpriseId)
  349. set, err := nursingHomeSetDb.GetNursingHomeSet()
  350. if err != nil {
  351. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  352. return
  353. }
  354. if set == nil {
  355. set = &model.NursingHomeSet{
  356. EnterpriseId: enterpriseId,
  357. IsOpenReportMealForDay: 0,
  358. IsOpenReportMealForMonth: 0,
  359. IsOpenReportMealForYear: 0,
  360. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  361. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  362. }
  363. _, err2 := nursingHomeSetDb.NursingHomeSetInsert(set)
  364. if err2 != nil {
  365. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  366. return
  367. }
  368. }
  369. //2、获取 nursing_home_with_spec
  370. nursingHomeWithSpec := db.NursingHomeWithSpec{}
  371. nursingHomeWithSpec.Set(enterpriseId)
  372. spec, err := nursingHomeWithSpec.GetNursingHomeWithSpec()
  373. if err != nil {
  374. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  375. return
  376. }
  377. if spec == nil {
  378. spec = &model.NursingHomeWithSpec{
  379. EnterpriseId: enterpriseId,
  380. IsOpenBreakfast: 0,
  381. IsOpenLunch: 0,
  382. IsOpenDinner: 0,
  383. BreakfastUnitPrice: "0",
  384. LunchUnitPrice: "0",
  385. DinnerUnitPrice: "0",
  386. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  387. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  388. }
  389. _, err2 := nursingHomeWithSpec.NursingHomeWithSpecInsert(spec)
  390. if err2 != nil {
  391. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  392. return
  393. }
  394. }
  395. //3、更新 `enterprise`
  396. enterpriseDb := db.EnterpriseDb{}
  397. enterpriseDb.Set()
  398. enterprise, err := enterpriseDb.GetEnterprise(enterpriseId)
  399. if err != nil {
  400. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  401. return
  402. }
  403. if enterprise == nil {
  404. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  405. return
  406. }
  407. e.OutSuc(c, map[string]interface{}{
  408. "central_kitchen_for_school_set": set,
  409. "central_kitchen_for_school_with_spec": spec,
  410. "enterprise": enterprise,
  411. }, nil)
  412. return
  413. }
  414. func NursingHomeOrdList(c *gin.Context) {
  415. var req md.NursingHomeOrdListReq
  416. err := c.ShouldBindJSON(&req)
  417. if err != nil {
  418. err = validate.HandleValidateErr(err)
  419. err1 := err.(e.E)
  420. e.OutErr(c, err1.Code, err1.Error())
  421. return
  422. }
  423. resp, total, err := svc2.NursingHomeOrdList(req)
  424. if err != nil {
  425. e.OutErr(c, e.ERR, err.Error())
  426. return
  427. }
  428. e.OutSuc(c, map[string]interface{}{
  429. "list": resp,
  430. "total": total,
  431. "kind_list": []map[string]string{
  432. {
  433. "name": "按年购买",
  434. "value": "1",
  435. },
  436. {
  437. "name": "按月购买",
  438. "value": "2",
  439. },
  440. {
  441. "name": "按天购买",
  442. "value": "3",
  443. },
  444. {
  445. "name": "补餐",
  446. "value": "4",
  447. },
  448. },
  449. "state_list": []map[string]interface{}{
  450. {
  451. "name": enum.NursingHomePackageOrdState.String(enum.NursingHomePackageOrdStateForWait),
  452. "value": enum.NursingHomePackageOrdStateForWait,
  453. },
  454. {
  455. "name": enum.NursingHomePackageOrdState.String(enum.NursingHomePackageOrdStateForSuccess),
  456. "value": enum.NursingHomePackageOrdStateForSuccess,
  457. },
  458. {
  459. "name": enum.NursingHomePackageOrdState.String(enum.NursingHomePackageOrdStateForFail),
  460. "value": enum.NursingHomePackageOrdStateForFail,
  461. },
  462. },
  463. "ord_state_list": []map[string]interface{}{
  464. {
  465. "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForWait),
  466. "value": enum.NursingHomePackageOrdOrdStateForWait,
  467. },
  468. {
  469. "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForSuccess),
  470. "value": enum.NursingHomePackageOrdOrdStateForSuccess,
  471. },
  472. {
  473. "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForRefunding),
  474. "value": enum.NursingHomePackageOrdOrdStateForRefunding,
  475. },
  476. {
  477. "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForPartRefunded),
  478. "value": enum.NursingHomePackageOrdOrdStateForPartRefunded,
  479. },
  480. {
  481. "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForRefunded),
  482. "value": enum.NursingHomePackageOrdOrdStateForRefunded,
  483. },
  484. {
  485. "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForComplete),
  486. "value": enum.NursingHomePackageOrdOrdStateForComplete,
  487. },
  488. },
  489. "user_identity_kind_list": []map[string]interface{}{
  490. {
  491. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent),
  492. "value": enum.UserIdentityForCentralKitchenForStudent,
  493. },
  494. {
  495. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher),
  496. "value": enum.UserIdentityForCentralKitchenForTeacher,
  497. },
  498. {
  499. "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker),
  500. "value": enum.UserIdentityForCentralKitchenForWorker,
  501. },
  502. {
  503. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent),
  504. "value": enum.UserIdentityForSelfSupportForStudent,
  505. },
  506. {
  507. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher),
  508. "value": enum.UserIdentityForSelfSupportForTeacher,
  509. },
  510. {
  511. "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker),
  512. "value": enum.UserIdentityForSelfSupportForWorker,
  513. },
  514. },
  515. }, nil)
  516. return
  517. }
  518. func NursingHomeReserveList(c *gin.Context) {
  519. var req md.NursingHomeReserveListReq
  520. err := c.ShouldBindJSON(&req)
  521. if err != nil {
  522. err = validate.HandleValidateErr(err)
  523. err1 := err.(e.E)
  524. e.OutErr(c, err1.Code, err1.Error())
  525. return
  526. }
  527. resp, total, err := svc2.NursingHomeReserveList(req)
  528. if err != nil {
  529. e.OutErr(c, e.ERR, err.Error())
  530. return
  531. }
  532. e.OutSuc(c, map[string]interface{}{
  533. "list": resp,
  534. "total": total,
  535. "kind_list": []map[string]interface{}{
  536. {
  537. "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForBreakfast),
  538. "value": enum.NursingHomeUserWithDayKindForBreakfast,
  539. },
  540. {
  541. "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForLunch),
  542. "value": enum.NursingHomeUserWithDayKindForLunch,
  543. },
  544. {
  545. "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForDinner),
  546. "value": enum.NursingHomeUserWithDayKindForDinner,
  547. },
  548. },
  549. }, nil)
  550. return
  551. }
  552. func NursingHomeReserveDetail(c *gin.Context) {
  553. id := c.DefaultQuery("id", "")
  554. NursingHomePackageOrdForReserveDb := db.NursingHomePackageOrdForReserve{}
  555. NursingHomePackageOrdForReserveDb.Set("")
  556. NursingHomePackageOrdForReserve, err := NursingHomePackageOrdForReserveDb.GetNursingHomePackageOrdForReserveById(utils.StrToInt(id))
  557. if err != nil {
  558. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  559. return
  560. }
  561. if NursingHomePackageOrdForReserve == nil {
  562. e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
  563. return
  564. }
  565. var m []model.NursingHomeUserWithDay
  566. err = db.Db.Where("ord_no =?", NursingHomePackageOrdForReserve.OutTradeNo).
  567. And("date >=? and date <=?", NursingHomePackageOrdForReserve.MealTimeStart, NursingHomePackageOrdForReserve.MealTimeEnd).
  568. Find(&m)
  569. if err != nil {
  570. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  571. return
  572. }
  573. e.OutSuc(c, map[string]interface{}{
  574. "list": m,
  575. "kind_list": []map[string]interface{}{
  576. {
  577. "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForBreakfast),
  578. "value": enum.NursingHomeUserWithDayKindForBreakfast,
  579. },
  580. {
  581. "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForLunch),
  582. "value": enum.NursingHomeUserWithDayKindForLunch,
  583. },
  584. {
  585. "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForDinner),
  586. "value": enum.NursingHomeUserWithDayKindForDinner,
  587. },
  588. },
  589. "state_list": []map[string]interface{}{
  590. {
  591. "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForWait),
  592. "value": enum.NursingHomeUserWithDayStateForWait,
  593. },
  594. {
  595. "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForAlready),
  596. "value": enum.NursingHomeUserWithDayStateForAlready,
  597. },
  598. {
  599. "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForCanceling),
  600. "value": enum.NursingHomeUserWithDayStateForCanceling,
  601. },
  602. {
  603. "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForCancel),
  604. "value": enum.NursingHomeUserWithDayStateForCancel,
  605. },
  606. },
  607. }, nil)
  608. return
  609. }
  610. func NursingHomeOrdRefund(c *gin.Context) {
  611. var req md.NursingHomeOrdRefundReq
  612. err := c.ShouldBindJSON(&req)
  613. if err != nil {
  614. err = validate.HandleValidateErr(err)
  615. err1 := err.(e.E)
  616. e.OutErr(c, err1.Code, err1.Error())
  617. return
  618. }
  619. enterpriseDb := db.EnterpriseDb{}
  620. enterpriseDb.Set()
  621. enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId)
  622. if err != nil {
  623. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  624. return
  625. }
  626. if enterprise == nil {
  627. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  628. return
  629. }
  630. err = svc2.NursingHomeOrdRefund(req)
  631. if err != nil {
  632. e.OutErr(c, e.ERR, err.Error())
  633. return
  634. }
  635. e.OutSuc(c, "success", nil)
  636. return
  637. }
  638. func NursingHomeOrdDetail(c *gin.Context) {
  639. outTradeNo := c.DefaultQuery("out_trade_no", "")
  640. nursingHomePackageOrd := db.NursingHomePackageOrd{}
  641. nursingHomePackageOrd.Set(outTradeNo)
  642. ord, err := nursingHomePackageOrd.GetNursingHomePackageOrd()
  643. if err != nil {
  644. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  645. return
  646. }
  647. if ord == nil {
  648. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应订单记录")
  649. return
  650. }
  651. nursingHomeUserWithDayDb := db.NursingHomeUserWithDayDb{}
  652. nursingHomeUserWithDayDb.Set(0)
  653. list, err := nursingHomeUserWithDayDb.FindNursingHomeUserWithDayByOrdNo(ord.OutTradeNo)
  654. if err != nil {
  655. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  656. return
  657. }
  658. e.OutSuc(c, map[string]interface{}{
  659. "list": list,
  660. "kind_list": []map[string]interface{}{
  661. {
  662. "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForBreakfast),
  663. "value": enum.NursingHomeUserWithDayKindForBreakfast,
  664. },
  665. {
  666. "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForLunch),
  667. "value": enum.NursingHomeUserWithDayKindForLunch,
  668. },
  669. {
  670. "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForDinner),
  671. "value": enum.NursingHomeUserWithDayKindForDinner,
  672. },
  673. },
  674. "state_list": []map[string]interface{}{
  675. {
  676. "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForWait),
  677. "value": enum.NursingHomeUserWithDayStateForWait,
  678. },
  679. {
  680. "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForAlready),
  681. "value": enum.NursingHomeUserWithDayStateForAlready,
  682. },
  683. {
  684. "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForCanceling),
  685. "value": enum.NursingHomeUserWithDayStateForCanceling,
  686. },
  687. {
  688. "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForCancel),
  689. "value": enum.NursingHomeUserWithDayStateForCancel,
  690. },
  691. },
  692. }, nil)
  693. return
  694. }
  695. func DeleteNursingHomePackage(c *gin.Context) {
  696. packageId := c.Param("id")
  697. err := svc.DeleteNursingHomePackage(utils.StrToInt(packageId))
  698. if err != nil {
  699. e.OutErr(c, e.ERR, err.Error())
  700. return
  701. }
  702. e.OutSuc(c, "success", nil)
  703. return
  704. }