svip.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <!-- svip页面 -->
  2. <template>
  3. <view class="ezy-svip-page">
  4. <view class="icon-title-navBar-box">
  5. <!-- 返回按钮 ↓ -->
  6. <view class="nav-bar-icon" @click="goBack"></view>
  7. <view class="nav-bar-title">开通svip</view>
  8. </view>
  9. <!-- :class="'svip-login'+Id" 改到下方 -->
  10. <icon :class="'svip-login'+cardId"></icon>
  11. <view class="svip-list-box">
  12. <view v-for="(item, index) in svipArr" :key="index" class="list-item-box">
  13. <icon class="list-icon" :style="{backgroundImage: 'url(' + item.iconPath + ')'}"></icon>
  14. <view>
  15. <view class="list-title">{{item.title}}</view>
  16. <view class="list-content" v-html="item.content"></view>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="open-svip-box">
  21. <view class="svip-price-box" v-if="cardId ==1">
  22. <view>原价:<text class="original-price">¥499</text></view>
  23. <view class="discount-price">活动价:¥299</view>
  24. </view>
  25. <view class="svip-price-box" v-if="cardId ==2">
  26. <view>原价:<text class="original-price">¥399</text></view>
  27. <view class="discount-price">活动价:¥199</view>
  28. </view>
  29. <radio-group v-if="currentPlatform =='android'" @change="radioChange" class="pay-type-box">
  30. <view class="type-radio-title">支付方式</view>
  31. <view class="type-radio-content">
  32. <view class="type-radio-box">
  33. <icon class="wx-radio"></icon>
  34. <text>微信</text>
  35. <radio value="weixin" :checked="payType==='weixin'" activeBackgroundColor="transparent"
  36. :class="{'radio-checked': payType==='weixin'}" />
  37. </view>
  38. <view class="type-radio-box">
  39. <icon class="zfb-radio"></icon>
  40. <text>支付宝</text>
  41. <radio value="zhifubao" :checked="payType==='zhifubao'" activeBackgroundColor="transparent"
  42. :class="{'radio-checked': payType==='zhifubao'}" style="margin-right: 0;" />
  43. </view>
  44. </view>
  45. </radio-group>
  46. <view v-if="currentPlatform =='android'" class="open-svip-btn" @touchstart="creatOrder">立即开通</view>
  47. <view v-if="currentPlatform =='ios'&&!disabled" style="margin-top: 20rpx;" class="open-svip-btn"
  48. @touchstart="creatOrderIos">立即开通</view>
  49. <view v-if="currentPlatform =='ios'&&disabled" style="margin-top: 20rpx;" class="open-svip-btn-hui"
  50. >立即开通</view>
  51. </view>
  52. <CustomTabBar></CustomTabBar>
  53. <!-- 蛋破壳 -->
  54. <pay-success ref="daoPokeRef"></pay-success>
  55. <pay-successAll ref="daoPokeAllRef"></pay-successAll>
  56. </view>
  57. </template>
  58. <script setup>
  59. import {
  60. ref
  61. } from "vue";
  62. import {
  63. orderAdd,
  64. orderPayAli,
  65. orderPayWx,
  66. orderPayApple,
  67. orderCheck
  68. } from "@/api/order.js"
  69. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  70. import cacheManager from "@/utils/cacheManager.js";
  71. import paySuccess from './paySuccess.vue';
  72. import paySuccessAll from './paySuccessAll.vue';
  73. import {
  74. onLoad,
  75. onReady
  76. } from '@dcloudio/uni-app';
  77. import {
  78. toast,
  79. getUserIdentity
  80. } from "@/utils/common";
  81. import {
  82. debounce
  83. } from "@/utils/common";
  84. let payType = ref('zhifubao')
  85. let cardId = ref('')
  86. let formPage = ref('')
  87. let isLoading = ref(false)
  88. const daoPokeRef = ref(null);
  89. const daoPokeAllRef = ref(null);
  90. let orderId = ref('');
  91. let productId = ref(null)
  92. let iapChannel = ref(null)
  93. let quantity = ref(1)
  94. let channel = ref('')
  95. let disabled = ref(false)
  96. let appleFlag = ref('')
  97. let currentPlatform = ref('')
  98. const isVip = getUserIdentity();
  99. const svipArr = [{
  100. iconPath: 'static/images/pay/svip-list-icon1.png',
  101. title: '学习资源,随心畅学',
  102. content: `解锁L1~L6全等级数学思维优质学习资源,<br/>满足多样学习需求`
  103. },
  104. {
  105. iconPath: 'static/images/pay/svip-list-icon2.png',
  106. title: '名师打造,优质路径',
  107. content: '资深名师精心规划学习路径,引领高效提升方向'
  108. },
  109. {
  110. iconPath: 'static/images/pay/svip-list-icon3.png',
  111. title: '进度分析,个性贴心',
  112. content: '优先参与丰富真题测试,精准洞察学习状况'
  113. },
  114. {
  115. iconPath: 'static/images/pay/svip-list-icon4.png',
  116. title: '真题测试,优先体验',
  117. content: '成为会员,即刻畅享专属权益,开启无忧学习之旅'
  118. }
  119. ];
  120. onLoad((options) => {
  121. isIOSorAndroid()
  122. appleFlag.value = cacheManager.get("auth").appleFlag
  123. console.log('appleFlag', appleFlag.value);
  124. cardId.value = options.cardId
  125. formPage.value = options.formPage
  126. if (options.orderId) {
  127. orderId.value = options.orderId
  128. } else {
  129. orderId.value = ''
  130. }
  131. })
  132. const isIOSorAndroid = () => {
  133. const systemInfo = uni.getSystemInfoSync();
  134. console.log('systemInfo', systemInfo);
  135. if (systemInfo.platform == 'ios') {
  136. return currentPlatform.value = 'ios'
  137. } else {
  138. return systemInfo.platform = 'android'
  139. }
  140. }
  141. function radioChange(data) {
  142. payType.value = data.detail.value;
  143. }
  144. function genggaiVip() {
  145. uni.hideLoading();
  146. isLoading.value = false;
  147. cacheManager.updateVipStatus('auth', cardId.value)
  148. cacheManager.updateObject('auth', {
  149. growthType: 1
  150. })
  151. console.log('isVip', isVip);
  152. if (isVip != 'VIP') {
  153. daoPokeRef.value.handleShow();
  154. } else {
  155. daoPokeAllRef.value.handleShow();
  156. }
  157. setTimeout(() => {
  158. daoPokeRef.value.handleClose();
  159. daoPokeAllRef.value.handleClose();
  160. if (formPage.value == 'my') {
  161. uni.redirectTo({
  162. url: '/pages/my/index'
  163. })
  164. } else {
  165. uni.redirectTo({
  166. url: '/pages/study/index'
  167. })
  168. }
  169. }, 3000)
  170. }
  171. const creatOrderIos = debounce((data => {
  172. disabled.value = true
  173. uni.showLoading({
  174. title: '',
  175. mask: true
  176. });
  177. if (appleFlag.value.toString() == 'true') {
  178. productId.value = 'llisoftEzhuangyuanceshi'
  179. } else {
  180. if (cardId.value == 1) {
  181. productId.value = 'llisoftEzhuangyuan'
  182. } else {
  183. productId.value = 'llisoftEzhuangyuanYingyu'
  184. }
  185. }
  186. if (orderId.value) {
  187. uni.hideLoading();
  188. applePay()
  189. } else {
  190. let req = {
  191. cardId: cardId.value
  192. }
  193. orderAdd(req).then(res => {
  194. console.log('res', res);
  195. if (res.code == 0) {
  196. uni.hideLoading();
  197. orderId.value = res.data.id
  198. // 测试ios 1元
  199. applePay()
  200. } else {
  201. uni.hideLoading();
  202. disabled.value = false
  203. return false
  204. console.log('请求失败');
  205. }
  206. }).catch((e) => {
  207. uni.hideLoading();
  208. disabled.value = false
  209. console.log('创建订单失败');
  210. return false
  211. })
  212. }
  213. }), 500)
  214. function applePaySuccess(data) {
  215. uni.showLoading({
  216. title: '会员开通中',
  217. mask: true
  218. });
  219. let req = {
  220. "id": orderId.value,
  221. "paynum": data.transactionIdentifier,
  222. "receipt": data.transactionReceipt
  223. }
  224. console.log('reqreq', req);
  225. orderPayApple(req).then(res => {
  226. if (res.code == 0 && res.data) {
  227. iapChannel.finishTransaction(data.transactionIdentifier)
  228. console.log('resiapChanneliapChanneliapChannel', res);
  229. genggaiVip()
  230. } else {
  231. disabled.value = false
  232. iapChannel.finishTransaction(data.transactionIdentifier)
  233. uni.hideLoading();
  234. toast("苹果内购失败")
  235. console.log('orderPayApple失败');
  236. return false
  237. }
  238. })
  239. }
  240. function applePay() {
  241. console.log('123123');
  242. if (!productId.value) {
  243. uni.showToast({
  244. title: '苹果内购ID缺失,请选择其它支付方式或联系客服',
  245. icon: "none"
  246. });
  247. return false;
  248. }
  249. uni.showLoading({
  250. title: '正在支付中...'
  251. });
  252. try {
  253. plus.payment.getChannels(function(channels) { //判读项目支付通道开通情况
  254. for (var i in channels) {
  255. iapChannel = channels[i];
  256. // 获取 id 为 'appleiap' 的 channel
  257. console.info("支付通道", iapChannel)
  258. if (iapChannel.id === 'appleiap') { //开通了app应用内支付,在manifest.josn中设置,开通后需打自定议基座
  259. console.info("苹果支付通道", iapChannel)
  260. // ids 数组中的项为 App Store Connect 配置的内购买项目产品ID(productId)
  261. var ids = [productId.value];
  262. // iap 为应用内支付对象
  263. iapChannel.requestOrder(ids, function(e) {
  264. // 获取订单信息成功回调方法
  265. console.log('requestOrder success: ' + JSON.stringify(e));
  266. uni.requestPayment({
  267. provider: 'appleiap',
  268. orderInfo: {
  269. productid: productId.value, //产品id,来自于苹果
  270. quantity: quantity.value, //产品数量
  271. manualFinishTransaction: true
  272. },
  273. success: (e) => {
  274. uni.hideLoading();
  275. // toast("苹果内购成功")
  276. console.info("苹果内购成功", e)
  277. applePaySuccess(e)
  278. //e.payment.orderNo = that.orderNo
  279. //支付成功回调,前端调用后台接口
  280. },
  281. fail: (e) => {
  282. disabled.value = false
  283. uni.hideLoading();
  284. toast("苹果内购失败")
  285. console.info("苹果内购失败", e)
  286. },
  287. })
  288. },
  289. function(e) {
  290. // 获取订单信息失败回调方法
  291. console.log('requestOrder failed: ' + JSON.stringify(e));
  292. });
  293. } else {
  294. console.log('不支持苹果支付')
  295. }
  296. }
  297. },
  298. function(e) {
  299. console.log("获取iap支付通道失败:" + e.message);
  300. });
  301. } catch (e) {
  302. uni.showModal({
  303. title: "init",
  304. content: e.message,
  305. showCancel: false
  306. });
  307. disabled.value = false
  308. } finally {
  309. uni.hideLoading();
  310. }
  311. }
  312. const creatOrder = debounce((data) => {
  313. console.log('123123123123');
  314. if (isLoading.value) {
  315. return
  316. }
  317. isLoading.value = true;
  318. uni.showLoading({
  319. title: '',
  320. mask: true
  321. });
  322. if (payType.value == 'weixin') {
  323. let req = {
  324. cardId: cardId.value
  325. }
  326. console.log('创建订单11');
  327. orderAdd(req).then(res => {
  328. console.log('res', res);
  329. console.log(' res.data.id', res.data.id);
  330. orderId.value = res.data.id
  331. orderPayWx({
  332. id: res.data.id
  333. }).then(res2 => {
  334. uni.hideLoading();
  335. isLoading.value = false;
  336. console.log('res2', res2);
  337. uni.requestPayment({
  338. "provider": "wxpay",
  339. "orderInfo": {
  340. "appid": res2.data.appid, // 应用ID(AppID)
  341. "partnerid": res2.data.partnerId, // 商户号(PartnerID)
  342. "prepayid": res2.data.prepayId, // 预支付交易会话ID
  343. "package": res2.data.packageVal, // 固定值
  344. "noncestr": res2.data.nonceStr, // 随机字符串
  345. "timestamp": res2.data.timestamp, // 时间戳(单位:秒)
  346. "sign": res2.data.sign // 签名,这里用的 MD5 签名
  347. }, //此处为服务器返回的订单信息字符串
  348. success: function(res) {
  349. //var rawdata = JSON.parse(res.rawdata);
  350. // console.log('res',res);
  351. // console.log('支付成功');
  352. // console.log('rawdata', rawdata);
  353. uni.showLoading({
  354. title: '会员开通中,请稍后...'
  355. });
  356. orderCheck({
  357. id: orderId.value
  358. }).then(res3 => {
  359. console.log('res3', res3);
  360. if (res3.code == 0 && res3.data) {
  361. genggaiVip()
  362. } else {
  363. setTimeout(() => {
  364. orderCheck({
  365. id: orderId.value
  366. }).then(res4 => {
  367. if (res4.code ==
  368. 0 && res4
  369. .data) {
  370. genggaiVip()
  371. } else {
  372. toast(
  373. "开通失败,请联系管理员!"
  374. )
  375. uni
  376. .hideLoading();
  377. return false
  378. }
  379. }).catch(() => {
  380. uni.hideLoading();
  381. toast("check接口报错")
  382. return false
  383. })
  384. }, 5000)
  385. }
  386. }).catch(() => {
  387. uni.hideLoading();
  388. toast("check接口报错")
  389. return false
  390. })
  391. },
  392. fail: function(err) {
  393. uni.hideLoading();
  394. // toast('支付失败:' + JSON.stringify(err));
  395. console.log('支付失败:' + JSON.stringify(err));
  396. }
  397. });
  398. }).catch((error) => {
  399. uni.hideLoading();
  400. isLoading.value = false;
  401. console.log(error);
  402. })
  403. }).catch((err) => {
  404. uni.hideLoading();
  405. isLoading.value = false;
  406. toast("订单创建失败")
  407. return false
  408. })
  409. } else {
  410. let req = {
  411. cardId: cardId.value
  412. }
  413. orderAdd(req).then(res => {
  414. console.log('res', res);
  415. orderId.value = res.data.id
  416. orderPayAli({
  417. id: res.data.id
  418. }).then(res2 => {
  419. console.log('res2', res2);
  420. uni.hideLoading();
  421. isLoading.value = false;
  422. uni.requestPayment({
  423. "provider": "alipay",
  424. "orderInfo": res2.data.text, //此处为服务器返回的订单信息字符串
  425. success: function(res) {
  426. // var rawdata = JSON.parse(res.rawdata);
  427. // console.log('支付成功');
  428. // console.log('rawdata', rawdata);
  429. uni.showLoading({
  430. title: '会员开通中,请稍后...'
  431. });
  432. orderCheck({
  433. id: orderId.value
  434. }).then(res3 => {
  435. if (res3.code == 0 && res3.data) {
  436. genggaiVip()
  437. } else {
  438. setTimeout(() => {
  439. orderCheck({
  440. id: orderId.value
  441. }).then(res4 => {
  442. if (res4.code ==
  443. 0 && res4
  444. .data) {
  445. genggaiVip()
  446. } else {
  447. isLoading
  448. .value =
  449. false;
  450. toast(
  451. "开通失败,请联系管理员!"
  452. )
  453. uni
  454. .hideLoading();
  455. return false
  456. }
  457. }).catch(() => {
  458. isLoading.value =
  459. false;
  460. uni.hideLoading();
  461. toast("check接口报错")
  462. return false
  463. })
  464. }, 5000)
  465. }
  466. }).catch(() => {
  467. isLoading.value = false;
  468. uni.hideLoading();
  469. toast("check接口报错")
  470. return false
  471. })
  472. },
  473. fail: function(err) {
  474. isLoading.value = false;
  475. // toast('支付失败:' + JSON.stringify(err));
  476. console.log('支付失败:' + JSON.stringify(err));
  477. uni.hideLoading();
  478. }
  479. });
  480. })
  481. }).catch((err) => {
  482. isLoading.value = false;
  483. uni.hideLoading();
  484. toast("订单创建失败")
  485. return false
  486. })
  487. }
  488. }, 500)
  489. function goBack(data) {
  490. if (formPage.value == 'my') {
  491. uni.redirectTo({
  492. url: '/pages/my/index'
  493. })
  494. } else {
  495. uni.redirectTo({
  496. url: '/pages/study/index'
  497. })
  498. }
  499. }
  500. </script>
  501. <style>
  502. </style>