all.js 15 KB

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