all.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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. _request.sendInfo(val, channel_id, invite, that)
  182. that.onShow();
  183. // wx.showToast({
  184. // title: '请绑定手机号~',
  185. // icon: 'none',
  186. // duration: 2000
  187. // })
  188. // wx.navigateTo({
  189. // url: '/packageUser/pages/user/bind/bind'
  190. // })
  191. }
  192. },
  193. getUserProfile:function(){
  194. var that = this
  195. wx.getUserProfile({
  196. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  197. success: (res) => {
  198. this.setData({
  199. userInfo: res.userInfo,
  200. hasUserInfo: true
  201. })
  202. var channel_id = 0;
  203. invite = wx.getStorageSync('invite');
  204. if (channel && Number(channel.parent_id) > 0) {
  205. channel_id = Number(channel.parent_id)
  206. }
  207. var that = this
  208. console.log('res.userInfo',res.userInfo);
  209. // if (res.userInfo.detail.errMsg === 'getUserInfo:ok') {
  210. wx.showLoading({
  211. title: '加载中'
  212. })
  213. _request.sendInfo(res.userInfo, channel_id, invite, that)
  214. that.onShow();
  215. // }
  216. }
  217. })
  218. },
  219. getVersion: function (val) {
  220. this.check()
  221. },
  222. info(){
  223. var that = this
  224. var url = 'v1/user/info'
  225. var params = {}
  226. var success = function (res) {
  227. console.log(res)
  228. that.setData({
  229. info: res.data,
  230. show: res.data.wx_user.show_invite_mode
  231. })
  232. }
  233. _request.$get(url, params, success)
  234. },
  235. check () {
  236. var that = this
  237. var url = 'v1/user/check'
  238. var params = {
  239. cache: false
  240. }
  241. var success = function (res) {
  242. if (res.data.wx_user_id <= 0) {
  243. wx.login({
  244. success: res => {
  245. _request.login(res)
  246. }
  247. })
  248. } else {
  249. that.setData({
  250. checkData: res.data
  251. })
  252. if (that.data.checkData.merchant_id > 0) {
  253. that.getmerchant()
  254. }
  255. if (res.data.user_id > 0 && !that.data.bindTel) {
  256. that.setData({
  257. bindTel: true
  258. })
  259. that.getBalanceInfo()
  260. that.getIntegralInfo()
  261. that.info()
  262. }
  263. }
  264. }
  265. _request.$get(url, params, success)
  266. },
  267. buyVoucher(){
  268. if(this.data.info.user.tel == ''){//未绑定手机号
  269. wx.navigateTo({
  270. url: '/packageUser/pages/user/bind/bind'
  271. })
  272. wx.showToast({
  273. title: '请先绑定手机号~',
  274. icon: 'none',
  275. duration: 2000
  276. })
  277. //2020
  278. wx.setStorageSync('bindbackurl', '/packageUser/pages/user/buy/buy'); //存入手机绑定后跳转页面
  279. }else{
  280. wx.navigateTo({
  281. url: '/packageUser/pages/user/buy/buy'
  282. })
  283. }
  284. },
  285. getmerchant () {
  286. var that = this
  287. var url = 'v1/merchant/orders/count'
  288. var params = {
  289. merchant_id: that.data.checkData.merchant_id
  290. }
  291. var success = function (res) {
  292. var result = res.data
  293. that.setData({
  294. merchant: result
  295. })
  296. console.log(that.data.merchant)
  297. }
  298. _request.$get(url, params, success)
  299. },
  300. getBalanceInfo () {
  301. var that = this
  302. var url = 'v1/user/balance/info'
  303. var params = {
  304. }
  305. var success = function (res) {
  306. var result = res.data.total
  307. that.setData({
  308. balance: result
  309. })
  310. }
  311. _request.$get(url, params, success)
  312. },
  313. getIntegralInfo () {
  314. var that = this
  315. var url = 'v1/user/cent/info'
  316. var params = {
  317. }
  318. var success = function (res) {
  319. var result = res.data.total
  320. that.setData({
  321. integral: result
  322. })
  323. }
  324. _request.$get(url, params, success)
  325. },
  326. toInviteList () {
  327. wx.navigateTo({
  328. url: '/packageUser/pages/user/invite/invite'
  329. })
  330. },
  331. toCashList () {
  332. if(this.data.info.user.tel == ''){//未绑定手机号
  333. wx.navigateTo({
  334. url: '/packageUser/pages/user/bind/bind'
  335. })
  336. wx.showToast({
  337. title: '请先绑定手机号~',
  338. icon: 'none',
  339. duration: 2000
  340. })
  341. //2020
  342. wx.setStorageSync('bindbackurl', '/packageUser/pages/user/fund/fund'); //存入手机绑定后跳转页面
  343. }else{
  344. wx.navigateTo({
  345. url: '/packageUser/pages/user/fund/fund'
  346. })
  347. }
  348. },
  349. toBindOldSys () {
  350. let that = this;
  351. wx.navigateTo({
  352. url: '/packageUser/pages/user/bindoldsys/bindoldsys?id='+that.data.userInfo.id
  353. })
  354. },
  355. toIdentity () {
  356. wx.navigateTo({
  357. url: '/packageUser/pages/user/identity/identity'
  358. })
  359. },
  360. toBankInfo () {
  361. wx.navigateTo({
  362. url: '/packageUser/pages/user/bankinfo/bankinfo'
  363. })
  364. },
  365. toAddressList () {
  366. wx.navigateTo({
  367. url: '/packageUser/pages/user/address/address'
  368. })
  369. },
  370. toRadish () {
  371. wx.navigateTo({
  372. url: '/packageUser/pages/user/radish/radish'
  373. })
  374. },
  375. toIntegral () {
  376. wx.navigateTo({
  377. url: '/packageUser/pages/user/integral/integral'
  378. })
  379. },
  380. toSafe () {
  381. wx.navigateTo({
  382. url: '/packageUser/pages/user/safe/safe'
  383. })
  384. },
  385. toCustom () {
  386. wx.reLaunch({
  387. url: '/pages/customservice/customservice'
  388. })
  389. },
  390. toProxy () {
  391. wx.navigateTo({
  392. url: '/packageUser/pages/user/proxyList/proxyList'
  393. })
  394. },
  395. toApplyLeader () {
  396. wx.navigateTo({
  397. url: '/packageUser/pages/user/applyLeader/applyLeader'
  398. })
  399. },
  400. toAreaCart () {
  401. wx.navigateTo({
  402. url: '/pages/areacart/areacart'
  403. })
  404. },
  405. toBindTel () {
  406. wx.navigateTo({
  407. url: '/packageUser/pages/user/bind/bind'
  408. })
  409. },
  410. toAbout () {
  411. var host = getApp().globalData.d5c
  412. if (host === 'tm.d5ct.com') {
  413. wx.navigateTo({
  414. url: '/pages/parse/parse?id=2'
  415. })
  416. } else if (host === 'm.d5ct.com') {
  417. wx.navigateTo({
  418. url: '/pages/parse/parse?id=1'
  419. })
  420. }
  421. },
  422. toMerchant () {
  423. wx.navigateTo({
  424. url: '/packageMerchant/pages/merchant/orders/orders?id=' + this.data.checkData.merchant_id + '&is_super_admin=' + this.data.checkData.is_super_admin
  425. })
  426. },
  427. toMerchant1 () {
  428. wx.navigateTo({
  429. url: '/packageMerchant/pages/merchant/accounts/accounts?id=' + this.data.checkData.merchant_id
  430. })
  431. },
  432. onShareAppMessage: function (val) {
  433. return _request.share({
  434. sc: 'xcx_user'
  435. })
  436. }
  437. })