liujie
3 天以前 dd556df997e268153bf1a74616f49b25db11ed3f
cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupPaymentServiceImpl.java
@@ -7,23 +7,30 @@
import com.dsh.communityWorldCup.entity.WorldCup;
import com.dsh.communityWorldCup.entity.WorldCupPayment;
import com.dsh.communityWorldCup.entity.WorldCupPaymentParticipant;
import com.dsh.communityWorldCup.entity.WorldCupStore;
import com.dsh.communityWorldCup.feignclient.account.AppUserClient;
import com.dsh.communityWorldCup.feignclient.account.model.AppUser;
import com.dsh.communityWorldCup.feignclient.course.CoursePackageOrderStudentClient;
import com.dsh.communityWorldCup.feignclient.course.model.CoursePackageOrderStudent;
import com.dsh.communityWorldCup.feignclient.other.StoreClient;
import com.dsh.communityWorldCup.feignclient.other.model.Store;
import com.dsh.communityWorldCup.mapper.WorldCupPaymentMapper;
import com.dsh.communityWorldCup.model.DeductionClassHourList;
import com.dsh.communityWorldCup.service.IWorldCupPaymentParticipantService;
import com.dsh.communityWorldCup.service.IWorldCupPaymentService;
import com.dsh.communityWorldCup.service.IWorldCupService;
import com.dsh.communityWorldCup.service.IWorldCupStoreService;
import com.dsh.communityWorldCup.util.PayMoneyUtil;
import com.dsh.communityWorldCup.util.ResultUtil;
import com.dsh.communityWorldCup.util.UUIDUtil;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -37,6 +44,8 @@
    @Autowired
    private IWorldCupPaymentParticipantService worldCupPaymentParticipantService;
    @Autowired
    private IWorldCupStoreService worldCupStoreService;
    @Autowired
    private IWorldCupService worldCupService;
@@ -46,6 +55,8 @@
    @Resource
    private AppUserClient appUserClient;
    @Resource
    private StoreClient storeClient;
    @Resource
    private CoursePackageOrderStudentClient coursePackageOrderStudentClient;
@@ -59,7 +70,7 @@
     * @return
     */
    @Override
    public ResultUtil cancelMyWorldCup(Long id) {
    public ResultUtil cancelMyWorldCup(Long id) throws Exception {
        WorldCupPaymentParticipant worldCupPaymentParticipant = worldCupPaymentParticipantService.getById(id);
        WorldCupPayment worldCupPayment = this.getById(worldCupPaymentParticipant.getWorldCupPaymentId());
        WorldCup worldCup = worldCupService.getById(worldCupPayment.getWorldCupId());
@@ -82,16 +93,32 @@
        //总排款金额(排除已经参加比赛的数据)
        BigDecimal multiply = worldCupPayment.getUnitPrice().multiply(new BigDecimal(list1.size()));
        //微信支付
        List<WorldCupStore> list = worldCupStoreService.lambdaQuery().eq(WorldCupStore::getWorldCupId, worldCup.getId()).list();
        Integer storeId = list.get(0).getStoreId();
        Store store = storeClient.queryStoreById(storeId);
        if(worldCupPayment.getPayType() == 1){
            Map<String, String> map = payMoneyUtil.wxRefund(worldCupPayment.getPayOrderNo(), worldCupPayment.getCode(),
                    worldCupPayment.getAmount().toString(), multiply.toString(), "/base/worldCup/wxRefundWorldCupCallback");
            if(!"SUCCESS".equals(map.get("return_code"))){
                System.err.println("-------------微信退款失败---------");
                System.err.println(map.get("return_msg"));
                return ResultUtil.error("微信退款失败");
            }else{
                worldCupPayment.setRefundAmount(multiply);
                this.updateById(worldCupPayment);
            if (store.getOperatorId()!=null && store.getOperatorId()!=0){
                String smidVx= storeClient.getmerchantNumberByOperatorId(store.getOperatorId());
                if (!StringUtils.hasLength(smidVx)){
                    System.err.println("运营商未配置微信商户号,获取支付失败!");
                }
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
                String codeRefund = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);// 退款单号
                // 运营商退款
                payMoneyUtil.weixinRefundV3(smidVx, codeRefund, worldCupPayment.getPayOrderNo(), worldCupPayment.getAmount().toString(), "/base/worldCup/wxRefundWorldCupCallback1");
            }else {
                Map<String, String> map = payMoneyUtil.wxRefund(worldCupPayment.getPayOrderNo(), worldCupPayment.getCode(),
                        worldCupPayment.getAmount().toString(), multiply.toString(), "/base/worldCup/wxRefundWorldCupCallback");
                if (!"SUCCESS".equals(map.get("return_code"))) {
                    System.err.println("-------------微信退款失败---------");
                    System.err.println(map.get("return_msg"));
                    return ResultUtil.error("微信退款失败");
                } else {
                    worldCupPayment.setRefundAmount(multiply);
                    worldCupPayment.setWorldCupId(null);
                    this.updateById(worldCupPayment);
                }
            }
        }
        //支付宝支付