yanghb
2023-04-10 b2f678ad387ca24e05a11100ea4583f0f2f730f0
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package com.stylefeng.guns.modular.CharteredCar.server.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.CharteredCar.dao.OrderCharteredCarMapper;
import com.stylefeng.guns.modular.CharteredCar.model.OrderCharteredCar;
import com.stylefeng.guns.modular.CharteredCar.server.IOrderCharteredCarService;
import com.stylefeng.guns.modular.crossCity.dao.OrderCrossCityMapper;
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
import com.stylefeng.guns.modular.specialTrain.dao.OrderPrivateCarMapper;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.system.dao.SensitiveWordsMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.DateUtil;
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.system.warpper.PreferentialDataVo;
import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
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 javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
@Service
public class OrderCharteredCarServiceImpl extends ServiceImpl<OrderCharteredCarMapper, OrderCharteredCar> implements IOrderCharteredCarService {
 
    @Resource
    private OrderCharteredCarMapper orderCharteredCarMapper;
 
    @Resource
    private SensitiveWordsMapper sensitiveWordsMapper;
 
    @Autowired
    private ICompanyCityService companyCityService;
 
    @Autowired
    private DateUtil dateUtil;
 
    @Autowired
    private IOrderCancelService orderCancelService;
 
    @Autowired
    private ISystemNoticeService systemNoticeService;
 
    @Resource
    private OrderPrivateCarMapper orderPrivateCarMapper;
 
    @Resource
    private OrderTaxiMapper orderTaxiMapper;
 
    @Resource
    private OrderCrossCityMapper orderCrossCityMapper;
 
    @Autowired
    private IUserInfoService userInfoService;
 
    @Autowired
    private PayMoneyUtil payMoneyUtil;
 
    @Autowired
    private IPaymentRecordService paymentRecordService;
 
    @Autowired
    private IIncomeService incomeService;
 
    @Autowired
    private ITransactionDetailsService transactionDetailsService;
 
    @Autowired
    private ISysIntegralService sysIntegralService;
 
 
 
