From d42040fbfd92839a51be19dffd0608c6e2d4bd98 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Tue, 5 Sep 2023 22:15:18 +0800 Subject: [PATCH] update --- app/admin/hdl/hdl_home_page.go | 176 ++++++++++++++++++ app/admin/md/md_enterprise_manage.go | 1 + .../svc_self_support_for_school.go | 8 + app/router/admin_router.go | 7 + 4 files changed, 192 insertions(+) create mode 100644 app/admin/hdl/hdl_home_page.go diff --git a/app/admin/hdl/hdl_home_page.go b/app/admin/hdl/hdl_home_page.go new file mode 100644 index 0000000..6609a03 --- /dev/null +++ b/app/admin/hdl/hdl_home_page.go @@ -0,0 +1,176 @@ +package hdl + +import ( + "applet/app/db" + "applet/app/e" + "applet/app/enum" + "applet/app/utils" + "fmt" + "github.com/gin-gonic/gin" + "time" +) + +func HomePageIndex(c *gin.Context) { + now := time.Now() + todayStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Format("2006-01-02 15:04:05") //今日开始时间 + todayEnd := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, now.Location()).Format("2006-01-02 15:04:05") //今日结束时间 + sql1 := fmt.Sprintf("SELECT sum('trade_amount') as total FROM self_support_for_school_ord where order_status = 2 and face_time >= '%s' and face_time < '%s'", todayStart, todayEnd) //统计今日"自营-学校"收益 + sql2 := fmt.Sprintf("SELECT sum('total_price') as total FROM central_kitchen_for_school_package_ord where state = 1 and create_at >= '%s' and create_at < '%s'", todayStart, todayEnd) //统计今日"央厨-学校"收益 + mapArr1, err := db.QueryNativeString(db.Db, sql1) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + mapArr2, err := db.QueryNativeString(db.Db, sql2) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + var result1, result2, todayIncome float64 + if mapArr1 != nil { + result1 = utils.StrToFloat64(mapArr1[0]["total"]) + } + if mapArr2 != nil { + result2 = utils.StrToFloat64(mapArr2[0]["total"]) + } + todayIncome = result1 + result2 + + sql3 := fmt.Sprintf("SELECT COUNT(*) as total,kind FROM `enterprise` GROUP BY kind") //统计校企类型数量 + mapArr3, err := db.QueryNativeString(db.Db, sql3) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + + var totalCentralKitchenForSchoolNums, totalCentralKitchenForFactoryNums, totalSelfSupportForSchoolNums, totalSelfSupportForFactoryNums int + if mapArr3 != nil { + for _, v := range mapArr3 { + if v["kind"] == utils.IntToStr(enum.EnterprisePvdByCentralKitchenForSchool) { + totalCentralKitchenForSchoolNums = utils.StrToInt(v["total"]) + } + if v["kind"] == utils.IntToStr(enum.EnterprisePvdByCentralKitchenForFactory) { + totalCentralKitchenForFactoryNums = utils.StrToInt(v["total"]) + } + if v["kind"] == utils.IntToStr(enum.EnterprisePvdBySelfSupportForSchool) { + totalSelfSupportForSchoolNums = utils.StrToInt(v["total"]) + } + if v["kind"] == utils.IntToStr(enum.EnterprisePvdBySelfSupportForFactory) { + totalSelfSupportForFactoryNums = utils.StrToInt(v["total"]) + } + } + } + + var totalCentralKitchenForSchoolUserIdentityNums, totalCentralKitchenForFactoryUserIdentityNums, totalSelfSupportForSchoolUserIdentityNums, totalSelfSupportForFactoryUserIdentityNums int + sql4 := fmt.Sprintf("select count(*) as total from `user_identity` where kind in (%d, %d) ", enum.UserIdentityForCentralKitchenForStudent, enum.UserIdentityForCentralKitchenForTeacher) //统计"央厨-学校"用户数 + sql5 := fmt.Sprintf("select count(*) as total from `user_identity` where kind in (%d, %d, %d) ", enum.UserIdentityForSelfSupportForStudent, enum.UserIdentityForSelfSupportForTeacher, enum.UserIdentityForSelfSupportForWorker) //统计"自营-学校"用户数 + mapArr4, err := db.QueryNativeString(db.Db, sql4) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + if mapArr4 != nil { + totalCentralKitchenForSchoolUserIdentityNums = utils.StrToInt(mapArr4[0]["total"]) + } + + mapArr5, err := db.QueryNativeString(db.Db, sql5) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + if mapArr5 != nil { + totalCentralKitchenForFactoryUserIdentityNums = utils.StrToInt(mapArr4[0]["total"]) + } + + e.OutSuc(c, map[string]interface{}{ + "data": map[string]interface{}{ + "todayIncome": todayIncome, + "totalCentralKitchenForSchoolNums": totalCentralKitchenForSchoolNums, + "totalCentralKitchenForFactoryNums": totalCentralKitchenForFactoryNums, + "totalSelfSupportForSchoolNums": totalSelfSupportForSchoolNums, + "totalSelfSupportForFactoryNums": totalSelfSupportForFactoryNums, + "totalCentralKitchenForSchoolUserIdentityNums": totalCentralKitchenForSchoolUserIdentityNums, + "totalCentralKitchenForFactoryUserIdentityNums": totalCentralKitchenForFactoryUserIdentityNums, + "totalSelfSupportForSchoolUserIdentityNums": totalSelfSupportForSchoolUserIdentityNums, + "totalSelfSupportForFactoryUserIdentityNums": totalSelfSupportForFactoryUserIdentityNums, + }, + }, nil) + return +} + +func ThisWeekData(c *gin.Context) { + now := time.Now() + var list []map[string]interface{} + for i := -6; i <= 0; i++ { + day := now.AddDate(0, 0, i).Format("2006-01-02") //7日前 + dayStart := now.AddDate(0, 0, i).Format("2006-01-02 15:04:05") + dayEnd := now.AddDate(0, 0, i+1).Format("2006-01-02 15:04:05") + sql1 := fmt.Sprintf("SELECT sum('trade_amount') as total FROM self_support_for_school_ord where order_status = 2 and face_time >= '%s' and face_time < '%s'", dayStart, dayEnd) //统计今日"自营-学校"收益 + sql2 := fmt.Sprintf("SELECT sum('total_price') as total FROM central_kitchen_for_school_package_ord where state = 1 and create_at >= '%s' and create_at < '%s'", dayStart, dayEnd) //统计今日"央厨-学校"收益 + mapArr1, err := db.QueryNativeString(db.Db, sql1) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + mapArr2, err := db.QueryNativeString(db.Db, sql2) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + var result1, result2, todayIncome float64 + if mapArr1 != nil { + result1 = utils.StrToFloat64(mapArr1[0]["total"]) + } + if mapArr2 != nil { + result2 = utils.StrToFloat64(mapArr2[0]["total"]) + } + todayIncome = result1 + result2 + list = append(list, map[string]interface{}{ + "date": day, + "income": todayIncome, + }) + } + + e.OutSuc(c, map[string]interface{}{ + "data": list, + }, nil) + return +} + +func ThisMonthData(c *gin.Context) { + now := time.Now() + var list []map[string]interface{} + for i := -29; i <= 0; i++ { + day := now.AddDate(0, 0, i).Format("2006-01-02") //7日前 + dayStart := now.AddDate(0, 0, i).Format("2006-01-02 15:04:05") + dayEnd := now.AddDate(0, 0, i+1).Format("2006-01-02 15:04:05") + sql1 := fmt.Sprintf("SELECT count(*) as total FROM self_support_for_school_ord where order_status = 2 and face_time >= '%s' and face_time < '%s'", dayStart, dayEnd) //统计今日"自营-学校"收益 + sql2 := fmt.Sprintf("SELECT count(*) as total FROM central_kitchen_for_school_package_ord where state = 1 and create_at >= '%s' and create_at < '%s'", dayStart, dayEnd) //统计今日"央厨-学校"收益 + mapArr1, err := db.QueryNativeString(db.Db, sql1) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + mapArr2, err := db.QueryNativeString(db.Db, sql2) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + var result1, result2 int + if mapArr1 != nil { + result1 = utils.StrToInt(mapArr1[0]["total"]) + } + if mapArr2 != nil { + result2 = utils.StrToInt(mapArr2[0]["total"]) + } + list = append(list, map[string]interface{}{ + "date": day, + "self_support_for_school": result1, + "central_kitchen_for_school": result2, + }) + } + + e.OutSuc(c, map[string]interface{}{ + "data": list, + }, nil) + return +} diff --git a/app/admin/md/md_enterprise_manage.go b/app/admin/md/md_enterprise_manage.go index aee19d3..9903e29 100644 --- a/app/admin/md/md_enterprise_manage.go +++ b/app/admin/md/md_enterprise_manage.go @@ -423,6 +423,7 @@ type SelfSupportForSchoolOrdListReq struct { ClassId int `json:"class_id" label:"班级id"` StartDate string `json:"start_date" label:"刷脸-开始时间"` EndDate string `json:"end_date" label:"刷脸-截止时间"` + IsTeacher int `json:"is_teacher" label:"是否教师"` } type SelfSupportForSchoolArrearsOrdListReq struct { diff --git a/app/admin/svc/enterprise_manage/svc_self_support_for_school.go b/app/admin/svc/enterprise_manage/svc_self_support_for_school.go index 0c145f8..30ddbf0 100644 --- a/app/admin/svc/enterprise_manage/svc_self_support_for_school.go +++ b/app/admin/svc/enterprise_manage/svc_self_support_for_school.go @@ -585,6 +585,14 @@ func SelfSupportForSchoolOrdList(req md.SelfSupportForSchoolOrdListReq) (resp [] if req.OutTradeNo != "" { sess.And("self_support_for_school_ord.out_order_no like ?", "%"+req.OutTradeNo+"%") } + if req.IsTeacher != 0 { + if req.IsTeacher == 1 { + sess.And("user_identity.identity =?", enum2.UserIdentityForCentralKitchenForTeacher) + } + if req.IsTeacher == 2 { + sess.And("user_identity.identity !=?", enum2.UserIdentityForCentralKitchenForTeacher) + } + } if req.Name != "" { sess.And("user_identity.name like ?", "%"+req.Name+"%") diff --git a/app/router/admin_router.go b/app/router/admin_router.go index 647f3ec..13973a2 100644 --- a/app/router/admin_router.go +++ b/app/router/admin_router.go @@ -46,6 +46,12 @@ func rCompany(r *gin.RouterGroup) { r.DELETE("/delete/:id", hdl2.CompanyDelete) } +func rHomePage(r *gin.RouterGroup) { + r.GET("/index", hdl2.HomePageIndex) + r.GET("/thisWeekData", hdl2.ThisWeekData) + r.GET("/thisMonthData", hdl2.ThisMonthData) +} + func rNotice(r *gin.RouterGroup) { r.GET("/list", hdl2.NoticeList) r.POST("/add", hdl2.NoticeAdd) @@ -211,6 +217,7 @@ func AdminRoute(r *gin.RouterGroup) { r.Use(mw.CheckPermission) //检测权限 rOss(r.Group("/oss")) rComm(r.Group("/comm")) + rHomePage(r.Group("/homePage")) //首页 rCompany(r.Group("/company")) //公司管理 rNotice(r.Group("/notice")) //公告管理 rBanner(r.Group("/banner")) //轮播图管理