svip.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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. disabled.value = false
  154. }
  155. function genggaiVip() {
  156. uni.hideLoading();
  157. //disabled.value = false
  158. cacheManager.updateVipStatus('auth', cardId.value)
  159. cacheManager.updateObject('auth', {
  160. growthType: 1
  161. })
  162. console.log('isVip', isVip);
  163. if (isVip != 'VIP') {
  164. daoPokeRef.value.handleShow();
  165. } else {
  166. daoPokeAllRef.value.handleShow();
  167. }
  168. setTimeout(() => {
  169. daoPokeRef.value.handleClose();
  170. daoPokeAllRef.value.handleClose();
  171. if (formPage.value == 'my') {
  172. uni.redirectTo({
  173. url: '/pages/my/index'
  174. })
  175. } else {
  176. uni.redirectTo({
  177. url: '/pages/study/index'
  178. })
  179. }
  180. }, 3000)
  181. }
  182. const creatOrderIos = debounce((data => {
  183. disabled.value = true
  184. uni.showLoading({
  185. title: '',
  186. mask: true
  187. });
  188. if (appleFlag.value.toString() == 'true') {
  189. productId.value = 'llisoftEzhuangyuanceshi'
  190. } else {
  191. if (cardId.value == 1) {
  192. productId.value = 'llisoftEzhuangyuan'
  193. } else {
  194. productId.value = 'llisoftEzhuangyuanYingyu'
  195. }
  196. }
  197. if (orderId.value) {
  198. uni.hideLoading();
  199. applePay()
  200. } else {
  201. let req = {
  202. cardId: cardId.value
  203. }
  204. orderAdd(req).then(res => {
  205. console.log('res', res);
  206. if (res.code == 0) {
  207. uni.hideLoading();
  208. orderId.value = res.data.id
  209. // 测试ios 1元
  210. applePay()
  211. } else {
  212. uni.hideLoading();
  213. //disabled.value = false
  214. return false
  215. console.log('请求失败');
  216. }
  217. }).catch((e) => {
  218. uni.hideLoading();
  219. disabled.value = false
  220. toast("订单创建失败")
  221. return false
  222. })
  223. }
  224. }), 500)
  225. function applePaySuccess(data) {
  226. uni.showLoading({
  227. title: '会员开通中',
  228. mask: true
  229. });
  230. let req = {
  231. "id": orderId.value,
  232. "paynum": data.transactionIdentifier,
  233. "receipt": data.transactionReceipt
  234. }
  235. console.log('reqreq', req);
  236. orderPayApple(req).then(res => {
  237. if (res.code == 0 && res.data) {
  238. iapChannel.finishTransaction(data.transactionIdentifier)
  239. console.log('resiapChanneliapChanneliapChannel', res);
  240. genggaiVip()
  241. } else {
  242. //disabled.value = false
  243. iapChannel.finishTransaction(data.transactionIdentifier)
  244. uni.hideLoading();
  245. toast("苹果内购失败")
  246. console.log('orderPayApple失败');
  247. return false
  248. }
  249. })
  250. }
  251. function applePay() {
  252. console.log('123123');
  253. if (!productId.value) {
  254. uni.showToast({
  255. title: '苹果内购ID缺失,请选择其它支付方式或联系客服',
  256. icon: "none"
  257. });
  258. return false;
  259. }
  260. uni.showLoading({
  261. title: '正在支付中...'
  262. });
  263. try {
  264. plus.payment.getChannels(function(channels) { //判读项目支付通道开通情况
  265. for (var i in channels) {
  266. iapChannel = channels[i];
  267. // 获取 id 为 'appleiap' 的 channel
  268. console.info("支付通道", iapChannel)
  269. if (iapChannel.id === 'appleiap') { //开通了app应用内支付,在manifest.josn中设置,开通后需打自定议基座
  270. console.info("苹果支付通道", iapChannel)
  271. // ids 数组中的项为 App Store Connect 配置的内购买项目产品ID(productId)
  272. var ids = [productId.value];
  273. // iap 为应用内支付对象
  274. iapChannel.requestOrder(ids, function(e) {
  275. // 获取订单信息成功回调方法
  276. console.log('requestOrder success: ' + JSON.stringify(e));
  277. uni.requestPayment({
  278. provider: 'appleiap',
  279. orderInfo: {
  280. productid: productId.value, //产品id,来自于苹果
  281. quantity: quantity.value, //产品数量
  282. manualFinishTransaction: true
  283. },
  284. success: (e) => {
  285. uni.hideLoading();
  286. // toast("苹果内购成功")
  287. console.info("苹果内购成功", e)
  288. applePaySuccess(e)
  289. //e.payment.orderNo = that.orderNo
  290. //支付成功回调,前端调用后台接口
  291. },
  292. fail: (e) => {
  293. // disabled.value = false
  294. uni.hideLoading();
  295. toast("苹果内购失败")
  296. console.info("苹果内购失败", e)
  297. },
  298. })
  299. },
  300. function(e) {
  301. // 获取订单信息失败回调方法
  302. console.log('requestOrder failed: ' + JSON.stringify(e));
  303. });
  304. } else {
  305. console.log('不支持苹果支付')
  306. }
  307. }
  308. },
  309. function(e) {
  310. console.log("获取iap支付通道失败:" + e.message);
  311. });
  312. } catch (e) {
  313. uni.showModal({
  314. title: "init",
  315. content: e.message,
  316. showCancel: false
  317. });
  318. // disabled.value = false
  319. } finally {
  320. uni.hideLoading();
  321. }
  322. }
  323. function wxPay() {
  324. orderPayWx({
  325. id: orderId.value
  326. }).then(res2 => {
  327. uni.hideLoading();
  328. console.log('res2', res2);
  329. uni.requestPayment({
  330. "provider": "wxpay",
  331. "orderInfo": {
  332. "appid": res2.data.appid, // 应用ID(AppID)
  333. "partnerid": res2.data.partnerId, // 商户号(PartnerID)
  334. "prepayid": res2.data.prepayId, // 预支付交易会话ID
  335. "package": res2.data.packageVal, // 固定值
  336. "noncestr": res2.data.nonceStr, // 随机字符串
  337. "timestamp": res2.data.timestamp, // 时间戳(单位:秒)
  338. "sign": res2.data.sign // 签名,这里用的 MD5 签名
  339. }, //此处为服务器返回的订单信息字符串
  340. success: function(res) {
  341. //var rawdata = JSON.parse(res.rawdata);
  342. // console.log('res',res);
  343. // console.log('支付成功');
  344. // console.log('rawdata', rawdata);
  345. uni.showLoading({
  346. title: '会员开通中,请稍后...'
  347. });
  348. orderCheck({
  349. id: orderId.value
  350. }).then(res3 => {
  351. console.log('res3', res3);
  352. if (res3.code == 0 && res3.data) {
  353. genggaiVip()
  354. } else {
  355. setTimeout(() => {
  356. orderCheck({
  357. id: orderId.value
  358. }).then(res4 => {
  359. if (res4.code ==
  360. 0 && res4
  361. .data) {
  362. genggaiVip()
  363. } else {
  364. toast(
  365. "开通失败,请联系管理员!"
  366. )
  367. uni
  368. .hideLoading();
  369. return false
  370. }
  371. }).catch(() => {
  372. uni.hideLoading();
  373. toast("check接口报错")
  374. return false
  375. })
  376. }, 5000)
  377. }
  378. }).catch(() => {
  379. uni.hideLoading();
  380. toast("check接口报错")
  381. return false
  382. })
  383. },
  384. fail: function(err) {
  385. uni.hideLoading();
  386. // toast('支付失败:' + JSON.stringify(err));
  387. console.log('支付失败:' + JSON.stringify(err));
  388. }
  389. });
  390. }).catch((error) => {
  391. uni.hideLoading();
  392. // disabled.value = false
  393. console.log(error);
  394. })
  395. }
  396. function aliApy(){
  397. orderPayAli({
  398. id: orderId.value
  399. }).then(res2 => {
  400. console.log('res2', res2);
  401. uni.hideLoading();
  402. uni.requestPayment({
  403. "provider": "alipay",
  404. "orderInfo": res2.data.text, //此处为服务器返回的订单信息字符串
  405. success: function(res) {
  406. // var rawdata = JSON.parse(res.rawdata);
  407. // console.log('支付成功');
  408. // console.log('rawdata', rawdata);
  409. uni.showLoading({
  410. title: '会员开通中,请稍后...'
  411. });
  412. orderCheck({
  413. id: orderId.value
  414. }).then(res3 => {
  415. if (res3.code == 0 && res3.data) {
  416. genggaiVip()
  417. } else {
  418. setTimeout(() => {
  419. orderCheck({
  420. id: orderId.value
  421. }).then(res4 => {
  422. if (res4.code ==
  423. 0 && res4
  424. .data) {
  425. genggaiVip()
  426. } else {
  427. // disabled.value =false
  428. toast(
  429. "开通失败,请联系管理员!"
  430. )
  431. uni
  432. .hideLoading();
  433. return false
  434. }
  435. }).catch(() => {
  436. // disabled.value =false
  437. uni.hideLoading();
  438. toast("check接口报错")
  439. return false
  440. })
  441. }, 5000)
  442. }
  443. }).catch(() => {
  444. // disabled.value = false
  445. uni.hideLoading();
  446. toast("check接口报错")
  447. return false
  448. })
  449. },
  450. fail: function(err) {
  451. // disabled.value = false
  452. // toast('支付失败:' + JSON.stringify(err));
  453. console.log('支付失败:' + JSON.stringify(err));
  454. uni.hideLoading();
  455. }
  456. });
  457. })
  458. }
  459. const creatOrder = debounce((data) => {
  460. console.log('123123123123');
  461. disabled.value = true
  462. uni.showLoading({
  463. title: '',
  464. mask: true
  465. });
  466. if (payType.value == 'weixin') {
  467. console.log('创建订单11');
  468. if (orderId.value) {
  469. wxPay()
  470. } else {
  471. let req = {
  472. cardId: cardId.value
  473. }
  474. orderAdd(req).then(res => {
  475. console.log('res', res);
  476. console.log(' res.data.id', res.data.id);
  477. orderId.value = res.data.id
  478. wxPay()
  479. }).catch((err) => {
  480. uni.hideLoading();
  481. disabled.value = false
  482. toast("订单创建失败")
  483. return false
  484. })
  485. }
  486. } else {
  487. if(orderId.value){
  488. aliApy()
  489. }else{
  490. let req = {
  491. cardId: cardId.value
  492. }
  493. orderAdd(req).then(res => {
  494. console.log('res', res);
  495. orderId.value = res.data.id
  496. aliApy()
  497. }).catch((err) => {
  498. disabled.value = false
  499. uni.hideLoading();
  500. toast("订单创建失败")
  501. return false
  502. })
  503. }
  504. }
  505. }, 500)
  506. function goBack(data) {
  507. if (formPage.value == 'my') {
  508. uni.redirectTo({
  509. url: '/pages/my/index'
  510. })
  511. } else {
  512. uni.redirectTo({
  513. url: '/pages/study/index'
  514. })
  515. }
  516. }
  517. </script>
  518. <style>
  519. </style>