puzhibing
2023-10-08 22199bbdda579861736420fe26c2873ab0f5d21c
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
package com.sinata.shop.modular.mall.service.impl;
 
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sinata.core.exception.GunsException;
import com.sinata.core.exception.GunsExceptionEnum;
import com.sinata.shop.modular.mall.dao.MemMerchantMapper;
import com.sinata.shop.modular.mall.model.MemMerchant;
import com.sinata.shop.modular.mall.service.IMemMerchantService;
import com.sinata.shop.modular.system.service.ITSystemSetService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 门店信息 服务实现类
 * </p>
 *
 * @author frankevil
 * @since 2023-03-15
 */
@Service
public class MemMerchantServiceImpl extends ServiceImpl<MemMerchantMapper, MemMerchant> implements IMemMerchantService {
 
    @Resource
    private ITSystemSetService systemSetService;
 
    @Override
    public void wrapperMapMerchant(List<Map<String, Object>> list, String userKey) {
        // 用户ID串
        Object[] merchantIds = list.stream().map(o -> o.get(userKey)).collect(Collectors.toList()).toArray();
        // 用户列表
        List<MemMerchant> merchantList = baseMapper.selectList(
                new EntityWrapper<MemMerchant>()
                        .setSqlSelect("merchant_name merchantName")
                        .in("id", merchantIds)
        );
 
        // 封装数据
        for (Map<String, Object> map : list) {
            for (MemMerchant u : merchantList) {
                if (u.getId().toString().equals(map.get(userKey) + "")) {
                    map.put(userKey + "_merchantName", u.getMerchantName());
 
                }
            }
        }
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void upgradeMerchant(Integer merchantId, Integer gradeId) {
        MemMerchant merchant = this.selectById(merchantId);
        Integer oldGradeId = merchant.getGradeId();
        if (oldGradeId >= gradeId) {
            throw new GunsException(GunsExceptionEnum.REQUEST_NULL.getCode(), "只能升级为更高等级");
        }
        //升级金额配置
        BigDecimal mallMerchantUpVip = Convert.toBigDecimal(this.systemSetService.getKeyValue("MALL_MERCHANT_UP_VIP"), BigDecimal.ZERO);
        BigDecimal mallMerchantUpSuper = Convert.toBigDecimal(this.systemSetService.getKeyValue("MALL_MERCHANT_UP_SUPER"), BigDecimal.ZERO);
 
        //计算需要花费的金额
        BigDecimal startAmount = oldGradeId == 2 ? mallMerchantUpVip : BigDecimal.ZERO;
        BigDecimal endAmount = gradeId == 2 ? mallMerchantUpVip : (gradeId == 3 ? mallMerchantUpSuper : BigDecimal.ZERO);
 
        //设置等级
        merchant.setGradeId(gradeId);
        //修改门店等级
        this.updateById(merchant);
    }
 
    @Override
    public Integer getUserId(Integer merchantId) {
        return (Integer) this.selectObj(new EntityWrapper<MemMerchant>()
                .setSqlSelect("user_id")
                .eq("id", merchantId));
    }
 
    /**
     * 获取升级花费所有米粒值
     *
     * @return
     */
    private BigDecimal getUpgradePayRiceTotal(Integer merchantId) {
        return BigDecimal.ZERO;
    }
    @Override
    public List<MemMerchant> queryMerchantList(Page<MemMerchant> page, String beginTime, String endTime, String merchantName, Integer level) {
        return baseMapper.queryMerchantList(page,  beginTime,  endTime,  merchantName,  level);
    }
}