DrawApi.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const Api = require('../net/Api');
  2. class DrawApi {
  3. /**
  4. * 开始抽奖
  5. * @param typeId [long] 1 为第一个抽奖 2 为第二个抽奖 3 为第三个抽奖
  6. * @param isDiamond [int] 是否为钻石抽奖。1是0不 (只有第一个抽奖需要)
  7. */
  8. static startLottery(typeId, isDiamond = 0, success, fail) {
  9. let url = "/lottery/startLottery";
  10. let data = {type: typeId};
  11. if (typeId == 1) {
  12. data.isDiamond = isDiamond;
  13. } else {
  14. data.isDiamond = 1;
  15. }
  16. console.log(data);
  17. Api.httpPost(this.setRequestBody(url, data, success, fail));
  18. }
  19. /**
  20. * 开始抽奖 V1.1.0之后开始使用
  21. * @param typeId [long] 1 为第一个抽奖 2 为第二个抽奖 3 为第三个抽奖
  22. * @param isDiamond [int] 是否为钻石抽奖。1是0不 (只有第一个抽奖需要)
  23. */
  24. static startNewLottery(typeId, isDiamond = 0, success, fail) {
  25. let url = "/lottery/startLottery1";
  26. let data = {type: typeId};
  27. if (typeId == 1) {
  28. data.isDiamond = isDiamond;
  29. } else {
  30. data.isDiamond = 1;
  31. }
  32. console.log(data);
  33. Api.httpPost(this.setRequestBody(url, data, success, fail));
  34. }
  35. /// /user/getHbs 获取抽奖红包数据
  36. static getDrawHbs(success, fail) {
  37. let url = "/user/getHbs";
  38. Api.httpGet(this.setRequestBody(url, {}, success, fail));
  39. }
  40. /**
  41. * 获取抽奖相关信息
  42. */
  43. static getLotteryInfo(success, fail) {
  44. let url = "/lottery/getLotteryInfo.do";
  45. Api.httpGet(this.setRequestBody(url, {}, success, fail));
  46. }
  47. // 生成一个 RequestBody, 总是要写重复代码, 太恶心了
  48. static setRequestBody(url, data, success, fail) {
  49. let requestBody = {
  50. url: url,
  51. data: data,
  52. success: success,
  53. fail: fail,
  54. complete: () => {
  55. }
  56. };
  57. return requestBody;
  58. }
  59. }
  60. module.exports = DrawApi;