index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const wxpay = require('../../../utils/pay.js')
  2. const WXAPI = require('apifm-wxapi')
  3. Page({
  4. data: {
  5. dateBegin: undefined,
  6. dateEnd: undefined,
  7. sellerMobile: undefined,
  8. aggregate: {
  9. sum_sale_amount: 0
  10. }
  11. },
  12. onLoad(options) {},
  13. onShow: function () {
  14. //获取佣金列表
  15. this.getCommisionLog()
  16. },
  17. async getCommisionLog() {
  18. const postData = {
  19. token: wx.getStorageSync('token'),
  20. dateAddBegin: this.data.dateBegin ? this.data.dateBegin : '',
  21. dateAddEnd: this.data.dateEnd ? this.data.dateEnd : '',
  22. sellerMobile: this.data.sellerMobile ? this.data.sellerMobile : ''
  23. }
  24. await WXAPI.fxCommisionLog(postData).then(res => {
  25. if (res.code == 0) {
  26. const goodsMap = res.data.goodsMap
  27. const commisionLog = res.data.result
  28. if (goodsMap) {
  29. res.data.orderList.forEach(ele => {
  30. const _goods = goodsMap[ele.id] // 该订单下的商品列表
  31. if (_goods) {
  32. let totalCommision = 0
  33. _goods.forEach(c => {
  34. const commisionRecord = commisionLog.find(d => {
  35. return d.orderId == ele.id && d.goodsName == c.goodsName // FIXME 要么根据销售额,还是别的来匹配返佣记录
  36. })
  37. if (commisionRecord) {
  38. totalCommision += commisionRecord.money
  39. c.commisionRecord = commisionRecord
  40. ele.buyerUserNick = commisionRecord.nicks ? commisionRecord.nicks : '用户' + commisionRecord.uids
  41. }
  42. })
  43. ele.goodsList = _goods
  44. ele.totalCommision = totalCommision
  45. }
  46. })
  47. }
  48. this.setData({
  49. commisionLog,
  50. orderList: res.data.orderList,
  51. logisticsMap: res.data.logisticsMap,
  52. goodsMap,
  53. aggregate: res.data.aggregate,
  54. userInviter: res.data.userInviter,
  55. })
  56. } else {
  57. this.setData({
  58. commisionLog: [],
  59. orderList: [],
  60. logisticsMap: [],
  61. goodsMap: [],
  62. })
  63. }
  64. })
  65. },
  66. dateBeginCancel() {
  67. this.setData({
  68. dateBegin: null
  69. })
  70. },
  71. dateBeginChange(e) {
  72. this.setData({
  73. dateBegin: e.detail.value
  74. })
  75. },
  76. dateEndCancel() {
  77. this.setData({
  78. dateEnd: null
  79. })
  80. },
  81. dateEndChange(e) {
  82. this.setData({
  83. dateEnd: e.detail.value
  84. })
  85. }
  86. })