@@ -6,7 +6,6 @@ import ( | |||||
"applet/app/admin/svc" | "applet/app/admin/svc" | ||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/e" | "applet/app/e" | ||||
"applet/app/utils" | |||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"os" | "os" | ||||
) | ) | ||||
@@ -85,23 +84,35 @@ func CentralKitchenForSchoolDataStatisticsList(c *gin.Context) { | |||||
} | } | ||||
func CentralKitchenForSchoolDataStatisticsDelete(c *gin.Context) { | func CentralKitchenForSchoolDataStatisticsDelete(c *gin.Context) { | ||||
id := c.Param("id") | |||||
centralKitchenForSchoolExportRecordsDb := db.CentralKitchenForSchoolExportRecordsDb{} | |||||
centralKitchenForSchoolExportRecordsDb.Set() | |||||
centralKitchenForSchoolExportRecords, err := centralKitchenForSchoolExportRecordsDb.GetCentralKitchenForSchoolExportRecords(utils.StrToInt(id)) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
var req struct { | |||||
Ids []int `json:"ids"` | |||||
} | } | ||||
if centralKitchenForSchoolExportRecords == nil { | |||||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相关记录") | |||||
return | |||||
} | |||||
_, err = centralKitchenForSchoolExportRecordsDb.CentralKitchenForSchoolExportRecordsDelete(id) | |||||
err := c.ShouldBindJSON(&req) | |||||
if err != nil { | if err != nil { | ||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
err = validate.HandleValidateErr(err) | |||||
err1 := err.(e.E) | |||||
e.OutErr(c, err1.Code, err1.Error()) | |||||
return | return | ||||
} | } | ||||
for _, id := range req.Ids { | |||||
centralKitchenForSchoolExportRecordsDb := db.CentralKitchenForSchoolExportRecordsDb{} | |||||
centralKitchenForSchoolExportRecordsDb.Set() | |||||
centralKitchenForSchoolExportRecords, err0 := centralKitchenForSchoolExportRecordsDb.GetCentralKitchenForSchoolExportRecords(id) | |||||
if err0 != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err0.Error()) | |||||
return | |||||
} | |||||
if centralKitchenForSchoolExportRecords == nil { | |||||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相关记录") | |||||
return | |||||
} | |||||
_, err1 := centralKitchenForSchoolExportRecordsDb.CentralKitchenForSchoolExportRecordsDelete(id) | |||||
if err1 != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||||
return | |||||
} | |||||
} | |||||
e.OutSuc(c, "success", nil) | e.OutSuc(c, "success", nil) | ||||
return | return | ||||
} | } | ||||
@@ -208,24 +219,36 @@ func NursingHomeDataStatisticsList(c *gin.Context) { | |||||
} | } | ||||
func NursingHomeDataStatisticsDelete(c *gin.Context) { | func NursingHomeDataStatisticsDelete(c *gin.Context) { | ||||
id := c.Param("id") | |||||
nursingHomeExportRecordsDb := db.NursingHomeExportRecordsDb{} | |||||
nursingHomeExportRecordsDb.Set() | |||||
centralKitchenForSchoolExportRecords, err := nursingHomeExportRecordsDb.GetNursingHomeExportRecords(utils.StrToInt(id)) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
} | |||||
if centralKitchenForSchoolExportRecords == nil { | |||||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相关记录") | |||||
return | |||||
var req struct { | |||||
Ids []int `json:"ids"` | |||||
} | } | ||||
os.RemoveAll("./static" + centralKitchenForSchoolExportRecords.DownloadPath) //移除文件 | |||||
_, err = nursingHomeExportRecordsDb.NursingHomeExportRecordsDelete(id) | |||||
err := c.ShouldBindJSON(&req) | |||||
if err != nil { | if err != nil { | ||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
err = validate.HandleValidateErr(err) | |||||
err1 := err.(e.E) | |||||
e.OutErr(c, err1.Code, err1.Error()) | |||||
return | return | ||||
} | } | ||||
for _, id := range req.Ids { | |||||
nursingHomeExportRecordsDb := db.NursingHomeExportRecordsDb{} | |||||
nursingHomeExportRecordsDb.Set() | |||||
centralKitchenForSchoolExportRecords, err1 := nursingHomeExportRecordsDb.GetNursingHomeExportRecords(id) | |||||
if err1 != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||||
return | |||||
} | |||||
if centralKitchenForSchoolExportRecords == nil { | |||||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相关记录") | |||||
return | |||||
} | |||||
os.RemoveAll("./static" + centralKitchenForSchoolExportRecords.DownloadPath) //移除文件 | |||||
_, err2 := nursingHomeExportRecordsDb.NursingHomeExportRecordsDelete(id) | |||||
if err2 != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||||
return | |||||
} | |||||
} | |||||
e.OutSuc(c, "success", nil) | e.OutSuc(c, "success", nil) | ||||
return | return | ||||
} | } | ||||
@@ -310,24 +333,37 @@ func SelfSupportForSchoolDataStatisticsList(c *gin.Context) { | |||||
} | } | ||||
func SelfSupportForSchoolDataStatisticsDelete(c *gin.Context) { | func SelfSupportForSchoolDataStatisticsDelete(c *gin.Context) { | ||||
id := c.Param("id") | |||||
selfSupportForSchoolExportRecordsDb := db.SelfSupportForSchoolExportRecordsDb{} | |||||
selfSupportForSchoolExportRecordsDb.Set() | |||||
selfSupportForSchoolExportRecords, err := selfSupportForSchoolExportRecordsDb.GetSelfSupportForSchoolExportRecords(utils.StrToInt(id)) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
} | |||||
if selfSupportForSchoolExportRecords == nil { | |||||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相关记录") | |||||
return | |||||
var req struct { | |||||
Ids []int `json:"ids"` | |||||
} | } | ||||
os.RemoveAll("./static" + selfSupportForSchoolExportRecords.DownloadPath) //移除文件 | |||||
_, err = selfSupportForSchoolExportRecordsDb.SelfSupportForSchoolExportRecordsDelete(id) | |||||
err := c.ShouldBindJSON(&req) | |||||
if err != nil { | if err != nil { | ||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
err = validate.HandleValidateErr(err) | |||||
err1 := err.(e.E) | |||||
e.OutErr(c, err1.Code, err1.Error()) | |||||
return | return | ||||
} | } | ||||
for _, id := range req.Ids { | |||||
selfSupportForSchoolExportRecordsDb := db.SelfSupportForSchoolExportRecordsDb{} | |||||
selfSupportForSchoolExportRecordsDb.Set() | |||||
selfSupportForSchoolExportRecords, err1 := selfSupportForSchoolExportRecordsDb.GetSelfSupportForSchoolExportRecords(id) | |||||
if err1 != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||||
return | |||||
} | |||||
if selfSupportForSchoolExportRecords == nil { | |||||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相关记录") | |||||
return | |||||
} | |||||
os.RemoveAll("./static" + selfSupportForSchoolExportRecords.DownloadPath) //移除文件 | |||||
_, err2 := selfSupportForSchoolExportRecordsDb.SelfSupportForSchoolExportRecordsDelete(id) | |||||
if err2 != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||||
return | |||||
} | |||||
} | |||||
e.OutSuc(c, "success", nil) | e.OutSuc(c, "success", nil) | ||||
return | return | ||||
} | } | ||||
@@ -10,8 +10,13 @@ import ( | |||||
"applet/app/db/model" | "applet/app/db/model" | ||||
"applet/app/e" | "applet/app/e" | ||||
"applet/app/enum" | "applet/app/enum" | ||||
svc3 "applet/app/svc" | |||||
"applet/app/utils" | |||||
"fmt" | "fmt" | ||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"github.com/wechatpay-apiv3/wechatpay-go/core" | |||||
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic" | |||||
"math" | |||||
"time" | "time" | ||||
) | ) | ||||
@@ -71,24 +76,77 @@ func Demo(c *gin.Context) { | |||||
} | } | ||||
func DemoV1(c *gin.Context) { | func DemoV1(c *gin.Context) { | ||||
var outRequestNo = c.Query("out_request_no") | |||||
var outTradeNo = c.Query("out_no") | |||||
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} | centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} | ||||
centralKitchenForSchoolUserRefundDayDb.Set(0) | centralKitchenForSchoolUserRefundDayDb.Set(0) | ||||
var m []model.CentralKitchenForSchoolUserRefundDay | var m []model.CentralKitchenForSchoolUserRefundDay | ||||
if err := centralKitchenForSchoolUserRefundDayDb.Db.Where("state =1").Desc("id").Find(&m); err != nil { | |||||
e.OutErr(c, e.ERR, err.Error()) | |||||
if err := centralKitchenForSchoolUserRefundDayDb.Db.Where("out_request_no =?", outRequestNo).Desc("id").Find(&m); err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | return | ||||
} | } | ||||
var recordsId = map[int]bool{} | |||||
var repeatIds []int | |||||
centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} | |||||
centralKitchenForSchoolPackageOrd.Set(outTradeNo) | |||||
ord, _ := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd() | |||||
var dealReturnOrdMapForWx = map[string]struct { | |||||
OutRequestNo string `json:"out_request_no"` | |||||
Amount float64 `json:"amount"` | |||||
Total string `json:"total"` | |||||
WxMchId string `json:"wx_mch_id"` | |||||
}{} | |||||
companyWithWxpayInfoDb := db.CompanyWithWxpayInfoDb{} | |||||
companyWithWxpayInfoDb.Set() | |||||
wxMchId, _ := companyWithWxpayInfoDb.GetCompanyWithWxpayInfoByEnterprise(ord.EnterpriseId) | |||||
for _, v := range m { | for _, v := range m { | ||||
if recordsId[v.RecordsId] { | |||||
repeatIds = append(repeatIds, v.Id) | |||||
//centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayDelete(v.Id) | |||||
} | |||||
recordsId[v.RecordsId] = true | |||||
dealReturnOrdMapForWx[ord.OutTradeNo] = struct { | |||||
OutRequestNo string `json:"out_request_no"` | |||||
Amount float64 `json:"amount"` | |||||
Total string `json:"total"` | |||||
WxMchId string `json:"wx_mch_id"` | |||||
}(struct { | |||||
OutRequestNo string | |||||
Amount float64 | |||||
Total string | |||||
WxMchId string | |||||
}{OutRequestNo: outRequestNo, Amount: dealReturnOrdMapForWx[v.OutTradeNo].Amount + utils.StrToFloat64(v.Amount), Total: ord.TotalPrice, WxMchId: wxMchId}) | |||||
} | |||||
client, err1 := svc3.NewWxPayClient(c) //初始化微信连接 | |||||
if err1 != nil { | |||||
e.OutErr(c, e.ERR, err1.Error()) | |||||
return | |||||
} | } | ||||
e.OutSuc(c, repeatIds, nil) | |||||
sysCfgDb := db.SysCfgDb{} | |||||
sysCfgDb.Set() | |||||
sysCfg := sysCfgDb.SysCfgFindWithDb(enum.JsapiPayAppAutToken, enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey, enum.WxJsapiRefundPayNotifyUrl) | |||||
wxSvc := refunddomestic.RefundsApiService{Client: client} | |||||
for k, v := range dealReturnOrdMapForWx { | |||||
resp, _, err6 := wxSvc.Create(c, | |||||
refunddomestic.CreateRequest{ | |||||
SubMchid: core.String(v.WxMchId), | |||||
OutTradeNo: core.String(k), | |||||
OutRefundNo: core.String(v.OutRequestNo), | |||||
Reason: core.String("央厨订餐退款"), | |||||
NotifyUrl: core.String(sysCfg[enum.WxJsapiRefundPayNotifyUrl]), | |||||
Amount: &refunddomestic.AmountReq{ | |||||
Currency: core.String("CNY"), | |||||
Refund: core.Int64(int64(math.Round(v.Amount * 100))), | |||||
Total: core.Int64(int64(math.Round(utils.StrToFloat64(v.Total) * 100))), | |||||
}, | |||||
}, | |||||
) | |||||
fmt.Println(">>>>wxRefund<<<<", resp) | |||||
if err6 != nil { | |||||
fmt.Println(err6) | |||||
e.OutErr(c, e.ERR, err6.Error()) | |||||
return | |||||
} | |||||
} | |||||
e.OutSuc(c, dealReturnOrdMapForWx, nil) | |||||
return | |||||
} | } | ||||
func GoOnExecuting() { | func GoOnExecuting() { | ||||
@@ -369,7 +369,7 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta | |||||
} | } | ||||
var m []*db.SelfSupportForSchoolOrdWithUserIdentity | var m []*db.SelfSupportForSchoolOrdWithUserIdentity | ||||
sess := db.Db.Desc("self_support_for_school_ord.id") | |||||
sess := db.Db.Desc("self_support_for_school_ord.id").Where("self_support_for_school_ord.order_status =?", enum.SelfSupportForSchoolOrdOrderStatusForSuccess) | |||||
if req.EnterpriseId != 0 { | if req.EnterpriseId != 0 { | ||||
sess.And("self_support_for_school_ord.enterprise_id =?", req.EnterpriseId) | sess.And("self_support_for_school_ord.enterprise_id =?", req.EnterpriseId) | ||||
} | } | ||||
@@ -383,12 +383,7 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta | |||||
sess.And("enterprise.kind = ?", req.EnterPriseKind) | sess.And("enterprise.kind = ?", req.EnterPriseKind) | ||||
} | } | ||||
_, err = sess. | _, err = sess. | ||||
Join("LEFT", "user_identity", "self_support_for_school_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"). | |||||
Join("LEFT", "enterprise", "enterprise.id = self_support_for_school_ord.enterprise_id"). | |||||
FindAndCount(&m) | FindAndCount(&m) | ||||
if err != nil { | if err != nil { | ||||
logx.Error(err) | logx.Error(err) | ||||
@@ -117,18 +117,18 @@ func rDeviceManage(r *gin.RouterGroup) { | |||||
} | } | ||||
func rDataStatistics(r *gin.RouterGroup) { | func rDataStatistics(r *gin.RouterGroup) { | ||||
r.POST("/centralKitchenForSchool/export", hdl2.CentralKitchenForSchoolDataStatisticsExport) //数据统计-(央厨-学校)-导出 | |||||
r.POST("/centralKitchenForSchool/contrast", hdl2.CentralKitchenForSchoolDataStatisticsContrast) //数据统计-(央厨-学校)-数据对比 | |||||
r.POST("/centralKitchenForSchool/list", hdl2.CentralKitchenForSchoolDataStatisticsList) //数据统计-(央厨-学校)-列表 | |||||
r.DELETE("/centralKitchenForSchool/delete/:id", hdl2.CentralKitchenForSchoolDataStatisticsDelete) //数据统计-(央厨-学校)-删除 | |||||
r.POST("/nursingHome/export", hdl2.NursingHomeDataStatisticsExport) //数据统计-(养老院)-导出 | |||||
r.POST("/nursingHome/list", hdl2.NursingHomeDataStatisticsList) //数据统计-(养老院)-列表 | |||||
r.DELETE("/nursingHome/delete/:id", hdl2.NursingHomeDataStatisticsDelete) //数据统计-(养老院)-删除 | |||||
r.POST("/selfSupportForSchool/export", hdl2.SelfSupportForSchoolDataStatisticsExport) //数据统计-(自营-学校)-导出 | |||||
r.POST("/selfSupportForSchool/list", hdl2.SelfSupportForSchoolDataStatisticsList) //数据统计-(自营-学校)-列表 | |||||
r.DELETE("/selfSupportForSchool/delete/:id", hdl2.SelfSupportForSchoolDataStatisticsDelete) //数据统计-(自营-学校)-删除 | |||||
r.POST("/centralKitchenForSchool/export", hdl2.CentralKitchenForSchoolDataStatisticsExport) //数据统计-(央厨-学校)-导出 | |||||
r.POST("/centralKitchenForSchool/contrast", hdl2.CentralKitchenForSchoolDataStatisticsContrast) //数据统计-(央厨-学校)-数据对比 | |||||
r.POST("/centralKitchenForSchool/list", hdl2.CentralKitchenForSchoolDataStatisticsList) //数据统计-(央厨-学校)-列表 | |||||
r.POST("/centralKitchenForSchool/delete", hdl2.CentralKitchenForSchoolDataStatisticsDelete) //数据统计-(央厨-学校)-删除 | |||||
r.POST("/nursingHome/export", hdl2.NursingHomeDataStatisticsExport) //数据统计-(养老院)-导出 | |||||
r.POST("/nursingHome/list", hdl2.NursingHomeDataStatisticsList) //数据统计-(养老院)-列表 | |||||
r.POST("/nursingHome/delete", hdl2.NursingHomeDataStatisticsDelete) //数据统计-(养老院)-删除 | |||||
r.POST("/selfSupportForSchool/export", hdl2.SelfSupportForSchoolDataStatisticsExport) //数据统计-(自营-学校)-导出 | |||||
r.POST("/selfSupportForSchool/list", hdl2.SelfSupportForSchoolDataStatisticsList) //数据统计-(自营-学校)-列表 | |||||
r.POST("/selfSupportForSchool/delete", hdl2.SelfSupportForSchoolDataStatisticsDelete) //数据统计-(自营-学校)-删除 | |||||
} | } | ||||