@@ -1427,6 +1427,58 @@ func SelfSupportForSchoolOrdListExport(c *gin.Context) { | |||||
return | return | ||||
} | } | ||||
func SelfSupportForSchoolArrearsOrdListExport(c *gin.Context) { | |||||
var req md.SelfSupportForSchoolArrearsOrdListReq | |||||
err := c.ShouldBindJSON(&req) | |||||
if err != nil { | |||||
err = validate.HandleValidateErr(err) | |||||
err1 := err.(e.E) | |||||
e.OutErr(c, err1.Code, err1.Error()) | |||||
return | |||||
} | |||||
resp, err := svc2.SelfSupportForSchoolArrearsOrdListExport(req) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR, err.Error()) | |||||
return | |||||
} | |||||
titleList := []string{"订单编号", "家长电话", "就餐人姓名", "学校名称", "年级", "班级", "消费金额", "消费档口", "设备编号", "刷脸时间", "失败原因", "就餐类型"} | |||||
xlsx := excelize.NewFile() | |||||
xlsx.SetSheetRow("Sheet1", "A1", &titleList) | |||||
style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFF00"],"pattern":1}, "alignment":{"horizontal":"center"}}`) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR, err.Error()) | |||||
return | |||||
} | |||||
xlsx.SetCellStyle("Sheet1", "A1", "M1", style) | |||||
xlsx.SetColWidth("Sheet1", "A", "A", 35) | |||||
xlsx.SetColWidth("Sheet1", "B", "D", 20) | |||||
xlsx.SetColWidth("Sheet1", "E", "H", 15) | |||||
xlsx.SetColWidth("Sheet1", "I", "I", 25) | |||||
xlsx.SetColWidth("Sheet1", "J", "K", 20) | |||||
xlsx.SetColWidth("Sheet1", "L", "L", 15) | |||||
//表头被第一行用了,只能从第二行开始 | |||||
j := 2 | |||||
var totalAmount = 0.00 | |||||
for _, v := range resp { | |||||
totalAmount += utils.StrToFloat64(v.TotalPrice) | |||||
mealZh := svc3.JudgeSelfSupportForMealTime(v.FaceTime) | |||||
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.OutTradeNo, v.Phone, v.Name, v.EnterpriseName, v.Grade, v.Class, utils.StrToFloat64(v.TotalPrice), | |||||
v.ShopName, v.DeviceSn, v.FaceTime, v.DebtBusinessMsg, mealZh}) | |||||
j++ | |||||
} | |||||
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{"总计:", "-", "-", "-", "-", "-", totalAmount, "-", "-", "-", "-", "-"}) | |||||
c.Header("Content-Type", "application/octet-stream") | |||||
c.Header("Content-Disposition", "attachment; filename="+"消费记录"+".xlsx") | |||||
c.Header("Content-Transfer-Encoding", "binary") | |||||
//回写到web 流媒体 形成下载 | |||||
_ = xlsx.Write(c.Writer) | |||||
return | |||||
} | |||||
func SelfSupportForSchoolArrearsOrdList(c *gin.Context) { | func SelfSupportForSchoolArrearsOrdList(c *gin.Context) { | ||||
var req md.SelfSupportForSchoolArrearsOrdListReq | var req md.SelfSupportForSchoolArrearsOrdListReq | ||||
err := c.ShouldBindJSON(&req) | err := c.ShouldBindJSON(&req) | ||||
@@ -371,7 +371,9 @@ func CentralKitchenForSchoolStudentList(req md.CentralKitchenForSchoolStudentLis | |||||
classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) | classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) | ||||
} | } | ||||
} | } | ||||
sess := db.Db.Where("user_identity.enterprise_id =?", req.EnterpriseId).And("identity =?", enum2.UserIdentityForCentralKitchenForStudent) | |||||
sess := db.Db.Where("user_identity.enterprise_id =?", req.EnterpriseId). | |||||
And("identity =?", enum2.UserIdentityForCentralKitchenForStudent). | |||||
And("state =?", enum2.UserIdentityStateForNormal) | |||||
if req.Name != "" { | if req.Name != "" { | ||||
sess.And("user_identity.name like ?", "%"+req.Name+"%") | sess.And("user_identity.name like ?", "%"+req.Name+"%") | ||||
} | } | ||||
@@ -272,7 +272,9 @@ func SelfSupportForSchoolStudentList(req md.SelfSupportForSchoolStudentListReq) | |||||
classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) | classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) | ||||
} | } | ||||
} | } | ||||
sess := db.Db.Where("user_identity.enterprise_id =?", req.EnterpriseId).And("identity =?", enum2.UserIdentityForSelfSupportForStudent) | |||||
sess := db.Db.Where("user_identity.enterprise_id =?", req.EnterpriseId). | |||||
And("identity =?", enum2.UserIdentityForSelfSupportForStudent). | |||||
And("state =?", enum2.UserIdentityStateForNormal) | |||||
if req.Name != "" { | if req.Name != "" { | ||||
sess.And("user_identity.name like ?", "%"+req.Name+"%") | sess.And("user_identity.name like ?", "%"+req.Name+"%") | ||||
} | } | ||||
@@ -909,3 +911,128 @@ func SelfSupportForSchoolArrearsOrdList(req md.SelfSupportForSchoolArrearsOrdLis | |||||
} | } | ||||
return | return | ||||
} | } | ||||
func SelfSupportForSchoolArrearsOrdListExport(req md.SelfSupportForSchoolArrearsOrdListReq) (resp []md.SelfSupportForSchoolOrdListResp, err error) { | |||||
var classWithUserIdentityIdsOne []int | |||||
var classWithUserIdentityIdsTwo []int | |||||
classWithUserDb := db.ClassWithUserDb{} | |||||
classWithUserDb.Set() | |||||
if req.ClassId != 0 { | |||||
classWithUsers, err2 := classWithUserDb.FindUserIdentity(req.ClassId) | |||||
if err2 != nil { | |||||
return nil, err2 | |||||
} | |||||
for _, v := range *classWithUsers { | |||||
classWithUserIdentityIdsOne = append(classWithUserIdentityIdsOne, v.UserIdentityId) | |||||
} | |||||
} | |||||
if req.GradeId != 0 { | |||||
classDb := db.ClassDb{} | |||||
classDb.Set(req.GradeId) | |||||
classes, err3 := classDb.FindClass() | |||||
if err3 != nil { | |||||
return nil, err3 | |||||
} | |||||
var classesId []int | |||||
for _, v := range *classes { | |||||
classesId = append(classesId, v.Id) | |||||
} | |||||
classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId) | |||||
if err4 != nil { | |||||
return nil, err4 | |||||
} | |||||
for _, v := range *classWithUsers { | |||||
classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) | |||||
} | |||||
} | |||||
sess := db.Db.Desc("self_support_for_school_ord.id") | |||||
if req.EnterpriseId != 0 { | |||||
sess.And("self_support_for_school_ord.enterprise_id =?", req.EnterpriseId) | |||||
} | |||||
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.StartDate != "" { | |||||
sess.And("self_support_for_school_ord.face_time >= ?", req.StartDate) | |||||
} | |||||
if req.EndDate != "" { | |||||
sess.And("self_support_for_school_ord.face_time <= ?", req.EndDate) | |||||
} | |||||
//if req.OrderStatus != 0 { | |||||
sess.And("self_support_for_school_ord.order_status = ?", 1) // 支付状态 (1:待支付 2:支付成功) | |||||
//} | |||||
if req.OutTradeNo != "" { | |||||
sess.And("self_support_for_school_ord.out_order_no like ?", "%"+req.OutTradeNo+"%") | |||||
} | |||||
if req.EnterpriseKind != 0 { | |||||
sess.And("enterprise.kind = ?", req.EnterpriseKind) | |||||
} | |||||
if req.Name != "" { | |||||
sess.And("user_identity.name like ?", "%"+req.Name+"%") | |||||
} | |||||
if req.Phone != "" { | |||||
sess.And("user.phone like ?", "%"+req.Phone+"%") | |||||
} | |||||
if len(classWithUserIdentityIdsOne) > 0 { | |||||
sess.In("user_identity.id", classWithUserIdentityIdsOne) | |||||
} | |||||
if len(classWithUserIdentityIdsTwo) > 0 { | |||||
sess.In("user_identity.id", classWithUserIdentityIdsTwo) | |||||
} | |||||
var m []*db.SelfSupportForSchoolOrdWithUserIdentity | |||||
err = sess. | |||||
Join("LEFT", "user_identity", "self_support_for_school_ord.user_identity_id = user_identity.id"). | |||||
Join("LEFT", "enterprise", "enterprise.id = self_support_for_school_ord.enterprise_id"). | |||||
Join("LEFT", "user", "user.id = user_identity.uid"). | |||||
Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). | |||||
Join("LEFT", "class", "class_with_user.class_id = class.id"). | |||||
Join("LEFT", "grade", "class.grade_id = grade.id"). | |||||
Desc("self_support_for_school_ord.face_time").Find(&m) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
//查询出所有的设备 | |||||
var deviceList []*model.Device | |||||
err = db.Db.Where("enterprise_id != 0").Find(&deviceList) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
var deviceListMapping = map[string]model.Device{} | |||||
for _, v := range deviceList { | |||||
deviceListMapping[v.DeviceSn] = *v | |||||
} | |||||
for _, v := range m { | |||||
resp = append(resp, md.SelfSupportForSchoolOrdListResp{ | |||||
EnterpriseId: v.UserIdentity.EnterpriseId, | |||||
EnterpriseName: v.Enterprise.Name, | |||||
Uid: v.UserIdentity.Uid, | |||||
UserIdentityId: v.UserIdentity.Id, | |||||
UserIdentityName: v.SelfSupportForSchoolOrd.Consumer, | |||||
TotalPrice: v.SelfSupportForSchoolOrd.TradeAmount, | |||||
OutTradeNo: v.SelfSupportForSchoolOrd.OutOrderNo, | |||||
TradeNo: v.SelfSupportForSchoolOrd.TradeNo, | |||||
OrderStatus: v.SelfSupportForSchoolOrd.OrderStatus, | |||||
FaceTime: v.SelfSupportForSchoolOrd.FaceTime, | |||||
Phone: v.User.Phone, | |||||
Name: v.UserIdentity.Name, | |||||
Grade: v.Grade.Name, | |||||
GradeId: v.Grade.Id, | |||||
Class: v.Class.Name, | |||||
ClassId: v.Class.Id, | |||||
DeviceSn: v.SelfSupportForSchoolOrd.DeviceSn, | |||||
ShopName: deviceListMapping[v.SelfSupportForSchoolOrd.DeviceSn].Name, | |||||
CpMerchantId: v.SelfSupportForSchoolOrd.CpMerchantId, | |||||
DebtBusinessMsg: v.SelfSupportForSchoolOrd.DebtBusinessMsg, | |||||
}) | |||||
} | |||||
return | |||||
} |
@@ -659,25 +659,30 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta | |||||
totalData[k2]["amount"] = sumAmount | totalData[k2]["amount"] = sumAmount | ||||
} | } | ||||
xlsx.NewSheet("Sheet1") | |||||
//xlsx.NewSheet("所有档口") | |||||
xlsx.SetSheetName("Sheet1", "所有档口") | |||||
titleList = []string{" 设 备 分 餐 数 据 统 计 表 "} | titleList = []string{" 设 备 分 餐 数 据 统 计 表 "} | ||||
xlsx.SetSheetRow("Sheet1", "A1", &titleList) | |||||
xlsx.SetSheetRow("所有档口", "A1", &titleList) | |||||
titleList = []string{"名 称", "消费笔数", "消费金额"} | titleList = []string{"名 称", "消费笔数", "消费金额"} | ||||
xlsx.SetSheetRow("Sheet1", "A2", &titleList) | |||||
xlsx.SetSheetRow("所有档口", "A2", &titleList) | |||||
style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFF00"],"pattern":1}, "alignment":{"horizontal":"center"}}`) | style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFF00"],"pattern":1}, "alignment":{"horizontal":"center"}}`) | ||||
if err != nil { | if err != nil { | ||||
logx.Error(err) | logx.Error(err) | ||||
println("<<<<SelfSupportForSchoolDataStatisticsExport4>>>>>Error:::", err.Error()) | println("<<<<SelfSupportForSchoolDataStatisticsExport4>>>>>Error:::", err.Error()) | ||||
panic(err) | panic(err) | ||||
} | } | ||||
xlsx.MergeCell("Sheet1", "A1", "C1") //合并单元格 | |||||
xlsx.SetCellStyle("Sheet1", "A1", "C1", style) | |||||
xlsx.SetColWidth("Sheet1", "A", "C", 20) | |||||
xlsx.MergeCell("所有档口", "A1", "C1") //合并单元格 | |||||
xlsx.SetCellStyle("所有档口", "A1", "C1", style) | |||||
xlsx.SetColWidth("所有档口", "A", "C", 20) | |||||
j := 3 //表头前两行用了,只能从第三行开始 | j := 3 //表头前两行用了,只能从第三行开始 | ||||
var totalNum, totalAmount float64 | |||||
for key, val := range totalData { | for key, val := range totalData { | ||||
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{key, val["num"], val["amount"]}) | |||||
totalNum += val["num"] | |||||
totalAmount += val["amount"] | |||||
xlsx.SetSheetRow("所有档口", "A"+strconv.Itoa(j), &[]interface{}{key, val["num"], val["amount"]}) | |||||
j++ | j++ | ||||
} | } | ||||
xlsx.SetSheetRow("所有档口", "A"+strconv.Itoa(j), &[]interface{}{"合计", totalNum, totalAmount}) | |||||
//xlsx.DeleteSheet("Sheet1") //TODO::只能放这里删除 | //xlsx.DeleteSheet("Sheet1") //TODO::只能放这里删除 | ||||
//将文件保存至服务器 | //将文件保存至服务器 | ||||
@@ -224,6 +224,7 @@ func rEnterpriseManage(r *gin.RouterGroup) { | |||||
r.POST("/selfSupportForSchool/consumeLimit", hdl.SelfSupportForSchoolConsumeLimit) //"自营-学校"消费限制-编辑 | r.POST("/selfSupportForSchool/consumeLimit", hdl.SelfSupportForSchoolConsumeLimit) //"自营-学校"消费限制-编辑 | ||||
r.POST("/selfSupportForSchool/consumeLimitList", hdl.SelfSupportForSchoolConsumeLimitList) //"自营-学校"消费限制-列表 | r.POST("/selfSupportForSchool/consumeLimitList", hdl.SelfSupportForSchoolConsumeLimitList) //"自营-学校"消费限制-列表 | ||||
r.POST("/selfSupportForSchool/arrearsOrdList", hdl.SelfSupportForSchoolArrearsOrdList) //"自营-学校"订单欠费列表 | r.POST("/selfSupportForSchool/arrearsOrdList", hdl.SelfSupportForSchoolArrearsOrdList) //"自营-学校"订单欠费列表 | ||||
r.Any("/selfSupportForSchool/arrearsOrdListExport", hdl.SelfSupportForSchoolArrearsOrdListExport) //"自营-学校"订单欠费列表-导出 | |||||
r.POST("/selfSupportForSchool/blackList", hdl.SelfSupportForSchoolBlackList) //"自营-学校"黑名单列表 | r.POST("/selfSupportForSchool/blackList", hdl.SelfSupportForSchoolBlackList) //"自营-学校"黑名单列表 | ||||
r.POST("/selfSupportForSchool/arrearsOrdDebtRepay", hdl.SelfSupportForSchoolArrearsOrdDebtRepay) //"自营-学校"订单欠费催缴 | r.POST("/selfSupportForSchool/arrearsOrdDebtRepay", hdl.SelfSupportForSchoolArrearsOrdDebtRepay) //"自营-学校"订单欠费催缴 | ||||
r.POST("/selfSupportForSchool/arrearsOrdDebtCancel", hdl.SelfSupportForSchoolArrearsOrdDebtCancel) //"自营-学校"撤销欠款 | r.POST("/selfSupportForSchool/arrearsOrdDebtCancel", hdl.SelfSupportForSchoolArrearsOrdDebtCancel) //"自营-学校"撤销欠款 | ||||