p-honggang.li
9 天以前 bd125eecd57d2f4e559c6170d20157591300fe3d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import createAxios from '@/utils/axios'
 
let url = '/admin/api/points/'
 
const pointsApi = {
  // 积分规则设置相关接口
  // 获取积分规则配置
  getPointsRules(data: object): ApiPromise {
    return createAxios({
      url: `${url}main/page`,
      data: data,
    }) as ApiPromise
  },
 
  // 根据ID获取积分规则
  getPointsRuleById(data: URLSearchParams): ApiPromise {
    return createAxios({
      url: `${url}rule/list`,
      method: 'post',
      data: data,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    }) as ApiPromise
  },
 
  // 保存积分规则配置
  savePointsRules(data: object): ApiPromise {
    return createAxios({
      url: `${url}rule/update`,
      data: data,
    }) as ApiPromise
  },
 
  // 个人积分相关接口
  // 获取个人积分统计
  getPersonalPointsStats(userId: number): ApiPromise {
    return createAxios({
      url: `${url}/total/user/` + userId,
      method: 'get',
    }) as ApiPromise
  },
 
  // 获取个人积分流水
  getPersonalPointsFlow(data: object): ApiPromise {
    return createAxios({
      url: `${url}flow/personal/page`,
      data: data,
    }) as ApiPromise
  },
 
  // 新增:按规则名记账(个人)
  addPersonalFlowByRule(data: { ruleName: string; count?: number; name?: string }): ApiPromise {
    return createAxios({
      url: `${url}personal/flow/addByRule`,
      data,
    }) as ApiPromise
  },
 
  // 单位积分相关接口
  // 获取单位积分统计
  getUnitPointsStats(data: object): ApiPromise {
    return createAxios({
      url: `${url}unit/stats`,
      data: data,
    }) as ApiPromise
  },
 
  // 获取单位积分流水
  getUnitPointsFlow(data: object): ApiPromise {
    return createAxios({
      url: `${url}unit/flow`,
      data: data,
    }) as ApiPromise
  },
 
  // 新增:按规则名记账(单位)
  addUnitFlowByRule(data: { ruleName: string; count?: number; name?: string }): ApiPromise {
    return createAxios({
      url: `${url}unit/flow/addByRule`,
      data,
    }) as ApiPromise
  },
 
  // 获取积分流水数据类目列表
  getPointsFlowCategories(): ApiPromise {
    return createAxios({
      url: `${url}flow/categories`,
      method: 'get',
    }) as ApiPromise
  },
 
  // 获取用户积分余额 - 使用已存在的接口
  getUserPoints(userId: number): ApiPromise {
    return createAxios({
      url: `${url}total/user/${userId}`,  // 修改为实际存在的路径
      method: 'get',
    }) as ApiPromise
  },
 
  // 使用专门的积分扣减接口
  deductPointsByFlow(userId: string, unitId: string, points: number, orderId: string, remark?: string, dataCategory?: string, providerId?: String): ApiPromise {
    return createAxios({
      url: `${url}user/deduct`,  // 使用新的专门积分扣减接口
      method: 'post',
      data: {
        userId,
        unitId,
        points,                    // 直接传入要扣减的积分数量
        orderId,
        remark: remark || `订单${orderId}交易扣减积分`,
        dataCategory: dataCategory || 'resource_transaction',
        dataType: 1,               // 1表示消耗
        providerId: providerId
      },
    }) as ApiPromise
  },
}
 
export default pointsApi