all.js 15 KB

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