all.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. //logs.js
  2. const util = require('../../../utils/util.js')
  3. var _request = require('../../../utils/request.js')
  4. var version = getApp().globalData.version
  5. var channel // 渠道二维码信息
  6. var scene // 渠道二维码id
  7. var url = '' // 分享或模板落地页
  8. var invite = 0 //邀请id
  9. var poster = []
  10. var project = []
  11. Page({
  12. data: {
  13. userInfo: {},
  14. balance: 0,
  15. integral:0,
  16. bindTel: false,
  17. checkData: {},
  18. merchant: {},
  19. info: {},
  20. show: 0,
  21. checkhead:true,
  22. wxlogincode:'',
  23. bindTelfirst:0
  24. },
  25. onLoad: function () {
  26. //// console.log(options)
  27. // url = 0
  28. // if (options.scene) {
  29. // scene = decodeURIComponent(options.scene)
  30. // if (scene.indexOf('invite_wx_') > -1) {
  31. // invite = scene.slice(10)
  32. // } else if (scene.indexOf('poster') > -1) {
  33. // this.getPoster(scene)
  34. // } else if (scene.indexOf('project') > -1) {
  35. // this.getPosterProject(scene)
  36. // } else {
  37. // this.getScene(scene)
  38. // }
  39. // } else if (options.url) {
  40. // this.urlHandle(options)
  41. // }
  42. // if (options.invite) {
  43. // invite = options.invite
  44. // }
  45. // var that = this
  46. this.checkLogin();
  47. this.info();
  48. },
  49. onShow: function () {
  50. var that = this;
  51. // that.checkLogin();
  52. this.info();
  53. that.getBalanceInfo()
  54. that.getIntegralInfo()
  55. // if (this.data.bindTel) {
  56. // this.getBalanceInfo()
  57. // this.getIntegralInfo()
  58. // if (that.data.checkData.merchant_id > 0) {
  59. // that.getmerchant()
  60. // }
  61. // } else {
  62. // // this.check()
  63. // // this.info()
  64. // }
  65. //原登陆检测
  66. },
  67. checkLogin:function(){
  68. var that = this;
  69. //2020登陆检测
  70. wx.login({
  71. success: res => {
  72. getApp().globalData.try_login = true;
  73. console.log('checkLogin',res.code)
  74. var url = 'xcx/login';
  75. invite = wx.getStorageSync('invite');
  76. var params = {
  77. code: res.code,
  78. invite_id: invite//新token模式
  79. }
  80. that.setData({
  81. wxlogincode: res.code
  82. })
  83. var success = function (res) {
  84. console.log('pageLogin',res);
  85. wx.setStorageSync('lbt_session_key', res.data.session_key)
  86. wx.setStorageSync('lbt_session_time', Date.now())
  87. wx.setStorageSync('lbt_token_key', res.data.token)
  88. console.log('nowtoken',res.data.token);
  89. if(res.data.wx_user && res.data.wx_user.head != ''){
  90. var userInfo = res.data.wx_user;
  91. that.setData({
  92. userInfo: userInfo
  93. })
  94. that.info()
  95. that.getBalanceInfo()
  96. that.getIntegralInfo()
  97. // if (that.data.checkData.merchant_id > 0) {
  98. // that.getmerchant()
  99. // }
  100. //checkwxhead---start
  101. // console.log('that.data.checkhead',that.data.checkhead);
  102. if(res.data.wx_user.head == '' ){
  103. that.setData({
  104. checkhead: false
  105. })
  106. wx.getSetting({
  107. success: res => {
  108. var auth = res.authSetting
  109. if (auth['scope.userInfo']) {
  110. console.log('wxhead none')
  111. // wx.getUserInfo({
  112. // success: function(res3) {
  113. // console.log('userinfo',res3)
  114. // var url = 'xcx/save_wx_user/info'
  115. // var params = {
  116. // userinfo: JSON.stringify(res3)
  117. // }
  118. // var success = function (res4) {
  119. // console.log('authorize',res4)
  120. // that.onShow()
  121. // }
  122. // _request.$post(url, params, success)
  123. // }
  124. // })
  125. //新授权
  126. wx.getUserProfile({
  127. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  128. success: function(res3) {
  129. console.log('userinfo',res3)
  130. var url = 'xcx/save_wx_user/info'
  131. var params = {
  132. userinfo: JSON.stringify(res3.userInfo)
  133. }
  134. var success = function (res4) {
  135. console.log('authorize',res4);
  136. that.onLoad()
  137. }
  138. _request.$post(url, params, success)
  139. }
  140. })
  141. }else{
  142. that.setData({
  143. userInfo: 'nologin'
  144. })
  145. }
  146. }
  147. })
  148. }
  149. //checkwxhead---end
  150. }else{
  151. that.setData({
  152. userInfo: 'nologin'
  153. })
  154. }
  155. }
  156. _request.$get(url, params, success)
  157. }
  158. })
  159. },
  160. getPoster: function (val) {
  161. poster = val.split('$')
  162. if (poster.length > 0) {
  163. invite = poster[2]
  164. }
  165. },
  166. getPosterProject: function (val) {
  167. project = val.split('$')
  168. if (project.length > 0) {
  169. invite = project[2]
  170. }
  171. },
  172. urlHandle: function (val) {
  173. if (val.url) {
  174. url = val.url + '?'
  175. for (var i in val) {
  176. if (i !== 'url') {
  177. url += i + '=' + val[i] + '&'
  178. }
  179. }
  180. }
  181. },
  182. getScene: function () {
  183. var that = this
  184. var url = 'v1/xcx/channel/info/' + scene
  185. var params = {}
  186. var success = function (res) {
  187. channel = res.data
  188. }
  189. _request.$get(url, params, success)
  190. },
  191. getUserInfo: function (val) {
  192. var channel_id = 0;
  193. invite = wx.getStorageSync('invite');
  194. if (channel && Number(channel.parent_id) > 0) {
  195. channel_id = Number(channel.parent_id)
  196. }
  197. var that = this
  198. if (val.detail.errMsg === 'getUserInfo:ok') {
  199. wx.showLoading({
  200. title: '加载中'
  201. })
  202. console.log('val',val)
  203. // _request.sendInfo(val, channel_id, invite, that)
  204. that.onLoad();
  205. // wx.showToast({
  206. // title: '请绑定手机号~',
  207. // icon: 'none',
  208. // duration: 2000
  209. // })
  210. // wx.navigateTo({
  211. // url: '/packageUser/pages/user/bind/bind'
  212. // })
  213. }
  214. },
  215. getUserProfile:function(){
  216. console.log('tap')
  217. var that = this
  218. // wx.getUserProfile({
  219. // desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  220. // success: (res) => {
  221. // this.setData({
  222. // userInfo: res.userInfo,
  223. // hasUserInfo: true
  224. // })
  225. // var channel_id = 0;
  226. // invite = wx.getStorageSync('invite');
  227. // if (channel && Number(channel.parent_id) > 0) {
  228. // channel_id = Number(channel.parent_id)
  229. // }
  230. // var that = this
  231. // console.log('res',res);
  232. // if (res.errMsg === "getUserProfile:ok") {
  233. // wx.showLoading({
  234. // title: '加载中'
  235. // })
  236. // res['wxlogincode'] = that.data.wxlogincode;
  237. // _request.sendInfo(res, channel_id, invite, that)
  238. // that.onShow();
  239. // }
  240. // }
  241. // })
  242. wx.getUserProfile({
  243. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  244. success: function(res3) {
  245. console.log('userinfo',res3)
  246. var url = 'xcx/save_wx_user/info'
  247. var params = {
  248. userinfo: JSON.stringify(res3.userInfo)
  249. }
  250. var success = function (res4) {
  251. console.log('authorize',res4)
  252. that.onLoad()
  253. }
  254. _request.$post(url, params, success)
  255. }
  256. })
  257. },
  258. getVersion: function (val) {
  259. // this.check()
  260. },
  261. info(){
  262. console.log('oninfo');
  263. var that = this
  264. var url = 'v1/user/info'
  265. var params = {}
  266. var success = function (res) {
  267. console.log(res)
  268. that.setData({
  269. info: res.data,
  270. show: res.data.wx_user?res.data.wx_user.show_invite_mode:'',
  271. bindTel: res.data.user.tel ? true : false
  272. })
  273. console.log('untel',res.data.user.tel)
  274. console.log('res.data.wx_user',res.data.wx_user)
  275. if(res.data.wx_user.head == ''){
  276. console.log('indddddddddddddddddddddddd')
  277. that.setData({
  278. userInfo: 'nologin'
  279. })
  280. }
  281. if(that.data.userInfo != 'nologin' && res.data.user.tel == '' && that.data.bindTelfirst == 0){
  282. that.setData({
  283. bindTelfirst:1
  284. })
  285. wx.navigateTo({
  286. url: '/packageUser/pages/user/bind/bind'
  287. })
  288. wx.showToast({
  289. title: '请先绑定手机号~',
  290. icon: 'none',
  291. duration: 2000
  292. })
  293. }
  294. }
  295. _request.$get(url, params, success)
  296. },
  297. check () {
  298. var that = this
  299. var url = 'v1/user/check'
  300. var params = {
  301. cache: false
  302. }
  303. var success = function (res) {
  304. if (res.data.wx_user_id <= 0) {
  305. wx.login({
  306. success: res => {
  307. _request.login(res)
  308. }
  309. })
  310. } else {
  311. that.setData({
  312. checkData: res.data
  313. })
  314. if (that.data.checkData.merchant_id > 0) {
  315. that.getmerchant()
  316. }
  317. if (res.data.user_id > 0 && !that.data.bindTel) {
  318. // that.setData({
  319. // bindTel: true
  320. // })
  321. that.getBalanceInfo()
  322. that.getIntegralInfo()
  323. that.info()
  324. }
  325. }
  326. }
  327. _request.$get(url, params, success)
  328. },
  329. buyVoucher(){
  330. if(this.data.info.user.tel == ''){//未绑定手机号
  331. wx.navigateTo({
  332. url: '/packageUser/pages/user/bind/bind'
  333. })
  334. wx.showToast({
  335. title: '请先绑定手机号~',
  336. icon: 'none',
  337. duration: 2000
  338. })
  339. //2020
  340. wx.setStorageSync('bindbackurl', '/packageUser/pages/user/buy/buy'); //存入手机绑定后跳转页面
  341. }else{
  342. wx.navigateTo({
  343. url: '/packageUser/pages/user/buy/buy'
  344. })
  345. }
  346. },
  347. getmerchant () {
  348. var that = this
  349. var url = 'v1/merchant/orders/count'
  350. var params = {
  351. merchant_id: that.data.checkData.merchant_id
  352. }
  353. var success = function (res) {
  354. var result = res.data
  355. that.setData({
  356. merchant: result
  357. })
  358. console.log(that.data.merchant)
  359. }
  360. _request.$get(url, params, success)
  361. },
  362. getBalanceInfo () {
  363. var that = this
  364. var url = 'v1/user/balance/info'
  365. var params = {
  366. }
  367. var success = function (res) {
  368. var result = res.data.total
  369. that.setData({
  370. balance: result
  371. })
  372. }
  373. _request.$get(url, params, success)
  374. },
  375. getIntegralInfo () {
  376. var that = this
  377. var url = 'v1/user/cent/info'
  378. var params = {
  379. }
  380. var success = function (res) {
  381. var result = res.data.total
  382. that.setData({
  383. integral: result
  384. })
  385. }
  386. _request.$get(url, params, success)
  387. },
  388. toInviteList () {
  389. var that = this;
  390. if(that.data.info.user.tel == ''){
  391. wx.navigateTo({
  392. url: '/packageUser/pages/user/bind/bind'
  393. })
  394. wx.showToast({
  395. title: '请先绑定手机号~',
  396. icon: 'none',
  397. duration: 2000
  398. })
  399. }else{
  400. wx.navigateTo({
  401. url: '/packageUser/pages/user/invite/invite'
  402. })
  403. }
  404. },
  405. // checkbindtel(){
  406. // var that = this;
  407. // if(that.data.info.user.tel == ''){
  408. // setTimeout(function(){
  409. // wx.navigateTo({
  410. // url: '/packageUser/pages/user/bind/bind'
  411. // })
  412. // wx.showToast({
  413. // title: '请先绑定手机号~',
  414. // icon: 'none',
  415. // duration: 2000
  416. // })
  417. // },500)
  418. // }
  419. // },
  420. toCashList () {
  421. if(this.data.info.user.tel == ''){//未绑定手机号
  422. wx.navigateTo({
  423. url: '/packageUser/pages/user/bind/bind'
  424. })
  425. wx.showToast({
  426. title: '请先绑定手机号~',
  427. icon: 'none',
  428. duration: 2000
  429. })
  430. //2020
  431. wx.setStorageSync('bindbackurl', '/packageUser/pages/user/fund/fund'); //存入手机绑定后跳转页面
  432. }else{
  433. wx.navigateTo({
  434. url: '/packageUser/pages/user/fund/fund'
  435. })
  436. }
  437. },
  438. toUserInfo() {
  439. wx.navigateTo({
  440. url: '/packageUser/pages/user/userInfo/userInfo'
  441. })
  442. },
  443. toBindOldSys () {
  444. let that = this;
  445. wx.navigateTo({
  446. url: '/packageUser/pages/user/bindoldsys/bindoldsys?id='+that.data.userInfo.id
  447. })
  448. },
  449. toPromotion () {
  450. wx.navigateTo({
  451. url: '/packageUser/pages/user/promotion/promotion'
  452. })
  453. },
  454. toIdentity () {
  455. wx.navigateTo({
  456. url: '/packageUser/pages/user/identity/identity'
  457. })
  458. },
  459. toBankInfo () {
  460. wx.navigateTo({
  461. url: '/packageUser/pages/user/bankinfo/bankinfo'
  462. })
  463. },
  464. toAddressList () {
  465. wx.navigateTo({
  466. url: '/packageUser/pages/user/address/address'
  467. })
  468. },
  469. toRadish () {
  470. wx.navigateTo({
  471. url: '/packageUser/pages/user/radish/radish'
  472. })
  473. },
  474. toIntegral () {
  475. wx.navigateTo({
  476. url: '/packageUser/pages/user/integral/integral'
  477. })
  478. },
  479. toSafe () {
  480. wx.navigateTo({
  481. url: '/packageUser/pages/user/safe/safe'
  482. })
  483. },
  484. toCustom () {
  485. wx.reLaunch({
  486. url: '/pages/customservice/customservice'
  487. })
  488. },
  489. toProxy () {
  490. wx.navigateTo({
  491. url: '/packageUser/pages/user/proxyList/proxyList'
  492. })
  493. },
  494. toApplyLeader () {
  495. wx.navigateTo({
  496. url: '/packageUser/pages/user/applyLeader/applyLeader'
  497. })
  498. },
  499. toAreaCart () {
  500. wx.navigateTo({
  501. url: '/pages/areacart/areacart'
  502. })
  503. },
  504. toBindTel () {
  505. wx.navigateTo({
  506. url: '/packageUser/pages/user/bind/bind'
  507. })
  508. },
  509. toAbout () {
  510. var host = getApp().globalData.d5c
  511. if (host === 'tm.d5ct.com') {
  512. wx.navigateTo({
  513. url: '/pages/parse/parse?id=2'
  514. })
  515. } else if (host === 'm.d5ct.com') {
  516. wx.navigateTo({
  517. url: '/pages/parse/parse?id=1'
  518. })
  519. }
  520. },
  521. toMerchant () {
  522. wx.navigateTo({
  523. url: '/packageMerchant/pages/merchant/orders/orders?id=' + this.data.checkData.merchant_id + '&is_super_admin=' + this.data.checkData.is_super_admin
  524. })
  525. },
  526. toMerchant1 () {
  527. wx.navigateTo({
  528. url: '/packageMerchant/pages/merchant/accounts/accounts?id=' + this.data.checkData.merchant_id
  529. })
  530. },
  531. onShareAppMessage: function (val) {
  532. return _request.share({
  533. sc: 'xcx_user'
  534. })
  535. }
  536. })