mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
package com.panzhihua.service_dangjian.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.partybuilding.NewFightIntegral;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.building.NewFightShoppingOrderVO;
import com.panzhihua.common.model.vos.user.SysUserNoticeVO;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.utlis.Snowflake;
import com.panzhihua.service_dangjian.dao.NewFightShoppingOrderDao;
import com.panzhihua.service_dangjian.entity.ComActIntegralUser;
import com.panzhihua.service_dangjian.entity.NewFightShopping;
import com.panzhihua.service_dangjian.entity.NewFightShoppingOrder;
import com.panzhihua.service_dangjian.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
 
 
@Slf4j
@Service
public class NewFightShoppingOrderServiceImpl extends ServiceImpl<NewFightShoppingOrderDao,
        NewFightShoppingOrder> implements NewFightShoppingOrderService
{
 
    @Resource
    private NewFightShoppingService shoppingService;
 
    @Resource
    private ComActIntegralUsersService integralUsersService;
 
    @Resource
    private UserService userService;
 
    @Override
    public R getList(int pageNum,int pageSize,String userId,String goodsId,String orderNumber,
                     String goodName,String name,String cancelType,String communityId,String merchantId,String orderType)
    {
        Page page = new Page<NewFightShopping>(pageNum,pageSize);
        return R.ok(baseMapper.getList(page,userId,goodsId,orderNumber,goodName,name,cancelType,
                communityId, merchantId,orderType));
    }
 
    @Override
    public NewFightShoppingOrder getDetails(String id,String communityId) {
        return baseMapper.getDetails(id,communityId);
    }
 
 
    @Override
    public R addData(NewFightShoppingOrderVO item)
    {
        item.setOrderNumber(Snowflake.getId()+"");
 
 
        // 查询用户积分账户
        ComActIntegralUser integralUserDO =
                integralUsersService.getOne(new QueryWrapper<ComActIntegralUser>().lambda()
                        .eq(ComActIntegralUser::getUserId, item.getUserId())
                        .eq(ComActIntegralUser::getCommunityId, item.getCommunityId()));
 
        int allMoney=0;
        int getMoney=0;
 
        if(integralUserDO==null)
        {
            return R.fail("积分不足!");
        }
        allMoney=integralUserDO.getIntegralAvailableSum();
 
 
        //判断是线上下单  还是商家线下下单  1线上   2线下
        if(StringUtils.equals("2",item.getOrderType()))
        {
            getMoney=Integer.valueOf(item.getPalyMoney());
        }
        else
        {
            NewFightShopping goods=shoppingService.getDetails(item.getGoodsId());
            getMoney=Integer.valueOf(goods.getGoodPrice());
        }
 
 
        if(getMoney>allMoney)
        {
            return R.fail("积分不足!");
        }
 
        item.setCancelType("0");
        item.setPalyMoney(getMoney+"");
        int num= baseMapper.addData(item);
        if(num>0)
        {
            //修改个人积分总额
            allMoney=allMoney-getMoney;
            NewFightIntegral integral=new NewFightIntegral();
            integral.setIntegralNum(allMoney+"");
            integral.setAddOrReduce(2);
            integral.setCommunityId(item.getCommunityId());
            integral.setUserId(item.getUserId());
            if(StringUtils.equals("1",item.getOrderType()))
            {
 
                integral.setType("9");
                integral.setIdentityType("1");
                integral.setRemark("积分兑换商品");
            }
            else
            {
 
                integral.setType("10");
                integral.setIdentityType("1");
                integral.setRemark("商家兑换商品");
                integral.setMerchantId(item.getMerchantId());
                integral.setIntegralNum(item.getPalyMoney());
 
 
 
                SysUserNoticeVO sysUserNoticeVO = new SysUserNoticeVO();
                sysUserNoticeVO.setUserId(Long.valueOf(item.getUserId()));
                sysUserNoticeVO.setType(4);
                sysUserNoticeVO.setTitle("商家兑换成功");
                sysUserNoticeVO.setBusinessType(14);
                sysUserNoticeVO.setBusinessTitle(item.getRemark());
                sysUserNoticeVO
                        .setBusinessContent(String.format("兑换商品%s", item.getRemark()));
                sysUserNoticeVO.setStatus(0);
                sysUserNoticeVO.setBusinessStatus(1);
                sysUserNoticeVO.setBusinessId(Long.valueOf(item.getId()));
                sysUserNoticeVO.setActivityType(4);
                R r2 = userService.addNotice(sysUserNoticeVO);
                if (R.isOk(r2)) {
                    log.info("新增兑换商品通知成功【{}】", JSONObject.toJSONString(sysUserNoticeVO));
                }
            }
            integralUsersService.upIntegral(integral);
 
            return R.ok();
        }
        return R.fail("添加失败");
    }
 
    @Override
    public R editData(NewFightShoppingOrderVO item) {
        int num= baseMapper.editData(item);
        if(num>0)
        {
            return R.ok();
        }
        return R.fail("失败");
    }
 
    @Override
    public R cancelOrder(String orderId,String communityId)
    {
        NewFightShoppingOrder order=baseMapper.getDetails(orderId,communityId);
 
        if(!StringUtils.equals("0",order.getCancelType()))
        {
            return R.fail("订单不是待核销状态");
        }
 
        NewFightShoppingOrderVO orderVO=new NewFightShoppingOrderVO();
        orderVO.setId(orderId);
        orderVO.setCancelType("2");
        orderVO.setAbolishTime(new Date());
        int num=baseMapper.editData(orderVO);
        if(num>0)
        {
            // 查询用户积分账户
            ComActIntegralUser integralUserDO =
                    integralUsersService.getOne(new QueryWrapper<ComActIntegralUser>().lambda()
                            .eq(ComActIntegralUser::getUserId, order.getUserId())
                            .eq(ComActIntegralUser::getCommunityId, order.getCommunityId()));
 
            int allMoney=0;
            int getMoney=Integer.valueOf(order.getPalyMoney());
 
            allMoney=integralUserDO.getIntegralAvailableSum();
 
            //修改个人金汇币总额
            allMoney=allMoney+getMoney;
 
            NewFightIntegral integral=new NewFightIntegral();
 
            integral.setIntegralNum(allMoney+"");
            integral.setAddOrReduce(1);
            integral.setCommunityId(order.getCommunityId());
            integral.setUserId(order.getUserId());
 
            if(StringUtils.equals("1",order.getOrderType()))
            {
                integral.setType("9");
                integral.setIdentityType("1");
                integral.setRemark("积分兑换商品取消");
            }
            else
            {
                integral.setType("10");
                integral.setIdentityType("1");
                integral.setRemark("商家兑换商品取消");
                integral.setMerchantId(order.getMerchantId());
                integral.setIntegralNum(order.getPalyMoney());
            }
            integralUsersService.upIntegral(integral);
 
            return R.ok();
        }
        return R.fail("取消失败");
    }
 
    @Override
    public R expurgateData(String id,String communityId)
    {
        NewFightShoppingOrder order=baseMapper.getDetails(id,communityId);
 
        if(StringUtils.equals("0",order.getCancelType()))
        {
            return R.fail("待核销订单不能删除");
        }
 
        int num= baseMapper.expurgateData(id);
        if(num>0)
        {
            return R.ok();
        }
        return R.fail("添加失败");
    }
}