Helius
2022-05-12 bc0898f18e741571608176d89cdd16b94c781913
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
package com.matrix.system.hive.service.imp;
 
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.pojo.VerificationResult;
import com.matrix.core.tools.DateUtil;
import com.matrix.core.tools.LogUtil;
import com.matrix.system.common.dao.SysUsersDao;
import com.matrix.system.common.validate.GroupValidateStatusCheckUtil;
import com.matrix.system.common.validate.group.Group;
import com.matrix.system.constance.Dictionary;
import com.matrix.system.hive.bean.*;
import com.matrix.system.hive.dao.*;
import com.matrix.system.hive.dto.MoneyCardOperationDto;
import com.matrix.system.hive.plugin.util.MoneyUtil;
import com.matrix.system.hive.service.MoneyCardUseService;
import com.matrix.system.hive.service.ShoppingGoodsService;
import com.matrix.system.hive.service.SysOrderService;
import com.matrix.system.hive.validation.MoneyCardUseGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
 
/**
 * @date 2016-09-17 10:17
 */
@Service("moneyCardUseService")
public class MoneyCardUseServiceImpl extends ServiceImpl<MoneyCardUseDao, MoneyCardUse> implements MoneyCardUseService {
 
 
    @Autowired
    private MoneyCardUseDao moneyCardUseDao;
 
    @Autowired
    private MoneyCardUseFreezeDao moneyCardUseFreezeDao;
 
 
    @Autowired
    private SysVipInfoDao infoDao;
    @Autowired
    private SysOrderItemDao orderItemDao;
 
    @Autowired
    SysOrderService sysOrderService;
 
    @Autowired
    private SysVipLevelDao viplevelDao;
 
    @Autowired
    ShoppingGoodsDao shoppingGoodsDao;
 
    @Autowired
    MoneyCardAssembleDao moneyCardAssembleDao;
    @Autowired
    MoneyCardUseFlowDao moneyCardUseFlowDao;
 
    @Autowired
    SysUsersDao sysUsersDao;
 
    @Autowired
    private ShoppingGoodsService shoppingGoodsService;
 
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addVipMoneyCard(List<MoneyCardOperationDto> moneyCardOperationDtos) {
        moneyCardOperationDtos.forEach(dto -> {
 
            //参数校验
            GroupValidateStatusCheckUtil.check(dto,Group.ADD.class);
 
            ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(dto.getGoodsId());
            MoneyCardUse moneyCardUse = new MoneyCardUse();
            BeanUtil.copyProperties(dto, moneyCardUse);
            moneyCardUse.setGiftMoney(shoppingGoods.getReferencePice());
            moneyCardUse.setRealMoney(shoppingGoods.getSealPice());
            moneyCardUse.setGoodsId(shoppingGoods.getId());
            moneyCardUse.setStatus(Dictionary.MONEYCARD_STATUS_YX);
            moneyCardUse.setIsVipCar(Dictionary.FLAG_NO_N);
            moneyCardUse.setCardName(shoppingGoods.getName());
 
            //余次处理
            if (shoppingGoods.getCarUseCount() == null || shoppingGoods.getCarUseCount() == 0) {
                moneyCardUse.setUseTotal(999999999);
                moneyCardUse.setLastCount(999999999);
            } else {
                moneyCardUse.setUseTotal(shoppingGoods.getCarUseCount());
                moneyCardUse.setLastCount(shoppingGoods.getCarUseCount());
            }
            //失效时间处理
            Date invalidTime = shoppingGoodsService.calInvalidTime(shoppingGoods, 1, null);
            moneyCardUse.setFailTime(invalidTime);
            moneyCardUseDao.insert(moneyCardUse);
 
        });
    }
 
