midAutumn.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // pages/dragonBoatFestival/dragonBoatFestival.js
  2. var app = getApp();
  3. Page({
  4. data: {
  5. urlHttp: '',
  6. src:'',
  7. flag: 0, //隐藏引导页商品信息的标志位,0为隐藏,1为显示
  8. fromUserId : '',//分享者的un_id
  9. },
  10. onLoad: function (options) {
  11. var that = this;
  12. var partnerShare = options.partnerShare;
  13. var host = getApp().globalData.servsers;
  14. var fromUserId = options.fromUserId;
  15. var fromUserRole = options.fromUserRole;
  16. console.log("fromUserId:0000" + options.fromUserId);
  17. console.log("fromUserRole:0000" + options.fromUserRole);
  18. if (fromUserId != undefined){
  19. getApp().globalData.fromUserId = options.fromUserId;
  20. getApp().globalData.fromUserRole = options.fromUserRole;
  21. }
  22. that.setData({
  23. urlHttp: host
  24. })
  25. },
  26. onShow:function(e){
  27. var that = this;
  28. var host = getApp().globalData.servsers;
  29. var un_id = getApp().globalData.un_id;
  30. var openid = getApp().globalData.openid;
  31. var isNewUser = getApp().globalData.isNewUser;
  32. var fromUserId = getApp().globalData.fromUserId;
  33. var fromUserRole = getApp().globalData.fromUserRole;
  34. console.log("fromUserId:" + fromUserId);
  35. console.log("fromUserRole:" + fromUserRole);
  36. //来自分享
  37. if (fromUserId != ''){
  38. console.log("infor:来自分享");
  39. wx.getSetting({
  40. success: function (res) {
  41. console.log(res);
  42. if (res.authSetting['scope.userInfo']) {//授权过
  43. if (getApp().globalData.un_id && getApp().globalData.un_id != '' && getApp().globalData.un_id != undefined) {
  44. var isNewUser = getApp().globalData.isNewUser; //新用户标识
  45. if (isNewUser) {
  46. that.createRelation();
  47. } else {
  48. console.log("老用户-isNewUser:" + isNewUser);
  49. }
  50. } else {
  51. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  52. // 所以此处加入 callback 以防止 onLoad 和 onShow 在 onLaunch 之前执行
  53. getApp().employIdCallback = un_id => {
  54. if (un_id != '') {
  55. var isNewUser = getApp().globalData.isNewUser; //新用户标识
  56. console.log("isNewUser:" + isNewUser);
  57. if (isNewUser) {
  58. that.createRelation();
  59. } else {
  60. console.log("mid-isNewUser22:" + isNewUser);
  61. }
  62. }
  63. }
  64. }
  65. }else{
  66. wx.navigateTo({
  67. url: '/pages/authorize/authorize?link=midAutumn&fromUserId=fromUserId&fromUserRole=fromUserRole',
  68. })
  69. }
  70. }
  71. })
  72. }else{
  73. wx.getSetting({
  74. success: function (res) {
  75. console.log(res);
  76. if (res.authSetting['scope.userInfo']) {//授权过
  77. if (getApp().globalData.un_id && getApp().globalData.un_id != '' && getApp().globalData.un_id != undefined) {
  78. var isNewUser = getApp().globalData.isNewUser; //新用户标识
  79. if (isNewUser) {
  80. console.log("自己进入的新用户-1");
  81. } else {
  82. console.log("自己进入的老用户-1");
  83. }
  84. } else {
  85. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  86. // 所以此处加入 callback 以防止 onLoad 和 onShow 在 onLaunch 之前执行
  87. getApp().employIdCallback = un_id => {
  88. if (un_id != '') {
  89. if (isNewUser) {
  90. console.log("自己进入的新用户-2");
  91. } else {
  92. console.log("自己进入的老用户-2");
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. })
  100. }
  101. //隐藏引导页商品信息
  102. wx.request({
  103. url: host + "tempUpdate/getNum",
  104. data: {
  105. },
  106. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  107. header: {
  108. 'Accept': 'application/json'
  109. },
  110. success: function (res) {
  111. console.log(res.data);
  112. that.setData({
  113. //flag: res.data
  114. flag: 1
  115. })
  116. if (res == null || res.data == null) {
  117. console.error('网络请求失败');
  118. return;
  119. }
  120. }
  121. })
  122. },
  123. //获取用户角色
  124. getUserRole: function (id) {
  125. var that = this;
  126. var un_id = getApp().globalData.un_id;
  127. var openid = getApp().globalData.openid;
  128. var isNewUser = getApp().globalData.isNewUser;
  129. var fromUserId = that.data.fromUserId;
  130. var fromUserRole = that.data.fromUserRole;
  131. wx.login({
  132. success: function (res) {
  133. var code = res.code;
  134. console.log("get-code:" + code);
  135. wx.getUserInfo({
  136. withCredentials: true,
  137. success: function (res) {
  138. getApp().globalData.userInfo = res.userInfo;
  139. //console.log("code:" + code);
  140. //console.log("iv:" + res.iv);
  141. //console.log("encryptedData:" + res.encryptedData);
  142. wx.request({
  143. url: host + "api/distributeSell/getUserRole",
  144. data: {
  145. code: code,
  146. iv: res.iv,
  147. encryptedData: res.encryptedData,
  148. },
  149. method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  150. header: {
  151. 'content-type': 'application/x-www-form-urlencoded'
  152. },
  153. success: function (res) {
  154. console.log("user-infor");
  155. console.log(res);
  156. //成功
  157. if (res.data.code == '200') {
  158. getApp().globalData.un_id = res.data.data.user_id;
  159. getApp().globalData.openid = res.data.data.openid;
  160. getApp().globalData.isNewUser = false;//不是新用户
  161. getApp().globalData.userRole = res.data.data.userRole;
  162. getApp().globalData.userInfo.avatarUrl = res.data.data.icon;
  163. getApp().globalData.userInfo.nickName = res.data.data.name;
  164. console.log("getUserRole-openid1:" + res.data.data.openid);
  165. console.log("getUserRole-isNewUser2:" + res.data.data.isNewUser);
  166. console.log("getUserRole-userRole3:" + res.data.data.userRole);
  167. } else if (res.data.data == '') {
  168. getApp().globalData.isNewUser = true;//是新用户
  169. console.log("getUserRole-isNewUser:" + res.data.isNewUser);
  170. }
  171. if (res == null || res.data == null) {
  172. console.error('网络请求失败');
  173. return;
  174. }
  175. }
  176. });
  177. },
  178. fail: function (e) {
  179. console.log("需重新授权");
  180. }
  181. })
  182. }
  183. });
  184. },
  185. //创建分销关系-当被分享用户通过分享进入客户端时进行关系确立
  186. createRelation: function (e) {
  187. var that = this;
  188. var host = getApp().globalData.servsers;
  189. var un_id = getApp().globalData.un_id;
  190. var fromUserId = getApp().globalData.fromUserId;
  191. var fromUserRole = getApp().globalData.fromUserRole;
  192. console.log("from-fromUserId:" + fromUserId);
  193. console.log("create-un_id:" + un_id);
  194. console.log("from-userRole:" + fromUserRole);
  195. wx.request({
  196. url: host + "api/distributeSell/createRelation",
  197. data: {
  198. shareUserId: fromUserId,//分享者 - 用户userId
  199. currentUserId: un_id,//当前操作用户userId
  200. userRole: fromUserRole,//分享者 - 用户角色 0:普通用户 1:商务用户
  201. },
  202. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  203. header: {
  204. 'Accept': 'application/json'
  205. },
  206. success: function (res) {
  207. if (res.data.code == '200') {
  208. console.log('分销关系建立成功');
  209. }
  210. if (res == null) {
  211. console.log('网络异常,请重新操作!');
  212. return;
  213. }
  214. }
  215. })
  216. },
  217. linkIndex:function(){
  218. wx.switchTab({
  219. url:'/pages/index/index'
  220. })
  221. }
  222. })