svip.vue 14 KB

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