智慧食堂-队列消费项目
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.
 
 
 

825 lignes
22 KiB

  1. package hdl
  2. import (
  3. enum2 "applet/app/admin/enum"
  4. "applet/app/admin/lib/validate"
  5. "applet/app/admin/md"
  6. "applet/app/admin/svc"
  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 EnterpriseList(c *gin.Context) {
  16. var req md.EnterpriseListReq
  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. if req.Limit == 0 {
  25. req.Limit = 10
  26. }
  27. if req.Page == 0 {
  28. req.Page = 10
  29. }
  30. admin := svc.GetUser(c)
  31. enterprises, total, err := svc.EnterpriseList(*admin, req)
  32. if err != nil {
  33. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  34. return
  35. }
  36. e.OutSuc(c, map[string]interface{}{
  37. "list": enterprises,
  38. "total": total,
  39. "state": []map[string]interface{}{
  40. {
  41. "name": enum.EnterpriseState(enum.EnterpriseStateForNormal).String(),
  42. "value": enum.EnterpriseStateForNormal,
  43. },
  44. {
  45. "name": enum.EnterpriseState(enum.EnterpriseStateForFreeze).String(),
  46. "value": enum.EnterpriseStateForFreeze,
  47. },
  48. },
  49. "kind_by_mode": md.EnterpriseKindByMode,
  50. "pvd": []map[string]interface{}{
  51. {
  52. "name": enum.EnterprisePvd(enum.EnterprisePvdForOnlinePayment).String(),
  53. "value": enum.EnterprisePvdForOnlinePayment,
  54. },
  55. {
  56. "name": enum.EnterprisePvd(enum.EnterprisePvdForFaceScanPayment).String(),
  57. "value": enum.EnterprisePvdForFaceScanPayment,
  58. },
  59. },
  60. }, nil)
  61. return
  62. }
  63. func Detail(c *gin.Context) {
  64. enterpriseId := c.DefaultQuery("id", "")
  65. enterpriseDb := db.EnterpriseDb{}
  66. enterpriseDb.Set()
  67. enterprise, err := enterpriseDb.GetEnterprise(utils.StrToInt(enterpriseId))
  68. if err != nil {
  69. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  70. return
  71. }
  72. if enterprise.Pvd == enum.EnterprisePvdForFaceScanPayment && enterprise.Mode == enum.EnterpriseModeForSchool {
  73. detail, err := svc.EnterpriseDetailV2(utils.StrToInt(enterpriseId))
  74. if err != nil {
  75. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  76. return
  77. }
  78. e.OutSuc(c, detail, nil)
  79. return
  80. }
  81. detail, err := svc.EnterpriseDetail(utils.StrToInt(enterpriseId))
  82. if err != nil {
  83. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  84. return
  85. }
  86. e.OutSuc(c, detail, nil)
  87. return
  88. }
  89. func SchoolBelowGrade(c *gin.Context) {
  90. enterpriseId := c.DefaultQuery("enterprise_id", "")
  91. gradeDb := db.GradeDb{}
  92. gradeDb.Set(utils.StrToInt(enterpriseId))
  93. gradeList, err := gradeDb.FindGrade()
  94. if err != nil {
  95. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  96. return
  97. }
  98. e.OutSuc(c, map[string]interface{}{
  99. "list": gradeList,
  100. }, nil)
  101. return
  102. }
  103. func PeriodBelowGrade(c *gin.Context) {
  104. periodId := c.DefaultQuery("period_id", "")
  105. periodDb := db.PeriodDb{}
  106. periodDb.Set(0)
  107. period, err1 := periodDb.GetPeriod(utils.StrToInt(periodId))
  108. if err1 != nil {
  109. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  110. return
  111. }
  112. if period == nil {
  113. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关学段信息")
  114. return
  115. }
  116. gradeDb := db.GradeDb{}
  117. gradeDb.Set(period.EnterpriseId)
  118. gradeList, err := gradeDb.FindGradeByPeriodId(period.Id)
  119. if err != nil {
  120. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  121. return
  122. }
  123. e.OutSuc(c, map[string]interface{}{
  124. "list": gradeList,
  125. }, nil)
  126. return
  127. }
  128. func SchoolBelowPeriod(c *gin.Context) {
  129. enterpriseId := c.DefaultQuery("enterprise_id", "")
  130. periodDb := db.PeriodDb{}
  131. periodDb.Set(utils.StrToInt(enterpriseId))
  132. periodList, err := periodDb.FindPeriod()
  133. if err != nil {
  134. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  135. return
  136. }
  137. e.OutSuc(c, map[string]interface{}{
  138. "list": periodList,
  139. }, nil)
  140. return
  141. }
  142. func SchoolGradeBelowClass(c *gin.Context) {
  143. gradeId := c.DefaultQuery("grade_id", "")
  144. enterpriseId := c.DefaultQuery("enterprise_id", "")
  145. classDb := db.ClassDb{}
  146. if gradeId != "" {
  147. classDb.Set(utils.StrToInt(gradeId))
  148. classList, err := classDb.FindClass()
  149. if err != nil {
  150. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  151. return
  152. }
  153. e.OutSuc(c, map[string]interface{}{
  154. "list": classList,
  155. }, nil)
  156. } else {
  157. classDb.Set(0)
  158. classList, err := classDb.FindClassByEnterprise(enterpriseId)
  159. if err != nil {
  160. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  161. return
  162. }
  163. e.OutSuc(c, map[string]interface{}{
  164. "list": classList,
  165. }, nil)
  166. }
  167. return
  168. }
  169. func EnterpriseAdd(c *gin.Context) {
  170. var req md.EnterpriseAddReq
  171. err := c.ShouldBindJSON(&req)
  172. if err != nil {
  173. err = validate.HandleValidateErr(err)
  174. err1 := err.(e.E)
  175. e.OutErr(c, err1.Code, err1.Error())
  176. return
  177. }
  178. enterpriseDb := db.EnterpriseDb{}
  179. enterpriseDb.Set()
  180. now := time.Now()
  181. //var pvd = 2
  182. //if req.Kind == enum.EnterpriseKindByCentralKitchenForSchool || req.Kind == enum.EnterpriseKindByCentralKitchenForFactory {
  183. // pvd = 1
  184. //}
  185. enterprise := model.Enterprise{
  186. Name: req.Name,
  187. Pvd: req.Pvd,
  188. Mode: req.Mode,
  189. Kind: req.Kind,
  190. CompanyId: req.CompanyId,
  191. State: enum2.CompanyStateForNormal,
  192. Memo: req.Memo,
  193. CreateAt: now.Format("2006-01-02 15:04:05"),
  194. UpdateAt: now.Format("2006-01-02 15:04:05"),
  195. }
  196. enterpriseId, err := enterpriseDb.EnterpriseInsert(&enterprise)
  197. if err != nil {
  198. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  199. return
  200. }
  201. if req.Pvd == enum.EnterprisePvdForOnlinePayment && req.Mode == enum.EnterpriseModeForSchool {
  202. //新增 `central_kitchen_for_school_set` && `central_kitchen_for_school_with_spec`
  203. centralKitchenForSchoolSetDb := db.CentralKitchenForSchoolSetDb{}
  204. centralKitchenForSchoolSetDb.Set(enterpriseId)
  205. centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetInsert(&model.CentralKitchenForSchoolSet{
  206. EnterpriseId: enterpriseId,
  207. IsOpenTeacherReportMeal: 1,
  208. IsOpenReportMealForDay: 1,
  209. IsOpenReportMealForMonth: 1,
  210. IsOpenReportMealForSemester: 1,
  211. IsOpenTeacherReportMealForDay: 1,
  212. IsOpenTeacherReportMealForMonth: 1,
  213. IsOpenTeacherReportMealForSemester: 1,
  214. CreateAt: now.Format("2006-01-02 15:04:05"),
  215. UpdateAt: now.Format("2006-01-02 15:04:05"),
  216. })
  217. centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{}
  218. centralKitchenForSchoolWithSpec.Set(enterpriseId)
  219. centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecInsert(&model.CentralKitchenForSchoolWithSpec{
  220. EnterpriseId: enterpriseId,
  221. IsOpenBreakfast: 1,
  222. IsOpenLunch: 1,
  223. IsOpenDinner: 1,
  224. IsOpenBreakfastForTeacher: 1,
  225. IsOpenLunchForTeacher: 1,
  226. IsOpenDinnerForTeacher: 1,
  227. BreakfastUnitPrice: "0.00",
  228. LunchUnitPrice: "0.00",
  229. DinnerUnitPrice: "0.00",
  230. BreakfastUnitPriceForTeacher: "0.00",
  231. LunchUnitPriceForTeacher: "0.00",
  232. DinnerUnitPriceForTeacher: "0.00",
  233. BreakfastTeacherNotice: "",
  234. LunchTeacherNotice: "",
  235. DinnerTeacherNotice: "",
  236. CreateAt: now.Format("2006-01-02 15:04:05"),
  237. UpdateAt: now.Format("2006-01-02 15:04:05"),
  238. })
  239. }
  240. if req.Kind == enum.EnterpriseKindByNursingHome {
  241. //新增 `nursing_home_set` && `nursing_home_with_spec`
  242. nursingHomeSetDb := db.NursingHomeSetDb{}
  243. nursingHomeSetDb.Set(enterpriseId)
  244. nursingHomeSetDb.NursingHomeSetInsert(&model.NursingHomeSet{
  245. EnterpriseId: enterpriseId,
  246. IsOpenReportMealForDay: 1,
  247. IsOpenReportMealForMonth: 1,
  248. IsOpenReportMealForYear: 1,
  249. CreateAt: now.Format("2006-01-02 15:04:05"),
  250. UpdateAt: now.Format("2006-01-02 15:04:05"),
  251. })
  252. nursingHomeWithSpec := db.NursingHomeWithSpec{}
  253. nursingHomeWithSpec.Set(enterpriseId)
  254. nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{
  255. EnterpriseId: enterpriseId,
  256. IsOpenBreakfast: 1,
  257. IsOpenLunch: 1,
  258. IsOpenDinner: 1,
  259. BreakfastUnitPrice: "0.00",
  260. LunchUnitPrice: "0.00",
  261. DinnerUnitPrice: "0.00",
  262. CreateAt: now.Format("2006-01-02 15:04:05"),
  263. UpdateAt: now.Format("2006-01-02 15:04:05"),
  264. })
  265. }
  266. e.OutSuc(c, "success", nil)
  267. return
  268. }
  269. func EnterpriseDelete(c *gin.Context) {
  270. var req md.EnterpriseDeleteReq
  271. err := c.ShouldBindJSON(&req)
  272. if err != nil {
  273. err = validate.HandleValidateErr(err)
  274. err1 := err.(e.E)
  275. e.OutErr(c, err1.Code, err1.Error())
  276. return
  277. }
  278. err = svc.EnterpriseDelete(req.EnterpriseIds)
  279. if err != nil {
  280. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  281. return
  282. }
  283. e.OutSuc(c, "success", nil)
  284. return
  285. }
  286. func CentralKitchenForSchoolUpdate(c *gin.Context) {
  287. var req md.CentralKitchenForSchoolUpdateReq
  288. err := c.ShouldBindJSON(&req)
  289. if err != nil {
  290. err = validate.HandleValidateErr(err)
  291. err1 := err.(e.E)
  292. e.OutErr(c, err1.Code, err1.Error())
  293. return
  294. }
  295. //1、更新 enterprise
  296. enterpriseDb := db.EnterpriseDb{}
  297. enterpriseDb.Set()
  298. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  299. if err != nil {
  300. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  301. return
  302. }
  303. if enterprise == nil {
  304. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  305. return
  306. }
  307. now := time.Now()
  308. enterprise.Name = req.Name
  309. enterprise.Memo = req.Memo
  310. enterprise.CompanyId = req.CompanyId
  311. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  312. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "company_id", "update_at")
  313. if err != nil {
  314. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  315. return
  316. }
  317. //2、更新 period && grade && class 数据
  318. periodDb := db.PeriodDb{}
  319. periodDb.Set(req.Id)
  320. gradeDb := db.GradeDb{}
  321. gradeDb.Set(req.Id)
  322. classDb := db.ClassDb{}
  323. classDb.Set(0)
  324. //新增 grade 数据 && class 数据
  325. var classes []*model.Class
  326. for _, v := range req.PeriodList {
  327. if v.Id == 0 {
  328. //TODO::新增
  329. insertId, err1 := periodDb.PeriodInsert(&model.Period{
  330. EnterpriseId: req.Id,
  331. Name: v.Name,
  332. BreakfastUnitPrice: "0.00",
  333. LunchUnitPrice: "0.00",
  334. DinnerUnitPrice: "0.00",
  335. CreateAt: now.Format("2006-01-02 15:04:05"),
  336. UpdateAt: now.Format("2006-01-02 15:04:05"),
  337. })
  338. if err1 != nil {
  339. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  340. return
  341. }
  342. for _, v1 := range v.GradeList {
  343. insertId1, err2 := gradeDb.GradeInsert(&model.Grade{
  344. Name: v1.Name,
  345. Memo: "",
  346. PeriodId: insertId,
  347. EnterpriseId: req.Id,
  348. CreateAt: now.Format("2006-01-02 15:04:05"),
  349. UpdateAt: now.Format("2006-01-02 15:04:05"),
  350. })
  351. if err2 != nil {
  352. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  353. return
  354. }
  355. for _, v2 := range v1.ClassList {
  356. classes = append(classes, &model.Class{
  357. Name: v2.Name,
  358. Memo: "",
  359. GradeId: insertId1,
  360. EnterpriseId: req.Id,
  361. CreateAt: now.Format("2006-01-02 15:04:05"),
  362. UpdateAt: now.Format("2006-01-02 15:04:05"),
  363. })
  364. }
  365. }
  366. } else {
  367. //TODO::编辑
  368. period, err1 := periodDb.GetPeriod(v.Id)
  369. if err1 != nil {
  370. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  371. return
  372. }
  373. if period == nil {
  374. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关学段信息")
  375. return
  376. }
  377. period.Name = v.Name
  378. _, err2 := periodDb.PeriodUpdate(period, "name")
  379. if err2 != nil {
  380. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  381. return
  382. }
  383. for _, v1 := range v.GradeList {
  384. var gradeId int
  385. if v1.Id == 0 {
  386. gradeId, err2 = gradeDb.GradeInsert(&model.Grade{
  387. Name: v1.Name,
  388. Memo: "",
  389. PeriodId: period.Id,
  390. EnterpriseId: req.Id,
  391. CreateAt: now.Format("2006-01-02 15:04:05"),
  392. UpdateAt: now.Format("2006-01-02 15:04:05"),
  393. })
  394. if err2 != nil {
  395. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  396. return
  397. }
  398. } else {
  399. grade, err3 := gradeDb.GetGrade(v1.Id)
  400. if err3 != nil {
  401. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  402. return
  403. }
  404. if grade == nil {
  405. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
  406. return
  407. }
  408. grade.Name = v1.Name
  409. _, err4 := gradeDb.GradeUpdate(grade, "name")
  410. if err4 != nil {
  411. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  412. return
  413. }
  414. gradeId = grade.Id
  415. }
  416. for _, v2 := range v1.ClassList {
  417. if v2.Id == 0 {
  418. //新增
  419. classes = append(classes, &model.Class{
  420. Name: v2.Name,
  421. Memo: "",
  422. GradeId: gradeId,
  423. EnterpriseId: req.Id,
  424. CreateAt: now.Format("2006-01-02 15:04:05"),
  425. UpdateAt: now.Format("2006-01-02 15:04:05"),
  426. })
  427. } else {
  428. //编辑
  429. class, err4 := classDb.GetClass(v2.Id)
  430. if err4 != nil {
  431. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  432. return
  433. }
  434. if class == nil {
  435. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
  436. return
  437. }
  438. class.Name = v2.Name
  439. _, err6 := classDb.ClassUpdate(class, "name")
  440. if err6 != nil {
  441. e.OutErr(c, e.ERR_DB_ORM, err6.Error())
  442. return
  443. }
  444. }
  445. }
  446. }
  447. }
  448. }
  449. if len(classes) > 0 {
  450. _, err2 := classDb.BatchAddClass(classes)
  451. if err2 != nil {
  452. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  453. return
  454. }
  455. }
  456. e.OutSuc(c, "success", nil)
  457. return
  458. }
  459. func SelfSupportForSchoolUpdate(c *gin.Context) {
  460. var req md.SelfSupportForSchoolUpdateReq
  461. err := c.ShouldBindJSON(&req)
  462. if err != nil {
  463. err = validate.HandleValidateErr(err)
  464. err1 := err.(e.E)
  465. e.OutErr(c, err1.Code, err1.Error())
  466. return
  467. }
  468. //1、更新 enterprise
  469. enterpriseDb := db.EnterpriseDb{}
  470. enterpriseDb.Set()
  471. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  472. if err != nil {
  473. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  474. return
  475. }
  476. if enterprise == nil {
  477. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  478. return
  479. }
  480. now := time.Now()
  481. enterprise.Name = req.Name
  482. enterprise.Memo = req.Memo
  483. enterprise.CompanyId = req.CompanyId
  484. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  485. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "company_id", "update_at")
  486. if err != nil {
  487. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  488. return
  489. }
  490. //2、更新 grade && class 数据
  491. //2、删除 grade && class 数据
  492. gradeDb := db.GradeDb{}
  493. gradeDb.Set(req.Id)
  494. //_, err = gradeDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
  495. //if err != nil {
  496. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  497. // return
  498. //}
  499. classDb := db.ClassDb{}
  500. classDb.Set(0)
  501. //_, err = classDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
  502. //if err != nil {
  503. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  504. // return
  505. //}
  506. //新增 grade 数据 && class 数据
  507. for _, v := range req.GradeList {
  508. var classes []*model.Class
  509. if v.Id == 0 {
  510. //TODO::新增
  511. insertId, err1 := gradeDb.GradeInsert(&model.Grade{
  512. EnterpriseId: req.Id,
  513. Name: v.Name,
  514. Memo: "",
  515. CreateAt: now.Format("2006-01-02 15:04:05"),
  516. UpdateAt: now.Format("2006-01-02 15:04:05"),
  517. })
  518. if err1 != nil {
  519. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  520. return
  521. }
  522. for _, v1 := range v.ClassList {
  523. classes = append(classes, &model.Class{
  524. Name: v1.Name,
  525. Memo: "",
  526. GradeId: insertId,
  527. EnterpriseId: req.Id,
  528. CreateAt: now.Format("2006-01-02 15:04:05"),
  529. UpdateAt: now.Format("2006-01-02 15:04:05"),
  530. })
  531. }
  532. } else {
  533. //TODO::编辑
  534. grade, err3 := gradeDb.GetGrade(v.Id)
  535. if err3 != nil {
  536. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  537. return
  538. }
  539. if grade == nil {
  540. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
  541. return
  542. }
  543. grade.Name = v.Name
  544. _, err4 := gradeDb.GradeUpdate(grade, "name")
  545. if err4 != nil {
  546. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  547. return
  548. }
  549. for _, v1 := range v.ClassList {
  550. if v1.Id == 0 {
  551. //新增
  552. classes = append(classes, &model.Class{
  553. Name: v1.Name,
  554. Memo: "",
  555. GradeId: grade.Id,
  556. EnterpriseId: req.Id,
  557. CreateAt: now.Format("2006-01-02 15:04:05"),
  558. UpdateAt: now.Format("2006-01-02 15:04:05"),
  559. })
  560. } else {
  561. //编辑
  562. class, err5 := classDb.GetClass(v1.Id)
  563. if err5 != nil {
  564. e.OutErr(c, e.ERR_DB_ORM, err5.Error())
  565. return
  566. }
  567. if class == nil {
  568. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
  569. return
  570. }
  571. class.Name = v1.Name
  572. _, err6 := classDb.ClassUpdate(class, "name")
  573. if err6 != nil {
  574. e.OutErr(c, e.ERR_DB_ORM, err6.Error())
  575. return
  576. }
  577. }
  578. }
  579. }
  580. if len(classes) > 0 {
  581. _, err2 := classDb.BatchAddClass(classes)
  582. if err2 != nil {
  583. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  584. return
  585. }
  586. }
  587. }
  588. e.OutSuc(c, "success", nil)
  589. return
  590. }
  591. func EnterpriseAddGrade(c *gin.Context) {
  592. var req md.EnterpriseUpdateStateReq
  593. err := c.ShouldBindJSON(&req)
  594. if err != nil {
  595. err = validate.HandleValidateErr(err)
  596. err1 := err.(e.E)
  597. e.OutErr(c, err1.Code, err1.Error())
  598. return
  599. }
  600. enterpriseDb := db.EnterpriseDb{}
  601. enterpriseDb.Set()
  602. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  603. if err != nil {
  604. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  605. return
  606. }
  607. if enterprise == nil {
  608. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  609. return
  610. }
  611. now := time.Now()
  612. enterprise.State = req.State
  613. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  614. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  615. if err != nil {
  616. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  617. return
  618. }
  619. e.OutSuc(c, "success", nil)
  620. return
  621. }
  622. func EnterpriseUpdateState(c *gin.Context) {
  623. var req md.EnterpriseUpdateStateReq
  624. err := c.ShouldBindJSON(&req)
  625. if err != nil {
  626. err = validate.HandleValidateErr(err)
  627. err1 := err.(e.E)
  628. e.OutErr(c, err1.Code, err1.Error())
  629. return
  630. }
  631. enterpriseDb := db.EnterpriseDb{}
  632. enterpriseDb.Set()
  633. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  634. if err != nil {
  635. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  636. return
  637. }
  638. if enterprise == nil {
  639. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  640. return
  641. }
  642. now := time.Now()
  643. enterprise.State = req.State
  644. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  645. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  646. if err != nil {
  647. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  648. return
  649. }
  650. e.OutSuc(c, "success", nil)
  651. return
  652. }
  653. func ListCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  654. var req md.ListCentralKitchenForSchoolPackageForSystemReq
  655. err := c.ShouldBindJSON(&req)
  656. if err != nil {
  657. err = validate.HandleValidateErr(err)
  658. err1 := err.(e.E)
  659. e.OutErr(c, err1.Code, err1.Error())
  660. return
  661. }
  662. centralKitchenForSchoolPackageForSystemDb := db.CentralKitchenForSchoolPackageForSystemDb{}
  663. centralKitchenForSchoolPackageForSystemDb.Set()
  664. list, total, err := centralKitchenForSchoolPackageForSystemDb.CentralKitchenForSchoolPackageForSystemList(req)
  665. if err != nil {
  666. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  667. return
  668. }
  669. e.OutSuc(c, map[string]interface{}{
  670. "list": list,
  671. "total": total,
  672. }, nil)
  673. return
  674. }
  675. func SetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  676. var req md.SetCentralKitchenForSchoolWithSpecForSystemReq
  677. err := c.ShouldBindJSON(&req)
  678. if err != nil {
  679. err = validate.HandleValidateErr(err)
  680. err1 := err.(e.E)
  681. e.OutErr(c, err1.Code, err1.Error())
  682. return
  683. }
  684. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  685. centralKitchenForSchoolWithSpecForSystemDb.Set()
  686. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  687. if err != nil {
  688. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  689. return
  690. }
  691. system.BreakfastUnitPrice = req.BreakfastUnitPrice
  692. system.LunchUnitPrice = req.LunchUnitPrice
  693. system.DinnerUnitPrice = req.DinnerUnitPrice
  694. system.BreakfastUnitPriceForTeacher = req.BreakfastUnitPriceForTeacher
  695. system.LunchUnitPriceForTeacher = req.LunchUnitPriceForTeacher
  696. system.DinnerUnitPriceForTeacher = req.DinnerUnitPriceForTeacher
  697. system.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  698. updateAffected, err := centralKitchenForSchoolWithSpecForSystemDb.CentralKitchenForSchoolWithSpecForSystemUpdate(system.Id, system)
  699. if err != nil {
  700. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  701. return
  702. }
  703. if updateAffected <= 0 {
  704. e.OutErr(c, e.ERR, "更新数据失败")
  705. return
  706. }
  707. e.OutSuc(c, "success", nil)
  708. return
  709. }
  710. func GetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  711. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  712. centralKitchenForSchoolWithSpecForSystemDb.Set()
  713. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  714. if err != nil {
  715. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  716. return
  717. }
  718. e.OutSuc(c, map[string]interface{}{
  719. "data": system,
  720. }, nil)
  721. return
  722. }
  723. func SaveCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  724. var req md.SaveCentralKitchenForSchoolPackageForSystemReq
  725. err := c.ShouldBindJSON(&req)
  726. if err != nil {
  727. err = validate.HandleValidateErr(err)
  728. err1 := err.(e.E)
  729. e.OutErr(c, err1.Code, err1.Error())
  730. return
  731. }
  732. //判断是新增 / 编辑
  733. if req.Id > 0 {
  734. err = svc.UpdateCentralKitchenForSchoolPackageForSystem(req)
  735. if err != nil {
  736. e.OutErr(c, e.ERR, err.Error())
  737. return
  738. }
  739. } else {
  740. err = svc.AddCentralKitchenForSchoolPackageForSystem(req)
  741. if err != nil {
  742. e.OutErr(c, e.ERR, err.Error())
  743. return
  744. }
  745. }
  746. e.OutSuc(c, "success", nil)
  747. return
  748. }
  749. func SyncCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  750. var req md.SyncCentralKitchenForSchoolPackageForSystemReq
  751. err := c.ShouldBindJSON(&req)
  752. if err != nil {
  753. err = validate.HandleValidateErr(err)
  754. err1 := err.(e.E)
  755. e.OutErr(c, err1.Code, err1.Error())
  756. return
  757. }
  758. err = svc.SyncCentralKitchenForSchoolPackageForSystem(req)
  759. if err != nil {
  760. e.OutErr(c, e.ERR, err.Error())
  761. return
  762. }
  763. e.OutSuc(c, "success", nil)
  764. return
  765. }
  766. func DeleteCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  767. id := c.Param("id")
  768. err := svc.DeleteCentralKitchenForSchoolPackageForSystem(utils.StrToInt(id))
  769. if err != nil {
  770. e.OutErr(c, e.ERR, err.Error())
  771. return
  772. }
  773. e.OutSuc(c, "success", nil)
  774. return
  775. }