智慧食堂
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.

456 lines
14 KiB

  1. package svc
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/customer/md"
  5. "applet/app/db"
  6. "applet/app/db/model"
  7. "applet/app/utils"
  8. "encoding/json"
  9. "errors"
  10. "time"
  11. )
  12. func AesDecrypt(args md.CurlAesDecrypt) (error, interface{}) {
  13. url := cfg.SmartCanteenPay + "/alipay/decrypt/index"
  14. utils.FilePutContents("AesDecrypt", utils.SerializeStr(map[string]interface{}{
  15. "data": args,
  16. }))
  17. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  18. if err != nil {
  19. return err, nil
  20. }
  21. var result struct {
  22. Code int `json:"code"`
  23. Msg string `json:"msg"`
  24. Data interface{} `json:"data"`
  25. }
  26. utils.FilePutContents("AesDecrypt", utils.SerializeStr(result))
  27. err = json.Unmarshal(bytes, &result)
  28. if err != nil {
  29. return err, nil
  30. }
  31. if result.Code != 0 {
  32. if result.Msg != "" {
  33. return errors.New(result.Msg), nil
  34. }
  35. return errors.New("请求智慧餐厅支付 异常/失败"), nil
  36. }
  37. return nil, result.Data
  38. }
  39. func SystemOauthToken(args md.SystemOauthTokenReq) (error, interface{}) {
  40. url := cfg.SmartCanteenPay + "/alipay/systemOauthToken/index"
  41. utils.FilePutContents("SystemOauthToken", utils.SerializeStr(map[string]interface{}{
  42. "data": args,
  43. }))
  44. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  45. if err != nil {
  46. return err, nil
  47. }
  48. var result struct {
  49. Code int `json:"code"`
  50. Msg string `json:"msg"`
  51. Data interface{} `json:"data"`
  52. }
  53. utils.FilePutContents("SystemOauthToken", utils.SerializeStr(result))
  54. err = json.Unmarshal(bytes, &result)
  55. if err != nil {
  56. return err, nil
  57. }
  58. if result.Code != 0 {
  59. if result.Msg != "" {
  60. return errors.New(result.Msg), nil
  61. }
  62. return errors.New("请求智慧餐厅支付 异常/失败"), nil
  63. }
  64. return nil, result.Data
  65. }
  66. func CurlAlipayTradeCreate(args md.CurlAlipayTradeCreateReq) (err error, resp md.CurlAlipayTradeCreateResp) {
  67. url := cfg.SmartCanteenPay + "/alipay/pay/tradeCreate"
  68. utils.FilePutContents("CurlAlipayTradeCreate", utils.SerializeStr(map[string]interface{}{
  69. "args": args,
  70. }))
  71. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  72. if err != nil {
  73. return
  74. }
  75. var result struct {
  76. Code int `json:"code"`
  77. Msg string `json:"msg"`
  78. Data interface{} `json:"data"`
  79. }
  80. utils.FilePutContents("CurlAlipayTradeCreate", utils.SerializeStr(result))
  81. err = json.Unmarshal(bytes, &result)
  82. if err != nil {
  83. return
  84. }
  85. if result.Code != 0 {
  86. if result.Msg != "" {
  87. err = errors.New(result.Msg)
  88. return
  89. }
  90. err = errors.New("请求智慧餐厅支付 异常/失败")
  91. return
  92. }
  93. err = json.Unmarshal(utils.Serialize(result.Data), &resp)
  94. if err != nil {
  95. return
  96. }
  97. return
  98. }
  99. func CurlAlipayTradeQuery(args md.CurlAlipayTradeQueryReq) (err error, resp md.CurlAlipayTradeQueryResp) {
  100. url := cfg.SmartCanteenPay + "/alipay/pay/tradeCommonQuery"
  101. utils.FilePutContents("CurlAlipayTradeQuery", utils.SerializeStr(map[string]interface{}{
  102. "args": args,
  103. }))
  104. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  105. if err != nil {
  106. return
  107. }
  108. var result struct {
  109. Code int `json:"code"`
  110. Msg string `json:"msg"`
  111. Data interface{} `json:"data"`
  112. }
  113. utils.FilePutContents("CurlAlipayTradeQuery", utils.SerializeStr(result))
  114. err = json.Unmarshal(bytes, &result)
  115. if err != nil {
  116. return
  117. }
  118. if result.Code != 0 {
  119. if result.Msg != "" {
  120. err = errors.New(result.Msg)
  121. return
  122. }
  123. err = errors.New("请求智慧餐厅支付 异常/失败")
  124. return
  125. }
  126. err = json.Unmarshal(utils.Serialize(result.Data), &resp)
  127. if err != nil {
  128. return
  129. }
  130. return
  131. }
  132. func CurlAlipayTradeRefund(args md.CurlAlipayTradeRefundReq) (err error, resp interface{}) {
  133. url := cfg.SmartCanteenPay + "/alipay/pay/tradeRefund"
  134. utils.FilePutContents("CurlAlipayTradeRefund", utils.SerializeStr(map[string]interface{}{
  135. "args": args,
  136. }))
  137. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  138. if err != nil {
  139. return
  140. }
  141. var result struct {
  142. Code int `json:"code"`
  143. Msg string `json:"msg"`
  144. Data interface{} `json:"data"`
  145. }
  146. utils.FilePutContents("CurlAlipayTradeRefund", utils.SerializeStr(result))
  147. err = json.Unmarshal(bytes, &result)
  148. if err != nil {
  149. return
  150. }
  151. if result.Code != 0 {
  152. if result.Msg != "" {
  153. err = errors.New(result.Msg)
  154. return
  155. }
  156. err = errors.New("请求智慧餐厅支付 异常/失败")
  157. return
  158. }
  159. return nil, result.Data
  160. }
  161. func CurlEducateSceneTokenQuery(args md.CurlEducateSceneTokenReq, userIdentityId int, userToken string) (err error, resp interface{}) {
  162. utils.FilePutContents("CurlEducateSceneTokenQuery", utils.SerializeStr(map[string]interface{}{
  163. "args": args,
  164. }))
  165. if userToken == "" {
  166. //1、TODO::生成用户信息token(使用 alipay.commerce.educate.scene.token.create 接口生成用户信息token)
  167. url := cfg.SmartCanteenPay + "/alipay/faceCollection/educateSceneTokenCreate"
  168. bytes, err1 := utils.CurlPost(url, utils.Serialize(map[string]interface{}{
  169. "config": map[string]string{
  170. "ali_app_id": args.Config.AliAppId,
  171. "ali_private_key": args.Config.AliPrivateKey,
  172. "ali_public_key": args.Config.AliPublicKey,
  173. },
  174. "cert_no": args.CertNo,
  175. "school_std_code": args.SchoolStdCode,
  176. "student_name": args.StudentName,
  177. "out_user_id": args.OutUserId,
  178. "cert_type": "1",
  179. "sub_code": "SCHOOL_FACE_PASS_QUERY",
  180. }), nil)
  181. if err1 != nil {
  182. return
  183. }
  184. var result struct {
  185. Code int `json:"code"`
  186. Msg string `json:"msg"`
  187. Data interface{} `json:"data"`
  188. }
  189. utils.FilePutContents("CurlEducateSceneTokenCreate", utils.SerializeStr(result))
  190. err1 = json.Unmarshal(bytes, &result)
  191. if err1 != nil {
  192. return
  193. }
  194. if result.Code != 0 {
  195. if result.Msg != "" {
  196. err1 = errors.New(result.Msg)
  197. return
  198. }
  199. err1 = errors.New("请求智慧餐厅支付 异常/失败")
  200. return
  201. }
  202. resultMap, ok := result.Data.(map[string]interface{})
  203. if !ok {
  204. err1 = errors.New("获取 user_token 失败")
  205. return
  206. }
  207. if resultMap["code"].(string) != "10000" {
  208. return nil, resultMap
  209. }
  210. userToken = resultMap["token"].(string)
  211. }
  212. //2、TODO::查询用户一脸通行开通状态:根据获取到的用户信息token,使用 alipay.commerce.educate.scene.token.query 接口查询用户人脸采集状态
  213. url := cfg.SmartCanteenPay + "/alipay/faceCollection/educateSceneTokenQuery"
  214. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]string{
  215. "user_token": userToken,
  216. }), nil)
  217. if err != nil {
  218. return
  219. }
  220. var result1 struct {
  221. Code int `json:"code"`
  222. Msg string `json:"msg"`
  223. Data interface{} `json:"data"`
  224. }
  225. utils.FilePutContents("CurlEducateSceneTokenQuery", utils.SerializeStr(result1))
  226. err = json.Unmarshal(bytes, &result1)
  227. if err != nil {
  228. return
  229. }
  230. if result1.Code != 0 {
  231. if result1.Msg != "" {
  232. err = errors.New(result1.Msg)
  233. return
  234. }
  235. err = errors.New("请求智慧餐厅支付 异常/失败")
  236. return
  237. }
  238. // 更新/新增 `self_support_for_user_facel_info`
  239. selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
  240. selfSupportForUserFaceInfoDb.Set(userIdentityId)
  241. info, err := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo()
  242. if err != nil {
  243. return
  244. }
  245. now := time.Now().Format("2006-01-02 15:04:05")
  246. var res map[string]string
  247. utils.Unserialize([]byte(utils.SerializeStr(result1.Data)), &res)
  248. if info == nil {
  249. info = &model.SelfSupportForUserFaceInfo{
  250. UserIdentityId: userIdentityId,
  251. CollectFaceType: 1,
  252. SchoolCode: res["school_code"],
  253. SchoolStdCode: res["school_std_code"],
  254. ParentUserId: res["parent_user_id"],
  255. ParentLogonId: res["parent_logon_id"],
  256. UserId: res["user_id"],
  257. SchoolFacePassStatus: res["school_face_pass_status"],
  258. SchoolFacePaymentStatus: res["school_face_payment_status"],
  259. CreateAt: now,
  260. UpdateAt: now,
  261. }
  262. _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(info)
  263. if err2 != nil {
  264. return err2, nil
  265. }
  266. } else {
  267. info.ParentUserId = res["parent_user_id"]
  268. info.ParentLogonId = res["parent_logon_id"]
  269. info.UserId = res["user_id"]
  270. info.SchoolFacePassStatus = res["school_face_pass_status"]
  271. info.SchoolFacePaymentStatus = res["school_face_payment_status"]
  272. info.UpdateAt = now
  273. _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoUpdate(info, "parent_user_id", "parent_logon_id", "user_id", "school_face_pass_status", "school_face_payment_status", "update_at")
  274. if err2 != nil {
  275. return err2, nil
  276. }
  277. }
  278. return nil, result1.Data
  279. }
  280. func CurlEducateSceneTokenCreateForApplet(args md.CurlEducateSceneTokenReq) (err error, resp interface{}) {
  281. utils.FilePutContents("CurlEducateSceneTokenCreateForApplet", utils.SerializeStr(map[string]interface{}{
  282. "args": args,
  283. }))
  284. //1、TODO::生成用户信息token(使用 alipay.commerce.educate.scene.token.create 接口生成用户信息token)
  285. url := cfg.SmartCanteenPay + "/alipay/faceCollection/educateSceneTokenCreate"
  286. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]interface{}{
  287. "config": map[string]string{
  288. "ali_app_id": args.Config.AliAppId,
  289. "ali_private_key": args.Config.AliPrivateKey,
  290. "ali_public_key": args.Config.AliPublicKey,
  291. },
  292. "cert_no": args.CertNo,
  293. "school_std_code": args.SchoolStdCode,
  294. "student_name": args.StudentName,
  295. "out_user_id": args.OutUserId,
  296. "cert_type": "1",
  297. "sub_code": "SCHOOL_FACE_PASS_NAVIGATE",
  298. }), nil)
  299. if err != nil {
  300. return
  301. }
  302. var result struct {
  303. Code int `json:"code"`
  304. Msg string `json:"msg"`
  305. Data interface{} `json:"data"`
  306. }
  307. utils.FilePutContents("CurlEducateSceneTokenCreateForApplet", utils.SerializeStr(result))
  308. err = json.Unmarshal(bytes, &result)
  309. if err != nil {
  310. return
  311. }
  312. if result.Code != 0 {
  313. if result.Msg != "" {
  314. err = errors.New(result.Msg)
  315. return
  316. }
  317. err = errors.New("请求智慧餐厅支付 异常/失败")
  318. return
  319. }
  320. return nil, result.Data
  321. }
  322. func CurlEducateSceneTokenCreateForConcentratedCollectApplet(args md.CurlEducateSceneTokenReq) (err error, resp interface{}) {
  323. utils.FilePutContents("CurlEducateSceneTokenCreateForConcentratedCollectApplet", utils.SerializeStr(map[string]interface{}{
  324. "args": args,
  325. }))
  326. //1、TODO::生成用户信息token(使用 alipay.commerce.educate.scene.token.create 接口生成用户信息token)
  327. url := cfg.SmartCanteenPay + "/alipay/faceCollection/educateSceneTokenCreate"
  328. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]interface{}{
  329. "config": map[string]string{
  330. "ali_app_id": args.Config.AliAppId,
  331. "ali_private_key": args.Config.AliPrivateKey,
  332. "ali_public_key": args.Config.AliPublicKey,
  333. },
  334. "cert_no": args.CertNo,
  335. "school_std_code": args.SchoolStdCode,
  336. "student_name": args.StudentName,
  337. "out_user_id": args.OutUserId,
  338. "cert_type": "1",
  339. "sub_code": "SCHOOL_PAYMENT_REMOTE_OPEN_ACCOUNT",
  340. "operator_user_id": args.OperatorUserId, //采集人员的支付宝会员标识。(当sub_code为SCHOOL_PAYMENT_REMOTE_OPEN_ACCOUNT时,当前参数必选)
  341. }), nil)
  342. if err != nil {
  343. return
  344. }
  345. var result struct {
  346. Code int `json:"code"`
  347. Msg string `json:"msg"`
  348. Data interface{} `json:"data"`
  349. }
  350. utils.FilePutContents("CurlEducateSceneTokenCreateForConcentratedCollectApplet", utils.SerializeStr(result))
  351. err = json.Unmarshal(bytes, &result)
  352. if err != nil {
  353. return
  354. }
  355. if result.Code != 0 {
  356. if result.Msg != "" {
  357. err = errors.New(result.Msg)
  358. return
  359. }
  360. err = errors.New("请求智慧餐厅支付 异常/失败")
  361. return
  362. }
  363. return nil, result.Data
  364. }
  365. func CurlEducateFacepayApply(args md.CurlEducateFacepayApplyReq) (err error, resp interface{}) {
  366. utils.FilePutContents("CurlEducateFacepayApply", utils.SerializeStr(map[string]interface{}{
  367. "args": args,
  368. }))
  369. //1、TODO::alipay.commerce.educate.facepay.apply(人脸开通支付申请)
  370. url := cfg.SmartCanteenPay + "/alipay/faceScanPay/educateFacepayApply"
  371. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]interface{}{
  372. "config": map[string]string{
  373. "ali_app_id": args.Config.AliAppId,
  374. "ali_private_key": args.Config.AliPrivateKey,
  375. "ali_public_key": args.Config.AliPublicKey,
  376. },
  377. "face_uid": args.FaceUid,
  378. "school_std_code": args.SchoolStdCode,
  379. "face_open_id": args.FaceOpenId,
  380. }), nil)
  381. if err != nil {
  382. return
  383. }
  384. var result struct {
  385. Code int `json:"code"`
  386. Msg string `json:"msg"`
  387. Data interface{} `json:"data"`
  388. }
  389. utils.FilePutContents("CurlEducateFacepayApply", utils.SerializeStr(result))
  390. err = json.Unmarshal(bytes, &result)
  391. if err != nil {
  392. return
  393. }
  394. if result.Code != 0 {
  395. if result.Msg != "" {
  396. err = errors.New(result.Msg)
  397. return
  398. }
  399. err = errors.New("请求智慧餐厅支付 异常/失败")
  400. return
  401. }
  402. return nil, result.Data
  403. }
  404. func CurlAlipayPlanetEcocampusApiRosterSignUpInfo(args md.CurlAlipayPlanetEcocampusApiRosterSignUpInfoReq) (err error, resp interface{}) {
  405. url := cfg.SmartCanteenPay + "/alipay/bPass/alipayPlanetEcocampusApiRosterSignUpInfo"
  406. utils.FilePutContents("CurlAlipayPlanetEcocampusApiRosterSignUpInfo", utils.SerializeStr(map[string]interface{}{
  407. "args": args,
  408. }))
  409. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  410. if err != nil {
  411. return
  412. }
  413. var result struct {
  414. Code int `json:"code"`
  415. Msg string `json:"msg"`
  416. Data interface{} `json:"data"`
  417. }
  418. utils.FilePutContents("CurlAlipayPlanetEcocampusApiRosterSignUpInfo", utils.SerializeStr(result))
  419. err = json.Unmarshal(bytes, &result)
  420. if err != nil {
  421. return
  422. }
  423. if result.Code != 0 {
  424. if result.Msg != "" {
  425. err = errors.New(result.Msg)
  426. return
  427. }
  428. err = errors.New("请求智慧餐厅支付 异常/失败")
  429. return
  430. }
  431. return nil, result.Data
  432. }