svip.vue 14 KB

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