    @Override
    public void deleteByOrderItemId(Long orderItemId) {
 
        List<MoneyCardUse> moneyCardUseList = getMoneyCardUseListByOrderItemId(orderItemId);
        moneyCardUseList.forEach(moneyCardUse -> {
            MoneyCardUseFlow  moneyCardUseFlow=new MoneyCardUseFlow();
            moneyCardUseFlow.setCarUseId(moneyCardUse.getId());
            int i = moneyCardUseFlowDao.selectTotalRecord(moneyCardUseFlow);
            if(i>0){
                throw new GlobleException(moneyCardUse.getCardName()+"储值卡已经被启用无法删除");
            }else {
                LogUtil.info("根据订单明细id{},删除储值卡:{}", orderItemId,moneyCardUse.getCardName());
                moneyCardUseDao.deleteById(moneyCardUse.getId());
            }
        });
 
 
    }
 
 
    @Override
    public void moneyCardTk(List<MoneyCardOperationDto> moneyCardOperationDtos) {
 
        moneyCardOperationDtos.forEach(moneyCardOperationDto -> {
 
            GroupValidateStatusCheckUtil.check(moneyCardOperationDto, MoneyCardUseGroup.moneyCardUseTk.class);
 
            List<MoneyCardUse> moneyCardUseList = getMoneyCardUseListByOrderItemId(moneyCardOperationDto.getOrderItemId());
            for (MoneyCardUse moneyCardUse : moneyCardUseList) {
                //本金扣款
                if (moneyCardUse.getRealMoney() + moneyCardOperationDto.getRealMoney() >= 0) {
                    double surplus = MoneyUtil.add(moneyCardUse.getRealMoney(), moneyCardOperationDto.getRealMoney());
                    moneyCardUse.setRealMoney(surplus);
                } else {
                    throw new GlobleException(moneyCardUse.getCardName() + "余额不足");
                }
                //余额为0时充值卡变为无效
                if (moneyCardUse.getRealMoney().equals(0D)) {
                    moneyCardUse.setIsOver(Dictionary.FLAG_YES_Y);
                    moneyCardUse.setStatus(Dictionary.TAOCAN_STATUS_TK);
                }
                moneyCardUse.setGiftMoney(0D);
                moneyCardUseDao.update(moneyCardUse);
                saveMoneyCardUseFlow(moneyCardOperationDto,moneyCardUse);
            }
 
        });
    }
 
    /**
     * 根据订单明细id查询会员卡
     * @param orderItemId
     * @return
     */
    private List<MoneyCardUse> getMoneyCardUseListByOrderItemId(Long orderItemId) {
        LambdaQueryWrapper<MoneyCardUse> lambdaQueryChainWrapper = new LambdaQueryWrapper();
        lambdaQueryChainWrapper.eq(MoneyCardUse::getOrderItemId, orderItemId);
        List<MoneyCardUse> moneyCardUseList = list(lambdaQueryChainWrapper);
        return moneyCardUseList;
    }
 
