index.js 8.4 KB

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