Pu Zhibing
3 天以前 33632d86bbf74e922ce406d9032fadc90f6bba5e
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
package com.stylefeng.guns.modular.call.server.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.account.controller.AppOrderController;
import com.stylefeng.guns.modular.call.dao.OrderCallMapper;
import com.stylefeng.guns.modular.call.model.OrderCall;
import com.stylefeng.guns.modular.call.server.IOrderCallService;
import com.stylefeng.guns.modular.system.model.SysIntegral;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.IIncomeService;
import com.stylefeng.guns.modular.system.service.ISysIntegralService;
import com.stylefeng.guns.modular.system.service.ISystemNoticeService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.util.PayMoneyUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.util.UUIDUtil;
import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService;
import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
 
@Service
public class OrderCallServiceImpl extends ServiceImpl<OrderCallMapper, OrderCall> implements IOrderCallService {
 
    @Autowired
    private IUserInfoService userInfoService;
 
    @Autowired
    private PayMoneyUtil payMoneyUtil;
 
    @Autowired
    private IPaymentRecordService paymentRecordService;
 
    @Autowired
    private ISysIntegralService sysIntegralService;
 
    @Autowired
    private IIncomeService incomeService;
 
    @Autowired
    private ITransactionDetailsService transactionDetailsService;
 
    @Autowired
    private ISystemNoticeService systemNoticeService;
 
 
 
    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public ResultUtil payThankYouFee(Integer uid, Integer orderId, Double money, Integer payType, Integer type) throws Exception {
        UserInfo userInfo = userInfoService.selectById(uid);
        OrderCall orderCall = this.selectById(orderId);
        ResultUtil resultUtil = ResultUtil.success();
        if(payType == 1){//微信支付
            String app = type == 1 ? "APP" : "JSAPI";
            resultUtil = payMoneyUtil.weixinpay("感谢费", "", orderId + "_7_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/wxPayThankYouFee", app, userInfo.getAppletsOpenId());
            paymentRecordService.saveData(3, uid, 1, orderId, 7, 1, money, "", 1);//添加预支付数据
        }
        if(payType == 2){//支付宝支付
            resultUtil = payMoneyUtil.alipay("感谢费", "感谢费", "", orderId + "_7_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/aliPayThankYouFee");
            paymentRecordService.saveData(1, uid, 1, orderId, 7, 2, money, "", 1);//添加预支付数据
        }
        if(payType == 3){//余额支付
            if (userInfo.getBalance() == null || userInfo.getBalance() < money) {
                return ResultUtil.error("余额不足,无法完成支付");
            }
//            resultUtil= appOrderController.moneyPay(orderId,userInfo.getId(),money);
//            if(resultUtil.getCode()==500){
//                return ResultUtil.error("电子余额不足,无法完成支付");
//            }
    
            userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
    
            SysIntegral query1 = sysIntegralService.selectOne(new EntityWrapper<SysIntegral>().eq("companyId", orderCall.getCompanyId()));
            userInfo.setIntegral(userInfo.getIntegral() + (money.intValue() * query1.getIntegral()));//积分
    
            //添加交易明细
            transactionDetailsService.saveData(uid, "助老模式-感谢费", money, 2, 1, 1, 7, orderId);
            userInfoService.updateById(userInfo);
    
            orderCall.setThankYouFee(money);
            this.updateById(orderCall);
 
            //添加已收入明细
            incomeService.saveData(1, 1, 6, orderCall.getId(), 7, money);
            systemNoticeService.addSystemNotice(1, "您已使用余额成功完成感谢费支付,谢谢使用!", uid, 1);
 
        }
        if(payType==4){
            Double payMoney = orderCall.getThankYouFee();
            Integer integer = paymentRecordService.saveData(1, uid, 1, orderId, 7, 4, money, "", 1);
            resultUtil = appOrderController.placeAnOrder(new BigDecimal(money), 4,orderId,2,integer);
        }
        return resultUtil;
    }
 
    @Autowired
    private AppOrderController appOrderController;
 
    @Override
    public void payThankYouFeeCallback(Integer orderId, String order_id, Integer payType) throws Exception {
        OrderCall orderCall = this.selectById(orderId);
        PaymentRecord query = paymentRecordService.query(3, orderCall.getUserId(), 1, orderId, 7, payType, 1);
        query.setState(2);
        query.setCode(order_id);
        paymentRecordService.updateById(query);
 
        UserInfo userInfo = userInfoService.selectById(orderCall.getUserId());
        SysIntegral query1 = sysIntegralService.selectOne(new EntityWrapper<SysIntegral>().eq("companyId", orderCall.getCompanyId()));
        userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
        //添加交易明细
        transactionDetailsService.saveData(userInfo.getId(), "助老模式-感谢费", query.getAmount(), 2, 1, 1, 7, orderId);
        userInfoService.updateById(userInfo);
        orderCall.setThankYouFee(query.getAmount());
        this.updateById(orderCall);
 
        //添加已收入明细
        incomeService.saveData(1, 1, 6, orderCall.getId(), 7, query.getAmount());
        systemNoticeService.addSystemNotice(1, "您已使用" + (payType == 1 ? "微信" : (payType==2?"支付宝":"云闪付")) + "成功完成感谢费支付,谢谢使用!", userInfo.getId(), 1);
    }
}