    /**
     * 保存储值卡流水
     * @param moneyCardOperationDto
     * @param moneyCardUse
     */
    private  void saveMoneyCardUseFlow(MoneyCardOperationDto moneyCardOperationDto,MoneyCardUse moneyCardUse){
        MoneyCardUseFlow  moneyCardUseFlow=new MoneyCardUseFlow();
        moneyCardUseFlow.setCarUseId(moneyCardUse.getId());
        moneyCardUseFlow.setOrderNo(moneyCardOperationDto.getOrderNo());
        moneyCardUseFlow.setVipId(moneyCardUse.getVipId());
        moneyCardUseFlow.setTimes(moneyCardUse.getLastCount());
        moneyCardUseFlow.setType(moneyCardOperationDto.getType());
        moneyCardUseFlow.setCreateTime(new Date());
        moneyCardUseFlow.setOperationId(moneyCardOperationDto.getUpdateUser());
        moneyCardUseFlow.setTotal(moneyCardUse.getRealMoney());
        moneyCardUseFlow.setGiftMoney(moneyCardUse.getGiftMoney());
        moneyCardUseFlow.setTotal(moneyCardOperationDto.getRealMoney());
        moneyCardUseFlow.setBalance(moneyCardUse.getGiftMoney() + moneyCardUse.getRealMoney());
        moneyCardUseFlow.setStaffName(sysUsersDao.selectById(moneyCardOperationDto.getUpdateUser()).getSuName());
 
 
 
        moneyCardUseFlowDao.insert(moneyCardUseFlow);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void changeMoneyCard(List<MoneyCardOperationDto> moneyCardOperationDtoList) {
        moneyCardOperationDtoList.forEach(moneyCardOperationDto -> {
 
 
            if (MoneyCardUseFlow.USE_TYPE_CONSUMER.equals(moneyCardOperationDto.getType())) {
                //储值卡支付订单 扣减储值卡余额
                GroupValidateStatusCheckUtil.check(moneyCardOperationDto,MoneyCardUseGroup.moneyCardUseOrderChange.class);
                moneyCardPayOrder(moneyCardOperationDto);
            } else if (MoneyCardUseFlow.USE_TYPE_ORDRE_CANCEL.equals(moneyCardOperationDto.getType())) {
                //回退储值卡余额
                GroupValidateStatusCheckUtil.check(moneyCardOperationDto,MoneyCardUseGroup.moneyCardUseOrderChange.class);
                returnMoneyCard(moneyCardOperationDto);
            } else if (MoneyCardUseFlow.USE_TYPE_CZ.equals(moneyCardOperationDto.getType())) {
                //回退储值卡余额
                GroupValidateStatusCheckUtil.check(moneyCardOperationDto,MoneyCardUseGroup.moneyCardUseCz.class);
                moneyCardCz(moneyCardOperationDto);
            }
        });
    }
 
    /**
     * 会员卡充值
     * @param moneyCardOperationDto
     */
    private void moneyCardCz(MoneyCardOperationDto moneyCardOperationDto) {
 
        LogUtil.info("会员卡充值 {}", JSON.toJSONString(moneyCardOperationDto));
        MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(moneyCardOperationDto.getCarUseId());
 
 
        if (Objects.nonNull(moneyCardOperationDto.getGiftMoney())) {
            //jyytodo 余额余次的修改和新增在数据库层面做加减
            moneyCardUse.setGiftMoney(moneyCardUse.getGiftMoney() + moneyCardOperationDto.getGiftMoney());
        }
        if (Objects.nonNull(moneyCardOperationDto.getRealMoney())) {
            moneyCardUse.setRealMoney(moneyCardUse.getRealMoney() + moneyCardOperationDto.getRealMoney());
        }
        moneyCardUseDao.update(moneyCardUse);
        //设置卡项使用流水
        saveMoneyCardUseFlow(moneyCardOperationDto,moneyCardUse);
 
 
 
    }
 
    /**
     * 回退储值卡余额
     *
     * @param moneyCardOperationDto
     */
    private void returnMoneyCard(MoneyCardOperationDto moneyCardOperationDto) {
        LogUtil.info("回退储值卡余额 {}", JSON.toJSONString(moneyCardOperationDto));
        MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(moneyCardOperationDto.getCarUseId());
        MoneyCardUseFlow moneyCardUseFlow = new MoneyCardUseFlow();
 
        if (Objects.nonNull(moneyCardOperationDto.getGiftMoney())) {
            //jyytodo 余额余次的修改和新增在数据库层面做加减
            moneyCardUse.setGiftMoney(moneyCardUse.getGiftMoney() + moneyCardOperationDto.getGiftMoney());
        }
        if (Objects.nonNull(moneyCardOperationDto.getRealMoney())) {
            moneyCardUse.setRealMoney(moneyCardUse.getRealMoney() + moneyCardOperationDto.getRealMoney());
        }
        moneyCardUse.setIsOver(Dictionary.FLAG_YES_Y);
        moneyCardUse.setStatus(Dictionary.MONEYCARD_STATUS_YX);
        moneyCardUseDao.update(moneyCardUse);
 
 
        //设置卡项使用流水
        saveMoneyCardUseFlow(moneyCardOperationDto,moneyCardUse);
    }
 
    /**
     * 储值卡支付订单 扣减储值卡余额
     *
     * @param moneyCardOperationDto
     */
    private void moneyCardPayOrder(MoneyCardOperationDto moneyCardOperationDto) {
        // 判断商品是否在充值卡的限制购买
        VerificationResult verificationResult = checkIsBangding(moneyCardOperationDto.getCarUseId(), moneyCardOperationDto.getGoodsIds());
        if (!verificationResult.isJudgeResult()) {
            throw new GlobleException(verificationResult.getMsg());
        }
 
        LogUtil.info("扣减储值卡余额 {}", JSON.toJSONString(moneyCardOperationDto));
        MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(moneyCardOperationDto.getCarUseId());
 
        // 用户默认储值卡不进行欠款检查 20220512 wzy
        if (Dictionary.FLAG_NO_N.equals(moneyCardUse.getIsVipCar())) {
            //欠款检查
            checkOrderStatu(moneyCardUse.getOrderItemId());
        }
 
        //赠送金额扣款
        if (moneyCardUse.getGiftMoney() + moneyCardOperationDto.getGiftMoney() >= 0) {
            double surplus = MoneyUtil.add(moneyCardUse.getGiftMoney(), moneyCardOperationDto.getGiftMoney());
            moneyCardUse.setGiftMoney(surplus);
        } else {
            throw new GlobleException(moneyCardUse.getCardName() + "余额不足");
        }
        //本金扣款
        if (moneyCardUse.getRealMoney() + moneyCardOperationDto.getRealMoney() >= 0) {
            double surplus = MoneyUtil.add(moneyCardUse.getRealMoney(), moneyCardOperationDto.getRealMoney());
            moneyCardUse.setRealMoney(surplus);
        } else {
            throw new GlobleException(moneyCardUse.getCardName() + "余额不足");
        }
 
 
        if (moneyCardUse.getIsVipCar().equals(Dictionary.FLAG_NO_N)) {
            //余额为0时充值卡变为无效
            if (moneyCardUse.getRealMoney().equals(0D) && moneyCardUse.getGiftMoney().equals(0D)) {
                moneyCardUse.setIsOver(Dictionary.FLAG_YES_Y);
                moneyCardUse.setStatus(Dictionary.MONEYCARD_STATUS_WX);
            }
        }
 
        ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(moneyCardUse.getGoodsId());
        if (shoppingGoods != null) {
            Date invalidTime = shoppingGoodsService.calInvalidTime(shoppingGoods, 2, moneyCardUse.getFailTime());
            moneyCardUse.setFailTime(invalidTime);
        }
 
        // 储值卡不减少使用次数 20220512 wzy
        if (Dictionary.FLAG_NO_N.equals(moneyCardUse.getIsVipCar())) {
            moneyCardUse.setLastCount(moneyCardUse.getLastCount() - moneyCardOperationDto.getCount());
        }
 
        // 更新充值卡信息
        moneyCardUseDao.update(moneyCardUse);
        //设置卡项使用流水
        saveMoneyCardUseFlow(moneyCardOperationDto,moneyCardUse);
    }
 
    /**
     * 检查商品是否在储值卡的消费范围内
     *
     * @param moneyCardUseId 储值卡id
     * @param goodsIds       商品id集合
     * @return
     */
    private VerificationResult checkIsBangding(Long moneyCardUseId, List<Long> goodsIds) {
        // 如果是一卡通则肯定在绑定范围内
        MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(moneyCardUseId);
        //默认储值卡可以购买所有产品
        if (moneyCardUse.getIsVipCar().equals(Dictionary.FLAG_YES_Y)) {
            return VerificationResult.success();
        } else {
            // 不是默认储值卡判断卡是否可应用于所有产品
            ShoppingGoods cardGoods = shoppingGoodsDao.selectById(moneyCardUse.getGoodsId());
            if (cardGoods != null) {
                if (Dictionary.FLAG_YES.equals(cardGoods.getCarIsAll())) {
                    return VerificationResult.success();
                }
            }
            // 比较分类
            MoneyCardAssemble moneyCardAssemble = new MoneyCardAssemble();
            moneyCardAssemble.setCardId(moneyCardUse.getGoodsId());
            List<MoneyCardAssemble> cardAssembleList = moneyCardAssembleDao.selectByModel(moneyCardAssemble);
            List<ShoppingGoods> yhGoods = shoppingGoodsDao.selectByIds(goodsIds);
 
            StringBuilder msgBuilder = new StringBuilder();
 
            for (ShoppingGoods goods : yhGoods) {
                boolean isMatch = false;
                for (MoneyCardAssemble cardAssemble : cardAssembleList) {
                    // 比较类型
                    if (cardAssemble.getType().equals(Dictionary.CZK_ASSEMBLE_FL)) {
 
                        if (goods.getCateId().equals(cardAssemble.getCateId())) {
                            isMatch = true;
                            break;
                        }
                    } else {
                        // 比较绑定
                        if (goods.getId().equals(cardAssemble.getGoodsId())) {
                            isMatch = true;
                            break;
                        }
                    }
                }
                if (!isMatch) {
                    msgBuilder.append(goods.getName() + "不在" + moneyCardUse.getCardName() + "优惠中 ");
                }
            }
            if (msgBuilder.length() > 0) {
                return VerificationResult.fail(msgBuilder.toString());
            } else {
                return VerificationResult.success();
            }
 
        }
    }
 
    @Override
    public int add(MoneyCardUse moneyCardUse) {
 
        return moneyCardUseDao.insert(moneyCardUse);
 
    }
 
    @Override
    public int modify(MoneyCardUse moneyCardUse) {
 
        return moneyCardUseDao.update(moneyCardUse);
 
    }
 
    @Override
    public int remove(List<Long> list) {
 
        return moneyCardUseDao.deleteByIds(list);
 
    }
 
    @Override
    public int removeById(Long id) {
 
        return moneyCardUseDao.deleteById(id);
 
    }
 
    @Override
    public List<MoneyCardUse> findInPage(MoneyCardUse moneyCardUse, PaginationVO pageVo) {
 
        return moneyCardUseDao.selectInPage(moneyCardUse, pageVo);
 
    }
 
    @Override
    public List<MoneyCardUse> findByModel(MoneyCardUse moneyCardUse) {
 
        return moneyCardUseDao.selectByModel(moneyCardUse);
 
    }
 
    @Override
    public int findTotal(MoneyCardUse moneyCardUse) {
 
        return moneyCardUseDao.selectTotalRecord(moneyCardUse);
 
    }
 
    @Override
    public MoneyCardUse findById(Long id) {
        return moneyCardUseDao.selectById(id);
 
    }
 
    @Override
    public MoneyCardUse findByVipId(Long id) {
        return moneyCardUseDao.selectVipCard(id);
    }
 
    @Override
    public List<MoneyCardUse> findVipCardUseInPage(MoneyCardUse moneyCardUse, PaginationVO pageVo) {
        return moneyCardUseDao.selectVipCardUseInPage(moneyCardUse, pageVo);
    }
 
    @Override
    public List<MoneyCardUse> findVipCardUse(MoneyCardUse moneyCardUse) {
        return moneyCardUseDao.selectVipCardUse(moneyCardUse);
    }
 
    @Override
    public Integer findTotalVipCardUse(MoneyCardUse moneyCardUse) {
        return moneyCardUseDao.selectVipCardUseTotal(moneyCardUse);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int freeze(MoneyCardUse moneyCardUse) {
        // 态为有效的才能冻结
        MoneyCardUse moneyCard = moneyCardUseDao.selectById(moneyCardUse.getId());
        if (!moneyCard.getStatus().equals(Dictionary.TAOCAN_STATUS_YX)) {
            throw new GlobleException("不是有效充值卡");
        }
 
        // 将充值卡的状态改为冻结
        moneyCard.setStatus(Dictionary.TAOCAN_STATUS_DJ);
        moneyCardUseDao.update(moneyCard);
        // 冻结记录
        MoneyCardUseFreeze freeze = new MoneyCardUseFreeze();
        freeze.setFreezeTime(new Date());
        freeze.setCardUseId(moneyCard.getId());
        ;
        MoneyCardUseFreeze getfreeze = moneyCardUseFreezeDao.selectByMoneyCardUseId(moneyCard.getId());
 
        //更新会员等级
        moneyCard.getVipInfo().setLevelId(0L);
        infoDao.update(moneyCard.getVipInfo());
 
        int i = 0;
        if (getfreeze != null) {
            freeze.setId(getfreeze.getId());
            i = moneyCardUseFreezeDao.update(freeze);
        } else {
            i = moneyCardUseFreezeDao.insert(freeze);
        }
        //记录流水
        String content = moneyCard.getCardName() + "冻结";
        return i;
    }
 
    //转让充值卡
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void transfer(MoneyCardUse moneyCardUse, Long vipId2, Double money) {
        Long oldId = moneyCardUse.getId();
 
        moneyCardUse = moneyCardUseDao.selectById(moneyCardUse.getId());
        if (moneyCardUse.getVipId().equals(vipId2)) {
            throw new GlobleException("转让人不能是该充值卡拥有者!");
        }
        System.out.println("id ====== " + moneyCardUse.getId());
        // 查询要转让的充值卡
        MoneyCardUse getObj = moneyCardUseDao.selectById(moneyCardUse.getId());
 
        //检测商品是否已付款完成
        if (getObj.getOrderItemId() != 1) {//不是数据迁移过来的判断付款状态
            checkOrderStatu(getObj.getOrderItemId());
        }
 
        if (!(getObj.getStatus().equals(Dictionary.TAOCAN_STATUS_YX))) {
            throw new GlobleException("不是有效的充值卡!");
        }
        SysVipInfo info = infoDao.selectById(vipId2);
 
        if (money >= getObj.getRealMoney()) {//如果全部转让出去
            //更新状态
            moneyCardUse.setStatus(Dictionary.TAOCAN_SOURCE_ZR);
            moneyCardUseDao.update(moneyCardUse);
        }
 
        //更新会员等级
        getObj.getVipInfo().setLevelId(0L);
        infoDao.update(getObj.getVipInfo());
        //新增转让流水
        StringBuilder content = new StringBuilder();
 
        content.append(getObj.getCardName() + "转让给会员" + getObj.getCardName());
 
 
        MoneyCardUse infoCard = moneyCardUseDao.selectVipCard(info.getId());
        //清空content
 
 
        //判断会员没有会籍卡,或者该充值卡不为会籍卡
        if (infoCard == null || Dictionary.FLAG_YES_Y.equals(getObj.getIsVipCar())) {
            //添加一条接受转让的记录到充值卡使用情况表中
 
            if (!getObj.getSource().contains(Dictionary.TAOCAN_STATUS_ZR)) {
                getObj.setSource(getObj.getSource() + Dictionary.TAOCAN_STATUS_ZR);
            }
            getObj.setVipId(vipId2);
            getObj.setId(null);
            content = new StringBuilder();
            moneyCardUseDao.insert(getObj);
            content.append("获取会员" + getObj.getVipInfo().getVipName() + "的" + getObj.getCardName())
                    .append(",余次:" + getObj.getLastCountName())
                    .append(",本金余额:" + getObj.getRealMoney())
                    .append(",有效期:" + DateUtil.dateToString(getObj.getFailTime(), DateUtil.DATE_FORMAT_MM))
                    .append(",是否赠送:" + getObj.getSourceName());
        }
    }
 
 
    //设置为有效
    @Override
    public void active(MoneyCardUse proj) {
 
        proj.setStatus(Dictionary.TAOCAN_STATUS_YX);
        if (Dictionary.FLAG_YES_Y.equals(proj.getIsVipCar())) {
            MoneyCardUse cardUse = moneyCardUseDao.selectVipCard(proj.getVipId());
            if (cardUse != null && !cardUse.getId().equals(proj.getId())) {
                throw new GlobleException("该会员已经存在有效的会籍卡!");
            }
        }
        moneyCardUseDao.update(proj);
 
    }
 
    //设置为失效
    @Override
    public void invalid(MoneyCardUse proj) {
 
        proj.setStatus(Dictionary.TAOCAN_STATUS_WX);
        moneyCardUseDao.update(proj);
        StringBuilder content = new StringBuilder();
        content.append(proj.getCardName() + "设置失效");
    }
 
    /**
     * 检测订单条目是否已付款完毕
     */
    public void checkOrderStatu(Long orderItemId) {
        SysOrder order = sysOrderService.findById(orderItemDao.selectById(orderItemId).getOrderId());
        if (!Dictionary.ORDER_STATU_YFK.equals(order.getStatu())) {
            throw new GlobleException("储值卡购买订单还存在欠款,在补交欠款后才能使用!");
        }
    }
 
}