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.

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