all.js 11 KB

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