admin
2021-04-12 5129d2c63fbef70c6ee45ba5ec12654937e05231
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
package com.yeshi.buwan.service.manager;
 
import com.ks.goldcorn.exception.GoldAppException;
import com.ks.goldcorn.exception.GoldTradeException;
import com.ks.goldcorn.exception.GoldUserException;
import com.ks.goldcorn.service.remote.GoldCornTradeService;
import com.yeshi.buwan.domain.vip.OrderType;
import com.yeshi.buwan.domain.vip.OrderRecord;
import com.yeshi.buwan.exception.goldcorn.GoldCornException;
import com.yeshi.buwan.service.inter.system.SystemConfigService;
import com.yeshi.buwan.util.StringUtil;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
@Component
public class GoldCornManager {
 
 
    @Resource
    private SystemConfigService systemConfigService;
 
    @Reference(version = "1.0")
    private GoldCornTradeService goldCornTradeService;
 
 
    /**
     * 获取金币系统的用户ID
     *
     * @param uid
     * @return
     * @throws Exception
     */
    public String getUid(String uid) throws Exception {
        String prefix = systemConfigService.getConfigValueByKeyCache("thirdUidPrefix");
        if (StringUtil.isNullOrEmpty(prefix)) {
            throw new Exception("用户ID前缀获取出错");
        }
        return prefix + uid;
    }
 
    public String getAppCode() throws GoldAppException {
        String appCode = systemConfigService.getConfigValueByKeyCache("goldCornAppCode");
        if (StringUtil.isNullOrEmpty(appCode)) {
            throw new GoldAppException(GoldAppException.CODE_NOT_EXIST, "应用不存在");
        }
        return appCode;
    }
 
 
    /**
     * 金币消耗
     *
     * @param record
     * @param goldCornCount 金币数量
     * @throws GoldCornException
     * @throws Exception
     */
    public void consumeGoldCorn(OrderRecord record, int goldCornCount) throws GoldCornException, Exception {
        String tuid = getUid(record.getUid());
        String appCode = getAppCode();
        String sourceCode = "";
        String title = "";
        String desc = "";
        if (record.getOrderType() == OrderType.vip) {
            sourceCode = "buyVIP";
            title = "购买VIP";
        } else if (record.getOrderType() == OrderType.video) {
            sourceCode = "buyVideo";
            title = "购买单片";
        }
        consumeGoldCorn(appCode, tuid, sourceCode, goldCornCount, title, desc);
    }
 
    /**
     * 返回影视豆
     *
     * @param record
     * @throws GoldCornException
     * @throws Exception
     */
    public void drawbackGoldCorn(OrderRecord record) throws GoldCornException, Exception {
        String tuid = getUid(record.getUid());
        String appCode = getAppCode();
        String sourceCode = "";
        String title = "";
        String desc = "";
        if (record.getOrderType() == OrderType.vip) {
            sourceCode = "buyVIP";
            title = "购买VIP退款";
        } else if (record.getOrderType() == OrderType.video) {
            sourceCode = "buyVideo";
            title = "购买单片退款";
        }
        addGoldCorn(appCode, tuid, sourceCode, record.getGoldCorn(), title, desc);
    }
 
    private void addGoldCorn(String appCode, String uid, String sourceCode, Integer goldCornCount, String title, String desc) throws GoldUserException, GoldAppException, GoldTradeException {
        goldCornTradeService.addGoldCorn(appCode, uid, sourceCode, goldCornCount, title, desc);
    }
 
 
    private void consumeGoldCorn(String appCode, String uid, String sourceCode, Integer goldCornCount, String title, String desc) throws GoldUserException, GoldAppException, GoldTradeException {
        goldCornTradeService.consumeGoldCorn(appCode, uid, sourceCode, goldCornCount, title, desc);
    }
 
 
}