index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. }
  36. this.setData({
  37. Containnerheight: server.getWindowHeight(),
  38. });
  39. this.getUserInfo();
  40. this.updateProgram();
  41. },
  42. //得到用户信息
  43. getUserInfo: function (cb) {
  44. var that = this
  45. //调用登录接口
  46. wx.login({
  47. success: function (res0) {
  48. app.globalData.userInfo = {};
  49. app.globalData.userInfo.Code = res0.code;
  50. //console.log("Code:" + res0.code);
  51. wx.getSetting({
  52. scope: "scope.userInfo",
  53. success(res) {
  54. if (!res.authSetting['scope.userInfo']) {
  55. app.globalData.userInfo.nickName = "陌生用户";
  56. app.globalData.userInfo.language = "";
  57. app.globalData.userInfo.gender = "0";
  58. app.globalData.userInfo.city = "";
  59. app.globalData.userInfo.province = "";
  60. app.globalData.userInfo.country = "";
  61. app.globalData.userInfo.avatarUrl = "";
  62. that.login(app.globalData.userInfo);
  63. } else {
  64. wx.getUserInfo({
  65. withCredentials: false,
  66. success: function (res) {
  67. app.globalData.userInfo = res.userInfo;
  68. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  69. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  70. app.globalData.userInfo.Code = res0.code;
  71. that.login(app.globalData.userInfo);
  72. },
  73. fail: function (res) {
  74. that.login(app.globalData.userInfo);
  75. }
  76. });
  77. }
  78. }
  79. });
  80. },
  81. fail: function () {
  82. timeout2 = setTimeout(function () {
  83. that.getUserInfo();
  84. console.log("reboot:" + new Date().getTime());
  85. }, 2000);
  86. }
  87. });
  88. },
  89. login: function (param) {
  90. var that = this;
  91. server.getLocalHost(function () {
  92. server.postData('MathLogin', {
  93. Code: param.Code,
  94. NickName: param.nickName,
  95. Language: param.language,
  96. Gender: param.gender,
  97. City: param.city,
  98. Province: param.province,
  99. Country: param.country,
  100. AvatarUrl: param.avatarUrl,
  101. Introducer: app.globalData.introducer,
  102. UserSource: app.globalData.userSource,
  103. SourceID: app.globalData.SourceID,
  104. LastUserSource: app.globalData.userSource,
  105. Brand: app.globalData.systemInfo.brand,
  106. Model: app.globalData.systemInfo.model,
  107. PixelRatio: app.globalData.systemInfo.pixelRatio,
  108. ScreenWidth: app.globalData.systemInfo.screenWidth,
  109. ScreenHeight: app.globalData.systemInfo.screenHeight,
  110. WindowWidth: app.globalData.systemInfo.windowWidth,
  111. WindowHeight: app.globalData.systemInfo.windowHeight,
  112. WXLanguage: app.globalData.systemInfo.language,
  113. WXVersion: app.globalData.systemInfo.version,
  114. System: app.globalData.systemInfo.system,
  115. Platform: app.globalData.systemInfo.platform,
  116. SDKVersion: app.globalData.systemInfo.SDKVersion,
  117. ProgramVersion: app.globalData.version,
  118. }, function (data) {
  119. //console.log("UserInfo:" + data);
  120. if (!data) {
  121. timeout3 = setTimeout(function () {
  122. that.getUserInfo();
  123. console.log("reboot:" + new Date().getTime());
  124. }, 2000);
  125. } else {
  126. app.globalData.userInfo = data;
  127. var isShow = data.IsShow;
  128. if (isShow == -1) {
  129. isShow = 0;
  130. }
  131. else {
  132. var systemInfo = wx.getSystemInfoSync();
  133. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  134. isShow = 1;
  135. }
  136. }
  137. if (data.DayNumber>=5){
  138. app.globalData.IsLocked =true;
  139. }
  140. console.log(data.DayNumber);
  141. app.globalData.IsShow = isShow;
  142. //app.globalData.userInfo.AvatarUrl = param.avatarUrl;
  143. that.getQuestionType(function () {
  144. if (that.data.ProductID) {
  145. var url = "../../package4/main/activateOK?ProductID=" + that.data.ProductID
  146. + "&ProductUserID=" + that.data.ProductUserID
  147. + "&CurrentUserID=" + app.globalData.userInfo.UserID
  148. + "&CurrentProductID=" + app.globalData.ProgramID;
  149. wx.redirectTo({
  150. url: url
  151. });
  152. }
  153. else {
  154. setTimeout(function () {
  155. common.getStorageValue(that, "IsStart", false, function () {
  156. if (that.data.IsStart) {
  157. wx.redirectTo({
  158. url: '../main/default'
  159. })
  160. }
  161. else {
  162. wx.redirectTo({
  163. url: '../main/help'
  164. })
  165. }
  166. });
  167. }, 2000);
  168. }
  169. that.getPriceList();
  170. });
  171. }
  172. });
  173. });
  174. },
  175. getQuestionType: function (callback) {
  176. var that = this;
  177. server.getData('GetQuestionTypes?Mode=2', function (data) {
  178. if (data) {
  179. //var arr = common.Decrypt(data);
  180. var arr = data;
  181. wx.setStorageSync("QuestionTypeList", arr);
  182. callback();
  183. }
  184. });
  185. server.getData('GetBaiduToken', function (data) {
  186. if (data) {
  187. app.globalData.BaiduToken = data;
  188. }
  189. });
  190. },
  191. getPriceList: function () {
  192. var that = this;
  193. if (!wx.getStorageSync("ProductPrice")) {
  194. server.getData('ProductPayPriceList500', function (data) {
  195. if (data) {
  196. var arrProduct = JSON.parse(common.Decrypt(data));
  197. var programList = server.getProgramList();
  198. for (var j = 0; j < arrProduct.length; j++) {
  199. arrProduct[j].ProductList = [];
  200. var arr = arrProduct[j].ProductNum.split(",");
  201. for (var k = 0; k < arr.length; k++) {
  202. for (var i = 0; i < programList.length; i++) {
  203. if (programList[i].ID == arr[k]) {
  204. arrProduct[j].ProductList.push(programList[i]);
  205. }
  206. }
  207. }
  208. }
  209. wx.setStorageSync("ProductPrice", arrProduct);
  210. }
  211. });
  212. }
  213. },
  214. updateProgram: function () {
  215. const updateManager = wx.getUpdateManager();
  216. updateManager.onCheckForUpdate(function (res) {
  217. // 请求完新版本信息的回调
  218. console.log(res.hasUpdate)
  219. });
  220. updateManager.onUpdateReady(function () {
  221. wx.showModal({
  222. title: '更新提示',
  223. content: '新版本已经准备好,是否重启应用?',
  224. success: function (res) {
  225. if (res.confirm) {
  226. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  227. updateManager.applyUpdate()
  228. }
  229. }
  230. });
  231. });
  232. },
  233. onShareAppMessage: function () {
  234. return {
  235. title: app.globalData.ShareTitle,
  236. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  237. imageUrl: app.globalData.ShareImageUrl,
  238. }
  239. },
  240. })