C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

324 lines
8.3 KiB

  1. let config = require("../../../config/config.js");
  2. let util = require("../../../utils/util");
  3. let Http = require("../../../utils/HttpBasics");
  4. let app = getApp();
  5. const imgurl = require("../../../utils/imgurl");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. succUrl: imgurl.succ.url,
  12. spcodeUrl: imgurl.spcode.url,
  13. teljpgUrl: imgurl.teljpg.url,
  14. newUrl: imgurl.new.url,
  15. weixinTitle: imgurl.weixinTitle.url,
  16. showModalStatus: false,
  17. flag: 0,
  18. order: null,
  19. orderId: null,
  20. //存储计时器
  21. setInter: "",
  22. mystatus: '',
  23. staticGamedata: {},
  24. showIf: false,
  25. showPage:false,
  26. showButton:false,
  27. cardDetail:null,
  28. supportTransfer:''
  29. },
  30. phone: function (e) {
  31. let that = this;
  32. console.log(e);
  33. wx.makePhoneCall({
  34. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  35. });
  36. },
  37. //转赠给微信好友
  38. goToTranser() {
  39. },
  40. getUserInfo: function () {
  41. let that = this;
  42. // 获取用户信息
  43. Http.get({
  44. url: config.api.getScore,
  45. data: {}
  46. })
  47. .then(res => {
  48. console.log(res)
  49. that.setData({
  50. userName: res.data.nickName,
  51. avatarUrl: res.data.avatarUrl
  52. })
  53. })
  54. },
  55. // onShareAppMessage: function (res) {
  56. // let _this = this;
  57. // return {
  58. // title: '领取卡',
  59. // path: '/pages/index/index?couponChannelId=' + this.data.order.couponChannelId + '&cuserId=' + this.data.order.cuserId + '&couponId=' + this.data.order.productId + '&coverImg=' + this.data.order.coverImg + '&userName=' + this.data.userName + '&avatarUrl=' + this.data.avatarUrl + '&couponOrderId=' + this.data.order.couponOrderId + '&updateDate=' + this.data.order.updateDate,
  60. // imageUrl: this.data.order.coverImg,
  61. // success: function (res) {
  62. // // 转发成功
  63. // },
  64. // fail: function (res) {
  65. // // 转发失败
  66. // }
  67. // }
  68. // },
  69. powerDrawer: function (e) {
  70. let that = this;
  71. console.log(e)
  72. // couponOrderStatus
  73. // 0 未使用
  74. // 1 已使用
  75. // 2 已过期
  76. // 3 已经退款
  77. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  78. wx.navigateTo({
  79. url: `/pages/orderquanma/index?quancode=${
  80. e.currentTarget.dataset.quancode
  81. }&title=${e.currentTarget.dataset.title}&subtitle=${
  82. e.currentTarget.dataset.subtitle
  83. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  84. e.currentTarget.dataset.couponorderstatus
  85. }`
  86. });
  87. } else {
  88. wx.navigateTo({
  89. url: `/pages/orderquanma/index?quancode=${
  90. e.currentTarget.dataset.quancode
  91. }&title=${e.currentTarget.dataset.title}&subtitle=${
  92. e.currentTarget.dataset.subtitle
  93. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  94. that.data.mystatus
  95. }`
  96. });
  97. }
  98. },
  99. gotogame: function () {
  100. let that = this;
  101. wx.navigateTo({
  102. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  103. })
  104. },
  105. // 买完卡跳转到立即使用页面
  106. gotoUse:function(){
  107. wx.navigateTo({
  108. url: '/pages/cardorder/index/index'
  109. })
  110. },
  111. // 获取游戏
  112. getStaticGame(token) {
  113. let _this = this;
  114. Http.get({
  115. url: config.api.getGame,
  116. data: {
  117. triggleAction: 3
  118. }
  119. }).then(res => {
  120. if (res.data.id) {
  121. _this.setData({
  122. showIf: true
  123. })
  124. }
  125. _this.setData({
  126. staticGamedata: res.data
  127. })
  128. })
  129. .catch(err => {
  130. console.log(err);
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面加载
  135. */
  136. onLoad: function (options) {
  137. let that = this;
  138. this.setData({
  139. orderId: options.orderId
  140. });
  141. wx.showLoading({
  142. title: "加载中"
  143. });
  144. setTimeout(function () {
  145. wx.hideLoading();
  146. }, 1500);
  147. Http.get({
  148. url: config.api.orderDetail,
  149. data: {
  150. orderId: options.orderId
  151. }
  152. })
  153. .then(res => {
  154. if(res.code == 200){
  155. that.getUserInfo()
  156. that.setData({
  157. showPage:true
  158. })
  159. }
  160. that.setData({
  161. order: res.data,
  162. supportTransfer: res.data.supportTransfer
  163. });
  164. that.getStaticGame()
  165. //createDate 创建时间
  166. var createDate = util.formatTime(res.data.createDate, "yyyy-MM-dd hh:mm:ss");
  167. that.setData({
  168. createDate: createDate
  169. });
  170. })
  171. .catch(error=>{
  172. wx.showModal({
  173. title: '提示',
  174. content: error.errMsg,
  175. showCancel:false
  176. })
  177. })
  178. },
  179. onShow:function(){
  180. let that = this;
  181. that.setData({
  182. showButton: false
  183. })
  184. },
  185. /**
  186. * 发起支付
  187. */
  188. orderFunc(e) {
  189. var that = this;
  190. that.setData({
  191. showButton: true
  192. })
  193. wx.showLoading({
  194. title: "加载中..."
  195. });
  196. const orderId = "" + that.data.orderId;
  197. if (that.data.order.payment > 0) {
  198. // 支付金额不为0
  199. Http.post({
  200. url: config.api.payOrderCreate,
  201. data: {
  202. orderId: orderId
  203. }
  204. }).then(res => {
  205. /// Begin payment ----
  206. that.setData({
  207. showButton: false
  208. })
  209. var payOrderId = "" + res.data.payOrderId;
  210. wx.hideLoading();
  211. wx.requestPayment({
  212. timeStamp: res.data.timeStamp,
  213. nonceStr: res.data.nonceStr,
  214. package: res.data.package,
  215. signType: (res.data.signType) ? res.data.signType : "MD5",
  216. paySign: res.data.paySign,
  217. success: res => {
  218. wx.showLoading({
  219. title: '订单正在处理中...',
  220. })
  221. setTimeout(function () {
  222. wx.hideLoading()
  223. }, 5000)
  224. that.payOrderUpdate(that.data.orderId, payOrderId, 1,'','',that); // 支付成功
  225. if (res.errMsg == "requestPayment:ok") {
  226. if (that.data.order.type == 100) {
  227. wx.setStorage({
  228. key: 'couponNum2',
  229. data: "couponNum2"
  230. })
  231. } else if (that.data.order.type != 5) {
  232. wx.setStorage({
  233. key: 'couponNum',
  234. data: "couponNum"
  235. })
  236. }
  237. }
  238. },
  239. fail: res => {
  240. that.setData({
  241. showButton:false
  242. })
  243. that.payOrderUpdate(that.data.orderId, payOrderId, 2,'','fail',that);
  244. return;
  245. },
  246. });
  247. /// End payment --------
  248. });
  249. } else {
  250. // 免费券
  251. that.payOrderUpdate(orderId, "0", 1,'','free') // 支付成功
  252. if (that.data.order.type == 100) {
  253. wx.setStorage({
  254. key: 'couponNum2',
  255. data: "couponNum2"
  256. })
  257. } else if (that.data.order.type != "5") {
  258. wx.setStorage({
  259. key: 'couponNum',
  260. data: "couponNum"
  261. })
  262. }
  263. wx.showToast({
  264. title: "支付成功",
  265. duration: 2000,
  266. image: imgurl.success.url,
  267. });
  268. }
  269. },
  270. /**
  271. * 支付订单更新
  272. */
  273. payOrderUpdate: (orderId, payOrderId, status, reason,type,_this) => {
  274. // 支付成功
  275. Http.post({
  276. url: config.api.payOrderUpdate,
  277. data: {
  278. payOrderId: payOrderId,
  279. orderId: orderId,
  280. status: status,
  281. reason: reason
  282. }
  283. })
  284. .then(res => {
  285. wx.hideLoading()
  286. if (!type&&type!='free') {
  287. wx.showToast({
  288. title: "购买成功",
  289. duration: 2000,
  290. image: imgurl.success.url,
  291. mask: false,
  292. success: function () {
  293. wx.showLoading({
  294. title: "加载中..."
  295. });
  296. setTimeout(function () {
  297. wx.hideLoading();
  298. }, 1600);
  299. setTimeout(() => {
  300. wx.redirectTo({
  301. url: `/pages/order/detail/index?orderId=${orderId}`
  302. });
  303. }, 1600);
  304. }
  305. });
  306. } else if (type == 'free'){
  307. wx.redirectTo({
  308. url: `/pages/order/detail/index?orderId=${orderId}`
  309. });
  310. }
  311. })
  312. .catch(err => {
  313. console.log(err)
  314. if (!type) {
  315. setTimeout(function () {
  316. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  317. }, 1500)
  318. }
  319. });
  320. },
  321. });