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

819 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, memo 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. data.Memo = memo
  289. req, err := SetReqData(data)
  290. if err != nil {
  291. log.Println("AddUserUpgrade crypter error:", err)
  292. return 0, err
  293. }
  294. res := &Response{}
  295. err = conn.AddUserUpgrade(req, res)
  296. if err != nil {
  297. log.Println("userrpc AddUserUpgrade error:", err)
  298. return 0, err
  299. }
  300. res_data_de, err := GetResData(res)
  301. if err != nil {
  302. return 0, err
  303. }
  304. if res_data_de == "" {
  305. return 0, nil
  306. }
  307. var insertId int64
  308. err = json.Unmarshal([]byte(res_data_de), &insertId)
  309. if err != nil {
  310. return 0, err
  311. }
  312. return insertId, nil
  313. }
  314. /**
  315. * 更新成长值记录
  316. * @2021/09/30
  317. * @bin
  318. */
  319. func UpdateUserUpgrade(dbname, userId, upgrade string, url ...string) (bool, error) {
  320. if dbname == "" || userId == "" || upgrade == "" {
  321. return false, errors.New("参数错误")
  322. }
  323. conn, err := rpc_server_conn(url...)
  324. if err != nil {
  325. return false, err
  326. }
  327. defer conn.Close()
  328. data := GetAddReq{}
  329. data.Dbname = dbname
  330. data.UserId = userId
  331. data.Value = upgrade
  332. req, err := SetReqData(data)
  333. if err != nil {
  334. log.Println("UpdateUserUpgrade crypter error:", err)
  335. return false, err
  336. }
  337. res := &Response{}
  338. err = conn.UpdateUserUpgrade(req, res)
  339. if err != nil {
  340. log.Println("userrpc UpdateUserUpgrade error:", err)
  341. return false, err
  342. }
  343. res_data_de, err := GetResData(res)
  344. if err != nil {
  345. return false, err
  346. }
  347. if res_data_de == "" {
  348. return false, nil
  349. }
  350. var updateres bool
  351. err = json.Unmarshal([]byte(res_data_de), &updateres)
  352. if err != nil {
  353. return false, err
  354. }
  355. return updateres, nil
  356. }
  357. /**
  358. * 增加成长值日志
  359. * @2021/09/30
  360. * @bin
  361. */
  362. func AddUserUpgradeLog(dbname, UserId, Upgrade, Before, After, Source, Memo string, url ...string) (int64, error) {
  363. if dbname == "" || UserId == "" || Upgrade == "" || After == "" {
  364. return 0, errors.New("参数错误")
  365. }
  366. conn, err := rpc_server_conn(url...)
  367. if err != nil {
  368. return 0, err
  369. }
  370. defer conn.Close()
  371. data := GetUpgradeLogReq{}
  372. data.Dbname = dbname
  373. data.UserId = UserId
  374. data.Upgrade = Upgrade
  375. data.Before = Before
  376. data.After = After
  377. data.Source = Source
  378. data.Memo = Memo
  379. req, err := SetReqData(data)
  380. if err != nil {
  381. log.Println("AddUserUpgradeLog crypter error:", err)
  382. return 0, err
  383. }
  384. res := &Response{}
  385. err = conn.AddUserUpgradeLog(req, res)
  386. if err != nil {
  387. log.Println("userrpc AddUserUpgradeLog error:", err)
  388. return 0, err
  389. }
  390. res_data_de, err := GetResData(res)
  391. if err != nil {
  392. return 0, err
  393. }
  394. if res_data_de == "" {
  395. return 0, nil
  396. }
  397. var insertId int64
  398. err = json.Unmarshal([]byte(res_data_de), &insertId)
  399. if err != nil {
  400. return 0, err
  401. }
  402. return insertId, nil
  403. }
  404. /**
  405. * 添加红包
  406. * @2021/09/30
  407. * @bin
  408. */
  409. func AddUserRedEnvelope(dbname, userId, money, memo string, url ...string) (int64, error) {
  410. if dbname == "" || userId == "" || money == "" {
  411. return 0, errors.New("参数错误")
  412. }
  413. conn, err := rpc_server_conn(url...)
  414. if err != nil {
  415. return 0, err
  416. }
  417. defer conn.Close()
  418. data := GetAddReq{}
  419. data.Dbname = dbname
  420. data.UserId = userId
  421. data.Value = money
  422. data.Memo = memo
  423. req, err := SetReqData(data)
  424. if err != nil {
  425. log.Println("AddUserRedEnvelope crypter error:", err)
  426. return 0, err
  427. }
  428. res := &Response{}
  429. err = conn.AddUserRedEnvelope(req, res)
  430. if err != nil {
  431. log.Println("userrpc AddUserRedEnvelope error:", err)
  432. return 0, err
  433. }
  434. res_data_de, err := GetResData(res)
  435. if err != nil {
  436. return 0, err
  437. }
  438. if res_data_de == "" {
  439. return 0, nil
  440. }
  441. var insertId int64
  442. err = json.Unmarshal([]byte(res_data_de), &insertId)
  443. if err != nil {
  444. return 0, err
  445. }
  446. return insertId, nil
  447. }
  448. /**
  449. * 更新红包记录
  450. * @2021/09/30
  451. * @bin
  452. */
  453. func UpdateUserRedEnvelope(dbname, userId, money, used_money string, url ...string) (bool, error) {
  454. if dbname == "" || userId == "" || money == "" {
  455. return false, errors.New("参数错误")
  456. }
  457. conn, err := rpc_server_conn(url...)
  458. if err != nil {
  459. return false, err
  460. }
  461. defer conn.Close()
  462. data := GetUpdateReq{}
  463. data.Dbname = dbname
  464. data.UserId = userId
  465. data.Value = money
  466. data.UsedValue = used_money
  467. req, err := SetReqData(data)
  468. if err != nil {
  469. log.Println("UpdateUserRedEnvelope crypter error:", err)
  470. return false, err
  471. }
  472. res := &Response{}
  473. err = conn.UpdateUserRedEnvelope(req, res)
  474. if err != nil {
  475. log.Println("userrpc UpdateUserRedEnvelope error:", err)
  476. return false, err
  477. }
  478. res_data_de, err := GetResData(res)
  479. if err != nil {
  480. return false, err
  481. }
  482. if res_data_de == "" {
  483. return false, nil
  484. }
  485. var updateres bool
  486. err = json.Unmarshal([]byte(res_data_de), &updateres)
  487. if err != nil {
  488. return false, err
  489. }
  490. return updateres, nil
  491. }
  492. /**
  493. * 增加红包日志
  494. * @2021/09/30
  495. * @bin
  496. */
  497. func AddUserRedEnvelopeLog(dbname, UserId, Money, Before, After, Source, SourceId, OrderSn, Target, TargetId, Memo string, url ...string) (int64, error) {
  498. if dbname == "" || UserId == "" || Money == "" || After == "" {
  499. return 0, errors.New("参数错误")
  500. }
  501. conn, err := rpc_server_conn(url...)
  502. if err != nil {
  503. return 0, err
  504. }
  505. defer conn.Close()
  506. data := GetLogReq{}
  507. data.Dbname = dbname
  508. data.UserId = UserId
  509. data.Value = Money
  510. data.Before = Before
  511. data.After = After
  512. data.Source = Source
  513. data.SourceId = SourceId
  514. data.OrderSn = OrderSn
  515. data.Target = Target
  516. data.TargetId = TargetId
  517. data.Memo = Memo
  518. req, err := SetReqData(data)
  519. if err != nil {
  520. log.Println("AddUserRedEnvelopeLog crypter error:", err)
  521. return 0, err
  522. }
  523. res := &Response{}
  524. err = conn.AddUserRedEnvelopeLog(req, res)
  525. if err != nil {
  526. log.Println("userrpc AddUserRedEnvelopeLog error:", err)
  527. return 0, err
  528. }
  529. res_data_de, err := GetResData(res)
  530. if err != nil {
  531. return 0, err
  532. }
  533. if res_data_de == "" {
  534. return 0, nil
  535. }
  536. var insertId int64
  537. err = json.Unmarshal([]byte(res_data_de), &insertId)
  538. if err != nil {
  539. return 0, err
  540. }
  541. return insertId, nil
  542. }
  543. /**
  544. * 添加优惠券
  545. * @2021/09/30
  546. * @bin
  547. */
  548. func AddUserCoupon(dbname, userId, couponId, expireTime, orderSn, remark string, url ...string) (int64, error) {
  549. if dbname == "" || userId == "" || couponId == "" {
  550. return 0, errors.New("参数错误")
  551. }
  552. conn, err := rpc_server_conn(url...)
  553. if err != nil {
  554. return 0, err
  555. }
  556. defer conn.Close()
  557. data := GetCouponReq{}
  558. data.Dbname = dbname
  559. data.UserId = userId
  560. data.CouponId = couponId
  561. data.ExpireTime = expireTime
  562. data.OrderSn = orderSn
  563. data.Remark = remark
  564. req, err := SetReqData(data)
  565. if err != nil {
  566. log.Println("AddUserCoupon crypter error:", err)
  567. return 0, err
  568. }
  569. res := &Response{}
  570. err = conn.AddUserCoupon(req, res)
  571. if err != nil {
  572. log.Println("userrpc AddUserCoupon error:", err)
  573. return 0, err
  574. }
  575. res_data_de, err := GetResData(res)
  576. if err != nil {
  577. return 0, err
  578. }
  579. if res_data_de == "" {
  580. return 0, nil
  581. }
  582. var insertId int64
  583. err = json.Unmarshal([]byte(res_data_de), &insertId)
  584. if err != nil {
  585. return 0, err
  586. }
  587. return insertId, nil
  588. }
  589. /**
  590. * 更新优惠券记录
  591. * @2021/09/30
  592. * @bin
  593. */
  594. func UpdateUserCoupon(dbname, userId, couponId, remark, orderSn, isUse, usetime string, url ...string) (bool, error) {
  595. if dbname == "" || userId == "" || couponId == "" {
  596. return false, errors.New("参数错误")
  597. }
  598. conn, err := rpc_server_conn(url...)
  599. if err != nil {
  600. return false, err
  601. }
  602. defer conn.Close()
  603. data := GetCouponReq{}
  604. data.Dbname = dbname
  605. data.UserId = userId
  606. data.CouponId = couponId
  607. data.Remark = remark
  608. data.OrderSn = orderSn
  609. data.IsUse = isUse
  610. data.Usertime = usetime
  611. req, err := SetReqData(data)
  612. if err != nil {
  613. log.Println("UpdateUserCoupon crypter error:", err)
  614. return false, err
  615. }
  616. res := &Response{}
  617. err = conn.UpdateUserCoupon(req, res)
  618. if err != nil {
  619. log.Println("userrpc UpdateUserCoupon error:", err)
  620. return false, err
  621. }
  622. res_data_de, err := GetResData(res)
  623. if err != nil {
  624. return false, err
  625. }
  626. if res_data_de == "" {
  627. return false, nil
  628. }
  629. var updateres bool
  630. err = json.Unmarshal([]byte(res_data_de), &updateres)
  631. if err != nil {
  632. return false, err
  633. }
  634. return updateres, nil
  635. }