liujie
2025-08-04 ddba15cfd1d654dc41de5dfdc587e12d96d84f4f
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package com.stylefeng.guns.modular.shunfeng.controller;
 
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.shunfeng.model.OrderRide;
import com.stylefeng.guns.modular.shunfeng.model.vo.ApiJson;
import com.stylefeng.guns.modular.shunfeng.service.IOrderRideService;
import com.stylefeng.guns.modular.shunfeng.service.IParamService;
import com.stylefeng.guns.modular.shunfeng.service.ITimeTaskService;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.ISystemNoticeService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
 
/**
 * 支付相关接口
 */
@Api(tags = "顺风车支付相关接口")
@Controller
@RequestMapping("/api/payInfo")
public class PayInfoController {
 
    @Autowired
    private IParamService paramService;
    @Autowired
    private IOrderRideService orderRideService;
    @Autowired
    private ITimeTaskService timeTaskService;
    @Autowired
    private IUserInfoService userInfoService;
    @Autowired
    private ISystemNoticeService systemNoticeService;
 
 
 
 
 
 
    /**
     * 顺风车支付
     * @param orderId
     * @param couponId
     * @return
     */
    public Object payBalanceRide(Integer orderId,Integer couponId){
        try {
            OrderRide orderRide=orderRideService.selectById(orderId);
            if(orderRide.getState() == 6){
                return ApiJson.returnNG("超出支付时间,订单已自动取消");
            }
            if(orderRide.getState() == 2){
                return ApiJson.returnNG("该订单已支付");
            }
            orderRide.setPayTime(new Date());
            orderRide.setPayType(1);//1余额
            orderRide.setState(2);//已支付
            Double couponMoney=0d;
            Integer cid=0;//优惠券id
            String couponName="";
            /*todo 如果使用了优惠券*/
            if(couponId!= null && couponId>0){
//            orderRide.setCouponId(couponId);
//            CouponUser couponUser=couponUserService.selectById(couponId);
//            if(couponUser!=null){
//                couponMoney=couponUser.getUsableMoney();
//                cid=couponUser.getCouponId();
//                couponName=couponUser.getCouponName();
//                //标记优惠券已使用
//                couponUser.setState(3);
//                couponUserService.updateById(couponUser);
//            }
            }
            /*支付金额=订单金额-优惠券*/
            Double money=orderRide.getMoney()-couponMoney<0?0:orderRide.getMoney()-couponMoney;
            //减去用户余额
            UserInfo userInfo = userInfoService.selectById(orderRide.getUserId());
            if((userInfo.getBalance() == null ?0 : userInfo.getBalance()) < money){
                return ApiJson.returnNG("用户余额不足");
            }
            if(cid>0){
                //todo 优惠券总额
//            Coupon coupon=couponService.selectById(cid);
//            //优惠券类型(1注册、2分享、3活动、4验票)
//            coupon.setUseNumber(coupon.getUseNumber()+1);
//            coupon.setUseMoney(coupon.getUseMoney()+couponMoney);
//            couponService.updateById(coupon);
//            orderRide.setCouponName(couponName);
//            orderRide.setCouponMoney(couponMoney);
            }
            orderRideService.updateById(orderRide);
            //系统消息
            systemNoticeService.addSystemNotice(1, "您成功支付从"+orderRide.getStartName()+"到"+orderRide.getEndName()+"的顺风车订单",
                    orderRide.getUserId(),1);
            /*修改用户余额*/
            userInfo.setBalance(userInfo.getBalance() - money);
            userInfoService.updateById(userInfo);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ApiJson.returnOK("支付成功");
    }
 
    /**
     * 线上支付
     * @param orderId 订单ID
     * @param type (1:订单支付,2:充值 3:出租车红包支付,4:服务费用缴费,5顺风车支付)
     * @param  payType (1:支付宝,2:微信 3:银行卡 ,4:小程序)
     * @param isBalance (是否开启余额支付 1否,2是)
     * @param  code 微信小程序支付需要
     * @return
     */
    @ResponseBody
    @RequestMapping("/payOnline")
    public Object payOnline(Integer orderId,Integer type,String code,Integer payType,Integer isBalance,HttpServletRequest request,Integer couponId){
        try {
            if(orderId == null || orderId == 0){
                return ApiJson.returnNG("订单ID不能为空");
            }
            if(type == null || type == 0){
                return ApiJson.returnNG("type不能为空");
            }
            if(payType == null || payType == 0){
                return ApiJson.returnNG("payType不能为空");
            }
            Object info=new Object();
            String openId=null;
            if(ToolUtil.isNotEmpty(code)){
                /*根据微信端的code获取openId*/
//                openId=new JsapiTicketUtilX().getOpenId(code);
            }
    
            OrderRide orderRide=orderRideService.selectById(orderId);
            if(orderRide.getState()==6){
                return ApiJson.returnNG("该订单已取消");
            }
            if(orderRide.getState()==2){//已支付
                return ApiJson.returnNG("该订单不需要支付");
            }
            info = new PayUtil().getPayInfo(payType,orderRide.getOrderNum(),openId,request);
            return ApiJson.returnOK(info);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ApiJson.returnNG("购票失败");
    }
    /**
     * 支付宝回调
     * @return
     */
    @ResponseBody
    @RequestMapping("/alipay/notify")
    public void notifyUrl(HttpServletRequest request, HttpServletResponse response) {
        new PayUtil().notifyUrl(request,response);
    }
 
    /**
     * 微信回调
     * @param request
     * @param response
     */
    @ResponseBody
    @RequestMapping("/wxpay/notify")
    public void wxnotify(HttpServletRequest request, HttpServletResponse response) {
        new PayUtil().wxnotify(request,response);
    }
}