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.

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