myorderdetail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. // pages/mine/myorder/myorderdetail/myorderdetail.js
  2. const app = getApp()
  3. const utilMd5 = require('../../../../utils/md5.js')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. orderPay: [],
  10. od_product_id: '',
  11. loaddisplay: true,
  12. od_product_name: '',
  13. od_status: '',
  14. od_user_address: '',
  15. od_consultantname: '',
  16. od_mmname: '',
  17. od_date: '',
  18. od_no: '',
  19. od_contract: '',
  20. od_startdate: '',
  21. od_enddate: '',
  22. od_date: '',
  23. od_order_amount: '',
  24. od_discount: '',
  25. od_discountName: '',
  26. od_paid: '',
  27. arrearage: '',
  28. discount_show: false,
  29. od_refund: '',
  30. paySum:'',
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. var that = this
  37. wx.request({
  38. url: app.globalData.url + '/getYSOrder',
  39. method: 'get',
  40. data: {
  41. id: options.id
  42. },
  43. success: function (resp) {
  44. // console.log(resp.data.orderPay.length+1)
  45. let paySum = resp.data.paySum;
  46. let orderInfo = resp.data.orderInfo;
  47. let orderPay = resp.data.orderPay;
  48. that.setData({
  49. orderPay: orderPay,
  50. od_product_id: orderInfo.od_product_id,
  51. od_product_name: orderInfo.od_product_name,
  52. od_status: orderInfo.od_status,
  53. od_user_address: orderInfo.od_user_address,
  54. od_consultantname: orderInfo.od_consultantname,
  55. od_mmname: orderInfo.od_mmname,
  56. od_mmid: orderInfo.od_mmid,
  57. od_date: orderInfo.od_date,
  58. od_no: orderInfo.od_no,
  59. od_contract: orderInfo.od_contract,
  60. od_startdate: orderInfo.od_startdate,
  61. od_enddate: orderInfo.od_enddate,
  62. od_date: orderInfo.od_date,
  63. od_order_amount: Number(orderInfo.od_order_amount).toFixed(2),
  64. od_paid: (Number(orderInfo.od_earnestpay) + Number(orderInfo.od_balancepay)).toFixed(2),
  65. arrearage: Number(resp.data.customerPay).toFixed(2),
  66. paySum:paySum
  67. })
  68. if (orderInfo.od_promotion_discount !== 0) {
  69. that.setData({
  70. od_discountName: '活动优惠',
  71. od_discount: Number(orderInfo.od_promotion_discount).toFixed(2),
  72. discount_show: true
  73. })
  74. } else if (orderInfo.od_other_discount !== 0) {
  75. that.setData({
  76. od_discountName: '其他优惠',
  77. od_discount: Number(orderInfo.od_other_discount).toFixed(2),
  78. discount_show: true
  79. })
  80. } else if (orderInfo.od_mgm_discount !== 0) {
  81. that.setData({
  82. od_discountName: '推荐优惠',
  83. od_discount: Number(orderInfo.od_mgm_discount).toFixed(2),
  84. discount_show: true
  85. })
  86. }
  87. if (orderInfo.od_status == 9) {
  88. wx.request({
  89. url: app.globalData.url + '/queryYSOrderReturn',
  90. method: 'get',
  91. data: {
  92. od_no: orderInfo.od_no
  93. },
  94. success: function (res) {
  95. if (res.data.od_refund != null) {
  96. that.setData({
  97. od_refund: res.data.od_refund.toFixed(2),
  98. })
  99. } else {
  100. that.setData({
  101. od_refund: '0.00'
  102. })
  103. }
  104. },
  105. fail() {
  106. app.timeOut()
  107. }
  108. })
  109. }
  110. that.setData({
  111. loaddisplay: 'none'
  112. })
  113. },
  114. fail() {
  115. app.timeOut()
  116. }
  117. })
  118. let _this = this;
  119. _this.setData({
  120. navH: app.globalData.navHeight
  121. })
  122. },
  123. /**
  124. * 生命周期函数--监听页面初次渲染完成
  125. */
  126. onReady: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面显示
  130. */
  131. onShow: function () {
  132. },
  133. /**
  134. * 生命周期函数--监听页面隐藏
  135. */
  136. onHide: function () {
  137. },
  138. /**
  139. * 生命周期函数--监听页面卸载
  140. */
  141. onUnload: function () {
  142. },
  143. /**
  144. * 页面相关事件处理函数--监听用户下拉动作
  145. */
  146. onPullDownRefresh: function () {
  147. },
  148. /**
  149. * 页面上拉触底事件的处理函数
  150. */
  151. onReachBottom: function () {
  152. },
  153. /**
  154. * 用户点击右上角分享
  155. */
  156. onShareAppMessage: function () {
  157. },
  158. orderSign: function (e) {
  159. //验证订单月嫂 首付款时
  160. var that = this
  161. if (this.data.od_status == 1) {
  162. wx.request({
  163. url: app.globalData.url + '/checkStockDate',
  164. method: 'post',
  165. header: { "Content-Type": "application/x-www-form-urlencoded" },
  166. data: {
  167. servant_code: this.data.od_mmid,
  168. start_date: this.data.od_startdate,
  169. end_date: this.data.od_enddate
  170. },
  171. success: function (res) {
  172. if (res.data != 1) {
  173. wx.showToast({
  174. title: '当前月嫂不能服务,请联系您的专属顾问!',
  175. icon: 'none',
  176. duration: 2000
  177. })
  178. return false;
  179. } else {
  180. that.goPay();
  181. }
  182. },
  183. fail() {
  184. app.timeOut()
  185. }
  186. })
  187. } else {
  188. that.goPay();
  189. }
  190. },
  191. randomString: function () {
  192. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
  193. var maxPos = chars.length;
  194. var pwd = '';
  195. for (var i = 0; i < 32; i++) {
  196. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  197. }
  198. return pwd;
  199. },
  200. goPay: function () {
  201. if (this.data.arrearage == null) {
  202. wx.showToast({
  203. title: '无待支付金额!',
  204. icon: 'none',
  205. duration: 1500
  206. })
  207. return false;
  208. }
  209. //支付test
  210. // this.setData({
  211. // arrearage: 0.01
  212. // })
  213. //获取支付参数
  214. var that = this
  215. //校验是否支付过!
  216. var staus = null
  217. if (this.data.od_status == 1) {
  218. staus = 2
  219. } else if (this.data.od_status == 2) {
  220. staus = 3
  221. }
  222. wx.request({
  223. url: app.globalData.url + '/checkCustomerPay',
  224. method: 'POST',
  225. header: { "Content-Type": "application/x-www-form-urlencoded" },
  226. data: {
  227. cp_ordertype: 2,
  228. cp_orderno: this.data.od_no,
  229. cp_orderstatus: staus
  230. },
  231. success: function (res) {
  232. if(res.data === 1) {
  233. wx.showToast({
  234. title: '订单已经支付过啦!',
  235. icon: 'none',
  236. duration: 1500
  237. })
  238. } else {
  239. wx.request({
  240. url: app.globalData.payurl,
  241. method: 'post',
  242. data: {
  243. orderNo: that.data.od_no + 'SEQ' +Number(that.data.orderPay.length+1),
  244. channel: "wx_mini_ys",
  245. price: Number(that.data.arrearage).toFixed(2),
  246. originPrice: Number(that.data.od_order_amount).toFixed(2),
  247. openId: app.globalData.openid,
  248. title: that.data.od_product_name + "*1",
  249. productName: that.data.od_product_name,
  250. productId: that.data.od_product_id
  251. },
  252. success: function (res) {
  253. let data = res.data.body;
  254. console.log(data)
  255. // 调用支付接口
  256. // var timeStamp = String(parseInt(new Date().getTime() / 1000));timeStamp
  257. var timeStamp = data.timeStamp;
  258. // var nonceStr = that.randomString();nonceStr
  259. var nonceStr = data.nonceStr;
  260. var newpaySign = "appId=" + res.data.body.appId + "&nonceStr=" + nonceStr + "&package=" + res.data.body.package + "&signType=MD5" + "&timeStamp=" + timeStamp + "&key=" + app.globalData.key;
  261. // var paySign = utilMd5.hexMD5(newpaySign).toUpperCase();
  262. var paySign = data.sign;
  263. console.log(newpaySign)
  264. console.log(paySign)
  265. console.log(timeStamp,nonceStr,data.package,paySign)
  266. wx.requestPayment(
  267. {
  268. 'timeStamp': timeStamp,
  269. 'nonceStr': nonceStr,
  270. 'package': data.package,
  271. 'signType': 'MD5',
  272. 'paySign': paySign,
  273. 'success': function (res) {
  274. console.log(res)
  275. wx.showToast({
  276. title: '付款成功!',
  277. icon: 'none',
  278. duration: 1500
  279. })
  280. var date = new Date();
  281. var year = date.getFullYear();
  282. var month = ("0" + (date.getMonth() + 1)).slice(-2);;
  283. var strDate = ("0" + (date.getDate())).slice(-2);
  284. var hours = ("0" + (date.getHours())).slice(-2);
  285. var minutes = ("0" + (date.getMinutes())).slice(-2);
  286. var seconds = ("0" + (date.getSeconds())).slice(-2);
  287. var eh_time = year + '-' + month + '-' + strDate + ' ' + hours + ':' + minutes + ':' + seconds;
  288. //增加用户支付信息,更新订单状态
  289. // wx.request({
  290. // url: app.globalData.url + '/insertYsOrderPay',
  291. // method: 'post',
  292. // header: { "Content-Type": "application/x-www-form-urlencoded" },
  293. // data: {
  294. // cp_ordertype: 2,
  295. // cp_orderno: that.data.od_no,
  296. // cp_orderstatus: staus,
  297. // cp_discount: 0,
  298. // cp_paytype: 2,
  299. // cp_payamount: that.data.arrearage,
  300. // cp_usercode: 1,
  301. // cp_date: eh_time
  302. // },
  303. // success: function (res) {
  304. // //发送消息到微信
  305. // wx.request({
  306. // url: app.globalData.url + '/WXSendYSOrderMessage',
  307. // method: 'get',
  308. // data: {
  309. // orderno: that.data.od_no,
  310. // total: that.data.arrearage,
  311. // date: eh_time,
  312. // type: staus
  313. // }
  314. // })
  315. // //返回订单列表页面?
  316. // wx.navigateBack({
  317. // delta: 1
  318. // })
  319. // },
  320. // fail() {
  321. // app.timeOut()
  322. // }
  323. // })
  324. },
  325. 'fail': function (res1) {
  326. console.log(res1,timeStamp,nonceStr,res.data.body.package,paySign)
  327. wx.showToast({
  328. title: '付款失败!',
  329. icon: 'none',
  330. duration: 1500
  331. })
  332. },
  333. 'complete': function (res) {
  334. console.log(res)
  335. }
  336. })
  337. },
  338. fail() {
  339. app.timeOut()
  340. }
  341. })
  342. }
  343. },
  344. fail() {
  345. app.timeOut()
  346. }
  347. })
  348. }
  349. })