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.

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