Browse Source

update

tmp
DengBiao 8 months ago
parent
commit
557fe0f850
3 changed files with 272 additions and 0 deletions
  1. +116
    -0
      app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go
  2. +155
    -0
      app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go
  3. +1
    -0
      app/router/admin_router.go

+ 116
- 0
app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go View File

@@ -12,7 +12,9 @@ import (
"applet/app/utils"
"applet/app/utils/cache"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/gin-gonic/gin"
"strconv"
"time"
)

@@ -940,6 +942,120 @@ func CentralKitchenForSchoolOrdList(c *gin.Context) {
return
}

func CentralKitchenForSchoolOrdListExport(c *gin.Context) {
var req md.CentralKitchenForSchoolOrdListReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}

if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, e.ERR, "查询时间段不能为空")
return
}

resp, _, err := svc2.CentralKitchenForSchoolOrdListExport(c, 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", "B", 30)
xlsx.SetColWidth("Sheet1", "C", "E", 15)
xlsx.SetColWidth("Sheet1", "F", "I", 10)
xlsx.SetColWidth("Sheet1", "J", "J", 20)
xlsx.SetColWidth("Sheet1", "K", "K", 10)
xlsx.SetColWidth("Sheet1", "L", "L", 25)
xlsx.SetColWidth("Sheet1", "M", "M", 15)
//表头被第一行用了,只能从第二行开始
j := 2
var totalAmount = 0.00
for _, v := range resp {
var kind, payWay, payState, orderState string
switch v.Kind {
case 1:
kind = "按学期购买"
break
case 2:
kind = "按月购买"
break
case 3:
kind = "按天购买"
break
case 4:
kind = "补餐"
break
}
switch v.PayWay {
case 1:
payWay = "支付宝"
break
case 2:
payWay = "微信"
break
}
switch v.State {
case 0:
payState = "待支付"
break
case 1:
payState = "支付成功"
break
case 2:
payState = "支付失败"
break
}
switch v.OrdState {
case 0:
orderState = "待支付"
break
case 1:
orderState = "预约成功"
break
case 2:
orderState = "退款中"
break
case 3:
orderState = "部分退款"
break
case 4:
orderState = "已退款"
break
case 5:
orderState = "已完成"
break
}
totalAmount += utils.StrToFloat64(v.TotalPrice)
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{
v.OutTradeNo, v.TradeNo, v.Phone, v.Name, v.EnterpriseName, v.Class, v.Grade,
kind, utils.StrToFloat64(v.TotalPrice), payWay, payState, v.CreateAt, orderState,
})
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 CentralKitchenForSchoolReserveList(c *gin.Context) {
var req md.CentralKitchenForSchoolReserveListReq
err := c.ShouldBindJSON(&req)


+ 155
- 0
app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go View File

@@ -754,6 +754,161 @@ func CentralKitchenForSchoolOrdList(c *gin.Context, req md.CentralKitchenForScho
return
}

func CentralKitchenForSchoolOrdListExport(c *gin.Context, req md.CentralKitchenForSchoolOrdListReq) (resp []md.CentralKitchenForSchoolOrdListResp, count int64, 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, 0, 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, 0, err3
}
var classesId []int
for _, v := range *classes {
classesId = append(classesId, v.Id)
}
classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId)
if err4 != nil {
return nil, 0, err4
}
for _, v := range *classWithUsers {
classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId)
}
}

sess := db.Db.Desc("central_kitchen_for_school_package_ord.id")
admin := svc.GetUser(c)
if admin.IsSuperAdministrator != enum.IsSuperAdministratorTure {
adminWithEnterpriseDb := db.AdminWithEnterpriseDb{}
adminWithEnterpriseDb.Set()
adminWithEnterprise, err1 := adminWithEnterpriseDb.FindAdminWithEnterprise(admin.AdmId)
if err1 != nil {
e.OutErr(c, e.ERR_DB_ORM, err1.Error())
return
}
var enterPriseIds []int
for _, v1 := range *adminWithEnterprise {
enterPriseIds = append(enterPriseIds, v1.EnterpriseId)
}
if len(enterPriseIds) == 0 {
return
}
sess.In("central_kitchen_for_school_package_ord.enterprise_id", enterPriseIds)
}

