index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. const app = getApp()
  2. const WXAPI = require('apifm-wxapi')
  3. const AUTH = require('../../../utils/auth')
  4. const wxpay = require('../../../utils/pay.js')
  5. const ImageUtil = require('../../../utils/image')
  6. const APP = getApp()
  7. // fixed首次打开不显示标题的bug
  8. var sliderWidth = 96; // 需要设置slider的宽度,用于计算中间位置
  9. Date.prototype.format = function(format) {
  10. var date = {
  11. "M+": this.getMonth() + 1,
  12. "d+": this.getDate(),
  13. "h+": this.getHours(),
  14. "m+": this.getMinutes(),
  15. "s+": this.getSeconds(),
  16. "q+": Math.floor((this.getMonth() + 3) / 3),
  17. "S+": this.getMilliseconds()
  18. };
  19. if (/(y+)/i.test(format)) {
  20. format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  21. }
  22. for (var k in date) {
  23. if (new RegExp("(" + k + ")").test(format)) {
  24. format = format.replace(RegExp.$1, RegExp.$1.length == 1
  25. ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
  26. }
  27. }
  28. return format;
  29. }
  30. Page({
  31. /**
  32. * 页面的初始数据
  33. */
  34. data: {
  35. wxlogin: true,
  36. balance: 0,
  37. freeze: 0,
  38. score: 0,
  39. score_sign_continuous: 0,
  40. cashlogs: undefined,
  41. tabs: ["资金明细", "提现记录", "押金记录"],
  42. activeIndex: 0,
  43. sliderOffset: 0,
  44. sliderLeft: 0,
  45. withDrawlogs: undefined,
  46. depositlogs: undefined,
  47. rechargeOpen: false, // 是否开启充值[预存]功能
  48. TzCount: 0, //团长数
  49. TyCount: 0, //团员数
  50. commisionData: {
  51. today: 0,
  52. yesday: 0,
  53. thisMonth: 0,
  54. lastMonth: 0,
  55. todayXiaoshou: 0,
  56. yesdayXiaoshou: 0,
  57. thisMonthXiaoshou: 0,
  58. lastMonthXiaoshou: 0,
  59. },
  60. tzid:"",//团长id
  61. originShow:false,//显示固定得二维码 不带参数
  62. },
  63. /**
  64. * 生命周期函数--监听页面加载
  65. */
  66. onLoad: function (options) {
  67. const that = this;
  68. wx.getSystemInfo({
  69. success: function (res) {
  70. that.setData({
  71. sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
  72. sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
  73. });
  74. }
  75. });
  76. },
  77. /**
  78. * 生命周期函数--监听页面初次渲染完成
  79. */
  80. onReady: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面显示
  84. */
  85. onShow: function () {
  86. this.setData({
  87. navHeight: APP.globalData.navHeight,
  88. navTop: APP.globalData.navTop,
  89. windowHeight: APP.globalData.windowHeight,
  90. menuButtonObject: APP.globalData.menuButtonObject //小程序胶囊信息
  91. })
  92. AUTH.checkHasLogined().then(isLogined => {
  93. this.setData({
  94. wxlogin: isLogined
  95. })
  96. if (isLogined) {
  97. this.doneShow();
  98. this.getUserApiInfo();
  99. this.getTz(1);
  100. this.getTy(2);
  101. this.getfxMoney();
  102. this.fxMembers();
  103. this.getMembersStatistics();
  104. }
  105. })
  106. },
  107. async commision() {
  108. const uid = this.data.apiUserInfoMap.base.id
  109. var commisionData = this.data.commisionData
  110. const nowDate = new Date()
  111. console.log('今天', nowDate.format('yyyyMMdd'))
  112. console.log('本月', nowDate.format('yyyyMM'))
  113. const yestoday = new Date(nowDate.getTime() - 24 * 60 * 60 * 1000)
  114. console.log('昨天', yestoday.format('yyyyMMdd'))
  115. // 上个月
  116. let year = nowDate.getFullYear()
  117. let month = nowDate.getMonth() + 1
  118. if (month == 1) {
  119. month = 12
  120. year--
  121. } else {
  122. month--
  123. }
  124. const lastMonth = year + "" + (month < 10 ? ('0' + month) : month)
  125. console.log('上个月', lastMonth)
  126. let res = await WXAPI.siteStatisticsSaleroom({
  127. dateBegin: nowDate.format('yyyyMMdd'),
  128. dateEnd: nowDate.format('yyyyMMdd'),
  129. uid: uid
  130. })
  131. if (res.code === 0) {
  132. commisionData.today = res.data[0].amount
  133. commisionData.todayXiaoshou = res.data[0].saleroom
  134. }
  135. res = await WXAPI.siteStatisticsSaleroom({
  136. dateBegin: yestoday.format('yyyyMMdd'),
  137. dateEnd: yestoday.format('yyyyMMdd'),
  138. uid: uid
  139. })
  140. if (res.code === 0) {
  141. commisionData.yesday = res.data[0].amount
  142. commisionData.yesdayXiaoshou = res.data[0].saleroom
  143. }
  144. res = await WXAPI.siteStatisticsSaleroom({
  145. dateBegin: nowDate.format('yyyyMM'),
  146. dateEnd: nowDate.format('yyyyMM'),
  147. uid: uid
  148. })
  149. if (res.code === 0) {
  150. commisionData.thisMonth = res.data[0].amount
  151. commisionData.thisMonthXiaoshou = res.data[0].saleroom
  152. }
  153. res = await WXAPI.siteStatisticsSaleroom({
  154. dateBegin: lastMonth,
  155. dateEnd: lastMonth,
  156. uid: uid
  157. })
  158. if (res.code === 0) {
  159. commisionData.lastMonth = res.data[0].amount
  160. commisionData.lastMonthXiaoshou = res.data[0].saleroom
  161. }
  162. this.setData({
  163. commisionData:commisionData
  164. })
  165. },
  166. backto() {
  167. wx.navigateBack()
  168. },
  169. getUserApiInfo: function () {
  170. var that = this;
  171. WXAPI.userDetail(wx.getStorageSync('token')).then(function (res) {
  172. if (res.code == 0) {
  173. let _data = {}
  174. _data.apiUserInfoMap = res.data
  175. if (res.data.base.mobile) {
  176. _data.userMobile = res.data.base.mobile
  177. }
  178. if (that.data.order_hx_uids && that.data.order_hx_uids.indexOf(res.data.base.id) != -1) {
  179. _data.canHX = true // 具有扫码核销的权限
  180. }
  181. const adminUserIds = wx.getStorageSync('adminUserIds')
  182. if (adminUserIds && adminUserIds.indexOf(res.data.base.id) != -1) {
  183. _data.isAdmin = true
  184. }
  185. if (res.data.peisongMember && res.data.peisongMember.status == 1) {
  186. _data.memberChecked = false
  187. } else {
  188. _data.memberChecked = true
  189. }
  190. that.setData(_data);
  191. that.commision();
  192. if(res.data.base.isTeamLeader || res.data.partnerInfo) {
  193. that.fetchQrcode(false)
  194. }
  195. }
  196. })
  197. },
  198. doneShow: function () {
  199. const _this = this
  200. const token = wx.getStorageSync('token')
  201. if (!token) {
  202. this.setData({
  203. wxlogin: false
  204. })
  205. return
  206. }
  207. WXAPI.userAmount(token).then(function (res) {
  208. if (res.code == 700) {
  209. wx.showToast({
  210. title: '当前账户存在异常',
  211. icon: 'none'
  212. })
  213. return
  214. }
  215. if (res.code == 2000) {
  216. this.setData({
  217. wxlogin: false
  218. })
  219. return
  220. }
  221. if (res.code == 0) {
  222. _this.setData({
  223. balance: res.data.balance.toFixed(2),
  224. freeze: res.data.freeze.toFixed(2),
  225. totleConsumed: res.data.totleConsumed.toFixed(2),
  226. score: res.data.score
  227. });
  228. }
  229. })
  230. this.fetchTabData(this.data.activeIndex)
  231. },
  232. async getfxMoney(){
  233. const res = await WXAPI.partnerSetting()
  234. console.log("getfxMoney",res)
  235. if(res.code==0){
  236. this.setData({
  237. fxData:res.data
  238. })
  239. }
  240. },
  241. async payFx(){
  242. var money = this.data.fxData.priceLeader;
  243. wxpay.wxpay('payTz', money, '', "/pages/packageA/pages/vip/index");
  244. },
  245. fetchTabData(activeIndex) {
  246. if (activeIndex == 0) {
  247. this.cashLogs()
  248. }
  249. if (activeIndex == 1) {
  250. this.withDrawlogs()
  251. }
  252. if (activeIndex == 2) {
  253. this.depositlogs()
  254. }
  255. },
  256. cashLogs() {
  257. const _this = this
  258. WXAPI.cashLogsV2({
  259. token: wx.getStorageSync('token'),
  260. page: 1,
  261. pageSize: 50
  262. }).then(res => {
  263. if (res.code == 0) {
  264. _this.setData({
  265. cashlogs: res.data.result
  266. })
  267. }
  268. })
  269. },
  270. withDrawlogs() {
  271. const _this = this
  272. WXAPI.withDrawLogs({
  273. token: wx.getStorageSync('token'),
  274. page: 1,
  275. pageSize: 50
  276. }).then(res => {
  277. if (res.code == 0) {
  278. _this.setData({
  279. withDrawlogs: res.data
  280. })
  281. }
  282. })
  283. },
  284. depositlogs() {
  285. const _this = this
  286. WXAPI.depositList({
  287. token: wx.getStorageSync('token'),
  288. page: 1,
  289. pageSize: 50
  290. }).then(res => {
  291. if (res.code == 0) {
  292. _this.setData({
  293. depositlogs: res.data.result
  294. })
  295. }
  296. })
  297. },
  298. recharge: function (e) {
  299. wx.navigateTo({
  300. url: "/pages/recharge/index"
  301. })
  302. },
  303. withdraw: function (e) {
  304. wx.navigateTo({
  305. url: "/pages/withdraw/index"
  306. })
  307. },
  308. payDeposit: function (e) {
  309. wx.navigateTo({
  310. url: "/pages/deposit/pay"
  311. })
  312. },
  313. tabClick: function (e) {
  314. this.setData({
  315. sliderOffset: e.currentTarget.offsetLeft,
  316. activeIndex: e.currentTarget.id
  317. });
  318. this.fetchTabData(e.currentTarget.id)
  319. },
  320. cancelLogin() {
  321. wx.switchTab({
  322. url: '/pages/my/index'
  323. })
  324. },
  325. processLogin(e) {
  326. if (!e.detail.userInfo) {
  327. wx.showToast({
  328. title: '已取消',
  329. icon: 'none',
  330. })
  331. return;
  332. }
  333. AUTH.register(this);
  334. },
  335. async getcashLogJD() { //获取金豆
  336. const _this = this
  337. await WXAPI.cashLogsV2({
  338. token: wx.getStorageSync('token'),
  339. page: 1,
  340. pageSize: 50000,
  341. type: 7
  342. }).then(res => {
  343. if (res.code == 0) {
  344. _this.setData({
  345. cashLogJD: res.data
  346. })
  347. _this.setData({
  348. invite_count: res.data.totalRow,
  349. getJD: res.data.totalRow,
  350. })
  351. } else {
  352. _this.setData({
  353. invite_count: 0,
  354. getJD: 0,
  355. })
  356. }
  357. })
  358. },
  359. async getcashLogJDtx() { //获取金豆(已提现)
  360. const _this = this
  361. await WXAPI.cashLogsV2({
  362. token: wx.getStorageSync('token'),
  363. page: 1,
  364. pageSize: 50000,
  365. type: 1
  366. }).then(res => {
  367. if (res.code == 0) {
  368. _this.setData({
  369. txJD: res.data.totalRow,
  370. })
  371. } else {
  372. _this.setData({
  373. txJD: 0
  374. })
  375. }
  376. })
  377. },
  378. copyContent(e) {
  379. console.log("1")
  380. var data = e.currentTarget.dataset.id + ""
  381. wx.setClipboardData({
  382. data: data,
  383. success(res) {
  384. wx.getClipboardData({
  385. success(res) {
  386. console.log(res.data) // data
  387. }
  388. })
  389. }
  390. })
  391. },
  392. async getMembersStatistics() { //团队情况
  393. const res = await WXAPI.partnerMembersStatistics(wx.getStorageSync('token'))
  394. if (res.code == 0) {
  395. this.setData({
  396. membersStatistics: res.data
  397. })
  398. }
  399. },
  400. async getTz(name) { //团长
  401. const res = await WXAPI.fxMembers({
  402. token: wx.getStorageSync('token'),
  403. page: 1,
  404. pageSize: 50,
  405. level: name, // "不填全部,1为团队长,2为团员"
  406. statisticsDay: "2021"
  407. })
  408. if (res.code == 0) {
  409. this.setData({
  410. TzCount: res.data.result.length
  411. })
  412. }
  413. },
  414. async getTy(name) { //团员
  415. const res = await WXAPI.fxMembers({
  416. token: wx.getStorageSync('token'),
  417. page: 1,
  418. pageSize: 50,
  419. level: name, // "不填全部,1为团队长,2为团员"
  420. statisticsDay: "2021"
  421. })
  422. if (res.code == 0) {
  423. this.setData({
  424. TyCount: res.data.result.length
  425. })
  426. }
  427. },
  428. async fxMembers(){
  429. const res = await WXAPI.fxMembers({
  430. token:wx.getStorageSync('token')
  431. })
  432. console.log("fxmenber",res)
  433. },
  434. goFxmem(e){
  435. var level = e.currentTarget.dataset.level
  436. wx.navigateTo({
  437. url: 'fxmember?level='+level,
  438. })
  439. },
  440. goCommision(){
  441. wx.navigateTo({
  442. url: '../commisionLog/index',
  443. })
  444. },
  445. async partnerBindTeamLeader() {
  446. var uid = this.data.tzid;
  447. const res = await WXAPI.partnerBindTeamLeader(wx.getStorageSync('token'),uid)
  448. if (res.code != 0) {
  449. wx.showToast({
  450. title: res.msg,
  451. icon: 'none'
  452. })
  453. } else if (res.code == 0) {
  454. wx.showToast({
  455. title: '设置团长成功',
  456. })
  457. setTimeout(() => {
  458. this.onShow()
  459. }, 1000);
  460. }
  461. },
  462. onChange(e){
  463. this.setData({
  464. tzid:e.detail
  465. })
  466. },
  467. fetchQrcode(test){
  468. const _this = this
  469. wx.showLoading({
  470. title: '加载中',
  471. mask: true
  472. })
  473. WXAPI.wxaQrcode({
  474. scene: 'inviter_id=' + wx.getStorageSync('uid'),
  475. page: 'pages/index/index',
  476. is_hyaline: true,
  477. autoColor: true,
  478. expireHours: 1,
  479. check_path: test ? false : true
  480. }).then(res => {
  481. wx.hideLoading()
  482. if (res.code == 41030) {
  483. _this.fetchQrcode(true)
  484. return
  485. }
  486. if (res.code == 0) {
  487. _this.showCanvas(res.data)
  488. }
  489. })
  490. },
  491. showCanvas(qrcode){
  492. const _this = this
  493. let ctx
  494. wx.getImageInfo({
  495. src: qrcode,
  496. success: (res) => {
  497. const imageSize = ImageUtil.imageUtil(res.width, res.height)
  498. const qrcodeWidth = 160
  499. console.log("imageSize",imageSize)
  500. _this.setData({
  501. canvasHeight: qrcodeWidth
  502. })
  503. ctx = wx.createCanvasContext('firstCanvas')
  504. ctx.setFillStyle('#fff')
  505. ctx.fillRect(0, 0, imageSize.windowWidth, imageSize.imageHeight + qrcodeWidth)
  506. ctx.drawImage(res.path, 0, 0, qrcodeWidth, qrcodeWidth)
  507. setTimeout(function () {
  508. wx.hideLoading()
  509. ctx.draw()
  510. }, 1000)
  511. }
  512. })
  513. },
  514. // =====================保存推荐二维码图片到手机==========================
  515. saveToMobile() { //下载二维码到手机
  516. wx.canvasToTempFilePath({
  517. canvasId: 'firstCanvas',
  518. success: function (res) {
  519. let tempFilePath = res.tempFilePath
  520. wx.saveImageToPhotosAlbum({
  521. filePath: tempFilePath,
  522. success: (res) => {
  523. wx.showModal({
  524. content: '二维码已保存到手机相册',
  525. showCancel: false,
  526. confirmText: '知道了',
  527. confirmColor: '#333'
  528. })
  529. },
  530. fail: (res) => {
  531. wx.showToast({
  532. title: res.errMsg,
  533. icon: 'none',
  534. duration: 2000
  535. })
  536. }
  537. })
  538. }
  539. })
  540. },
  541. // =====================保存固定二维码图片到手机==========================
  542. saveOri() {
  543. let that = this
  544. //若二维码未加载完毕,加个动画提高用户体验
  545. wx.showToast({
  546. icon: 'loading',
  547. title: '正在保存图片',
  548. duration: 1000
  549. })
  550. //判断用户是否授权"保存到相册"
  551. wx.getSetting({
  552. success (res) {
  553. //没有权限,发起授权
  554. if (!res.authSetting['scope.writePhotosAlbum']) {
  555. wx.authorize({
  556. scope: 'scope.writePhotosAlbum',
  557. success () {//用户允许授权,保存图片到相册
  558. that.savePhoto();
  559. },
  560. fail () {//用户点击拒绝授权,跳转到设置页,引导用户授权
  561. wx.openSetting({
  562. success () {
  563. wx.authorize({
  564. scope: 'scope.writePhotosAlbum',
  565. success() {
  566. that.savePhoto();
  567. }
  568. })
  569. }
  570. })
  571. }
  572. })
  573. } else {//用户已授权,保存到相册
  574. that.savePhoto()
  575. }
  576. }
  577. })
  578. },
  579. //保存图片到相册,提示保存成功
  580. savePhoto() {
  581. let that = this
  582. wx.downloadFile({
  583. url: 'https://dcdn.it120.cc/2021/01/24/928782d2-062c-4a45-9911-b331fdf38ed9.jpg',
  584. success: function (res) {
  585. wx.saveImageToPhotosAlbum({
  586. filePath: res.tempFilePath,
  587. success(res) {
  588. wx.showToast({
  589. title: '保存成功',
  590. icon: "success",
  591. duration: 1000
  592. })
  593. }
  594. })
  595. }
  596. })
  597. },
  598. })