outmoney.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. // pages/outmoney/outmoney.js
  2. let log = require('../../utils/log.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. outMoney: null,
  9. checkPass: false,
  10. msg:null,
  11. userInfo: {},
  12. isLogin: false,
  13. remarkArray: [{
  14. value: 1,
  15. text: '平台使用不方便'
  16. }, {
  17. value: 2,
  18. text: '车卖了'
  19. }, {
  20. value: 3,
  21. text: '换地方住'
  22. }, {
  23. value: 4,
  24. text: '其他'
  25. }],
  26. remarkArrayIndex: null
  27. },
  28. outMoney(e) {
  29. console.log(e);
  30. let outMoney = e.detail.value;
  31. this.setData({
  32. outMoney
  33. });
  34. if (this.data.userInfo.repaidbalance && outMoney && outMoney >= 0.3 && outMoney <= this.data.userInfo.repaidbalance) {
  35. if (this.data.remarkArrayIndex){
  36. this.setData({
  37. checkPass: true
  38. });
  39. }else{
  40. this.setData({
  41. checkPass: false
  42. });
  43. }
  44. } else {
  45. this.setData({
  46. checkPass: false
  47. });
  48. }
  49. },
  50. beginOutMoney(e) {
  51. if (this.data.msg) {
  52. wx.showModal({
  53. showCancel: false,
  54. content: this.data.msg
  55. });
  56. return;
  57. }
  58. log.info('[提现]', '[用户触发提现流程]');
  59. wx.showLoading({
  60. title: '提现中...',
  61. mask: true
  62. });
  63. let that = this;
  64. log.info('[提现]', '[用户触发提现流程]', '[wx.login请求]');
  65. wx.login({
  66. success(res) {
  67. console.log(res);
  68. log.info('[提现]', '[用户触发提现流程]', '[wx.login响应]', res);
  69. if (res.code) {
  70. // 发起网络请求
  71. log.info('[提现]', '[服务端提现]', '[请求]', {
  72. //outTradeNo: new Date().getTime(), //订单号
  73. //totalFee: that.data.chargemoney_select, //钱
  74. totalFee: that.data.outMoney,
  75. userId: that.data.userInfo.userId,
  76. loginName: that.data.userInfo.loginName,
  77. remark: that.data.remarkArray[that.data.remarkArrayIndex].text,
  78. code: res.code
  79. });
  80. wx.request({
  81. url: getApp().globalData.postHeadAgreement +'/restapi/wechatpay/dopayTransfers',
  82. data: {
  83. //outTradeNo: new Date().getTime(), //订单号
  84. //totalFee: that.data.chargemoney_select, //钱
  85. totalFee: that.data.outMoney,
  86. userId: that.data.userInfo.userId,
  87. loginName: that.data.userInfo.loginName,
  88. remark: that.data.remarkArray[that.data.remarkArrayIndex].text,
  89. code: res.code
  90. },
  91. header: {
  92. 'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
  93. },
  94. method: 'POST',
  95. success(res1) {
  96. wx.hideLoading();
  97. let {
  98. data
  99. } = res1;
  100. log.info('[提现]', '[服务端提现]', '[响应]', data);
  101. if (data && data.code == 200) {
  102. wx.navigateBack();
  103. wx.showModal({
  104. showCancel: false,
  105. content: '提现成功'
  106. });
  107. log.info('[提现]', '[服务端提现]', '[提现成功]', data);
  108. } else {
  109. wx.showModal({
  110. showCancel: false,
  111. content: data.msg
  112. });
  113. log.info('[提现]', '[服务端提现]', '[提现失败data null||data.code<>200]', data);
  114. }
  115. }
  116. });
  117. } else {
  118. wx.hideLoading();
  119. console.log('登录失败!' + res.errMsg);
  120. log.info('[提现]', '[用户触发提现流程]', '[wx.login响应失败code null]', res);
  121. }
  122. }
  123. })
  124. },
  125. bindRemarkChange: function (e) {
  126. //console.log(e.detail.value);
  127. //let remarkValue = this.data.remarkArray[e.detail.value].value;
  128. this.setData({
  129. remarkArrayIndex: e.detail.value
  130. });
  131. if (this.data.userInfo.repaidbalance && this.data.outMoney && this.data.outMoney >= 0.3 && this.data.outMoney <= this.data.userInfo.repaidbalance) {
  132. this.setData({
  133. checkPass: true
  134. });
  135. }else{
  136. this.setData({
  137. checkPass: false
  138. });
  139. }
  140. },
  141. /**
  142. * 生命周期函数--监听页面加载
  143. */
  144. onLoad: function(options) {
  145. },
  146. /**
  147. * 生命周期函数--监听页面初次渲染完成
  148. */
  149. onReady: function() {
  150. },
  151. /**
  152. * 生命周期函数--监听页面显示
  153. */
  154. onShow: function() {
  155. log.info('[提现]', '[加载完成]');
  156. let userInfo = wx.getStorageSync('userInfo');
  157. let isLogin = wx.getStorageSync('isLogin');
  158. let that = this;
  159. log.info('[提现]', '[同步用户数据]', '[请求]', {
  160. loginName: userInfo.loginName
  161. });
  162. wx.request({
  163. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/syncUser',
  164. data: {
  165. loginName: userInfo.loginName
  166. },
  167. method: 'POST',
  168. success: function(res) {
  169. let {
  170. data
  171. } = res;
  172. log.info('[提现]', '[同步用户数据]', '[响应]', data);
  173. if (data.code && data.code != 200) {
  174. wx.removeStorageSync('userInfo');
  175. wx.removeStorageSync('isLogin');
  176. let url = '/pages/login/login';
  177. wx.redirectTo({
  178. url,
  179. });
  180. log.info('[提现]', '[同步用户数据]', '[失败data null||data.code<>200跳转登陆界面]', data);
  181. } else {
  182. that.setData({
  183. userInfo: data,
  184. isLogin: true
  185. });
  186. wx.setStorageSync('userInfo', data);
  187. wx.setStorageSync('isLogin', true);
  188. log.info('[提现]', '[同步用户数据]', '[成功]', data);
  189. log.info('[提现]', '[获取用户是否有未完成订单]', '[请求]', {
  190. userId: userInfo.userId
  191. });
  192. wx.request({
  193. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  194. data: {
  195. userId: userInfo.userId
  196. },
  197. method: 'POST',
  198. success(res) {
  199. let {
  200. data
  201. } = res;
  202. log.info('[提现]', '[获取用户是否有未完成订单]', '[响应]', data);
  203. if (data && data.code == 200) {
  204. //有正在充电的订单
  205. that.setData({
  206. msg: '暂时无法退款,请先完成订单!'
  207. });
  208. log.info('[提现]', '[获取用户是否有未完成订单]', '[用户有未完成订单无法体现]', data);
  209. } else {
  210. console.log(res);
  211. log.info('[提现]', '[获取用户是否有未完成订单]', '[用户没有未完成订单]', data);
  212. }
  213. }
  214. });
  215. log.info('[提现]', '[获取用户是否有未支付订单]', '[请求]', {
  216. userId: that.data.userInfo.userId
  217. });
  218. wx.request({
  219. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  220. data: {
  221. userId: that.data.userInfo.userId
  222. },
  223. method: 'POST',
  224. success(res) {
  225. let {
  226. data
  227. } = res;
  228. log.info('[提现]', '[获取用户是否有未支付订单]', '[响应]', data);
  229. let {
  230. result: order
  231. } = data;
  232. if (data && order && data.code == 200) {
  233. //有未支付的订单
  234. that.setData({
  235. msg: '暂时无法退款,请先完成订单!'
  236. });
  237. log.info('[提现]', '[获取用户是否有未支付订单]','[用户有未支付订单无法提现]');
  238. } else {
  239. console.log(res);
  240. log.info('[提现]', '[获取用户是否有未支付订单]', '[用户没有未支付订单]');
  241. }
  242. }
  243. });
  244. }
  245. },
  246. fail(e) {
  247. console.log("用户数据同步失败");
  248. log.info('[提现]', '[同步用户数据]', '[fail]', e);
  249. }
  250. });
  251. },
  252. /**
  253. * 生命周期函数--监听页面隐藏
  254. */
  255. onHide: function() {
  256. },
  257. /**
  258. * 生命周期函数--监听页面卸载
  259. */
  260. onUnload: function() {
  261. },
  262. /**
  263. * 页面相关事件处理函数--监听用户下拉动作
  264. */
  265. onPullDownRefresh: function() {
  266. },
  267. /**
  268. * 页面上拉触底事件的处理函数
  269. */
  270. onReachBottom: function() {
  271. },
  272. /**
  273. * 用户点击右上角分享
  274. */
  275. onShareAppMessage: function() {
  276. }
  277. })