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.

364 line
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. 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. goToOrderGroup(orderId, orderGroupId, _this) {
  200. console.log(22222222)
  201. let that = this;
  202. // 支付成功
  203. Http.post({
  204. url: config.api.toOrderGroup,
  205. data: {
  206. id: orderGroupId,
  207. orderId,
  208. couponId: _this.data.order.productId
  209. }
  210. })
  211. .then(res => {
  212. wx.redirectTo({
  213. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}`
  214. });
  215. })
  216. .catch(err => {
  217. console.log(err);
  218. })
  219. // return;
  220. },
  221. /**
  222. * 发起支付
  223. */
  224. orderFunc(e) {
  225. var that = this;
  226. that.setData({
  227. showButton: true
  228. })
  229. wx.showLoading({
  230. title: "加载中..."
  231. });
  232. const orderId = "" + that.data.orderId;
  233. if (that.data.order.payment > 0) {
  234. // 支付金额不为0
  235. Http.post({
  236. url: config.api.payOrderCreate,
  237. data: {
  238. orderId: orderId
  239. }
  240. }).then(res => {
  241. /// Begin payment ----
  242. that.setData({
  243. showButton: false
  244. })
  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. /// End payment --------
  284. });
  285. } else {
  286. // 免费券
  287. that.payOrderUpdate(orderId, "0", 1,'','free') // 支付成功
  288. if (that.data.order.type == 100) {
  289. wx.setStorage({
  290. key: 'couponNum2',
  291. data: "couponNum2"
  292. })
  293. } else if (that.data.order.type != "5") {
  294. wx.setStorage({
  295. key: 'couponNum',
  296. data: "couponNum"
  297. })
  298. }
  299. wx.showToast({
  300. title: "支付成功",
  301. duration: 2000,
  302. image: imgurl.success.url,
  303. });
  304. }
  305. },
  306. /**
  307. * 支付订单更新
  308. */
  309. payOrderUpdate: (orderId, payOrderId, status, reason,type,_this) => {
  310. // 支付成功
  311. Http.post({
  312. url: config.api.payOrderUpdate,
  313. data: {
  314. payOrderId: payOrderId,
  315. orderId: orderId,
  316. status: status,
  317. reason: reason
  318. }
  319. })
  320. .then(res => {
  321. wx.hideLoading()
  322. if (!type&&type!='free') {
  323. wx.showToast({
  324. title: "购买成功",
  325. duration: 2000,
  326. image: imgurl.success.url,
  327. mask: false,
  328. success: function () {
  329. wx.showLoading({
  330. title: "加载中..."
  331. });
  332. setTimeout(function () {
  333. wx.hideLoading();
  334. }, 1600);
  335. if (_this.data.order.type==9){
  336. _this.goToOrderGroup(orderId, 0, _this)
  337. }else{
  338. setTimeout(() => {
  339. wx.redirectTo({
  340. url: `/pages/order/detail/index?orderId=${orderId}`
  341. });
  342. }, 1600);
  343. }
  344. }
  345. });
  346. } else if (type == 'free'){
  347. wx.redirectTo({
  348. url: `/pages/order/detail/index?orderId=${orderId}`
  349. });
  350. }
  351. })
  352. .catch(err => {
  353. console.log(err)
  354. if (!type) {
  355. setTimeout(function () {
  356. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  357. }, 1500)
  358. }
  359. });
  360. },
  361. });