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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package com.hollywood.applet.service.impl;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hollywood.applet.dto.PerformanceJoinDto;
import com.hollywood.applet.mapper.TPerformerActivityMapper;
import com.hollywood.applet.mapper.TPerformerActivityUserMapper;
import com.hollywood.applet.mapper.TUserMapper;
import com.hollywood.applet.query.TPerformerActivityQuery;
import com.hollywood.applet.service.TPerformerActivityService;
import com.hollywood.applet.service.TPerformerActivityUserService;
import com.hollywood.common.basic.ApiResult;
import com.hollywood.common.basic.PageInfo;
import com.hollywood.common.exception.ServiceException;
import com.hollywood.common.model.*;
 
import com.hollywood.common.redis.RedisAutoTemplate;
import com.hollywood.common.utils.PayMoneyUtil;
import com.hollywood.common.utils.UUIDUtil;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 演员活动 服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2024-02-29
 */
@Service
public class TPerformerActivityServiceImpl extends ServiceImpl<TPerformerActivityMapper, TPerformerActivity> implements TPerformerActivityService {
 
 
    @Autowired
    private PayMoneyUtil payMoneyUtil;
    @Autowired
    private TUserMapper userMapper;
    @Autowired
    private TPerformerActivityUserMapper tPerformerActivityUserMapper;
    @Autowired
    private RedisAutoTemplate redisAutoTemplate;
    @Override
    public PageInfo<TPerformerActivity> pageList(TPerformerActivityQuery query,List<Long> ids) {
        PageInfo<TPerformerActivity> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<TPerformerActivity> list = this.baseMapper.pageList(query,pageInfo,ids);
        for (TPerformerActivity tPerformerActivity : list) {
            tPerformerActivity.setHot(redisAutoTemplate.getSet("performer:hot:"+tPerformerActivity.getId()).size());
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
 
    @Override
    public int upAndDown(Long id, Integer status) {
        TPerformerActivity performerActivity = this.baseMapper.selectById(id);
        performerActivity.setStatus(status);
        return this.baseMapper.updateById(performerActivity);
    }
 
    @Override
    public ApiResult join(PerformanceJoinDto performanceJoinDto, Long userId) throws Exception {
 
 
        //进行支付操作
        if(performanceJoinDto.getPayType() == 1){//微信支付
            return weChatPaymentAPerformance(performanceJoinDto,userId);
        }
        if (performanceJoinDto.getPayType()==2){
            return  aliPayPerformance(performanceJoinDto,userId);
        }
        return ApiResult.failed("请选择支付方式");
    }
 
    public ApiResult weChatPaymentAPerformance(PerformanceJoinDto performanceJoinDto, Long userId) throws Exception{
        TPerformerActivity tPerformerActivity = this.baseMapper.selectById(performanceJoinDto.getAcId());
        
 
        TUser tUser = userMapper.selectById(userId);
 
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
 
        TPerformerActivityUser tPerformerActivityUser = new TPerformerActivityUser();
        tPerformerActivityUser.setActivityId(performanceJoinDto.getAcId());
        tPerformerActivityUser.setPersonName(performanceJoinDto.getName());
        tPerformerActivityUser.setPersonPhone(tUser.getUserPhone());
        tPerformerActivityUser.setGainVotesCount(0);
        tPerformerActivityUser.setSelfIntroduction(performanceJoinDto.getIntroduce());
        tPerformerActivityUser.setPerformerCover(performanceJoinDto.getIndexPic());
        tPerformerActivityUser.setDetailPicture(performanceJoinDto.getInfoPic());
        tPerformerActivityUser.setDetailPicture(performanceJoinDto.getInfoPic());
        if (tPerformerActivity.getRegistrationFee()==0) {
            tPerformerActivityUser.setIsPay(2);
        }else {
            tPerformerActivityUser.setIsPay(1);
        }
        tPerformerActivityUser.setMoney(BigDecimal.valueOf(tPerformerActivity.getRegistrationFee()));
        tPerformerActivityUser.setUserId(userId);
        tPerformerActivityUser.setCode(code);
        tPerformerActivityUserMapper.insert(tPerformerActivityUser);
 
        if (tPerformerActivity.getRegistrationFee()==0){
            return ApiResult.success();
        }
 
        ApiResult weixinpay = payMoneyUtil.weixinpay("参加演员活动", "", code,tPerformerActivity.getRegistrationFee().toString(), "/base/performance/callback", "APP");
 
        return weixinpay;
    }
 
 
    private ApiResult aliPayPerformance(PerformanceJoinDto performanceJoinDto, Long userId) {
        TPerformerActivity tPerformerActivity = this.baseMapper.selectById(performanceJoinDto.getAcId());
        TUser tUser = userMapper.selectById(userId);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
 
        TPerformerActivityUser tPerformerActivityUser = new TPerformerActivityUser();
        tPerformerActivityUser.setActivityId(performanceJoinDto.getAcId());
        tPerformerActivityUser.setPersonName(performanceJoinDto.getName());
        tPerformerActivityUser.setPersonPhone(tUser.getUserPhone());
        tPerformerActivityUser.setGainVotesCount(0);
        tPerformerActivityUser.setSelfIntroduction(performanceJoinDto.getIntroduce());
        tPerformerActivityUser.setPerformerCover(performanceJoinDto.getIndexPic());
        tPerformerActivityUser.setDetailPicture(performanceJoinDto.getInfoPic());
        tPerformerActivityUser.setDetailPicture(performanceJoinDto.getInfoPic());
        if (tPerformerActivity.getRegistrationFee()==0) {
            tPerformerActivityUser.setIsPay(2);
        }else {
            tPerformerActivityUser.setIsPay(1);
        }
        tPerformerActivityUser.setMoney(BigDecimal.valueOf(tPerformerActivity.getRegistrationFee()));
        tPerformerActivityUser.setUserId(userId);
        tPerformerActivityUser.setCode(code);
        tPerformerActivityUserMapper.insert(tPerformerActivityUser);
        if (tPerformerActivity.getRegistrationFee()==0) {
           return ApiResult.success();
        }
        ApiResult alipay = payMoneyUtil.alipay("参加演员活动", "参加演员活动", code, tPerformerActivity.getRegistrationFee().toString(), "/base/performance/aliPaymentCourseCallback");
        return alipay;
    }
}