xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
import com.stylefeng.guns.modular.system.dao.UserMerchantCouponMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.util.UUIDUtil;
import com.stylefeng.guns.modular.system.warpper.MerchantCouponWarpper;
import com.stylefeng.guns.modular.system.warpper.UserMerchantCouponWapper;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
import java.util.stream.Collectors;
 
@Service
public class UserMerchantCouponServiceImpl extends ServiceImpl<UserMerchantCouponMapper, UserMerchantCoupon> implements IUserMerchantCouponService {
 
    @Autowired
    private IMerchantService merchantService;
 
    @Autowired
    private IMerchantCouponService merchantCouponService;
 
    @Override
    public ResultUtil<UserMerchantCouponWapper> getUserMerchantCoupon(Integer uid, String code) throws Exception {
        Merchant merchant = merchantService.selectOne(new EntityWrapper<Merchant>().eq("userType", 2).eq("userId", uid).ne("state", 3));
        if(merchant.getAuditStatus() == 1){
            return ResultUtil.error("账户正在审核中");
        }
        if(merchant.getAuditStatus() == 3){
            return ResultUtil.error("账户审核不通过");
        }
        if(merchant.getState() == 2){
            return ResultUtil.error("账户被冻结");
        }
        UserMerchantCoupon userMerchantCoupon = this.selectOne(new EntityWrapper<UserMerchantCoupon>().eq("code", code).eq("state", 1));
        MerchantCoupon merchantCoupon = merchantCouponService.selectById(userMerchantCoupon.getMerchantCouponId());
        if(merchantCoupon.getMerchantId().compareTo(merchant.getId()) != 0){
            return ResultUtil.error("无效的核销码");
        }
        UserMerchantCouponWapper userMerchantCoupon1 = this.baseMapper.getUserMerchantCoupon(code);
        return ResultUtil.success(userMerchantCoupon1);
    }
 
    @Override
    public ResultUtil writeOffMerchantCoupon(Integer uid, String code) throws Exception {
        UserMerchantCoupon userMerchantCoupon = this.selectOne(new EntityWrapper<UserMerchantCoupon>().eq("code", code).eq("state", 1));
        if(null == userMerchantCoupon){
            return ResultUtil.error("无效的核销码");
        }
        if(System.currentTimeMillis() > userMerchantCoupon.getEndTime().getTime() || userMerchantCoupon.getStatus() == 3){
            return ResultUtil.error("优惠券已过期");
        }
        if(userMerchantCoupon.getStatus() == 2){
            return ResultUtil.error("优惠券已使用");
        }
        userMerchantCoupon.setStatus(2);
        userMerchantCoupon.setWriteOffTime(new Date());
        userMerchantCoupon.setWriteOffUserType(2);
        userMerchantCoupon.setWriteOffUserId(uid);
        this.updateById(userMerchantCoupon);
        return ResultUtil.success();
    }
 
    @Override
    public List<Map<String, Object>> getWriteOffHistory(Integer activityId, Integer id, Integer pageNum, Integer size) throws Exception {
        pageNum = (pageNum - 1) * size;
        return this.baseMapper.getWriteOffHistory(activityId, id, pageNum, size);
    }
 
    @Override
    public List<MerchantCouponWarpper> getMyMerchantCoupon(Integer uid, Integer type) throws Exception {
        return this.baseMapper.getMyMerchantCoupon(uid, type);
    }
 
    @Override
    public void updateExpired() throws Exception {
        this.baseMapper.updateExpired();
    }
 
}