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

470 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, userIdentity *model.UserIdentity, userToken, schoolName 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(userIdentity.Id)
  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. EnterpriseId: userIdentity.EnterpriseId,
  251. UserIdentityId: userIdentity.Id,
  252. CollectFaceType: 1,
  253. SchoolCode: res["school_code"],
  254. SchoolStdCode: res["school_std_code"],
  255. ParentUserId: res["parent_user_id"],
  256. ParentLogonId: res["parent_logon_id"],
  257. UserId: res["user_id"],
  258. SchoolFacePassStatus: res["school_face_pass_status"],
  259. SchoolFacePaymentStatus: res["school_face_payment_status"],
  260. CreateAt: now,
  261. UpdateAt: now,
  262. }
  263. _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(info)
  264. if err2 != nil {
  265. return err2, nil
  266. }
  267. } else {
  268. info.ParentUserId = res["parent_user_id"]
  269. info.ParentLogonId = res["parent_logon_id"]
  270. info.UserId = res["user_id"]
  271. info.SchoolFacePassStatus = res["school_face_pass_status"]
  272. info.SchoolFacePaymentStatus = res["school_face_payment_status"]
  273. info.UpdateAt = now
  274. _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoUpdate(info, "parent_user_id", "parent_logon_id", "user_id", "school_face_pass_status", "school_face_payment_status", "update_at")
  275. if err2 != nil {
  276. return err2, nil
  277. }
  278. }
  279. //TODO:: school_face_pass_status && school_face_payment_status 都为 open 状态,则 签约信息同步“alipay.planet.ecocampus.api.roster.signUpInfo” 至 行业云
  280. CurlAlipayPlanetEcocampusApiRosterSignUpInfo(md.CurlAlipayPlanetEcocampusApiRosterSignUpInfoReq{
  281. FaceUid: info.UserId,
  282. ParentUid: info.ParentUserId,
  283. ParentLogonId: info.ParentLogonId,
  284. RosterName: args.StudentName,
  285. OutRosterCode: args.OutUserId,
  286. SchoolCode: info.SchoolCode,
  287. SchoolName: schoolName,
  288. ScanFacePayStatus: "ON",
  289. FaceOpenStatus: "ON",
  290. })
  291. return nil, result1.Data
  292. }
  293. func CurlEducateSceneTokenCreateForApplet(args md.CurlEducateSceneTokenReq) (err error, resp interface{}) {
  294. utils.FilePutContents("CurlEducateSceneTokenCreateForApplet", utils.SerializeStr(map[string]interface{}{
  295. "args": args,
  296. }))
  297. //1、TODO::生成用户信息token(使用 alipay.commerce.educate.scene.token.create 接口生成用户信息token)
  298. url := cfg.SmartCanteenPay + "/alipay/faceCollection/educateSceneTokenCreate"
  299. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]interface{}{
  300. "config": map[string]string{
  301. "ali_app_id": args.Config.AliAppId,
  302. "ali_private_key": args.Config.AliPrivateKey,
  303. "ali_public_key": args.Config.AliPublicKey,
  304. },
  305. "cert_no": args.CertNo,
  306. "school_std_code": args.SchoolStdCode,
  307. "student_name": args.StudentName,
  308. "out_user_id": args.OutUserId,
  309. "cert_type": "1",
  310. "sub_code": "SCHOOL_FACE_PASS_NAVIGATE",
  311. }), nil)
  312. if err != nil {
  313. return
  314. }
  315. var result struct {
  316. Code int `json:"code"`
  317. Msg string `json:"msg"`
  318. Data interface{} `json:"data"`
  319. }
  320. utils.FilePutContents("CurlEducateSceneTokenCreateForApplet", utils.SerializeStr(result))
  321. err = json.Unmarshal(bytes, &result)
  322. if err != nil {
  323. return
  324. }
  325. if result.Code != 0 {
  326. if result.Msg != "" {
  327. err = errors.New(result.Msg)
  328. return
  329. }
  330. err = errors.New("请求智慧餐厅支付 异常/失败")
  331. return
  332. }
  333. return nil, result.Data
  334. }
  335. func CurlEducateSceneTokenCreateForConcentratedCollectApplet(args md.CurlEducateSceneTokenReq) (err error, resp interface{}) {
  336. utils.FilePutContents("CurlEducateSceneTokenCreateForConcentratedCollectApplet", utils.SerializeStr(map[string]interface{}{
  337. "args": args,
  338. }))
  339. //1、TODO::生成用户信息token(使用 alipay.commerce.educate.scene.token.create 接口生成用户信息token)
  340. url := cfg.SmartCanteenPay + "/alipay/faceCollection/educateSceneTokenCreate"
  341. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]interface{}{
  342. "config": map[string]string{
  343. "ali_app_id": args.Config.AliAppId,
  344. "ali_private_key": args.Config.AliPrivateKey,
  345. "ali_public_key": args.Config.AliPublicKey,
  346. },
  347. "cert_no": args.CertNo,
  348. "school_std_code": args.SchoolStdCode,
  349. "student_name": args.StudentName,
  350. "out_user_id": args.OutUserId,
  351. "cert_type": "1",
  352. "sub_code": "SCHOOL_PAYMENT_REMOTE_OPEN_ACCOUNT",
  353. "operator_user_id": args.OperatorUserId, //采集人员的支付宝会员标识。(当sub_code为SCHOOL_PAYMENT_REMOTE_OPEN_ACCOUNT时,当前参数必选)
  354. }), nil)
  355. if err != nil {
  356. return
  357. }
  358. var result struct {
  359. Code int `json:"code"`
  360. Msg string `json:"msg"`
  361. Data interface{} `json:"data"`
  362. }
  363. utils.FilePutContents("CurlEducateSceneTokenCreateForConcentratedCollectApplet", utils.SerializeStr(result))
  364. err = json.Unmarshal(bytes, &result)
  365. if err != nil {
  366. return
  367. }
  368. if result.Code != 0 {
  369. if result.Msg != "" {
  370. err = errors.New(result.Msg)
  371. return
  372. }
  373. err = errors.New("请求智慧餐厅支付 异常/失败")
  374. return
  375. }
  376. return nil, result.Data
  377. }
  378. func CurlEducateFacepayApply(args md.CurlEducateFacepayApplyReq) (err error, resp interface{}) {
  379. utils.FilePutContents("CurlEducateFacepayApply", utils.SerializeStr(map[string]interface{}{
  380. "args": args,
  381. }))
  382. //1、TODO::alipay.commerce.educate.facepay.apply(人脸开通支付申请)
  383. url := cfg.SmartCanteenPay + "/alipay/faceScanPay/educateFacepayApply"
  384. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]interface{}{
  385. "config": map[string]string{
  386. "ali_app_id": args.Config.AliAppId,
  387. "ali_private_key": args.Config.AliPrivateKey,
  388. "ali_public_key": args.Config.AliPublicKey,
  389. },
  390. "face_uid": args.FaceUid,
  391. "school_std_code": args.SchoolStdCode,
  392. "face_open_id": args.FaceOpenId,
  393. }), nil)
  394. if err != nil {
  395. return
  396. }
  397. var result struct {
  398. Code int `json:"code"`
  399. Msg string `json:"msg"`
  400. Data interface{} `json:"data"`
  401. }
  402. utils.FilePutContents("CurlEducateFacepayApply", utils.SerializeStr(result))
  403. err = json.Unmarshal(bytes, &result)
  404. if err != nil {
  405. return
  406. }
  407. if result.Code != 0 {
  408. if result.Msg != "" {
  409. err = errors.New(result.Msg)
  410. return
  411. }
  412. err = errors.New("请求智慧餐厅支付 异常/失败")
  413. return
  414. }
  415. return nil, result.Data
  416. }
  417. func CurlAlipayPlanetEcocampusApiRosterSignUpInfo(args md.CurlAlipayPlanetEcocampusApiRosterSignUpInfoReq) (err error, resp interface{}) {
  418. url := cfg.SmartCanteenPay + "/alipay/bPass/alipayPlanetEcocampusApiRosterSignUpInfo"
  419. utils.FilePutContents("CurlAlipayPlanetEcocampusApiRosterSignUpInfo", utils.SerializeStr(map[string]interface{}{
  420. "args": args,
  421. }))
  422. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  423. if err != nil {
  424. return
  425. }
  426. var result struct {
  427. Code int `json:"code"`
  428. Msg string `json:"msg"`
  429. Data interface{} `json:"data"`
  430. }
  431. utils.FilePutContents("CurlAlipayPlanetEcocampusApiRosterSignUpInfo", utils.SerializeStr(result))
  432. err = json.Unmarshal(bytes, &result)
  433. if err != nil {
  434. return
  435. }
  436. if result.Code != 0 {
  437. if result.Msg != "" {
  438. err = errors.New(result.Msg)
  439. return
  440. }
  441. err = errors.New("请求智慧餐厅支付 异常/失败")
  442. return
  443. }
  444. return nil, result.Data
  445. }