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

813 lines
15 KiB

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