C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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