luodangjia
2024-12-10 ee7ce5d1cbf80bee0a15c1e5bc5eaa30858d812b
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
package com.hollywood.applet.service.impl;
import java.time.LocalDateTime;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hollywood.applet.dto.PerformanceJoinDto;
import com.hollywood.applet.mapper.TUserMapper;
import com.hollywood.applet.mapper.TVipConfigMapper;
import com.hollywood.applet.mapper.TVipPurchaseRecordMapper;
import com.hollywood.applet.service.TVipConfigService;
import com.hollywood.common.basic.ApiResult;
import com.hollywood.common.model.*;
import com.hollywood.common.utils.PayMoneyUtil;
import com.hollywood.common.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
 
/**
 * <p>
 * 会员设置 服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2024-02-29
 */
@Service
public class TVipConfigServiceImpl extends ServiceImpl<TVipConfigMapper, TVipConfig> implements TVipConfigService {
 
    @Resource
    private TUserMapper userMapper;
    @Resource
    private TVipPurchaseRecordMapper vipPurchaseRecordMapper;
    @Autowired
    private PayMoneyUtil payMoneyUtil;
    @Override
    public ApiResult pay(Long userId, BigDecimal money, Integer month,Integer payType,Integer type) throws Exception {
        //进行支付操作
        if(payType == 1){//微信支付
            return weChatPaymentAPerformance(money,userId,month,type);
        }
        if (payType==2){
            return  aliPayPerformance(money,userId,month,type);
 
        }
        return ApiResult.failed("请选择支付方式");
    }
 
    public ApiResult weChatPaymentAPerformance(BigDecimal money, Long userId,Integer month,Integer type) throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
        TVipPurchaseRecord tVipPurchaseRecord = new TVipPurchaseRecord();
        tVipPurchaseRecord.setUserId(userId);
        if (type==1||type==2) {
            tVipPurchaseRecord.setVipType(1);
        } else if (type==3||type==4) {
            tVipPurchaseRecord.setVipType(2);
        }
        switch (type){
            case 1: tVipPurchaseRecord.setChargeType(1);
            case 2: tVipPurchaseRecord.setChargeType(2);
            case 3: tVipPurchaseRecord.setChargeType(1);
            case 4: tVipPurchaseRecord.setChargeType(2);
 
        }
        tVipPurchaseRecord.setPurchaseCount(month);
        tVipPurchaseRecord.setPayMoney(money.doubleValue());
        tVipPurchaseRecord.setPayTime(LocalDateTime.now());
        tVipPurchaseRecord.setCode(code);
        vipPurchaseRecordMapper.insert(tVipPurchaseRecord);
        ApiResult weixinpay = payMoneyUtil.weixinpay("参加演员活动", "", code,money.toString(), "/base/vip/wxcallback", "APP");
        return weixinpay;
    }
 
    private ApiResult aliPayPerformance(BigDecimal money, Long userId,Integer month,Integer type) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
        TVipPurchaseRecord tVipPurchaseRecord = new TVipPurchaseRecord();
        tVipPurchaseRecord.setUserId(userId);
        if (type==1||type==2) {
            tVipPurchaseRecord.setVipType(1);
        } else if (type==3||type==4) {
            tVipPurchaseRecord.setVipType(2);
        }
        switch (type){
            case 1: tVipPurchaseRecord.setChargeType(1);
            case 2: tVipPurchaseRecord.setChargeType(2);
            case 3: tVipPurchaseRecord.setChargeType(1);
            case 4: tVipPurchaseRecord.setChargeType(2);
 
        }
        tVipPurchaseRecord.setPurchaseCount(month);
        tVipPurchaseRecord.setPayMoney(money.doubleValue());
        tVipPurchaseRecord.setPayTime(LocalDateTime.now());
        tVipPurchaseRecord.setCode(code);
        tVipPurchaseRecord.setIsPay(1);
        vipPurchaseRecordMapper.insert(tVipPurchaseRecord);
        ApiResult alipay = payMoneyUtil.alipay("vip费用", "vip费用", code,money.toString(), "/base/vip/aliPaymentCourseCallback");
        return alipay;
    }
}