用户接口远程调用
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.

817 lines
14 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. package userrpc
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "log"
  6. )
  7. type GetAddReq struct {
  8. Req
  9. UserId string
  10. Value string
  11. Memo string
  12. Source string
  13. SourceId string
  14. }
  15. type GetUpdateReq struct {
  16. Req
  17. UserId string
  18. Value string
  19. UsedValue string
  20. }
  21. type GetLogReq struct {
  22. Req
  23. UserId string
  24. Value string
  25. Before string
  26. After string
  27. Source string
  28. SourceId string
  29. OrderSn string
  30. Target string
  31. TargetId string
  32. ProductThumb string
  33. Memo string
  34. }
  35. type GetUpgradeLogReq struct {
  36. Req
  37. UserId string
  38. Upgrade string
  39. Before string
  40. After string
  41. Source string
  42. Memo string
  43. }
  44. type GetCouponReq struct {
  45. Req
  46. UserId string
  47. CouponId string
  48. ExpireTime string
  49. OrderSn string
  50. Remark string
  51. IsUse string
  52. Usertime string
  53. }
  54. /**
  55. * 获取用户积分
  56. */
  57. func GetUserScore(dbname, userId string, url ...string) (string, error) {
  58. if dbname == "" || userId == "" {
  59. return "", errors.New("参数错误")
  60. }
  61. conn, err := rpc_server_conn(url...)
  62. if err != nil {
  63. return "", err
  64. }
  65. defer conn.Close()
  66. data := GetUserReq{}
  67. data.Dbname = dbname
  68. data.UserId = userId
  69. req, err := SetReqData(data)
  70. if err != nil {
  71. return "", err
  72. }
  73. res := &Response{}
  74. err = conn.GetUserScore(req, res)
  75. if err != nil {
  76. return "", err
  77. }
  78. res_data_de, err := GetResData(res)
  79. if err != nil {
  80. return "", err
  81. }
  82. if res_data_de == "" {
  83. return "", nil
  84. }
  85. var score string
  86. err = json.Unmarshal([]byte(res_data_de), &score)
  87. if err != nil {
  88. return "", err
  89. }
  90. return score, nil
  91. }
  92. /**
  93. * 获取用户红包
  94. */
  95. func GetUserRedEnvelope(dbname, userId string, url ...string) (string, error) {
  96. if dbname == "" || userId == "" {
  97. return "", errors.New("参数错误")
  98. }
  99. conn, err := rpc_server_conn(url...)
  100. if err != nil {
  101. return "", err
  102. }
  103. defer conn.Close()
  104. data := GetUserReq{}
  105. data.Dbname = dbname
  106. data.UserId = userId
  107. req, err := SetReqData(data)
  108. if err != nil {
  109. return "", err
  110. }
  111. res := &Response{}
  112. err = conn.GetUserRedEnvelope(req, res)
  113. if err != nil {
  114. return "", err
  115. }
  116. res_data_de, err := GetResData(res)
  117. if err != nil {
  118. return "", err
  119. }
  120. if res_data_de == "" {
  121. return "", nil
  122. }
  123. var redEnvelope string
  124. err = json.Unmarshal([]byte(res_data_de), &redEnvelope)
  125. if err != nil {
  126. return "", err
  127. }
  128. return redEnvelope, nil
  129. }
  130. /**
  131. * 添加积分
  132. * @2021/09/30
  133. * @bin
  134. */
  135. func AddUserScore(dbname, userId, score, memo string, url ...string) (int64, error) {
  136. if dbname == "" || userId == "" || score == "" {
  137. return 0, errors.New("参数错误")
  138. }
  139. conn, err := rpc_server_conn(url...)
  140. if err != nil {
  141. return 0, err
  142. }
  143. defer conn.Close()
  144. data := GetAddReq{}
  145. data.Dbname = dbname
  146. data.UserId = userId
  147. data.Value = score
  148. data.Memo = memo
  149. req, err := SetReqData(data)
  150. if err != nil {
  151. log.Println("AddUserScore crypter error:", err)
  152. return 0, err
  153. }
  154. res := &Response{}
  155. err = conn.AddUserScore(req, res)
  156. if err != nil {
  157. log.Println("userrpc AddUserScore error:", err)
  158. return 0, err
  159. }
  160. res_data_de, err := GetResData(res)
  161. if err != nil {
  162. return 0, err
  163. }
  164. if res_data_de == "" {
  165. return 0, nil
  166. }
  167. var insertId int64
  168. err = json.Unmarshal([]byte(res_data_de), &insertId)
  169. if err != nil {
  170. return 0, err
  171. }
  172. return insertId, nil
  173. }
  174. /**
  175. * 更新积分记录
  176. * @2021/09/30
  177. * @bin
  178. */
  179. func UpdateUserScore(dbname, userId, score, used_score string, url ...string) (bool, error) {
  180. if dbname == "" || userId == "" || score == "" {
  181. return false, errors.New("参数错误")
  182. }
  183. conn, err := rpc_server_conn(url...)
  184. if err != nil {
  185. return false, err
  186. }
  187. defer conn.Close()
  188. data := GetUpdateReq{}
  189. data.Dbname = dbname
  190. data.UserId = userId
  191. data.Value = score
  192. data.UsedValue = used_score
  193. req, err := SetReqData(data)
  194. if err != nil {
  195. log.Println("UpdateUserScore crypter error:", err)
  196. return false, err
  197. }
  198. res := &Response{}
  199. err = conn.UpdateUserScore(req, res)
  200. if err != nil {
  201. log.Println("userrpc UpdateUserScore error:", err)
  202. return false, err
  203. }
  204. res_data_de, err := GetResData(res)
  205. if err != nil {
  206. return false, err
  207. }
  208. if res_data_de == "" {
  209. return false, nil
  210. }
  211. var updateres bool
  212. err = json.Unmarshal([]byte(res_data_de), &updateres)
  213. if err != nil {
  214. return false, err
  215. }
  216. return updateres, nil
  217. }
  218. /**
  219. * 增加积分日志
  220. * @2021/09/30
  221. * @bin
  222. */
  223. func AddUserScoreLog(dbname, UserId, Score, Before, After, Source, SourceId, OrderSn, Target, TargetId, ProductThumb, Memo string, url ...string) (int64, error) {
  224. if dbname == "" || UserId == "" || Score == "" || After == "" {
  225. return 0, errors.New("参数错误")
  226. }
  227. conn, err := rpc_server_conn(url...)
  228. if err != nil {
  229. return 0, err
  230. }
  231. defer conn.Close()
  232. data := GetLogReq{}
  233. data.Dbname = dbname
  234. data.UserId = UserId
  235. data.Value = Score
  236. data.Before = Before
  237. data.After = After
  238. data.Source = Source
  239. data.SourceId = SourceId
  240. data.OrderSn = OrderSn
  241. data.Target = Target
  242. data.TargetId = TargetId
  243. data.ProductThumb = ProductThumb
  244. data.Memo = Memo
  245. req, err := SetReqData(data)
  246. if err != nil {
  247. log.Println("AddUserScoreLog crypter error:", err)
  248. return 0, err
  249. }
  250. res := &Response{}
  251. err = conn.AddUserScoreLog(req, res)
  252. if err != nil {
  253. log.Println("userrpc AddUserScoreLog error:", err)
  254. return 0, err
  255. }
  256. res_data_de, err := GetResData(res)
  257. if err != nil {
  258. return 0, err
  259. }
  260. if res_data_de == "" {
  261. return 0, nil
  262. }
  263. var insertId int64
  264. err = json.Unmarshal([]byte(res_data_de), &insertId)
  265. if err != nil {
  266. return 0, err
  267. }
  268. return insertId, nil
  269. }
  270. /**
  271. * 添加成长值
  272. * @2021/09/30
  273. * @bin
  274. */
  275. func AddUserUpgrade(dbname, userId, upgrade string, url ...string) (int64, error) {
  276. if dbname == "" || userId == "" || upgrade == "" {
  277. return 0, errors.New("参数错误")
  278. }
  279. conn, err := rpc_server_conn(url...)
  280. if err != nil {
  281. return 0, err
  282. }
  283. defer conn.Close()
  284. data := GetAddReq{}
  285. data.Dbname = dbname
  286. data.UserId = userId
  287. data.Value = upgrade
  288. req, err := SetReqData(data)
  289. if err != nil {
  290. log.Println("AddUserUpgrade crypter error:", err)
  291. return 0, err
  292. }
  293. res := &Response{}
  294. err = conn.AddUserUpgrade(req, res)
  295. if err != nil {
  296. log.Println("userrpc AddUserUpgrade error:", err)
  297. return 0, err
  298. }
  299. res_data_de, err := GetResData(res)
  300. if err != nil {
  301. return 0, err
  302. }
  303. if res_data_de == "" {
  304. return 0, nil
  305. }
  306. var insertId int64
  307. err = json.Unmarshal([]byte(res_data_de), &insertId)
  308. if err != nil {
  309. return 0, err
  310. }
  311. return insertId, nil
  312. }
  313. /**
  314. * 更新成长值记录
  315. * @2021/09/30
  316. * @bin
  317. */
  318. func UpdateUserUpgrade(dbname, userId, upgrade string, url ...string) (bool, error) {
  319. if dbname == "" || userId == "" || upgrade == "" {
  320. return false, errors.New("参数错误")
  321. }
  322. conn, err := rpc_server_conn(url...)
  323. if err != nil {
  324. return false, err
  325. }
  326. defer conn.Close()
  327. data := GetAddReq{}
  328. data.Dbname = dbname
  329. data.UserId = userId
  330. data.Value = upgrade
  331. req, err := SetReqData(data)
  332. if err != nil {
  333. log.Println("UpdateUserUpgrade crypter error:", err)
  334. return false, err
  335. }
  336. res := &Response{}
  337. err = conn.UpdateUserUpgrade(req, res)
  338. if err != nil {
  339. log.Println("userrpc UpdateUserUpgrade error:", err)
  340. return false, err
  341. }
  342. res_data_de, err := GetResData(res)
  343. if err != nil {
  344. return false, err
  345. }
  346. if res_data_de == "" {
  347. return false, nil
  348. }
  349. var updateres bool
  350. err = json.Unmarshal([]byte(res_data_de), &updateres)
  351. if err != nil {
  352. return false, err
  353. }
  354. return updateres, nil
  355. }
  356. /**
  357. * 增加成长值日志
  358. * @2021/09/30
  359. * @bin
  360. */
  361. func AddUserUpgradeLog(dbname, UserId, Upgrade, Before, After, Source, Memo string, url ...string) (int64, error) {
  362. if dbname == "" || UserId == "" || Upgrade == "" || After == "" {
  363. return 0, errors.New("参数错误")
  364. }
  365. conn, err := rpc_server_conn(url...)
  366. if err != nil {
  367. return 0, err
  368. }
  369. defer conn.Close()
  370. data := GetUpgradeLogReq{}
  371. data.Dbname = dbname
  372. data.UserId = UserId
  373. data.Upgrade = Upgrade
  374. data.Before = Before
  375. data.After = After
  376. data.Source = Source
  377. data.Memo = Memo
  378. req, err := SetReqData(data)
  379. if err != nil {
  380. log.Println("AddUserUpgradeLog crypter error:", err)
  381. return 0, err
  382. }
  383. res := &Response{}
  384. err = conn.AddUserUpgradeLog(req, res)
  385. if err != nil {
  386. log.Println("userrpc AddUserUpgradeLog error:", err)
  387. return 0, err
  388. }
  389. res_data_de, err := GetResData(res)
  390. if err != nil {
  391. return 0, err
  392. }
  393. if res_data_de == "" {
  394. return 0, nil
  395. }
  396. var insertId int64
  397. err = json.Unmarshal([]byte(res_data_de), &insertId)
  398. if err != nil {
  399. return 0, err
  400. }
  401. return insertId, nil
  402. }
  403. /**
  404. * 添加红包
  405. * @2021/09/30
  406. * @bin
  407. */
  408. func AddUserRedEnvelope(dbname, userId, money string, url ...string) (int64, error) {
  409. if dbname == "" || userId == "" || money == "" {
  410. return 0, errors.New("参数错误")
  411. }
  412. conn, err := rpc_server_conn(url...)
  413. if err != nil {
  414. return 0, err
  415. }
  416. defer conn.Close()
  417. data := GetAddReq{}
  418. data.Dbname = dbname
  419. data.UserId = userId
  420. data.Value = money
  421. req, err := SetReqData(data)
  422. if err != nil {
  423. log.Println("AddUserRedEnvelope crypter error:", err)
  424. return 0, err
  425. }
  426. res := &Response{}
  427. err = conn.AddUserRedEnvelope(req, res)
  428. if err != nil {
  429. log.Println("userrpc AddUserRedEnvelope error:", err)
  430. return 0, err
  431. }
  432. res_data_de, err := GetResData(res)
  433. if err != nil {
  434. return 0, err
  435. }
  436. if res_data_de == "" {
  437. return 0, nil
  438. }
  439. var insertId int64
  440. err = json.Unmarshal([]byte(res_data_de), &insertId)
  441. if err != nil {
  442. return 0, err
  443. }
  444. return insertId, nil
  445. }
  446. /**
  447. * 更新红包记录
  448. * @2021/09/30
  449. * @bin
  450. */
  451. func UpdateUserRedEnvelope(dbname, userId, money, used_money string, url ...string) (bool, error) {
  452. if dbname == "" || userId == "" || money == "" {
  453. return false, errors.New("参数错误")
  454. }
  455. conn, err := rpc_server_conn(url...)
  456. if err != nil {
  457. return false, err
  458. }
  459. defer conn.Close()
  460. data := GetUpdateReq{}
  461. data.Dbname = dbname
  462. data.UserId = userId
  463. data.Value = money
  464. data.UsedValue = used_money
  465. req, err := SetReqData(data)
  466. if err != nil {
  467. log.Println("UpdateUserRedEnvelope crypter error:", err)
  468. return false, err
  469. }
  470. res := &Response{}
  471. err = conn.UpdateUserRedEnvelope(req, res)
  472. if err != nil {
  473. log.Println("userrpc UpdateUserRedEnvelope error:", err)
  474. return false, err
  475. }
  476. res_data_de, err := GetResData(res)
  477. if err != nil {
  478. return false, err
  479. }
  480. if res_data_de == "" {
  481. return false, nil
  482. }
  483. var updateres bool
  484. err = json.Unmarshal([]byte(res_data_de), &updateres)
  485. if err != nil {
  486. return false, err
  487. }
  488. return updateres, nil
  489. }
  490. /**
  491. * 增加红包日志
  492. * @2021/09/30
  493. * @bin
  494. */
  495. func AddUserRedEnvelopeLog(dbname, UserId, Money, Before, After, Source, SourceId, OrderSn, Target, TargetId, Memo string, url ...string) (int64, error) {
  496. if dbname == "" || UserId == "" || Money == "" || After == "" {
  497. return 0, errors.New("参数错误")
  498. }
  499. conn, err := rpc_server_conn(url...)
  500. if err != nil {
  501. return 0, err
  502. }
  503. defer conn.Close()
  504. data := GetLogReq{}
  505. data.Dbname = dbname
  506. data.UserId = UserId
  507. data.Value = Money
  508. data.Before = Before
  509. data.After = After
  510. data.Source = Source
  511. data.SourceId = SourceId
  512. data.OrderSn = OrderSn
  513. data.Target = Target
  514. data.TargetId = TargetId
  515. data.Memo = Memo
  516. req, err := SetReqData(data)
  517. if err != nil {
  518. log.Println("AddUserRedEnvelopeLog crypter error:", err)
  519. return 0, err
  520. }
  521. res := &Response{}
  522. err = conn.AddUserRedEnvelopeLog(req, res)
  523. if err != nil {
  524. log.Println("userrpc AddUserRedEnvelopeLog error:", err)
  525. return 0, err
  526. }
  527. res_data_de, err := GetResData(res)
  528. if err != nil {
  529. return 0, err
  530. }
  531. if res_data_de == "" {
  532. return 0, nil
  533. }
  534. var insertId int64
  535. err = json.Unmarshal([]byte(res_data_de), &insertId)
  536. if err != nil {
  537. return 0, err
  538. }
  539. return insertId, nil
  540. }
  541. /**
  542. * 添加优惠券
  543. * @2021/09/30
  544. * @bin
  545. */
  546. func AddUserCoupon(dbname, userId, couponId, expireTime, orderSn, remark string, url ...string) (int64, error) {
  547. if dbname == "" || userId == "" || couponId == "" {
  548. return 0, errors.New("参数错误")
  549. }
  550. conn, err := rpc_server_conn(url...)
  551. if err != nil {
  552. return 0, err
  553. }
  554. defer conn.Close()
  555. data := GetCouponReq{}
  556. data.Dbname = dbname
  557. data.UserId = userId
  558. data.CouponId = couponId
  559. data.ExpireTime = expireTime
  560. data.OrderSn = orderSn
  561. data.Remark = remark
  562. req, err := SetReqData(data)
  563. if err != nil {
  564. log.Println("AddUserCoupon crypter error:", err)
  565. return 0, err
  566. }
  567. res := &Response{}
  568. err = conn.AddUserCoupon(req, res)
  569. if err != nil {
  570. log.Println("userrpc AddUserCoupon error:", err)
  571. return 0, err
  572. }
  573. res_data_de, err := GetResData(res)
  574. if err != nil {
  575. return 0, err
  576. }
  577. if res_data_de == "" {
  578. return 0, nil
  579. }
  580. var insertId int64
  581. err = json.Unmarshal([]byte(res_data_de), &insertId)
  582. if err != nil {
  583. return 0, err
  584. }
  585. return insertId, nil
  586. }
  587. /**
  588. * 更新优惠券记录
  589. * @2021/09/30
  590. * @bin
  591. */
  592. func UpdateUserCoupon(dbname, userId, couponId, remark, orderSn, isUse, usetime string, url ...string) (bool, error) {
  593. if dbname == "" || userId == "" || couponId == "" {
  594. return false, errors.New("参数错误")
  595. }
  596. conn, err := rpc_server_conn(url...)
  597. if err != nil {
  598. return false, err
  599. }
  600. defer conn.Close()
  601. data := GetCouponReq{}
  602. data.Dbname = dbname
  603. data.UserId = userId
  604. data.CouponId = couponId
  605. data.Remark = remark
  606. data.OrderSn = orderSn
  607. data.IsUse = isUse
  608. data.Usertime = usetime
  609. req, err := SetReqData(data)
  610. if err != nil {
  611. log.Println("UpdateUserCoupon crypter error:", err)
  612. return false, err
  613. }
  614. res := &Response{}
  615. err = conn.UpdateUserCoupon(req, res)
  616. if err != nil {
  617. log.Println("userrpc UpdateUserCoupon error:", err)
  618. return false, err
  619. }
  620. res_data_de, err := GetResData(res)
  621. if err != nil {
  622. return false, err
  623. }
  624. if res_data_de == "" {
  625. return false, nil
  626. }
  627. var updateres bool
  628. err = json.Unmarshal([]byte(res_data_de), &updateres)
  629. if err != nil {
  630. return false, err
  631. }
  632. return updateres, nil
  633. }