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.

356 line
9.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.new1.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: _this.data.userName+'赠送您一张' + _this.data.order.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. Http.get({
  156. url: config.api.orderDetail,
  157. data: {
  158. orderId: options.orderId
  159. }
  160. })
  161. .then(res => {
  162. wx.hideLoading();
  163. if(res.code == 200){
  164. that.getUserInfo()
  165. that.setData({
  166. showPage:true
  167. })
  168. }
  169. that.setData({
  170. order: res.data,
  171. supportTransfer: res.data.supportTransfer
  172. });
  173. that.getStaticGame()
  174. //createDate 创建时间
  175. var createDate = util.formatTime(res.data.createDate, "yyyy-MM-dd hh:mm:ss");
  176. that.setData({
  177. createDate: createDate
  178. });
  179. })
  180. .catch(error=>{
  181. wx.hideLoading();
  182. wx.showModal({
  183. title: '提示',
  184. content: error.errMsg,
  185. showCancel:false
  186. })
  187. })
  188. },
  189. onShow:function(){
  190. let that = this;
  191. that.setData({
  192. showButton: false
  193. })
  194. },
  195. /**
  196. * 去拼团
  197. */
  198. goToOrderGroup(orderId, orderGroupId, _this) {
  199. let that = this;
  200. // 支付成功
  201. Http.post({
  202. url: config.api.toOrderGroup,
  203. data: {
  204. id: orderGroupId,
  205. orderId,
  206. couponId: _this.data.order.productId
  207. }
  208. })
  209. .then(res => {
  210. wx.redirectTo({
  211. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}`
  212. });
  213. })
  214. .catch(err => {
  215. console.log(err);
  216. })
  217. // return;
  218. },
  219. /**
  220. * 发起支付
  221. */
  222. orderFunc(e) {
  223. var that = this;
  224. that.setData({
  225. showButton: true
  226. })
  227. wx.showLoading({
  228. title: "加载中..."
  229. });
  230. const orderId = "" + that.data.orderId;
  231. if (that.data.order.payment > 0) {
  232. // 支付金额不为0
  233. Http.post({
  234. url: config.api.payOrderCreate,
  235. data: {
  236. orderId: orderId
  237. }
  238. }).then(res => {
  239. var payOrderId = "" + res.data.payOrderId;
  240. wx.hideLoading();
  241. wx.requestPayment({
  242. timeStamp: res.data.timeStamp,
  243. nonceStr: res.data.nonceStr,
  244. package: res.data.package,
  245. signType: (res.data.signType) ? res.data.signType : "MD5",
  246. paySign: res.data.paySign,
  247. success: res => {
  248. wx.showLoading({
  249. title: '订单正在处理中...',
  250. })
  251. setTimeout(function () {
  252. wx.hideLoading()
  253. }, 5000)
  254. that.payOrderUpdate(that.data.orderId, payOrderId, 1,'','',that); // 支付成功
  255. if (res.errMsg == "requestPayment:ok") {
  256. if (that.data.order.type == 100) {
  257. wx.setStorage({
  258. key: 'couponNum2',
  259. data: "couponNum2"
  260. })
  261. } else if (that.data.order.type != 5) {
  262. wx.setStorage({
  263. key: 'couponNum',
  264. data: "couponNum"
  265. })
  266. }
  267. }
  268. },
  269. fail: res => {
  270. that.setData({
  271. showButton:false
  272. })
  273. that.payOrderUpdate(that.data.orderId, payOrderId, 2,'','fail',that);
  274. return;
  275. },
  276. });
  277. });
  278. } else {
  279. // 免费券
  280. that.payOrderUpdate(orderId, "0", 1,'','free') // 支付成功
  281. if (that.data.order.type == 100) {
  282. wx.setStorage({
  283. key: 'couponNum2',
  284. data: "couponNum2"
  285. })
  286. } else if (that.data.order.type != "5") {
  287. wx.setStorage({
  288. key: 'couponNum',
  289. data: "couponNum"
  290. })
  291. }
  292. wx.showToast({
  293. title: "支付成功",
  294. duration: 2000,
  295. image: imgurl.success.url,
  296. });
  297. }
  298. },
  299. /**
  300. * 支付订单更新
  301. */
  302. payOrderUpdate: (orderId, payOrderId, status, reason,type,_this) => {
  303. // 支付成功
  304. Http.post({
  305. url: config.api.payOrderUpdate,
  306. data: {
  307. payOrderId: payOrderId,
  308. orderId: orderId,
  309. status: status,
  310. reason: reason
  311. }
  312. })
  313. .then(res => {
  314. wx.hideLoading();
  315. this.setData({
  316. showButton: false
  317. })
  318. if (!type&&type!='free') {
  319. wx.showToast({
  320. title: "购买成功",
  321. duration: 2000,
  322. image: imgurl.success.url,
  323. mask: false,
  324. success: function () {
  325. wx.showLoading({
  326. title: "加载中..."
  327. });
  328. setTimeout(function () {
  329. wx.hideLoading();
  330. }, 1600);
  331. setTimeout(() => {
  332. wx.redirectTo({
  333. url: `/pages/order/detail/index?orderId=${orderId}`
  334. });
  335. }, 1600);
  336. }
  337. });
  338. } else if (type == 'free'){
  339. wx.redirectTo({
  340. url: `/pages/order/detail/index?orderId=${orderId}`
  341. });
  342. }
  343. })
  344. .catch(err => {
  345. console.log(err)
  346. if (!type) {
  347. setTimeout(function () {
  348. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  349. }, 1500)
  350. }
  351. });
  352. },
  353. });