pay.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. import {
  2. orderInfoSubmit,
  3. gotoMicroPay,
  4. gotoCashPay,
  5. payQuery,
  6. selectRegion,
  7. orderInfoCancel,
  8. factorAuth,
  9. selectMarketTeamBySourceApi,
  10. } from '@/api/windowTicketSales/ticketingSales'
  11. import {
  12. gotoCorporatePay,
  13. downOrderListXls,
  14. teamPayOrderUrlApi,
  15. balancePay as gotoBalancePay,
  16. creditPay as gotoQuotaPay
  17. } from '@/api/order/groupBuyingMr';
  18. import { pageList as getPrintListApi } from "@/api/device/pda";
  19. import { printApi } from '@/api/windowTicketSales/ticketingCollection'
  20. import { rebookApi } from '@/api/windowTicketSales/rebook'
  21. const mathM = require('mathjs')
  22. const https = require('https');
  23. const axios = require('axios');
  24. export default {
  25. data(){
  26. return {}
  27. },
  28. methods: {
  29. /** 取消订单 */
  30. async orderInfoCancelFun(type){
  31. // let payStatus = this.payStatus
  32. // this.payStatus = null
  33. try {
  34. this.loading = true
  35. this.loadingText = "取消订单中..."
  36. orderInfoCancel({
  37. orderId: this.orderId
  38. }).then((res)=>{
  39. if(res.code==200) {
  40. if(type){ // 关闭弹窗
  41. if(this.codeTime) {
  42. clearInterval(this.codeTime)
  43. }
  44. this.orderId = null
  45. this.payStatus = null
  46. this.$emit('clearDialogVisible')
  47. this.rebookDialog = false
  48. }else {
  49. this.payStatus = 9
  50. this.loading = false
  51. }
  52. }else {
  53. }
  54. }).catch(()=>{
  55. this.$message.error('订单关闭失败!!!');
  56. })
  57. } catch (error) {
  58. }
  59. },
  60. /** 生成订单 */
  61. async orderInfoSubmitFun(){
  62. this.loading = true
  63. try {
  64. this.orderId = null
  65. this.loadingText = "生成订单中..."
  66. let res = await rebookApi({
  67. ...this.rebookForm
  68. })
  69. if(res.code == 200){
  70. this.orderId = res.data.orderId
  71. if(this.rebookForm.paymentType == 2) { // 现金支付
  72. this.gotoCashPayFun(this.orderId)
  73. }else if(this.rebookForm.paymentType == 3 || this.rebookForm.paymentType == 6) { // 对公支付
  74. this.gotoCorporatePayFun(this.orderId)
  75. }else if(this.rebookForm.paymentType == 4){ // 账户余额
  76. this.gotoBalancePayFun(this.orderId)
  77. }else if(this.rebookForm.paymentType == 5){ // 授信余额
  78. this.gotoQuotaPayFun(this.orderId)
  79. }else if(this.rebookForm.paymentType == 7) {
  80. this.handPlaceAnOrder()
  81. }
  82. else {
  83. // 扫码支付
  84. this.loading = false
  85. this.payStatus = 2
  86. }
  87. }else{
  88. this.$message.error('生成订单失败!!!');
  89. this.loading = false
  90. this.payStatus = 1
  91. }
  92. } catch (error) {
  93. console.error(error)
  94. this.$message.error('生成订单失败!!!');
  95. this.loading = false
  96. this.payStatus = 1
  97. }
  98. },
  99. /** 调取 订单支付码支付 */
  100. async gotoMicroPayFun(orderId,code){
  101. this.loading = true
  102. try {
  103. this.loadingText = "订单支付中..."
  104. this.payStatus = ''
  105. let res = await gotoMicroPay({
  106. "orderId": orderId, // 订单编号-提交订单返回
  107. "authCode": code // 微信扫码支付-支付码
  108. })
  109. if(res.code == 200){
  110. this.payTimeNum = 0
  111. this.websocketClear()
  112. if(this.payTime){
  113. clearInterval(this.payTime)
  114. }
  115. this.payTime = setInterval(()=>{
  116. this.payQueryFun(this.orderId)
  117. },1500)
  118. }else{
  119. this.$message.error('支付失败!!!');
  120. this.payStatus = ''
  121. this.loading = false
  122. this.payStatus = 6
  123. }
  124. } catch (error) {
  125. this.$message.error('支付失败!!!');
  126. this.loading = false
  127. this.payStatus = 6
  128. }
  129. },
  130. /** 对公支付 */
  131. async gotoCorporatePayFun(orderId) {
  132. this.loading = true
  133. try {
  134. this.loadingText = "订单入库中..."
  135. let res = await gotoCorporatePay({
  136. "orderId": orderId, // 订单编号-提交订单返回
  137. "payAmount": this.rebookForm.realPrice,
  138. payOrCredit: this.rebookForm.paymentType = 3 ? '1' : '2',
  139. rePaymentTime: this.rebookForm.rePaymentTime,
  140. corporate: {
  141. voucherUrl: this.form.photoList.map(item => item).join(","),
  142. remark: this.form.corporate.remark
  143. }
  144. })
  145. if(res.code == 200){
  146. if(this.payTime){
  147. clearInterval(this.payTime)
  148. }
  149. this.payTimeNum = 0
  150. this.payTime = setInterval(()=>{
  151. this.payQueryFun(this.orderId)
  152. },1000)
  153. }else{
  154. this.$message.error('订单入库中失败!!!');
  155. this.loading = false
  156. this.payStatus = 3
  157. }
  158. } catch (error) {
  159. this.$message.error('订单入库中失败!!!');
  160. this.loading = false
  161. this.payStatus = 3
  162. }
  163. },
  164. /** 授信额度支付 */
  165. async gotoQuotaPayFun(orderId) {
  166. this.loading = true
  167. try {
  168. this.loadingText = "订单入库中..."
  169. let res = await gotoQuotaPay({
  170. "orderId": orderId, // 订单编号-提交订单返回
  171. })
  172. if(res.code == 200){
  173. if(this.payTime){
  174. clearInterval(this.payTime)
  175. }
  176. this.payTimeNum = 0
  177. this.payTime = setInterval(()=>{
  178. this.payQueryFun(this.orderId)
  179. },1000)
  180. }else{
  181. this.$message.error('订单入库中失败!!!');
  182. this.loading = false
  183. this.payStatus = 3
  184. }
  185. } catch (error) {
  186. this.$message.error('订单入库中失败!!!');
  187. this.loading = false
  188. this.payStatus = 3
  189. }
  190. },
  191. /** 余额支付 */
  192. async gotoBalancePayFun(orderId) {
  193. this.loading = true
  194. try {
  195. this.loadingText = "订单入库中..."
  196. let res = await gotoBalancePay({
  197. "orderId": orderId, // 订单编号-提交订单返回
  198. })
  199. if(res.code == 200){
  200. if(this.payTime){
  201. clearInterval(this.payTime)
  202. }
  203. this.payTimeNum = 0
  204. this.payTime = setInterval(()=>{
  205. this.payQueryFun(this.orderId)
  206. },1000)
  207. }else{
  208. this.$message.error('订单入库中失败!!!');
  209. this.loading = false
  210. this.payStatus = 3
  211. }
  212. } catch (error) {
  213. this.$message.error('订单入库中失败!!!');
  214. this.loading = false
  215. this.payStatus = 3
  216. }
  217. },
  218. /** 订单现金支付 */
  219. async gotoCashPayFun(orderId){
  220. this.loading = true
  221. try {
  222. this.loadingText = "订单入库中..."
  223. let res = await gotoCashPay({
  224. "orderId": orderId, // 订单编号-提交订单返回
  225. "payAmount": this.rebookForm.realPrice
  226. })
  227. if(res.code == 200){
  228. if(this.payTime){
  229. clearInterval(this.payTime)
  230. }
  231. this.payTimeNum = 0
  232. this.payTime = setInterval(()=>{
  233. this.payQueryFun(this.orderId)
  234. },1000)
  235. }else{
  236. this.$message.error('订单入库中失败!!!');
  237. this.loading = false
  238. this.payStatus = 3
  239. }
  240. } catch (error) {
  241. this.$message.error('订单入库中失败!!!');
  242. this.loading = false
  243. this.payStatus = 3
  244. }
  245. },
  246. /** 链接支付 */
  247. handPlaceAnOrder() {
  248. this.$confirm("确认要生成该订单的支付链接吗?温馨提示:请勿随意将链接发送给陌生人", '提示', {
  249. confirmButtonText: '生成并复制链接',
  250. cancelButtonText: '取消',
  251. type: 'warning'
  252. }).then(() => {
  253. teamPayOrderUrlApi({ orderId: this.orderId }).then((res) => {
  254. if (res.code == 200) {
  255. this.$message({
  256. type: 'success',
  257. message: res.msg
  258. });
  259. this.copyToClipboard(res.data.url)
  260. }
  261. });
  262. }).catch(() => { }).finally(() => {
  263. });
  264. },
  265. /** 复制内容 */
  266. copyToClipboard(text) {
  267. // 创建一个临时的textarea元素
  268. const tempInput = document.createElement('textarea');
  269. tempInput.value = text;
  270. document.body.appendChild(tempInput);
  271. tempInput.select();
  272. document.execCommand('copy');
  273. document.body.removeChild(tempInput);
  274. },
  275. // 跳转取票界面
  276. goTicketingCollections(){
  277. this.$router.push({
  278. path:"/windowTicketSales/ticketingCollections",
  279. query:{
  280. orderId: this.orderId
  281. }
  282. })
  283. },
  284. /** 查看支付 状态 */
  285. async payQueryFun(orderId){
  286. this.loading = true
  287. try {
  288. this.payTimeNum = this.payTimeNum + 1
  289. if(this.payTimeNum==15){
  290. if(this.payTime){
  291. clearInterval(this.payTime)
  292. }
  293. this.orderInfoCancelFun()
  294. return
  295. }
  296. if(this.rebookForm.paymentType == 2){
  297. this.loadingText = "订单入库中..."
  298. }else {
  299. this.loadingText = "订单支付中..."
  300. }
  301. this.payStatus = ''
  302. let res = await payQuery({
  303. orderId: orderId
  304. })
  305. if(res.code == 200){
  306. if(res.data) {
  307. if(res.data.payStatus == 0) {
  308. if(this.payTime){
  309. clearInterval(this.payTime)
  310. }
  311. if(this.rebookForm.paymentType == 2){
  312. this.$message.error('"订单入库中失败"');
  313. this.loading = false
  314. this.payStatus = 3
  315. }else {
  316. if(res.data.orderStatus == 9 || res.data.orderStatus == 4 || res.data.orderStatus == 5){
  317. this.$message.error('订单已关闭,请重新选择座位,再购买!!!');
  318. this.loading = false
  319. this.payStatus = 10
  320. }else {
  321. this.$message.error('用户未支付!!!');
  322. this.loading = false
  323. this.payStatus = 7
  324. }
  325. }
  326. }else if(res.data.payStatus == 1) {
  327. if(this.payTime){
  328. clearInterval(this.payTime)
  329. }
  330. if(this.rebookForm.paymentType == 2){
  331. this.$message({
  332. message: '订单入库成功',
  333. type: 'success'
  334. });
  335. this.loading = false
  336. // this.payStatus = 8
  337. // this.getPrintListApi()
  338. this.rebookDialog = false
  339. this.goTicketingCollections()
  340. }else {
  341. this.$message({
  342. message: '用户已支付成功,请打印门票',
  343. type: 'success'
  344. });
  345. // 开始 打印
  346. this.loading = false
  347. // this.payStatus = 8
  348. // this.getPrintListApi()
  349. this.goTicketingCollections()
  350. }
  351. }else if(res.data.payStatus == 2) {
  352. }else if(res.data.payStatus == 3) {
  353. if(this.payTime){
  354. clearInterval(this.payTime)
  355. }
  356. if(this.rebookForm.paymentType == 2){
  357. this.$message.error('"订单入库中失败"');
  358. this.loading = false
  359. this.payStatus = 3
  360. }else {
  361. if(res.data.orderStatus == 9 || res.data.orderStatus == 4 || res.data.orderStatus == 5){
  362. this.$message.error('订单已关闭,请重新选择座位,再购买!!!');
  363. this.loading = false
  364. this.payStatus = 10
  365. }else {
  366. this.$message.error('用户支付失败!!!');
  367. this.loading = false
  368. this.payStatus = 7
  369. }
  370. }
  371. }else if(res.data.payStatus == 4) {
  372. if(this.payTime){
  373. clearInterval(this.payTime)
  374. }
  375. if(this.rebookForm.paymentType == 2){
  376. this.$message.error('"订单入库中失败"');
  377. this.loading = false
  378. this.payStatus = 3
  379. }else {
  380. if(res.data.orderStatus == 9 || res.data.orderStatus == 4 || res.data.orderStatus == 5){
  381. this.$message.error('订单已关闭,请重新选择座位,再购买!!!');
  382. this.loading = false
  383. this.payStatus = 10
  384. }else {
  385. this.$message.error('支付退款!!!');
  386. this.loading = false
  387. this.payStatus = 7
  388. }
  389. }
  390. }
  391. }
  392. }else{
  393. this.$message.error('支付失败!!!');
  394. this.loading = false
  395. this.payStatus = 7
  396. }
  397. } catch (error) {
  398. this.$message.error('支付失败!!!');
  399. this.loading = false
  400. this.payStatus = 7
  401. }
  402. },
  403. /** 连接VBarServer */
  404. vbar_open() {
  405. this.loading = true
  406. this.loadingText = "连接扫码盒子中!!!"
  407. this.payStatus = null
  408. this.code = ''
  409. this.websocketClear()
  410. this.payStatus = 5 // 连接成功
  411. document.addEventListener('keydown',this.keydownAdd);
  412. this.loading = false
  413. },
  414. /** 连接结果 */
  415. websocket_open_state(message){
  416. console.log("连接结果 ===== ",message)
  417. this.codeTime = setInterval(()=>{
  418. console.log("检测是否连接")
  419. if(this.websocketData.readyState != WebSocket.OPEN) {
  420. this.payStatus = 6
  421. }
  422. },3000)
  423. //document.getElementById('wsocket').value = "已连接";
  424. },
  425. // 拼接字符串
  426. keydownAdd(e){
  427. console.log("e=====",e)
  428. console.log("this.code=====",this.code)
  429. if( this.payStatus == 5 && e.key != 'Enter') {
  430. this.code = this.code + e.key
  431. }
  432. if( e.key == 'Enter') {
  433. document.removeEventListener('keydown',this.keydownAdd);
  434. let codeCopy = this.code
  435. this.payStatus == 5.5
  436. this.code = ''
  437. this.gotoMicroPayFun(this.orderId,codeCopy)
  438. }
  439. },
  440. //接收扫码完整结果处理
  441. websocket_decode(code){
  442. console.log("orderId=========",this.orderId )
  443. console.log("code=========",code)
  444. if(this.orderId && this.payStatus == 5.5 && regex.test(code) ) {
  445. this.payStatus = 5.6 // 支付中
  446. let codeCopy = code.replace("%%%", "").replace("%%%", "")
  447. this.gotoMicroPayFun(this.orderId,codeCopy)
  448. }else if(!code){
  449. this.payStatus = 5
  450. this.code = ''
  451. }
  452. },
  453. /** 关闭通讯 */
  454. websocketClear(){
  455. document.removeEventListener('keydown',this.keydownAdd);
  456. },
  457. /** 读取身份证 */
  458. readCert(){
  459. this.idcardLoading = true
  460. var result = "";
  461. try {
  462. let xmlHttp = new XMLHttpRequest();
  463. let Protocol = window.location.protocol.split(':')[0];
  464. //获取当前协议,并且分割字符串,得到http或者https
  465. if (Protocol === 'https'){
  466. //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
  467. xmlHttp.open("POST", "http://127.0.0.1:18889/api/readCert?ReadSN=" + 0, false); //readCert读卡,生成正反面仿复印件
  468. }else {
  469. //创建请求 第一个参数是代表以post方式发送;第二个是请求端口和地址;第三个表示是否异步
  470. xmlHttp.open("POST", "http://127.0.0.1:18889/api/readCert?ReadSN=" + 0, false); //readCert读卡,生成正反面仿复印件
  471. }
  472. //发送请求
  473. xmlHttp.send();
  474. if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
  475. result = xmlHttp.responseText;
  476. xmlHttp.readyState = 1;
  477. }
  478. } catch (e) {
  479. console.error("e====",e)
  480. }
  481. let obj = JSON.parse(result)
  482. if(obj.resultContent && obj.resultContent.certNumber){
  483. this.$set(this.tableForm,"idcard",obj.resultContent.certNumber)
  484. this.$set(this.tableForm,"name",obj.resultContent.partyName)
  485. }else {
  486. this.$message.error('读取失败!!!');
  487. }
  488. this.idcardLoading = false
  489. //return result;
  490. console.log(result,obj)
  491. },
  492. /** 查询打印机列表 */
  493. getPrintListApi() {
  494. getPrintListApi({deviceType:5,pageNum: 1,
  495. pageSize: 999,})
  496. .then(response => {
  497. this.printList = response.data.rows;
  498. }).catch((error)=>{
  499. console.log("error===",error)
  500. }
  501. );
  502. },
  503. // 打印
  504. async print(list = []){
  505. if(!this.printListId) {
  506. this.$message.error('请选择打印机!!');
  507. return
  508. }
  509. this.loading = true
  510. this.loadingText = '打印中...'
  511. this.payStatus = ''
  512. try {
  513. let res = await printApi({
  514. orderId: this.orderId,
  515. source: 2,
  516. deviceId: this.printListId
  517. })
  518. if(res.code == 200) {
  519. let url = res.data.linkIp
  520. let printInfo = res.data.printInfo
  521. this.connectPrint(url,printInfo)
  522. }else {
  523. throw new Error(res)
  524. }
  525. } catch (error) {
  526. this.loading = false
  527. this.payStatus = 8
  528. console.error("error=====",error)
  529. }
  530. },
  531. /** 连接打印机 */
  532. connectPrint(url,data){
  533. // 创建忽略 SSL 的 axios 实例
  534. const ignoreSSL = axios.create({
  535. httpsAgent: new https.Agent({
  536. rejectUnauthorized: false
  537. }),
  538. withCredentials: true, // 跨域请求时发送Cookie
  539. timeout: 60000, // 请求超时
  540. headers: {
  541. "Content-Type": "application/json; charset=UTF-8;"
  542. }
  543. });
  544. ignoreSSL.post(url,
  545. { ...data }
  546. ).then(()=>{
  547. this.rebookDialog = false
  548. this.loading = false
  549. }).catch(()=>{
  550. this.loading = false
  551. this.payStatus = 8
  552. // this.rebookDialog = false
  553. // this.loading = false
  554. })
  555. // 在 axios 请求时,选择性忽略 SSL
  556. // const agent = new https.Agent({
  557. // rejectUnauthorized: false
  558. // });
  559. // axios.post(
  560. // url,
  561. // { httpsAgent: agent,...data }
  562. // ).then(()=>{
  563. // this.rebookDialog = false
  564. // this.loading = false
  565. // })
  566. // .catch(()=>{
  567. // this.rebookDialog = false
  568. // this.loading = false
  569. // })
  570. },
  571. /** 获取授信余额和账户余额 */
  572. async selectMarketTeamBySourceFun(value) {
  573. console.log("value===",value)
  574. try {
  575. if(!['10','11','13','14','18','19'].includes(value)) return
  576. let res = await selectMarketTeamBySourceApi({
  577. source: value
  578. })
  579. this.balance = res.data.balance
  580. if(res.data.grantQuota && res.data.grantUsed) {
  581. this.grantQuota = res.data.grantQuota - res.data.grantUsed
  582. }else if(res.data.grantQuota) {
  583. this.grantQuota = res.data.grantQuota
  584. }else {
  585. this.grantQuota = 0
  586. }
  587. } catch (error) {
  588. this.balance = null
  589. this.grantQuota = null
  590. }
  591. },
  592. },
  593. }