if req.EnterpriseId != 0 {
sess.And("central_kitchen_for_school_package_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("central_kitchen_for_school_package_ord.pay_at >= ?", req.StartDate)
}
if req.EndDate != "" {
sess.And("central_kitchen_for_school_package_ord.pay_at <= ?", req.EndDate)
}
if req.Kind != 0 {
sess.And("central_kitchen_for_school_package_ord.kind = ?", req.Kind)
}
if req.Sate != -1 {
sess.And("central_kitchen_for_school_package_ord.state = ?", req.Sate)
}
if req.OrdSate != -1 {
sess.And("central_kitchen_for_school_package_ord.ord_state = ?", req.OrdSate)
}
if req.PayWay != 0 {
sess.And("central_kitchen_for_school_package_ord.pay_way = ?", req.PayWay)
}
if req.OutTradeNo != "" {
sess.And("central_kitchen_for_school_package_ord.out_trade_no like ?", "%"+req.OutTradeNo+"%")
}

if req.Name != "" {
sess.And("user_identity.name like ?", "%"+req.Name+"%")
}
if req.Phone != "" {
userDb := db.UserDb{}
userDb.Set()
user, err1 := userDb.GetUserByPhone(req.Phone)
if err1 != nil {
return nil, 0, err1
}
if user != nil {
sess.And("central_kitchen_for_school_package_ord.uid = ?", user.Id)
} else {
sess.And("user.phone like ?", "%"+req.Phone+"%")
}
}

if req.EnterPriseKind != 0 {
sess.And("enterprise.kind = ?", req.EnterPriseKind)
}

if len(classWithUserIdentityIdsOne) > 0 {
sess.In("user_identity.id", classWithUserIdentityIdsOne)
}
if len(classWithUserIdentityIdsTwo) > 0 {
sess.In("user_identity.id", classWithUserIdentityIdsTwo)
}

var m []*db.CentralKitchenForSchoolPackageOrdWithUserIdentity
count, err = sess.
Join("LEFT", "user_identity", "central_kitchen_for_school_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", "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").
FindAndCount(&m)
if err != nil {
return nil, 0, err
}

for _, v := range m {
resp = append(resp, md.CentralKitchenForSchoolOrdListResp{
EnterpriseId: v.UserIdentity.EnterpriseId,
EnterpriseName: v.Enterprise.Name,
Uid: v.UserIdentity.Uid,
UserIdentityId: v.UserIdentity.Id,
UserIdentityKind: v.UserIdentity.Kind,
UserIdentityName: v.CentralKitchenForSchoolPackageOrd.UserIdentityName,
TotalPrice: v.CentralKitchenForSchoolPackageOrd.TotalPrice,
Kind: v.CentralKitchenForSchoolPackageOrd.Kind,
OutTradeNo: v.CentralKitchenForSchoolPackageOrd.OutTradeNo,
TradeNo: v.CentralKitchenForSchoolPackageOrd.TradeNo,
State: v.CentralKitchenForSchoolPackageOrd.State,
OrdState: v.CentralKitchenForSchoolPackageOrd.OrdState,
PayWay: v.CentralKitchenForSchoolPackageOrd.PayWay,
CreateAt: v.CentralKitchenForSchoolPackageOrd.CreateAt,
Phone: v.User.Phone,
Name: v.UserIdentity.Name,
Grade: v.Grade.Name,
GradeId: v.Grade.Id,
Class: v.Class.Name,
ClassId: v.Class.Id,
})
}
return
}

func CentralKitchenForSchoolOrdStatistics(c *gin.Context, req md.CentralKitchenForSchoolOrdListReq) (personNum, orderCountByDay, orderCountByMonth, orderCountByTerm int64, consumeAmount float64, err error) {
var classWithUserIdentityIdsOne []int
var classWithUserIdentityIdsTwo []int


+ 1
- 0
app/router/admin_router.go View File

@@ -98,6 +98,7 @@ func rAuditCenter(r *gin.RouterGroup) {

func rFinanceManage(r *gin.RouterGroup) {
r.POST("/centralKitchenForSchool/ordList", hdl.CentralKitchenForSchoolOrdList) //财务管理-(央厨-学校)订单列表
r.Any("/centralKitchenForSchool/ordListExport", hdl.CentralKitchenForSchoolOrdListExport) //财务管理-(央厨-学校)订单列表导出
r.GET("/centralKitchenForSchool/ordDetail", hdl.CentralKitchenForSchoolOrdDetail) //财务管理-(央厨-学校)订单详情
r.POST("/centralKitchenForSchool/ordRefund", hdl.CentralKitchenForSchoolOrdRefund) //财务管理-(央厨-学校)订单退款
r.POST("/selfSupportForSchool/ordList", hdl.SelfSupportForSchoolOrdList) //财务管理-(自营-学校)订单列表


Loading…
Cancel
Save