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.

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