    /**
     * 保存数据
     * @param traveltime
     * @param carTime
     * @param modelUse
     * @param peopleNumber
     * @param contactPerson
     * @param contactPhone
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil orderCharteredCar(Date travelTime, Integer carTime, Integer serverCarModelId, String modelUse, Integer peopleNumber,
                                        String contactPerson, String contactPhone, String placeLonLat, Integer uid) throws Exception {
 
        /**
         * 1.出租车、专车、跨城有待支付的订单不能叫车
         * 2.小件物流有未完成的订单可以下跨城、专车、出租车
         * 3.出租车、专车、跨城有预约单可以下即时单
         */
        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryByState(uid, null, 1, 7, 12);
        if(orderPrivateCars.size() > 0){
            return ResultUtil.error("有未完成的订单");
        }
        List<OrderTaxi> list = orderTaxiMapper.queryByState_(uid, null, 1, 7, 12);
        if(list.size() > 0){
            return ResultUtil.error("有未完成的订单");
        }
        List<OrderCrossCity> orderCrossCities1 = orderCrossCityMapper.queryByState(uid, 7, 12);
        if(orderCrossCities1.size() > 0){
            return ResultUtil.error("有未完成的订单");
        }
 
 
        OrderCharteredCar orderCharteredCar = new OrderCharteredCar();
        orderCharteredCar.setUserId(uid);
        Company query = companyCityService.query(placeLonLat.split(",")[0], placeLonLat.split(",")[1]);
        if(null == query){
            return ResultUtil.error("该地点暂无企业服务");
        }
        orderCharteredCar.setCompanyId(query.getId());
        orderCharteredCar.setOrderNumber(this.getOrderNum());
        orderCharteredCar.setTraveltime(travelTime);
        orderCharteredCar.setCarTime(carTime);
        orderCharteredCar.setServerCarModelId(serverCarModelId);
        orderCharteredCar.setModelUse(modelUse);
        orderCharteredCar.setPeopleNumber(peopleNumber);
        orderCharteredCar.setContactPerson(contactPerson);
        orderCharteredCar.setContactPhone(contactPhone);
        orderCharteredCar.setState(1);
        orderCharteredCar.setIsDelete(1);
        orderCharteredCar.setInsertTime(new Date());
        this.insert(orderCharteredCar);
        return ResultUtil.success();
    }
 
 
    /**
     * 获取个人中心订单列表
     * @param uid
     * @param pageNum
     * @param size
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryMyOrderList(Integer uid, Integer pageNum, Integer size) throws Exception {
        pageNum = (pageNum - 1) * size;
        List<Map<String, Object>> maps = orderCharteredCarMapper.queryMyOrderList(uid, pageNum, size);
        return maps;
    }
 
 
    @Override
    public ResultUtil addCancle(Integer id, String reason, String remark, Integer uid) throws Exception {
        if(ToolUtil.isNotEmpty(remark)){
            if(ToolUtil.isNotEmpty(remark)){
                List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null);
                for(SensitiveWords s : sensitiveWords){
                    remark = remark.replaceAll(s.getContent(), "***");
                }
            }
        }
 
        OrderCharteredCar orderCharteredCar = this.selectById(id);
        if(null == orderCharteredCar){
            return ResultUtil.error("取消订单失败,订单信息有误");
        }
        if(orderCharteredCar.getState() != 1){
            return ResultUtil.error("取消订单失败,不合法的操作");
        }
 
        OrderCancel orderCancel = new OrderCancel();
        orderCancel.setOrderId(id);
        orderCancel.setOrderType(6);
        orderCancel.setReason(reason);
        orderCancel.setRemark(remark);
        orderCancel.setState(2);
        orderCancel.setInsertTime(new Date());
        orderCancel.setUserType(1);
        orderCancelService.insert(orderCancel);
        orderCharteredCar.setState(3);
        this.updateById(orderCharteredCar);
 
        //添加消息
        systemNoticeService.addSystemNotice(1, "您已成功取消旅游包车订单,谢谢使用!", orderCharteredCar.getUserId(), 1);
        Map<String, Object> map = new HashMap<>();
        map.put("id", orderCancel.getId());
        return ResultUtil.success(map);
    }
 
 
 
 
    public synchronized String getOrderNum() throws Exception{
        int size = this.selectCount(null);
        return "CHARTERED" + String.valueOf(1000000 + size + 1).substring(1);
    }
 
    @Override
    public ResultUtil payThankYouFee(Integer uid, Integer orderId, Double money, Integer payType, Integer type) throws Exception {
        UserInfo userInfo = userInfoService.selectById(uid);
        OrderCharteredCar orderCharteredCar = this.selectById(orderId);
        ResultUtil resultUtil = ResultUtil.success();
        if(payType == 1){//微信支付
            String app = type == 1 ? "APP" : "JSAPI";
            resultUtil = payMoneyUtil.weixinpay("感谢费", "", orderId + "_6_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/wxPayThankYouFee", app, userInfo.getAppletsOpenId());
            paymentRecordService.saveData(3, uid, 1, orderId, 6, 1, money, "", 1);//添加预支付数据
        }
        if(payType == 2){//支付宝支付
            resultUtil = payMoneyUtil.alipay("感谢费", "感谢费", "", orderId + "_6_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/aliPayThankYouFee");
            paymentRecordService.saveData(1, uid, 1, orderId, 6, 2, money, "", 1);//添加预支付数据
        }
        if(payType == 3){//余额支付
            if(userInfo.getBalance() == null || userInfo.getBalance() < money){
                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", orderCharteredCar.getCompanyId()));
            userInfo.setIntegral(userInfo.getIntegral() + (money.intValue() * query1.getIntegral()));//积分
 
            //添加交易明细
            transactionDetailsService.saveData(uid, "包车-感谢费", money, 2, 1, 1, 6, orderId);
            userInfoService.updateById(userInfo);
 
            orderCharteredCar.setThankYouFee(money);
            this.updateById(orderCharteredCar);
 
            //添加已收入明细
            incomeService.saveData(1, 1, 6, orderCharteredCar.getId(), 6, money);
            systemNoticeService.addSystemNotice(1, "您已使用余额成功完成感谢费支付,谢谢使用!", uid, 1);
        }
        return resultUtil;
    }
 
    @Override
    public void payThankYouFeeCallback(Integer orderId, String order_id, Integer payType) throws Exception {
        OrderCharteredCar orderCharteredCar = this.selectById(orderId);
        PaymentRecord query = paymentRecordService.query(3, orderCharteredCar.getUserId(), 1, orderId, 6, payType, 1);
        query.setState(2);
        query.setCode(order_id);
        paymentRecordService.updateById(query);
 
        UserInfo userInfo = userInfoService.selectById(orderCharteredCar.getUserId());
        SysIntegral query1 = sysIntegralService.selectOne(new EntityWrapper<SysIntegral>().eq("companyId", orderCharteredCar.getCompanyId()));
        userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
        //添加交易明细
        transactionDetailsService.saveData(userInfo.getId(), "包车-感谢费", query.getAmount(), 2, 1, 1, 6, orderId);
        userInfoService.updateById(userInfo);
 
        orderCharteredCar.setThankYouFee(query.getAmount());
        this.updateById(orderCharteredCar);
 
        //添加已收入明细
        incomeService.saveData(1, 1, 6, orderCharteredCar.getId(), 6, query.getAmount());
        systemNoticeService.addSystemNotice(1, "您已使用" + (payType == 1 ? "微信" : "支付宝") + "成功完成感谢费支付,谢谢使用!", userInfo.getId(), 1);
    }
 
    @Override
    public PreferentialDataVo queryBalance1(Integer orderId, Integer uid) throws Exception {
        PreferentialDataVo preferentialDataVo = new PreferentialDataVo();
        UserInfo userInfo = userInfoService.selectById(uid);
        preferentialDataVo.setBalance(userInfo.getBalance());
        return preferentialDataVo;
    }
}