智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_demo.go 12 KiB

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