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.

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