|
|
@@ -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 |
|
|
|