@@ -1,10 +1,14 @@ | |||||
package hdl | package hdl | ||||
import ( | import ( | ||||
"applet/app/admin/md" | |||||
"applet/app/admin/svc" | |||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/e" | "applet/app/e" | ||||
"applet/app/enum" | "applet/app/enum" | ||||
"applet/app/utils" | "applet/app/utils" | ||||
"applet/app/utils/cache" | |||||
"encoding/json" | |||||
"fmt" | "fmt" | ||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"time" | "time" | ||||
@@ -137,36 +141,54 @@ func ThisWeekData(c *gin.Context) { | |||||
} | } | ||||
func ThisMonthData(c *gin.Context) { | func ThisMonthData(c *gin.Context) { | ||||
now := time.Now() | |||||
var list []map[string]interface{} | 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 { | |||||
admin := svc.GetUser(c) | |||||
cacheKey := fmt.Sprintf(md.AdminHomePageDataKey, utils.GetIP(c.Request), utils.AnyToString(admin.AdmId)) | |||||
var adminHomePageDataString string | |||||
adminHomePageDataString, _ = cache.GetString(cacheKey) | |||||
if adminHomePageDataString != "" { | |||||
if err := json.Unmarshal([]byte(adminHomePageDataString), &list); err != nil { | |||||
e.OutErr(c, e.ERR, err.Error()) | e.OutErr(c, e.ERR, err.Error()) | ||||
return | return | ||||
} | } | ||||
mapArr2, err := db.QueryNativeString(db.Db, sql2) | |||||
} else { | |||||
now := time.Now() | |||||
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, | |||||
}) | |||||
} | |||||
marshal, err := json.Marshal(list) | |||||
if err != nil { | if err != nil { | ||||
e.OutErr(c, e.ERR, err.Error()) | e.OutErr(c, e.ERR, err.Error()) | ||||
return | 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, | |||||
}) | |||||
adminHomePageDataString = string(marshal) | |||||
_, err = cache.SetEx(cacheKey, adminHomePageDataString, md.AdminHomePageDataCacheTime) | |||||
} | } | ||||
e.OutSuc(c, map[string]interface{}{ | e.OutSuc(c, map[string]interface{}{ | ||||
@@ -6,6 +6,8 @@ const ( | |||||
JwtTokenCacheTime = 3600 * 24 | JwtTokenCacheTime = 3600 * 24 | ||||
AdminRolePermissionKey = "%s:smart_canteen_admin_role_permission:%s" // 占位符:ip, admin:id | AdminRolePermissionKey = "%s:smart_canteen_admin_role_permission:%s" // 占位符:ip, admin:id | ||||
AdminRolePermissionCacheTime = 3600 * 24 * 0.5 | AdminRolePermissionCacheTime = 3600 * 24 * 0.5 | ||||
AdminHomePageDataKey = "%s:smart_canteen_admin_home_data:%s" // 占位符:ip, admin:id | |||||
AdminHomePageDataCacheTime = 60 * 10 | |||||
CfgCacheTime = 86400 | CfgCacheTime = 86400 | ||||
AppCfgCacheKey = "smart_canteen:%s" // 占位符: key的第一个字母 | AppCfgCacheKey = "smart_canteen:%s" // 占位符: key的第一个字母 | ||||
WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母 | WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母 | ||||
@@ -1,12 +1,13 @@ | |||||
package md | package md | ||||
type EnterpriseUserListReq struct { | type EnterpriseUserListReq struct { | ||||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||||
Limit int `json:"limit" binding:"required"` | |||||
Page int `json:"page" binding:"required"` | |||||
Nickname string `json:"nickname" label:"支付宝昵称"` | |||||
Phone string `json:"phone" label:"手机号"` | |||||
IsTeacher int `json:"is_teacher" label:"是否教师"` | |||||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||||
Limit int `json:"limit" binding:"required"` | |||||
Page int `json:"page" binding:"required"` | |||||
Nickname string `json:"nickname" label:"支付宝昵称"` | |||||
Phone string `json:"phone" label:"手机号"` | |||||
IsTeacher int `json:"is_teacher" label:"是否教师"` | |||||
EnterpriseName string `json:"enterprise_name" label:"校企名称"` | |||||
} | } | ||||
type EnterpriseUserListByCentralKitchenForSchoolStruct struct { | type EnterpriseUserListByCentralKitchenForSchoolStruct struct { | ||||
@@ -131,8 +131,6 @@ func EnterpriseUserListByNursingHome(req md.EnterpriseUserListReq) (resp md.Ente | |||||
return | return | ||||
} | } | ||||
resp.Total = count | resp.Total = count | ||||
classWithUserDb := db.ClassWithUserDb{} | |||||
classWithUserDb.Set() | |||||
for _, v := range m { | for _, v := range m { | ||||
temp := md.EnterpriseUserListByNursingHomeStruct{ | temp := md.EnterpriseUserListByNursingHomeStruct{ | ||||
Id: v.Id, | Id: v.Id, | ||||
@@ -143,19 +141,12 @@ func EnterpriseUserListByNursingHome(req md.EnterpriseUserListReq) (resp md.Ente | |||||
} | } | ||||
for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] { | for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] { | ||||
fmt.Println(">>>>>>>>>>>>", userIdentitiesMap[utils.IntToStr(v.Id)]) | fmt.Println(">>>>>>>>>>>>", userIdentitiesMap[utils.IntToStr(v.Id)]) | ||||
data, err2 := classWithUserDb.GetInfoByUserIdentityId(v1.Id) | |||||
if err2 != nil { | |||||
return resp, err2 | |||||
} | |||||
if data == nil { | |||||
continue | |||||
} | |||||
temp.UserIdentities = append(temp.UserIdentities, struct { | temp.UserIdentities = append(temp.UserIdentities, struct { | ||||
Id int `json:"id" label:"身份id"` | Id int `json:"id" label:"身份id"` | ||||
IdNo string `json:"id_no" label:"身份证号"` | IdNo string `json:"id_no" label:"身份证号"` | ||||
EnterpriseName string `json:"enterprise_name" label:"单位名"` | EnterpriseName string `json:"enterprise_name" label:"单位名"` | ||||
Name string `json:"name" label:"姓名"` | Name string `json:"name" label:"姓名"` | ||||
}{Id: v1.Id, IdNo: data.UserIdentity.IdNo, EnterpriseName: data.Enterprise.Name, Name: data.UserIdentity.Name}) | |||||
}{Id: v1.Id, IdNo: v1.IdNo, EnterpriseName: req.EnterpriseName, Name: v1.Name}) | |||||
} | } | ||||
resp.List = append(resp.List, temp) | resp.List = append(resp.List, temp) | ||||
} | } | ||||
@@ -149,8 +149,8 @@ func NursingHomeOrdList(req md.NursingHomeOrdListReq) (resp []md.NursingHomeOrdL | |||||
var m []*db.NursingHomePackageOrdWithUserIdentity | var m []*db.NursingHomePackageOrdWithUserIdentity | ||||
count, err = sess. | count, err = sess. | ||||
Join("LEFT", "user_identity", "nursing_home_package_ord.user_identity_id = user_identity.id"). | Join("LEFT", "user_identity", "nursing_home_package_ord.user_identity_id = user_identity.id"). | ||||
Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). | |||||
Join("LEFT", "user", "user.id = user_identity.uid"). | |||||
Join("LEFT", "enterprise", "enterprise.id = nursing_home_package_ord.enterprise_id"). | |||||
Join("LEFT", "user", "user.id = nursing_home_package_ord.uid"). | |||||
Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) | Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) | ||||
if err != nil { | if err != nil { | ||||
return nil, 0, err | return nil, 0, err | ||||
@@ -163,7 +163,7 @@ func NursingHomeOrdList(req md.NursingHomeOrdListReq) (resp []md.NursingHomeOrdL | |||||
Uid: v.UserIdentity.Uid, | Uid: v.UserIdentity.Uid, | ||||
UserIdentityId: v.UserIdentity.Id, | UserIdentityId: v.UserIdentity.Id, | ||||
UserIdentityKind: v.UserIdentity.Kind, | UserIdentityKind: v.UserIdentity.Kind, | ||||
UserIdentityName: v.UserIdentity.Name, | |||||
UserIdentityName: v.NursingHomePackageOrd.UserIdentityName, | |||||
TotalPrice: v.TotalPrice, | TotalPrice: v.TotalPrice, | ||||
Kind: v.NursingHomePackageOrd.Kind, | Kind: v.NursingHomePackageOrd.Kind, | ||||
OutTradeNo: v.NursingHomePackageOrd.OutTradeNo, | OutTradeNo: v.NursingHomePackageOrd.OutTradeNo, | ||||