wzy
2021-01-10 16da0ad1fda1dffa3019425a6887d38ed4217f44
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
package com.matrix.system.shopXcx.api.service.impl;
 
import com.matrix.system.common.bean.CustomerDataDictionary;
import com.matrix.system.common.dao.CustomerDataDictionaryDao;
import com.matrix.system.shopXcx.api.service.WxShopMemberDayService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
 
/**
 * @description 会员日服务层
 * @author wlz
 * @date 2019-07-04 10:58
 */
@Service
public class WxShopMemberDayServiceImpl implements WxShopMemberDayService {
    @Autowired
    private CustomerDataDictionaryDao dictionaryDao;
 
 
    @Override
    public Double getMemberDay() {
        String weekOfDate = getWeekOfDate(new Date());
        CustomerDataDictionary memberDay = dictionaryDao.selectByTypeCode("member_day");
        List<String> result = new ArrayList<>();
        String extValue = memberDay.getExtValue();
        String discount = memberDay.getValue();
        if(null != extValue && !"".equals(extValue)){
            result = Arrays.asList(extValue.split(",|,"));
        }
        if(CollectionUtils.isNotEmpty(result) && result.size() >0){
            for(String memberDaySelect : result){
                if(weekOfDate.equals(memberDaySelect)){
                    return Double.valueOf(discount);
                }
 
            }
        }
        return 1.0;
    }
 
    /**
     * 获取当前日期是星期几
     *
     * @param dt
     * @return 当前日期是星期几
     */
    public static String getWeekOfDate(Date dt) {
        String[] weekDays = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
 
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0) {
            w = 0;
        }
        return weekDays[w];
    }
}