svip.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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 systemInfo.platform = '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. console.log('创建订单失败');
  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. const creatOrder = debounce((data) => {
  323. console.log('123123123123');
  324. disabled.value = true
  325. uni.showLoading({
  326. title: '',
  327. mask: true
  328. });
  329. if (payType.value == 'weixin') {
  330. let req = {
  331. cardId: cardId.value
  332. }
  333. console.log('创建订单11');
  334. orderAdd(req).then(res => {
  335. console.log('res', res);
  336. console.log(' res.data.id', res.data.id);
  337. orderId.value = res.data.id
  338. orderPayWx({
  339. id: res.data.id
  340. }).then(res2 => {
  341. uni.hideLoading();
  342. console.log('res2', res2);
  343. uni.requestPayment({
  344. "provider": "wxpay",
  345. "orderInfo": {
  346. "appid": res2.data.appid, // 应用ID(AppID)
  347. "partnerid": res2.data.partnerId, // 商户号(PartnerID)
  348. "prepayid": res2.data.prepayId, // 预支付交易会话ID
  349. "package": res2.data.packageVal, // 固定值
  350. "noncestr": res2.data.nonceStr, // 随机字符串
  351. "timestamp": res2.data.timestamp, // 时间戳(单位:秒)
  352. "sign": res2.data.sign // 签名,这里用的 MD5 签名
  353. }, //此处为服务器返回的订单信息字符串
  354. success: function(res) {
  355. //var rawdata = JSON.parse(res.rawdata);
  356. // console.log('res',res);
  357. // console.log('支付成功');
  358. // console.log('rawdata', rawdata);
  359. uni.showLoading({
  360. title: '会员开通中,请稍后...'
  361. });
  362. orderCheck({
  363. id: orderId.value
  364. }).then(res3 => {
  365. console.log('res3', res3);
  366. if (res3.code == 0 && res3.data) {
  367. genggaiVip()
  368. } else {
  369. setTimeout(() => {
  370. orderCheck({
  371. id: orderId.value
  372. }).then(res4 => {
  373. if (res4.code ==
  374. 0 && res4
  375. .data) {
  376. genggaiVip()
  377. } else {
  378. toast(
  379. "开通失败,请联系管理员!"
  380. )
  381. uni
  382. .hideLoading();
  383. return false
  384. }
  385. }).catch(() => {
  386. uni.hideLoading();
  387. toast("check接口报错")
  388. return false
  389. })
  390. }, 5000)
  391. }
  392. }).catch(() => {
  393. uni.hideLoading();
  394. toast("check接口报错")
  395. return false
  396. })
  397. },
  398. fail: function(err) {
  399. uni.hideLoading();
  400. // toast('支付失败:' + JSON.stringify(err));
  401. console.log('支付失败:' + JSON.stringify(err));
  402. }
  403. });
  404. }).catch((error) => {
  405. uni.hideLoading();
  406. disabled.value = false
  407. console.log(error);
  408. })
  409. }).catch((err) => {
  410. uni.hideLoading();
  411. disabled.value = false
  412. toast("订单创建失败")
  413. return false
  414. })
  415. } else {
  416. let req = {
  417. cardId: cardId.value
  418. }
  419. orderAdd(req).then(res => {
  420. console.log('res', res);
  421. orderId.value = res.data.id
  422. orderPayAli({
  423. id: res.data.id
  424. }).then(res2 => {
  425. console.log('res2', res2);
  426. uni.hideLoading();
  427. uni.requestPayment({
  428. "provider": "alipay",
  429. "orderInfo": res2.data.text, //此处为服务器返回的订单信息字符串
  430. success: function(res) {
  431. // var rawdata = JSON.parse(res.rawdata);
  432. // console.log('支付成功');
  433. // console.log('rawdata', rawdata);
  434. uni.showLoading({
  435. title: '会员开通中,请稍后...'
  436. });
  437. orderCheck({
  438. id: orderId.value
  439. }).then(res3 => {
  440. if (res3.code == 0 && res3.data) {
  441. genggaiVip()
  442. } else {
  443. setTimeout(() => {
  444. orderCheck({
  445. id: orderId.value
  446. }).then(res4 => {
  447. if (res4.code ==
  448. 0 && res4
  449. .data) {
  450. genggaiVip()
  451. } else {
  452. disabled
  453. .value =
  454. false
  455. toast(
  456. "开通失败,请联系管理员!"
  457. )
  458. uni
  459. .hideLoading();
  460. return false
  461. }
  462. }).catch(() => {
  463. disabled.value =
  464. false
  465. uni.hideLoading();
  466. toast("check接口报错")
  467. return false
  468. })
  469. }, 5000)
  470. }
  471. }).catch(() => {
  472. disabled.value = false
  473. uni.hideLoading();
  474. toast("check接口报错")
  475. return false
  476. })
  477. },
  478. fail: function(err) {
  479. disabled.value = false
  480. // toast('支付失败:' + JSON.stringify(err));
  481. console.log('支付失败:' + JSON.stringify(err));
  482. uni.hideLoading();
  483. }
  484. });
  485. })
  486. }).catch((err) => {
  487. disabled.value = false
  488. uni.hideLoading();
  489. toast("订单创建失败")
  490. return false
  491. })
  492. }
  493. }, 500)
  494. function goBack(data) {
  495. if (formPage.value == 'my') {
  496. uni.redirectTo({
  497. url: '/pages/my/index'
  498. })
  499. } else {
  500. uni.redirectTo({
  501. url: '/pages/study/index'
  502. })
  503. }
  504. }
  505. </script>
  506. <style>
  507. </style>