index.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. import { ref, reactive, shallowRef, computed } from 'vue'
  2. import { useAccountStore, useUserStore, useLoginStore } from '@/stores'
  3. import {
  4. t2bBankWithdraw,
  5. queryBankAccountSign,
  6. t2bBankDeposit,
  7. queryCusBankSignBank,
  8. t2bBankSign,
  9. t2bBankCancelSign,
  10. accountFundInfoReq,
  11. queryBankCusBankExtendConfigs,
  12. t2bSMSVerificationCode,
  13. YJF_GetWithholdSignInSMSVCode,
  14. YJF_WithholdInApply,
  15. YJF_WithholdSignInSMS,
  16. YJF_WithholdSignOut
  17. } from '@/services/api/bank'
  18. import { SignStatus } from '@/constants/bank'
  19. import { decryptAES } from '@/services/websocket/package/crypto'
  20. import moment from "moment"
  21. import { v4 } from 'uuid'
  22. const accountStore = useAccountStore()
  23. const loginStore = useLoginStore()
  24. const useStore = useUserStore()
  25. const { getSystemParamValue } = useUserStore()
  26. // 出金请求
  27. export function useDoWithdraw() {
  28. const loading = shallowRef(false)
  29. /// 获取当前是否已签约
  30. const bankAccountSign = shallowRef<Model.BankAccountSignRsp[]>([])
  31. const sign = computed<Partial<Model.BankAccountSignRsp>>(() => {
  32. if (bankAccountSign.value.length) {
  33. return bankAccountSign.value[0]
  34. }
  35. return {}
  36. })
  37. const formData = reactive<Partial<Proto.t2bBankWithdrawReq>>({
  38. AccountType: useStore.userInfo?.userinfotype,
  39. AppDateTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  40. })
  41. /// 查询签约信息
  42. const request = queryBankAccountSign().then((res) => {
  43. if (res.data.length) {
  44. bankAccountSign.value = res.data
  45. const data = res.data[0]
  46. formData.Currency = data.currency
  47. formData.CusBankID = data.cusbankid
  48. formData.BankAccoutName = data.bankaccountname
  49. formData.OpenCardBankId = data.bankid
  50. formData.AccountCode = data.accountcode
  51. formData.BranchBankName = data.branchbankname
  52. formData.BankAccoutName = data.bankaccountname2
  53. formData.BankAccoutNum = data.bankaccountno2
  54. }
  55. })
  56. const onSubmit = async () => {
  57. await request
  58. loading.value = true
  59. return t2bBankWithdraw({
  60. data: {
  61. ...formData,
  62. ExtOperatorID: new Date().getTime()
  63. }
  64. }).finally(() => {
  65. loading.value = false
  66. })
  67. }
  68. return {
  69. loading,
  70. onSubmit,
  71. formData,
  72. sign
  73. }
  74. }
  75. // 充值请求
  76. export function useDoDeposit(userid?: number) {
  77. const loading = shallowRef(false)
  78. /// 获取当前是否已签约
  79. const sign = shallowRef<Model.BankAccountSignRsp[]>([])
  80. /// formData
  81. const formData = reactive<Partial<Proto.t2bBankDepositReq>>({})
  82. const request = queryBankAccountSign({
  83. data: {
  84. userid: userid ?? loginStore.userId
  85. }
  86. }).then((res) => {
  87. if (res.data.length) {
  88. sign.value = res.data
  89. const data = res.data[0]
  90. formData.Currency = data.currency
  91. formData.CusBankID = data.cusbankid
  92. formData.BankAccoutName = data.bankaccountname2
  93. formData.OpenCardBankId = data.bankid
  94. formData.AccountCode = data.accountcode
  95. formData.BankAccoutNum = data.bankaccountno2
  96. }
  97. })
  98. const onSubmit = async () => {
  99. await request
  100. loading.value = true
  101. return t2bBankDeposit({
  102. data: {
  103. ...formData,
  104. ExtOperatorID: new Date().getTime(),
  105. }
  106. }).finally(() => {
  107. loading.value = false
  108. })
  109. }
  110. return {
  111. loading,
  112. onSubmit,
  113. formData,
  114. sign
  115. }
  116. }
  117. /// 银行签约请求
  118. export function useDoBankSign() {
  119. const { userInfo } = useUserStore()
  120. const loading = shallowRef(false)
  121. const bankInfo = shallowRef<Model.BankAccountSignRsp>()
  122. /// 托管银行信息
  123. const cusSignBank = shallowRef<Model.CusBankSignBankRsp>()
  124. /// 查询签约银行信息
  125. const request = queryCusBankSignBank().then((res) => {
  126. if (res.data.length) {
  127. const data = res.data[0]
  128. cusSignBank.value = data
  129. formData.Currency = data.currency
  130. formData.CusBankID = data.cusbankid
  131. formData.TradeDate = data.tradedate
  132. }
  133. })
  134. /// 银行列表
  135. const banklist = computed(() => {
  136. return (cusSignBank.value?.Banklst ?? []).filter(e => e.status == 0)
  137. })
  138. /// 判断是否有签约信息 有就做修改
  139. queryBankAccountSign().then((res) => {
  140. bankInfo.value = res.data.filter(obj => {
  141. return ![SignStatus.Rescinded].includes(obj.signstatus)
  142. })[0]
  143. if (bankInfo.value) {
  144. ({
  145. currency: formData.Currency,
  146. cusbankid: formData.CusBankID,
  147. accountcode: formData.AccountCode,
  148. branchbankname: formData.OpenBankName,
  149. bankaccountno: formData.BankAccountNo,
  150. bankid: formData.OpenBankAccId,
  151. } = bankInfo.value)
  152. }
  153. })
  154. /// 数据
  155. const formData = reactive<Partial<Proto.t2bBankSignReq>>({
  156. AccountType: useStore.userInfo?.userinfotype,
  157. IsForce: 0,
  158. AgentCertType: 0,
  159. BankCardType: 0,
  160. BankAccountType: useStore.userInfo?.userinfotype,
  161. AccountCode: accountStore.currentAccountId.toString(),
  162. CertID: decryptAES(userInfo?.cardnum ?? ''),
  163. CertType: userInfo?.cardtypeid.toString(),
  164. BankAccountName: userInfo?.customername,
  165. MobilePhone: userInfo?.mobile2,
  166. BankAccountNo: decryptAES(userInfo.bankaccount),
  167. AccountName: userInfo?.customername,
  168. OpenBankAccId: userInfo.bankid
  169. })
  170. const onSubmit = async () => {
  171. await request
  172. loading.value = true
  173. // 默认未签约状态
  174. const { signstatus = SignStatus.Unsigned } = bankInfo.value ?? {}
  175. return t2bBankSign({
  176. data: {
  177. ...formData,
  178. OperateType: signstatus === SignStatus.Unsigned ? 1 : 2,
  179. ExtOperatorID: new Date().getTime(),
  180. AccountName: userInfo?.customername,
  181. ExBankName: banklist.value.find(obj => obj.bankid === formData.OpenBankAccId)?.bankname
  182. }
  183. }).finally(() => {
  184. loading.value = false
  185. })
  186. }
  187. return {
  188. loading,
  189. formData,
  190. banklist,
  191. onSubmit,
  192. bankInfo
  193. }
  194. }
  195. /// 银行解约请求
  196. export function useDoCancelBankSign() {
  197. /// 获取UserId
  198. const loading = shallowRef(false)
  199. const isloaded = shallowRef(false)
  200. const bankInfo = shallowRef<Model.BankAccountSignRsp>()
  201. /// 表单信息
  202. const formData = reactive<Partial<Proto.t2bBankCancelSignReq>>({
  203. IsForce: 0,
  204. })
  205. /// 获取当前是否已签约
  206. const sign = shallowRef<Model.BankAccountSignRsp[]>([])
  207. const formRefresh = () => {
  208. queryBankAccountSign().then((res) => {
  209. bankInfo.value = res.data[0];
  210. ({
  211. currency: formData.Currency,
  212. cusbankid: formData.CusBankID,
  213. accountcode: formData.AccountCode,
  214. } = bankInfo.value ?? {})
  215. }).finally(() => {
  216. isloaded.value = true
  217. })
  218. }
  219. const cancelSubmit = async () => {
  220. loading.value = true
  221. /// 发起请求
  222. return t2bBankCancelSign({
  223. data: {
  224. ...formData,
  225. ExtOperatorID: new Date().getTime(),
  226. }
  227. }).finally(() => {
  228. loading.value = false
  229. })
  230. }
  231. return {
  232. loading,
  233. isloaded,
  234. cancelSubmit,
  235. formData,
  236. sign,
  237. bankInfo,
  238. formRefresh
  239. }
  240. }
  241. /// 账户资金信息请求
  242. export function useAccountFundInfo() {
  243. /// 数据
  244. const fund = shallowRef<Partial<Proto.AccountFundInfoRsp>>({})
  245. /// 账户资金信息
  246. accountFundInfoReq({
  247. data: {
  248. QueryBitMask: 2,
  249. OrderId: new Date().getTime(),
  250. AccountId: accountStore.currentAccountId,
  251. }
  252. }).then((res) => {
  253. fund.value = res
  254. })
  255. return {
  256. fund
  257. }
  258. }
  259. /// 查询托管银行扩展配置信息
  260. export function useDoCusBankExtendConfigs(extendbiztype?: number) {
  261. /// 托管银行拓展信息
  262. const configs = ref<(Model.BankCusBankExtendConfigRsp & { value: string })[]>([])
  263. /// 托管银行信息
  264. const cusBank = shallowRef<Partial<Model.CusBankSignBankRsp>>({})
  265. const end = shallowRef<string>('')
  266. /// 查询签约银行信息
  267. queryCusBankSignBank().then((res) => {
  268. if (res.data.length) {
  269. const data = res.data[0]
  270. cusBank.value = data
  271. end.value = (data.cusbankid === 'jdjs' ? getSystemParamValue('1003') : getSystemParamValue('013')) ?? ''
  272. /// 查询配置信息
  273. queryBankCusBankExtendConfigs({
  274. data: {
  275. cusbankid: data?.cusbankid,
  276. extendbiztype: extendbiztype
  277. },
  278. }).then((res) => {
  279. if (res.data.length != 0) {
  280. configs.value = res.data.map(obj => ({
  281. ...obj,
  282. value: obj.fieldcode === 'legal_name' ? (useStore.userInfo?.legalpersonname ?? '') : ''
  283. }))
  284. }
  285. })
  286. }
  287. })
  288. return {
  289. configs,
  290. end,
  291. cusBank
  292. }
  293. }
  294. /// 查询托管银行信息
  295. export function useQueryCusBankSignBank() {
  296. /// 数据
  297. const cusBank = shallowRef<Partial<Model.CusBankSignBankRsp>>({})
  298. /// 查询签约银行信息
  299. const request = queryCusBankSignBank().then((res) => {
  300. if (res.data.length) {
  301. const data = res.data[0]
  302. cusBank.value = data
  303. }
  304. })
  305. /// 银行列表
  306. const banklist = computed(() => {
  307. return (cusBank.value?.Banklst ?? []).filter(e => e.status == 0)
  308. })
  309. return { cusBank, banklist, request }
  310. }
  311. /// 银行获取手机验证码请求
  312. export function useT2bSMSVerificationCode() {
  313. const loading = shallowRef(false)
  314. /// 查询签约银行信息
  315. const request = queryCusBankSignBank().then((res) => {
  316. if (res.data.length) {
  317. const data = res.data[0]
  318. swsFormData.CusBankID = data.cusbankid
  319. swsFormData.TradeDate = data.tradedate
  320. }
  321. })
  322. /// 数据
  323. const swsFormData = reactive<Partial<Proto.t2bSWSVerificationCodeReq>>({
  324. Mobile: useStore.userInfo?.mobile2,
  325. AccountCode: accountStore.currentAccountId.toString(),
  326. extend_info: JSON.stringify({ "sex": 1 })
  327. })
  328. const smsVerificationCode = async () => {
  329. await request
  330. loading.value = true
  331. return t2bSMSVerificationCode({
  332. data: {
  333. ExtOperatorID: new Date().getTime(),
  334. ...swsFormData,
  335. }
  336. }).finally(() => {
  337. loading.value = false
  338. })
  339. }
  340. return {
  341. loading,
  342. swsFormData,
  343. smsVerificationCode
  344. }
  345. }
  346. /// 云缴费代扣解约请求
  347. export function useDoYJF_WithholdSignOut() {
  348. /// 获取UserId
  349. const loading = shallowRef(false)
  350. /// 表单信息
  351. const formData = reactive<Partial<Proto.YJF_WithholdSignOutReq>>({
  352. AccountID: accountStore.currentAccountId,
  353. UserID: useStore.userInfo.userid,
  354. LoginID: loginStore.loginId,
  355. ClientSerialNo: v4()
  356. })
  357. const onSubmit = async () => {
  358. loading.value = true
  359. /// 发起请求
  360. return YJF_WithholdSignOut({
  361. data: {
  362. ...formData,
  363. }
  364. }).finally(() => {
  365. loading.value = false
  366. })
  367. }
  368. return {
  369. loading,
  370. onSubmit,
  371. formData
  372. }
  373. }
  374. /// 云缴费代扣入金申请
  375. export function useDoYJF_WithholdInApply() {
  376. /// 获取UserId
  377. const loading = shallowRef(false)
  378. /// 判断是否有签约信息
  379. const bankaccountno = shallowRef('')
  380. /// 表单信息
  381. const formData = reactive<Partial<Proto.YJF_WithholdInApplyReq>>({
  382. AccountID: accountStore.currentAccountId,
  383. UserID: useStore.userInfo.userid,
  384. LoginID: loginStore.loginId,
  385. ClientSerialNo: v4(),
  386. BillAmount: "0"
  387. })
  388. /// 判断是否有签约信息
  389. queryBankAccountSign().then((res) => {
  390. bankaccountno.value = res.data.filter(obj => { return ![SignStatus.Rescinded].includes(obj.signstatus) })[0].bankaccountno
  391. })
  392. const onSubmit = async () => {
  393. loading.value = true
  394. /// 发起请求
  395. return YJF_WithholdInApply({
  396. data: {
  397. ...formData,
  398. }
  399. }).finally(() => {
  400. loading.value = false
  401. })
  402. }
  403. return {
  404. loading,
  405. onSubmit,
  406. formData,
  407. bankaccountno
  408. }
  409. }
  410. /// 云缴费代扣签约申请
  411. export function useDoYJF_WithholdSignInSMS() {
  412. /// 获取UserId
  413. const loading = shallowRef(false)
  414. /// 表单信息
  415. const formData = reactive<Partial<Proto.YJF_WithholdSignInSMSReq>>({
  416. AccountID: accountStore.currentAccountId,
  417. UserID: useStore.userInfo.userid,
  418. LoginID: loginStore.loginId,
  419. ClientSerialNo: v4()
  420. })
  421. const onSubmit = async () => {
  422. loading.value = true
  423. /// 发起请求
  424. return YJF_WithholdSignInSMS({
  425. data: {
  426. ...formData,
  427. }
  428. }).finally(() => {
  429. loading.value = false
  430. })
  431. }
  432. return {
  433. loading,
  434. onSubmit,
  435. formData
  436. }
  437. }
  438. /// 云缴费获取代扣签约短信验证码
  439. export function useDoYJFGetWithholdSignInSMSVCode() {
  440. /// 获取UserId
  441. const loading = shallowRef(false)
  442. /// 判断是否有签约信息
  443. const bankaccountno = shallowRef('')
  444. /// 表单信息
  445. const formData = reactive<Partial<Proto.YJF_GetWithholdSignInSMSVCodeReq>>({
  446. AccountID: accountStore.currentAccountId,
  447. UserID: useStore.userInfo.userid,
  448. LoginID: loginStore.loginId,
  449. ClientSerialNo: v4()
  450. })
  451. /// 判断是否有签约信息
  452. queryBankAccountSign().then((res) => {
  453. bankaccountno.value = res.data.filter(obj => { return ![SignStatus.Rescinded].includes(obj.signstatus) })[0].bankaccountno
  454. })
  455. const onSubmit = async () => {
  456. loading.value = true
  457. /// 发起请求
  458. return YJF_GetWithholdSignInSMSVCode({
  459. data: {
  460. ...formData,
  461. }
  462. }).finally(() => {
  463. loading.value = false
  464. })
  465. }
  466. return {
  467. loading,
  468. onSubmit,
  469. formData,
  470. bankaccountno
  471. }
  472. }