index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. const req = require('../../../utils/request')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. length: 0,
  10. earnings: 0,
  11. list: [{
  12. 'num': '提现到银行卡'
  13. }],
  14. idx: null,
  15. name: null,
  16. price: null,
  17. checked: true,
  18. merchant: null,
  19. names: null,
  20. bankName: null,
  21. accountId: null,
  22. activeColor: getApp().globalData.activeColor,
  23. titleColor: getApp().globalData.titleColor,
  24. times:null,
  25. minCount:null,
  26. bankList: [],
  27. bank_index:null
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad:async function (options) {
  33. let earnings = options.earnings
  34. let merchant = wx.getStorageSync('merchant'); //用户
  35. this.setData({
  36. earnings: earnings,
  37. merchant: merchant.objectId
  38. })
  39. let d = new Date();
  40. this.date = d
  41. let data = new Date(d.getFullYear(), d.getMonth() + 1, 0);
  42. let day = data.getDate();
  43. let year = d.getFullYear()
  44. let month = d.getMonth() + 1 > 9 ? d.getMonth() + 1 : "0" + (d.getMonth() + 1)
  45. // 当前月份的 第一天 和最后一天
  46. let startTime = year + "-" + month + "-" + "01" + " 00:00:00"
  47. let endTime = year + "-" + month + "-" + day + " 23:59:57"
  48. await this.getSeeting()
  49. await this.getTotal(startTime, endTime)
  50. // await this.getBank()
  51. },
  52. async getSeeting() {
  53. let sql = `select "value" from "Setting" where "oid" = '${company}' and "key" = 'store-withdraw' and "type" = 'company'`
  54. let setting = await req.customSQL(sql)
  55. if(setting && setting.length > 0) {
  56. console.log(setting)
  57. if(setting[0] && setting[0].value ) {
  58. this.setData({
  59. times: setting[0].value.times? setting[0].value.times : null,
  60. minCount: setting[0].value.minCount? setting[0].value.minCount : null
  61. })
  62. }
  63. }
  64. },
  65. async getBank() {
  66. let user = Parse.User.current()
  67. let Account = new Parse.Query('Account')
  68. Account.equalTo('company', company)
  69. Account.equalTo('user',user)
  70. Account.select('bank')
  71. let account = await Account.first()
  72. if(account && account.id) {
  73. this.setData({
  74. bankList: account.get('bank') ? account.get('bank') : []
  75. })
  76. }
  77. },
  78. onChangBank(e) {
  79. let {
  80. index, item
  81. } = e.currentTarget.dataset
  82. this.setData({
  83. bank_index: index,
  84. names: item.name,
  85. accountId:item.cardId,
  86. bankName: item.bankName
  87. })
  88. },
  89. async getUserAgentWithdraw() {
  90. let store = wx.getStorageSync("store");
  91. if (store == "") {
  92. wx.redirectTo({
  93. url: '/nova-bzzb/pages/my/login/index'
  94. });
  95. return;
  96. }
  97. let uid = store.user.objectId
  98. if (this.data.times && this.data.length >= this.data.times) {
  99. wx.showToast({
  100. title: '您本月的提现次数已到上限',
  101. icon: 'none',
  102. });
  103. return;
  104. }
  105. if (this.data.minCount && this.data.minCount > Number(this.data.price)) {
  106. wx.showToast({
  107. title: '提现金额小于最小提现金额',
  108. icon: 'none',
  109. });
  110. return
  111. }
  112. if (!this.data.price) {
  113. wx.showToast({
  114. title: '请输入提现金额',
  115. icon: 'none',
  116. });
  117. return
  118. }
  119. if (Number(this.data.price) > Number(this.data.earnings)) {
  120. wx.showToast({
  121. title: '您输入的金额超过了您的可提现金额',
  122. icon: 'none',
  123. });
  124. return
  125. }
  126. if (!this.data.name) {
  127. wx.showToast({
  128. title: '请选择提现方式',
  129. icon: 'none',
  130. });
  131. return
  132. }
  133. if (!this.data.names || !this.data.bankName || !this.data.accountId) {
  134. wx.showToast({
  135. title: '请输入完整银行卡信息',
  136. icon: 'none',
  137. });
  138. return
  139. }
  140. let UserAgentWithdraw = Parse.Object.extend("UserAgentWithdraw")
  141. let userAgentWithdraw = new UserAgentWithdraw()
  142. userAgentWithdraw.set("count", Number(this.data.price))
  143. userAgentWithdraw.set("type", "bank")
  144. userAgentWithdraw.set("isVerified", false)
  145. userAgentWithdraw.set("name", store.storeName)
  146. userAgentWithdraw.set("company", {
  147. __type: 'Pointer',
  148. className: 'Company',
  149. objectId: company
  150. })
  151. userAgentWithdraw.set("user", {
  152. __type: 'Pointer',
  153. className: '_User',
  154. objectId: uid
  155. })
  156. userAgentWithdraw.set("info", [{
  157. name: this.data.names,
  158. accountId: this.data.accountId,
  159. bankName: this.data.bankName
  160. }])
  161. userAgentWithdraw.set("bank", {
  162. name: this.data.names,
  163. accountId: this.data.accountId,
  164. bankName: this.data.bankName
  165. })
  166. userAgentWithdraw.set("channel", "shopStore")
  167. userAgentWithdraw.save().then(res => {
  168. if(res && res.id) {
  169. wx.showToast({
  170. title: '提现成功',
  171. icon: 'none',
  172. });
  173. setTimeout(()=> {
  174. wx.navigateBack({
  175. delta: 1
  176. })
  177. },500)
  178. }
  179. })
  180. },
  181. bindBank() {
  182. wx.navigateTo({
  183. url: `/common-page/pages/info/bindBank/index`,
  184. })
  185. },
  186. goIndex(e) {
  187. let index = e.currentTarget.dataset.index;
  188. let name = e.currentTarget.dataset.item.num
  189. if (index == this.data.idx) {
  190. this.setData({
  191. idx: null,
  192. name: null
  193. })
  194. } else {
  195. this.setData({
  196. idx: index,
  197. name: name
  198. })
  199. }
  200. },
  201. // 输入框失去焦点 触发事件
  202. blur(e) {
  203. let name = e.currentTarget.dataset.name
  204. this.setData({
  205. [name]: e.detail.value
  206. })
  207. },
  208. //
  209. async getTotal(startTime, endTime) {
  210. let UserAgentWithdraw = new Parse.Query('UserAgentWithdraw')
  211. UserAgentWithdraw.equalTo('user', this.data.merchant)
  212. UserAgentWithdraw.equalTo('type', 'bank')
  213. UserAgentWithdraw.greaterThan('createdAt', startTime)
  214. UserAgentWithdraw.lessThan('createdAt', endTime)
  215. let userAgentWithdraw = await UserAgentWithdraw.find()
  216. let length
  217. if (userAgentWithdraw) {
  218. console.log(userAgentWithdraw.length);
  219. length = userAgentWithdraw.length
  220. }
  221. this.setData({
  222. length: length
  223. })
  224. console.log(this.data.length);
  225. },
  226. /**
  227. * 生命周期函数--监听页面初次渲染完成
  228. */
  229. onReady: function () {
  230. },
  231. /**
  232. * 生命周期函数--监听页面显示
  233. */
  234. onShow: async function () {
  235. await this.getBank()
  236. },
  237. /**
  238. * 生命周期函数--监听页面隐藏
  239. */
  240. onHide: function () {
  241. },
  242. /**
  243. * 生命周期函数--监听页面卸载
  244. */
  245. onUnload: function () {
  246. },
  247. /**
  248. * 页面相关事件处理函数--监听用户下拉动作
  249. */
  250. onPullDownRefresh: function () {
  251. },
  252. /**
  253. * 页面上拉触底事件的处理函数
  254. */
  255. onReachBottom: function () {
  256. },
  257. /**
  258. * 用户点击右上角分享
  259. */
  260. onShareAppMessage: function () {
  261. }
  262. })