智慧食堂
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

hdl_demo.go 12 KiB

1 yıl önce
9 ay önce
1 yıl önce
1 yıl önce
9 ay önce
1 yıl önce
1 yıl önce
8 ay önce
1 yıl önce
1 yıl önce
8 ay önce
1 yıl önce
1 yıl önce
8 ay önce
3 ay önce
5 ay önce
7 ay önce
3 ay önce
7 ay önce
3 ay önce
5 ay önce
7 ay önce
5 ay önce
3 ay önce
5 ay önce
3 ay önce
7 ay önce
8 ay önce
9 ay önce
1 yıl önce
1 yıl önce
5 ay önce
1 yıl önce
1 yıl önce
7 ay önce
1 yıl önce
10 ay önce
1 yıl önce
1 yıl önce
1 yıl önce
1 yıl önce
9 ay önce
8 ay önce
9 ay önce
8 ay önce
9 ay önce
8 ay önce
9 ay önce
8 ay önce
9 ay önce
8 ay önce
9 ay önce
1 yıl önce
1 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. package hdl
  2. import (
  3. "applet/app/admin/lib/validate"
  4. "applet/app/admin/md"
  5. svc "applet/app/admin/svc/order"
  6. md2 "applet/app/customer/md"
  7. svc2 "applet/app/customer/svc"
  8. "applet/app/db"
  9. "applet/app/db/model"
  10. "applet/app/e"
  11. "applet/app/enum"
  12. svc3 "applet/app/svc"
  13. "applet/app/utils"
  14. "fmt"
  15. "github.com/gin-gonic/gin"
  16. "github.com/wechatpay-apiv3/wechatpay-go/core"
  17. "github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
  18. "math"
  19. "time"
  20. )
  21. // Demo 测试
  22. func Demo(c *gin.Context) {
  23. eg := db.Db
  24. var mm []model.CentralKitchenForSchoolWithSpec
  25. if err1 := eg.Asc("id").Find(&mm); err1 != nil {
  26. e.OutErr(c, e.ERR, err1.Error())
  27. return
  28. }
  29. now := time.Now()
  30. for _, v := range mm {
  31. m := new(model.MealLabel)
  32. has, err := db.Db.Where("enterprise_id =?", v.EnterpriseId).Get(m)
  33. if err != nil {
  34. fmt.Println(err)
  35. return
  36. }
  37. if !has {
  38. //查找所有年级
  39. gradeDb := db.GradeDb{}
  40. gradeDb.Set(v.EnterpriseId)
  41. gradeList, err := gradeDb.FindGrade()
  42. if err != nil {
  43. fmt.Println(err)
  44. return
  45. }
  46. for _, grade := range *gradeList {
  47. period := new(model.Period)
  48. has1, err := db.Db.Where("id =?", grade.PeriodId).Get(period)
  49. if err != nil {
  50. fmt.Println(err)
  51. return
  52. }
  53. if !has1 {
  54. continue
  55. }
  56. if v.IsOpenBreakfast == 1 {
  57. m = &model.MealLabel{
  58. Name: "早餐",
  59. EnterpriseId: v.EnterpriseId,
  60. GradeId: grade.Id,
  61. Kind: 1,
  62. Price: period.BreakfastUnitPrice,
  63. CreateAt: now.Format("2006-01-02 15:04:05"),
  64. UpdateAt: now.Format("2006-01-02 15:04:05"),
  65. }
  66. _, err2 := db.Db.Insert(m)
  67. if err2 != nil {
  68. fmt.Println(err2)
  69. return
  70. }
  71. }
  72. if v.IsOpenLunch == 1 {
  73. m = &model.MealLabel{
  74. Name: "午餐",
  75. EnterpriseId: v.EnterpriseId,
  76. GradeId: grade.Id,
  77. Kind: 2,
  78. Price: period.LunchUnitPrice,
  79. CreateAt: now.Format("2006-01-02 15:04:05"),
  80. UpdateAt: now.Format("2006-01-02 15:04:05"),
  81. }
  82. _, err2 := db.Db.Insert(m)
  83. if err2 != nil {
  84. fmt.Println(err2)
  85. return
  86. }
  87. }
  88. if v.IsOpenDinner == 1 {
  89. m = &model.MealLabel{
  90. Name: "晚餐",
  91. EnterpriseId: v.EnterpriseId,
  92. GradeId: grade.Id,
  93. Kind: 3,
  94. Price: period.DinnerUnitPrice,
  95. CreateAt: now.Format("2006-01-02 15:04:05"),
  96. UpdateAt: now.Format("2006-01-02 15:04:05"),
  97. }
  98. _, err2 := db.Db.Insert(m)
  99. if err2 != nil {
  100. fmt.Println(err2)
  101. return
  102. }
  103. }
  104. }
  105. }
  106. }
  107. return
  108. var m []model.CentralKitchenForSchoolUserWithDay
  109. if err1 := eg.Where("state = 3").Asc("id").Find(&m); err1 != nil {
  110. e.OutErr(c, e.ERR, err1.Error())
  111. return
  112. }
  113. var records []int
  114. for _, v := range m {
  115. mm := new(model.CentralKitchenForSchoolUserRefundDay)
  116. has, err := db.Db.Where("records_id =? and state = 1", v.Id).Get(mm)
  117. if err != nil {
  118. fmt.Println(err)
  119. return
  120. }
  121. if has == false {
  122. centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
  123. centralKitchenForSchoolUserRefundDayDb.Set(0)
  124. _, err = centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayInsert(&model.CentralKitchenForSchoolUserRefundDay{
  125. OutTradeNo: v.OrdNo,
  126. OutRequestNo: "",
  127. Uid: v.Uid,
  128. IdentityId: v.IdentityId,
  129. RecordsId: v.Id,
  130. State: enum.CentralKitchenForSchoolUserRefundDayStateForAuditing,
  131. Amount: v.Amount,
  132. Memo: "fill",
  133. CreateAt: now.Format("2006-01-02 15:04:05"),
  134. UpdateAt: now.Format("2006-01-02 15:04:05"),
  135. })
  136. records = append(records, v.Id)
  137. }
  138. }
  139. e.OutSuc(c, records, nil)
  140. return
  141. var req md.CentralKitchenForSchoolOrderRefundAuditReq
  142. err := c.ShouldBindJSON(&req)
  143. if err != nil {
  144. err = validate.HandleValidateErr(err)
  145. err1 := err.(e.E)
  146. e.OutErr(c, err1.Code, err1.Error())
  147. return
  148. }
  149. err1 := svc.CentralKitchenForSchoolOrderRefundAudit(c, req)
  150. if err1 != nil {
  151. fmt.Println(err1.Error())
  152. e.OutErr(c, e.ERR, err1.Error())
  153. return
  154. }
  155. e.OutSuc(c, "success", nil)
  156. return
  157. sysCfgDb := db.SysCfgDb{}
  158. sysCfgDb.Set()
  159. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey)
  160. //调用支付宝进行退款
  161. err6, _ := svc2.OldCurlAlipayTradeRefund(md2.OldCurlAlipayTradeRefundReq{
  162. Config: struct {
  163. PayAliAppId string `json:"pay_ali_app_id" label:"支付宝开放平台-第三方应用-appid"`
  164. PayAliPrivateKey string `json:"pay_ali_private_key" label:"支付宝开放平台-第三方应用-接口加签-应用私钥"`
  165. PayAliPublicKey string `json:"pay_ali_public_key" label:"支付宝开放平台-第三方应用-接口加签-支付宝公钥"`
  166. }{
  167. PayAliAppId: sysCfg[enum.OpenAlipayAppid],
  168. PayAliPrivateKey: sysCfg[enum.OpenAlipayAppPrivateKey],
  169. PayAliPublicKey: sysCfg[enum.OpenAlipayPublicKey],
  170. },
  171. OutTradeNo: "800169659125681442",
  172. RefundAmount: "180.00",
  173. RefundReason: "央厨订餐退款",
  174. OutRequestNo: "r_800169659125681442_1705546121",
  175. AppAuthToken: "202308BB8ef30019cd8d4a40a3853192c397dX35",
  176. })
  177. if err6 != nil {
  178. fmt.Println(err6.Error())
  179. }
  180. return
  181. qrcodeWithBatchRecordsDb := db.AdminDb{}
  182. qrcodeWithBatchRecordsDb.Set()
  183. data, _, err := qrcodeWithBatchRecordsDb.GetAdminRolePermission(1001)
  184. if err != nil {
  185. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  186. return
  187. }
  188. e.OutSuc(c, data, nil)
  189. go GoOnExecuting()
  190. return
  191. }
  192. // Demo 测试
  193. func TempDemo(c *gin.Context) {
  194. eg := db.Db
  195. var list []*model.CentralKitchenForSchoolUserWithDay
  196. err := db.Db.Where("state = 3").Asc("id").Find(&list)
  197. if err != nil {
  198. return
  199. }
  200. for _, m := range list {
  201. mm := new(model.CentralKitchenForSchoolUserRefundDay)
  202. has, err := db.Db.Where("records_id =? and state = 4", m.Id).Get(mm)
  203. if err != nil {
  204. fmt.Println(err)
  205. return
  206. }
  207. if has {
  208. m.State = 4
  209. updateAffetcd, err := db.Db.Where("id =?", m.Id).Cols("state").Update(m)
  210. if err != nil {
  211. fmt.Println(err)
  212. return
  213. }
  214. fmt.Println(">>>>>>>>>>>", updateAffetcd)
  215. }
  216. }
  217. return
  218. var m []model.CentralKitchenForSchoolUserWithDay
  219. if err1 := eg.Where("state = 3").Asc("id").Find(&m); err1 != nil {
  220. e.OutErr(c, e.ERR, err1.Error())
  221. return
  222. }
  223. now := time.Now()
  224. var records []int
  225. for _, v := range m {
  226. mm := new(model.CentralKitchenForSchoolUserRefundDay)
  227. has, err := db.Db.Where("records_id =? and state = 1", v.Id).Get(mm)
  228. if err != nil {
  229. fmt.Println(err)
  230. return
  231. }
  232. if has == false {
  233. centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
  234. centralKitchenForSchoolUserRefundDayDb.Set(0)
  235. _, err = centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayInsert(&model.CentralKitchenForSchoolUserRefundDay{
  236. OutTradeNo: v.OrdNo,
  237. OutRequestNo: "",
  238. Uid: v.Uid,
  239. IdentityId: v.IdentityId,
  240. RecordsId: v.Id,
  241. State: enum.CentralKitchenForSchoolUserRefundDayStateForAuditing,
  242. Amount: v.Amount,
  243. Memo: "fill",
  244. CreateAt: now.Format("2006-01-02 15:04:05"),
  245. UpdateAt: now.Format("2006-01-02 15:04:05"),
  246. })
  247. records = append(records, v.Id)
  248. }
  249. }
  250. e.OutSuc(c, records, nil)
  251. return
  252. var req md.CentralKitchenForSchoolOrderRefundAuditReq
  253. err = c.ShouldBindJSON(&req)
  254. if err != nil {
  255. err = validate.HandleValidateErr(err)
  256. err1 := err.(e.E)
  257. e.OutErr(c, err1.Code, err1.Error())
  258. return
  259. }
  260. err1 := svc.CentralKitchenForSchoolOrderRefundAudit(c, req)
  261. if err1 != nil {
  262. fmt.Println(err1.Error())
  263. e.OutErr(c, e.ERR, err1.Error())
  264. return
  265. }
  266. e.OutSuc(c, "success", nil)
  267. return
  268. sysCfgDb := db.SysCfgDb{}
  269. sysCfgDb.Set()
  270. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey)
  271. //调用支付宝进行退款
  272. err6, _ := svc2.OldCurlAlipayTradeRefund(md2.OldCurlAlipayTradeRefundReq{
  273. Config: struct {
  274. PayAliAppId string `json:"pay_ali_app_id" label:"支付宝开放平台-第三方应用-appid"`
  275. PayAliPrivateKey string `json:"pay_ali_private_key" label:"支付宝开放平台-第三方应用-接口加签-应用私钥"`
  276. PayAliPublicKey string `json:"pay_ali_public_key" label:"支付宝开放平台-第三方应用-接口加签-支付宝公钥"`
  277. }{
  278. PayAliAppId: sysCfg[enum.OpenAlipayAppid],
  279. PayAliPrivateKey: sysCfg[enum.OpenAlipayAppPrivateKey],
  280. PayAliPublicKey: sysCfg[enum.OpenAlipayPublicKey],
  281. },
  282. OutTradeNo: "800169659125681442",
  283. RefundAmount: "180.00",
  284. RefundReason: "央厨订餐退款",
  285. OutRequestNo: "r_800169659125681442_1705546121",
  286. AppAuthToken: "202308BB8ef30019cd8d4a40a3853192c397dX35",
  287. })
  288. if err6 != nil {
  289. fmt.Println(err6.Error())
  290. }
  291. return
  292. qrcodeWithBatchRecordsDb := db.AdminDb{}
  293. qrcodeWithBatchRecordsDb.Set()
  294. data, _, err := qrcodeWithBatchRecordsDb.GetAdminRolePermission(1001)
  295. if err != nil {
  296. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  297. return
  298. }
  299. e.OutSuc(c, data, nil)
  300. go GoOnExecuting()
  301. return
  302. }
  303. func DemoV1(c *gin.Context) {
  304. var outRequestNo = c.Query("out_request_no")
  305. var outTradeNo = c.Query("out_no")
  306. centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
  307. centralKitchenForSchoolUserRefundDayDb.Set(0)
  308. var m []model.CentralKitchenForSchoolUserRefundDay
  309. if err := centralKitchenForSchoolUserRefundDayDb.Db.Where("out_request_no =?", outRequestNo).Desc("id").Find(&m); err != nil {
  310. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  311. return
  312. }
  313. centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
  314. centralKitchenForSchoolPackageOrd.Set(outTradeNo)
  315. ord, _ := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd()
  316. var dealReturnOrdMapForWx = map[string]struct {
  317. OutRequestNo string `json:"out_request_no"`
  318. Amount float64 `json:"amount"`
  319. Total string `json:"total"`
  320. WxMchId string `json:"wx_mch_id"`
  321. }{}
  322. companyWithWxpayInfoDb := db.CompanyWithWxpayInfoDb{}
  323. companyWithWxpayInfoDb.Set()
  324. wxMchId, _ := companyWithWxpayInfoDb.GetCompanyWithWxpayInfoByEnterprise(ord.EnterpriseId)
  325. for _, v := range m {
  326. dealReturnOrdMapForWx[ord.OutTradeNo] = struct {
  327. OutRequestNo string `json:"out_request_no"`
  328. Amount float64 `json:"amount"`
  329. Total string `json:"total"`
  330. WxMchId string `json:"wx_mch_id"`
  331. }(struct {
  332. OutRequestNo string
  333. Amount float64
  334. Total string
  335. WxMchId string
  336. }{OutRequestNo: outRequestNo, Amount: dealReturnOrdMapForWx[v.OutTradeNo].Amount + utils.StrToFloat64(v.Amount), Total: ord.TotalPrice, WxMchId: wxMchId})
  337. }
  338. client, err1 := svc3.NewWxPayClient(c) //初始化微信连接
  339. if err1 != nil {
  340. e.OutErr(c, e.ERR, err1.Error())
  341. return
  342. }
  343. sysCfgDb := db.SysCfgDb{}
  344. sysCfgDb.Set()
  345. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.JsapiPayAppAutToken, enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey, enum.WxJsapiRefundPayNotifyUrl)
  346. wxSvc := refunddomestic.RefundsApiService{Client: client}
  347. for k, v := range dealReturnOrdMapForWx {
  348. resp, _, err6 := wxSvc.Create(c,
  349. refunddomestic.CreateRequest{
  350. SubMchid: core.String(v.WxMchId),
  351. OutTradeNo: core.String(k),
  352. OutRefundNo: core.String(v.OutRequestNo),
  353. Reason: core.String("央厨订餐退款"),
  354. NotifyUrl: core.String(sysCfg[enum.WxJsapiRefundPayNotifyUrl]),
  355. Amount: &refunddomestic.AmountReq{
  356. Currency: core.String("CNY"),
  357. Refund: core.Int64(int64(math.Round(v.Amount * 100))),
  358. Total: core.Int64(int64(math.Round(utils.StrToFloat64(v.Total) * 100))),
  359. },
  360. },
  361. )
  362. fmt.Println(">>>>wxRefund<<<<", resp)
  363. if err6 != nil {
  364. fmt.Println(err6)
  365. e.OutErr(c, e.ERR, err6.Error())
  366. return
  367. }
  368. }
  369. e.OutSuc(c, dealReturnOrdMapForWx, nil)
  370. return
  371. }
  372. func GoOnExecuting() {
  373. for i := 0; i < 20; i++ {
  374. time.Sleep(1 * time.Second)
  375. fmt.Println(i)
  376. }
  377. }