finance.service.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import Content from '@/sheep/layouts/content.vue';
  2. import { SELECT, CRUD } from '@/sheep/request/crud';
  3. import { request } from '@/sheep/request';
  4. import i18n from '@/locales';
  5. // 获取 t 函数
  6. const { t } = i18n.global;
  7. // 财务模块公共配置
  8. const financeConfig = {
  9. // 币种配置
  10. currencies: {
  11. 1: 'BDT',
  12. },
  13. // 状态配置
  14. status: {
  15. recharge: {
  16. 1: () => t('modules.recharge.processing'),
  17. 2: () => t('modules.recharge.success'),
  18. 3: () => t('modules.recharge.failed'),
  19. 4: () => t('modules.recharge.timeout'),
  20. },
  21. withdraw: {
  22. 1: () => t('modules.withdraw.processing'),
  23. 2: () => t('modules.withdraw.approved'),
  24. 3: () => t('modules.withdraw.rejected'),
  25. 4: () => t('modules.withdraw.success'),
  26. 5: () => t('modules.withdraw.failed'),
  27. 6: () => t('modules.withdraw.timeout'),
  28. },
  29. },
  30. // 账户类型配置
  31. accountTypes: {
  32. 1: () => t('modules.finance.walletBalance'),
  33. 2: () => t('modules.finance.accountEarnings'),
  34. },
  35. // 操作日志类型配置
  36. logTypes: {
  37. 1: () => t('modules.finance.submitRechargeOrder'),
  38. 2: () => t('modules.finance.rechargeCallThirdParty'),
  39. 3: () => t('modules.finance.rechargeCallbackSuccess'),
  40. 4: () => t('modules.finance.submitWithdrawApplication'),
  41. 5: () => t('modules.finance.withdrawApproved'),
  42. 6: () => t('modules.finance.withdrawRejected'),
  43. 7: () => t('modules.finance.withdrawCallThirdParty'),
  44. 8: () => t('modules.finance.withdrawCallbackSuccess'),
  45. },
  46. };
  47. // 公共工具函数
  48. const financeUtils = {
  49. // 获取币种文本
  50. getCurrencyText: (currency) => financeConfig.currencies[currency] || 'BDT',
  51. // 获取充值状态文本
  52. getRechargeStatusText: (status) => {
  53. const statusFn = financeConfig.status.recharge[status];
  54. return statusFn ? statusFn() : t('common.unknown');
  55. },
  56. // 获取提现状态文本
  57. getWithdrawStatusText: (status) => {
  58. const statusFn = financeConfig.status.withdraw[status];
  59. return statusFn ? statusFn() : t('common.unknown');
  60. },
  61. // 获取账户类型文本
  62. getAccountTypeText: (accountType) => {
  63. const typeFn = financeConfig.accountTypes[accountType];
  64. return typeFn ? typeFn() : t('common.unknown');
  65. },
  66. // 获取操作日志类型文本
  67. getLogTypeText: (type) => {
  68. const typeFn = financeConfig.logTypes[type];
  69. return typeFn ? typeFn() : t('modules.finance.unknownOperation');
  70. },
  71. // 获取状态类型(用于标签颜色)
  72. getStatusType: (status, type = 'withdraw') => {
  73. if (type === 'recharge') {
  74. const statusMap = {
  75. 1: 'warning', // 处理中
  76. 2: 'success', // 充值成功
  77. 3: 'danger', // 充值失败
  78. 4: 'info', // 超时取消
  79. };
  80. return statusMap[status] || 'info';
  81. } else {
  82. const statusMap = {
  83. 1: 'warning', // 处理中
  84. 2: 'success', // 审核通过
  85. 3: 'danger', // 审核拒绝
  86. 4: 'success', // 提现成功
  87. 5: 'danger', // 提现失败
  88. 6: 'info', // 超时取消
  89. };
  90. return statusMap[status] || 'info';
  91. }
  92. },
  93. // 获取渠道类型(用于标签颜色)
  94. getChannelType: (channel) => {
  95. const channelMap = {
  96. 1: 'info', // TKPAY
  97. 2: 'success', // 3QPAY
  98. };
  99. return channelMap[channel] || 'info';
  100. },
  101. // 佣金相关状态处理函数
  102. getCommissionStatusText: (status) => {
  103. const statusMap = {
  104. 1: () => t('modules.finance.unsettled'),
  105. 2: () => t('modules.finance.settled'),
  106. };
  107. const statusFn = statusMap[status];
  108. return statusFn ? statusFn() : t('common.unknown');
  109. },
  110. getCommissionStatusType: (status) => {
  111. const statusMap = {
  112. 1: 'warning', // 未结算
  113. 2: 'success', // 已结算
  114. };
  115. return statusMap[status] || 'info';
  116. },
  117. getBizTypeText: (bizType) => {
  118. const typeMap = {
  119. 1001: () => t('modules.finance.recharge'),
  120. 2001: () => t('modules.finance.withdraw'),
  121. 3001: () => t('modules.finance.groupPayment'),
  122. 3002: () => t('modules.finance.joinPayment'),
  123. 4001: () => t('modules.finance.incompleteRefund'),
  124. 4002: () => t('modules.finance.completeRefund'),
  125. 5001: () => t('modules.finance.groupRedPacketEarnings'),
  126. 5002: () => t('modules.finance.joinRedPacketEarnings'),
  127. 5003: () => t('modules.finance.signInRedPacketEarnings'),
  128. 5004: () => t('modules.finance.subordinateRedPacketCommission'),
  129. 5005: () => t('modules.finance.subSubordinateRedPacketCommission'),
  130. 6001: () => t('modules.finance.rechargeRebate'),
  131. 7001: () => t('modules.finance.withdrawalFee'),
  132. };
  133. const typeFn = typeMap[bizType];
  134. return typeFn ? typeFn() : t('modules.finance.unknownType');
  135. },
  136. // 格式化金额,保留两位小数
  137. formatAmount: (amount) => {
  138. if (amount === null || amount === undefined) return '0.00';
  139. return Number(amount || 0).toFixed(2);
  140. },
  141. // 格式化金额并添加货币符号
  142. formatCurrency: (amount, currency = 'BDT') => {
  143. const formattedAmount = financeUtils.formatAmount(amount);
  144. return `৳${formattedAmount}`;
  145. },
  146. };
  147. const route = {
  148. path: 'finance',
  149. name: 'shop.admin.finance',
  150. component: Content,
  151. meta: {
  152. title: '财务',
  153. },
  154. children: [
  155. {
  156. path: 'commission',
  157. name: 'shop.admin.finance.commission',
  158. component: () => import('@/app/shop/admin/finance/commission/index.vue'),
  159. meta: {
  160. title: '佣金管理',
  161. },
  162. },
  163. {
  164. path: 'recharge',
  165. name: 'shop.admin.finance.recharge',
  166. component: () => import('@/app/shop/admin/finance/recharge/index.vue'),
  167. meta: {
  168. title: '充值管理',
  169. },
  170. },
  171. {
  172. path: 'withdraw',
  173. name: 'shop.admin.finance.withdraw',
  174. component: () => import('@/app/shop/admin/finance/withdraw/index.vue'),
  175. meta: {
  176. title: '提现管理',
  177. },
  178. },
  179. {
  180. path: 'report',
  181. name: 'shop.admin.finance.report',
  182. component: () => import('@/app/shop/admin/finance/report/index.vue'),
  183. meta: {
  184. title: '财务报表',
  185. },
  186. },
  187. ],
  188. };
  189. const api = {
  190. // 佣金相关 API
  191. commission: {
  192. ...CRUD('/cif/red/envelope', ['list', 'detail', 'report']),
  193. // 获取佣金类型枚举
  194. getTypes: () =>
  195. request({
  196. url: '/cif/api/user/getEnum',
  197. method: 'GET',
  198. params: { id: 5 },
  199. }),
  200. },
  201. // 充值相关 API
  202. recharge: {
  203. ...CRUD('cif/recharge/record', ['list', 'detail', 'report']),
  204. recordDetail: (id) =>
  205. request({
  206. url: `cif/recharge/record/detail`,
  207. method: 'GET',
  208. params: { id },
  209. }),
  210. select: (params) => SELECT('shop/admin/finance/recharge', params),
  211. confirm: (id) => ({
  212. error: 0,
  213. msg: t('modules.finance.confirmSuccess'),
  214. data: null,
  215. }),
  216. batchConfirm: (ids) => ({
  217. error: 0,
  218. msg: t('modules.finance.batchConfirmSuccess'),
  219. data: null,
  220. }),
  221. },
  222. // 提现相关 API
  223. withdraw: {
  224. ...CRUD('/cif/withdraw/record', ['list', 'detail', 'report']),
  225. withdrawDetail: (id) =>
  226. request({
  227. url: `cif/withdraw/record/detail`,
  228. method: 'GET',
  229. params: { id },
  230. }),
  231. // 审核接口
  232. review: (data) =>
  233. request({
  234. url: 'cif/withdraw/record/review',
  235. method: 'POST',
  236. data,
  237. }),
  238. batchApprove: (ids) => ({
  239. error: 0,
  240. msg: t('modules.finance.batchApproveSuccess'),
  241. data: null,
  242. }),
  243. batchReject: (ids, data) => ({
  244. error: 0,
  245. msg: t('modules.finance.batchRejectSuccess'),
  246. data: null,
  247. }),
  248. },
  249. // 财务报表相关 API
  250. report: {
  251. ...CRUD('/cif/subject', ['list', 'export'], { exportMethod: 'GET' }),
  252. },
  253. };
  254. export { route, api, financeConfig, financeUtils };