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.

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