index.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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. /// 不为空 入金取 318 出金取 319
  272. const msg = getSystemParamValue(extendbiztype === 2 ? '318' : '319') ?? ''
  273. const msg_013 = getSystemParamValue('013') ?? ''
  274. end.value = msg != '' ? msg : msg_013
  275. /// 查询配置信息
  276. queryBankCusBankExtendConfigs({
  277. data: {
  278. cusbankid: data?.cusbankid,
  279. extendbiztype: extendbiztype
  280. },
  281. }).then((res) => {
  282. if (res.data.length != 0) {
  283. configs.value = res.data.map(obj => ({
  284. ...obj,
  285. value: obj.fieldcode === 'legal_name' ? (useStore.userInfo?.legalpersonname ?? '') : ''
  286. }))
  287. }
  288. })
  289. }
  290. })
  291. return {
  292. configs,
  293. end,
  294. cusBank
  295. }
  296. }
  297. /// 查询托管银行信息
  298. export function useQueryCusBankSignBank() {
  299. /// 数据
  300. const cusBank = shallowRef<Partial<Model.CusBankSignBankRsp>>({})
  301. /// 查询签约银行信息
  302. const request = queryCusBankSignBank().then((res) => {
  303. if (res.data.length) {
  304. const data = res.data[0]
  305. cusBank.value = data
  306. }
  307. })
  308. /// 银行列表
  309. const banklist = computed(() => {
  310. return (cusBank.value?.Banklst ?? []).filter(e => e.status == 0)
  311. })
  312. return { cusBank, banklist, request }
  313. }
  314. /// 银行获取手机验证码请求
  315. export function useT2bSMSVerificationCode() {
  316. const loading = shallowRef(false)
  317. /// 查询签约银行信息
  318. const request = queryCusBankSignBank().then((res) => {
  319. if (res.data.length) {
  320. const data = res.data[0]
  321. swsFormData.CusBankID = data.cusbankid
  322. swsFormData.TradeDate = data.tradedate
  323. }
  324. })
  325. /// 数据
  326. const swsFormData = reactive<Partial<Proto.t2bSWSVerificationCodeReq>>({
  327. Mobile: useStore.userInfo?.mobile2,
  328. AccountCode: accountStore.currentAccountId.toString(),
  329. extend_info: JSON.stringify({ "sex": 1 })
  330. })
  331. const smsVerificationCode = async () => {
  332. await request
  333. loading.value = true
  334. return t2bSMSVerificationCode({
  335. data: {
  336. ExtOperatorID: new Date().getTime(),
  337. ...swsFormData,
  338. }
  339. }).finally(() => {
  340. loading.value = false
  341. })
  342. }
  343. return {
  344. loading,
  345. swsFormData,
  346. smsVerificationCode
  347. }
  348. }
  349. /// 云缴费代扣解约请求
  350. export function useDoYJF_WithholdSignOut() {
  351. /// 获取UserId
  352. const loading = shallowRef(false)
  353. /// 表单信息
  354. const formData = reactive<Partial<Proto.YJF_WithholdSignOutReq>>({
  355. AccountID: accountStore.currentAccountId,
  356. UserID: useStore.userInfo.userid,
  357. LoginID: loginStore.loginId,
  358. ClientSerialNo: v4()
  359. })
  360. const onSubmit = async () => {
  361. loading.value = true
  362. /// 发起请求
  363. return YJF_WithholdSignOut({
  364. data: {
  365. ...formData,
  366. }
  367. }).finally(() => {
  368. loading.value = false
  369. })
  370. }
  371. return {
  372. loading,
  373. onSubmit,
  374. formData
  375. }
  376. }
  377. /// 云缴费代扣入金申请
  378. export function useDoYJF_WithholdInApply() {
  379. /// 获取UserId
  380. const loading = shallowRef(false)
  381. /// 判断是否有签约信息
  382. const bankaccountno = shallowRef('')
  383. /// 表单信息
  384. const formData = reactive<Partial<Proto.YJF_WithholdInApplyReq>>({
  385. AccountID: accountStore.currentAccountId,
  386. UserID: useStore.userInfo.userid,
  387. LoginID: loginStore.loginId,
  388. ClientSerialNo: v4(),
  389. BillAmount: "0.0"
  390. })
  391. /// 判断是否有签约信息
  392. queryBankAccountSign().then((res) => {
  393. bankaccountno.value = res.data.filter(obj => { return [SignStatus.Signed].includes(obj.signstatus) })[0].bankaccountno
  394. })
  395. const onSubmit = async () => {
  396. loading.value = true
  397. /// 发起请求
  398. return YJF_WithholdInApply({
  399. data: {
  400. ...formData,
  401. }
  402. }).finally(() => {
  403. loading.value = false
  404. })
  405. }
  406. return {
  407. loading,
  408. onSubmit,
  409. formData,
  410. bankaccountno
  411. }
  412. }
  413. /// 云缴费代扣签约申请
  414. export function useDoYJF_WithholdSignInSMS() {
  415. /// 获取UserId
  416. const loading = shallowRef(false)
  417. /// 表单信息
  418. const formData = reactive<Partial<Proto.YJF_WithholdSignInSMSReq>>({
  419. AccountID: accountStore.currentAccountId,
  420. UserID: useStore.userInfo.userid,
  421. LoginID: loginStore.loginId,
  422. ClientSerialNo: v4()
  423. })
  424. const onSubmit = async () => {
  425. loading.value = true
  426. /// 发起请求
  427. return YJF_WithholdSignInSMS({
  428. data: {
  429. ...formData,
  430. }
  431. }).finally(() => {
  432. loading.value = false
  433. })
  434. }
  435. return {
  436. loading,
  437. onSubmit,
  438. formData
  439. }
  440. }
  441. /// 云缴费获取代扣签约短信验证码
  442. export function useDoYJFGetWithholdSignInSMSVCode() {
  443. /// 获取UserId
  444. const loading = shallowRef(false)
  445. /// 判断是否有签约信息
  446. const bankaccountno = shallowRef('')
  447. /// 表单信息
  448. const formData = reactive<Partial<Proto.YJF_GetWithholdSignInSMSVCodeReq>>({
  449. AccountID: accountStore.currentAccountId,
  450. UserID: useStore.userInfo.userid,
  451. LoginID: loginStore.loginId,
  452. ClientSerialNo: v4(),
  453. Yckfxe: '500000.00',
  454. Kkzqnkfxe: '0.00',
  455. Kkzqnxzbs: '0',
  456. Kksjbc: '99',
  457. Kksjdw: '1'
  458. })
  459. /// 判断是否有签约信息
  460. queryBankAccountSign().then((res) => {
  461. bankaccountno.value = res.data.filter(obj => { return [SignStatus.Signed].includes(obj.signstatus) })[0].bankaccountno
  462. })
  463. const onSubmit = async () => {
  464. loading.value = true
  465. /// 发起请求
  466. return YJF_GetWithholdSignInSMSVCode({
  467. data: {
  468. ...formData,
  469. }
  470. }).finally(() => {
  471. loading.value = false
  472. })
  473. }
  474. return {
  475. loading,
  476. onSubmit,
  477. formData,
  478. bankaccountno
  479. }
  480. }