index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var timeout2, timeout3;
  5. Page({
  6. data: {
  7. version: app.globalData.Version,
  8. },
  9. onLoad: function (options) {
  10. if (options) {
  11. if (options.UserID) {
  12. console.log("UserID:" + options.UserID);
  13. app.globalData.introducer = options.UserID;
  14. }
  15. if (options.SourceID) {
  16. console.log("SourceID:" + options.SourceID);
  17. app.globalData.SourceID = options.SourceID;
  18. }
  19. // 扫码介绍人
  20. if (options.scene) {
  21. var scene = decodeURIComponent(options.scene);
  22. console.log("scene:" + scene);
  23. var introducer = 0;
  24. if (scene.indexOf("UserID") >= 0)
  25. introducer = scene.substr(scene.indexOf("UserID") + 7);
  26. console.log("introducer:" + introducer);
  27. app.globalData.introducer = scene;
  28. }
  29. if (options.ProductID) {
  30. this.setData({
  31. ProductID: options.ProductID,
  32. ProductUserID: options.ProductUserID,
  33. });
  34. }
  35. if (options.GiftID) {
  36. this.setData({
  37. GiftID: options.GiftID,
  38. });
  39. }
  40. }
  41. this.setData({
  42. Containnerheight: server.getWindowHeight(),
  43. });
  44. this.getUserInfo();
  45. this.updateProgram();
  46. },
  47. //得到用户信息
  48. getUserInfo: function (cb) {
  49. var that = this
  50. //调用登录接口
  51. wx.login({
  52. success: function (res0) {
  53. app.globalData.userInfo = {};
  54. app.globalData.userInfo.Code = res0.code;
  55. //console.log("Code:" + res0.code);app.globalData.userInfo.nickName = "陌生用户";
  56. that.login(app.globalData.userInfo);
  57. },
  58. fail: function () {
  59. setTimeout(function () {
  60. that.getUserInfo();
  61. console.log("reboot:" + new Date().getTime());
  62. }, 2000);
  63. }
  64. });
  65. },
  66. login: function (param) {
  67. var that = this;
  68. server.getLocalHost(function () {
  69. server.postData('MathLogin', {
  70. Code: param.Code,
  71. Introducer: app.globalData.introducer,
  72. UserSource: app.globalData.userSource,
  73. SourceID: app.globalData.SourceID,
  74. LastUserSource: app.globalData.userSource,
  75. Brand: app.globalData.systemInfo.brand,
  76. Model: app.globalData.systemInfo.model,
  77. PixelRatio: app.globalData.systemInfo.pixelRatio,
  78. ScreenWidth: app.globalData.systemInfo.screenWidth,
  79. ScreenHeight: app.globalData.systemInfo.screenHeight,
  80. WindowWidth: app.globalData.systemInfo.windowWidth,
  81. WindowHeight: app.globalData.systemInfo.windowHeight,
  82. WXLanguage: app.globalData.systemInfo.language,
  83. WXVersion: app.globalData.systemInfo.version,
  84. System: app.globalData.systemInfo.system,
  85. Platform: app.globalData.systemInfo.platform,
  86. SDKVersion: app.globalData.systemInfo.SDKVersion,
  87. ProgramVersion: app.globalData.Version,
  88. }, function (data) {
  89. //console.log("UserInfo:" + data);
  90. if (!data) {
  91. timeout3 = setTimeout(function () {
  92. that.getUserInfo();
  93. console.log("reboot:" + new Date().getTime());
  94. }, 2000);
  95. } else {
  96. app.globalData.userInfo = data;
  97. //app.globalData.userInfo.AvatarUrl = param.avatarUrl;
  98. // var isShow = data.IsShow;
  99. // if (isShow == -1) {
  100. // isShow = 0;
  101. // }
  102. // else {
  103. // var systemInfo = wx.getSystemInfoSync();
  104. // if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  105. // isShow = 1;
  106. // }
  107. // }
  108. // app.globalData.userInfo.IsShow = isShow;
  109. app.globalData.userInfo.IsShow = data.IsShow;
  110. app.globalData.IsLocked = data.IsLocked;
  111. //app.globalData.userInfo.AvatarUrl = param.avatarUrl;
  112. that.getQuestionType(function () {
  113. if (that.data.GiftID) {
  114. var url = "../../package4/main/giftcard?GiftID=" + that.data.GiftID + "&UserID=" + app.globalData.introducer
  115. wx.redirectTo({
  116. url: url
  117. });
  118. }
  119. else if (that.data.ProductID) {
  120. var url = "../../package4/main/activateOK?ProductID=" + that.data.ProductID
  121. + "&ProductUserID=" + that.data.ProductUserID
  122. + "&CurrentUserID=" + app.globalData.userInfo.UserID
  123. + "&CurrentProductID=" + app.globalData.ProgramID;
  124. wx.redirectTo({
  125. url: url
  126. });
  127. }
  128. else {
  129. setTimeout(function () {
  130. common.getStorageValue(that, "IsStart", false, function () {
  131. if (that.data.IsStart) {
  132. wx.redirectTo({
  133. url: '../main/default'
  134. })
  135. }
  136. else {
  137. wx.redirectTo({
  138. url: '../main/help'
  139. })
  140. }
  141. });
  142. }, 2000);
  143. }
  144. that.getPriceList();
  145. wx.setStorageSync("IsShare", 0);
  146. });
  147. }
  148. });
  149. });
  150. },
  151. getQuestionType: function (callback) {
  152. var that = this;
  153. server.getData('GetQuestionTypes?Mode=2', function (data) {
  154. if (data) {
  155. //var arr = common.Decrypt(data);
  156. var arr = data;
  157. wx.setStorageSync("QuestionTypeList", arr);
  158. callback();
  159. }
  160. });
  161. //调用登录接口
  162. wx.login({
  163. success: function (res0) {
  164. server.getData('GetBaiduToken20220922?ProgramID='+app.globalData.ProgramID+'&Code='+res0.code, function (data) {
  165. if (data) {
  166. app.globalData.BaiduToken = data;
  167. }
  168. });
  169. }});
  170. },
  171. getPriceList: function () {
  172. var that = this;
  173. server.getData('ProductPayPriceList500', function (data) {
  174. if (data) {
  175. var arrProduct = JSON.parse(common.Decrypt(data));
  176. var programList = server.getProgramList();
  177. for (var j = 0; j < arrProduct.length; j++) {
  178. arrProduct[j].ProductList = [];
  179. var arr = arrProduct[j].ProductNum.split(",");
  180. for (var k = 0; k < arr.length; k++) {
  181. for (var i = 0; i < programList.length; i++) {
  182. if (programList[i].ID == arr[k]) {
  183. arrProduct[j].ProductList.push(programList[i]);
  184. }
  185. }
  186. }
  187. }
  188. wx.setStorageSync("ProductPrice", arrProduct);
  189. }
  190. });
  191. },
  192. updateProgram: function () {
  193. const updateManager = wx.getUpdateManager();
  194. updateManager.onCheckForUpdate(function (res) {
  195. // 请求完新版本信息的回调
  196. console.log(res.hasUpdate)
  197. });
  198. updateManager.onUpdateReady(function () {
  199. updateManager.applyUpdate();
  200. });
  201. },
  202. onShareAppMessage: function () {
  203. return {
  204. title: app.globalData.ShareTitle,
  205. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  206. imageUrl: app.globalData.ShareImage,
  207. }
  208. },
  209. })