shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
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
package com.ishop.merchant.platform;
 
import com.iplatform.base.Constants;
import com.iplatform.base.util.MenuUtils;
import com.iplatform.model.to.UserAndDeptTo;
import com.ishop.merchant.BaseController;
import com.ishop.merchant.pojo.MerchantParam;
import com.ishop.merchant.util.ImageUtils;
import com.ishop.merchant.util.VoUtils;
import com.ishop.model.po.EbMerchant;
import com.ishop.model.po.EbMerchantInfo;
import com.ishop.model.vo.PlatformMerDetailVo;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.time.TimeRange;
import com.walker.infrastructure.time.TimeRangeUtils;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.OrgType;
import com.walker.web.ResponseValue;
import com.walker.web.util.IdUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
@RequestMapping("/platform/merchant")
public class MerchantController extends BaseController {
 
    /**
     * 平台编辑商户,仅能该基本信息。其他要商户自己维护。
     * @return
     * @date 2023-07-20
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseValue update(@RequestBody EbMerchant merchant){
        if(merchant == null || merchant.getId() == null || merchant.getId() <= 0){
            return ResponseValue.error("编辑的商户不存在");
        }
 
        String qualificationPicture = merchant.getQualificationPicture();
        if(StringUtils.isNotEmpty(qualificationPicture)){
            merchant.setQualificationPicture(ImageUtils.clearCdnMultiImageUrl(qualificationPicture, this.getCdnUrl()));
        }
        if(StringUtils.isEmpty(merchant.getRemark())){
            merchant.setRemark(merchant.getKeywords());
        }
 
        UserAndDeptTo userAndDeptTo = new UserAndDeptTo();
        userAndDeptTo.setDeptName(merchant.getName());
        userAndDeptTo.setNickName(merchant.getName());
        userAndDeptTo.setPhone(merchant.getPhone());
        userAndDeptTo.setMail(merchant.getEmail());
        userAndDeptTo.setOrgId(merchant.getId());
 
        this.getMerchantService().execUpdateMerchantPlatform(merchant, userAndDeptTo);
        this.getMerchantCache().update(merchant);
        logger.info("平台更新商户基本信息成功:{}", merchant.getName());
        return ResponseValue.success();
    }
 
    /**
     * 平台查看商户详情。
     * @param id
     * @return
     * @date 2023-07-20
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public ResponseValue info(Integer id){
        if(id == null || id <= 0){
            return ResponseValue.error("商户编号错误");
        }
        EbMerchant merchant = this.getMerchantCache().get(id);
        PlatformMerDetailVo vo = VoUtils.acquirePlatformMerDetailVo(merchant);
        if(StringUtils.isNotEmpty(merchant.getQualificationPicture())){
            String imageList = ImageUtils.combineMultiImageUrl(merchant.getQualificationPicture(), this.getCdnUrl());
            vo.setQualificationPicture(imageList);
        }
        return ResponseValue.success(vo);
    }
 
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseValue list(MerchantParam merchantParam){
        if(merchantParam == null){
            return ResponseValue.error(Constants.ERROR_ARGUMENT);
        }
        logger.debug(merchantParam.toString());
        // 时间范围选择
        TimeRange timeRange = TimeRangeUtils.getDateLimit(merchantParam.getDateLimit());
        // 分页查询列表
        GenericPager<EbMerchant> pager = this.getMerchantService().queryPageMerchantList(merchantParam.getCategoryId()
                , merchantParam.getTypeId(), merchantParam.getPhone(), merchantParam.getIsSelf(), merchantParam.getIsSwitch()
                , timeRange, merchantParam.getKeywords());
        return ResponseValue.success(pager);
    }
 
    @RequestMapping(value = "/header/num", method = RequestMethod.GET)
    public ResponseValue listHeaderNum(MerchantParam merchantParam){
        if(merchantParam == null){
            return ResponseValue.error(Constants.ERROR_ARGUMENT);
        }
        logger.debug("date = " + merchantParam.getDateLimit());
        TimeRange timeRange = TimeRangeUtils.getDateLimit(merchantParam.getDateLimit());
        int openCount = this.getMerchantService().countMerchantTotal(merchantParam.getCategoryId()
                , merchantParam.getTypeId(), merchantParam.getPhone(), merchantParam.getIsSelf(), true, timeRange, merchantParam.getKeywords());
        int closeCount = this.getMerchantService().countMerchantTotal(merchantParam.getCategoryId()
                , merchantParam.getTypeId(), merchantParam.getPhone(), merchantParam.getIsSelf(), false, timeRange, merchantParam.getKeywords());
 
        Map<String, Object> data = new HashMap<>(4);
        data.put("openNum", openCount);
        data.put("closeNum", closeCount);
        return ResponseValue.success(data);
    }
 
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ResponseValue add(@RequestBody EbMerchant ebMerchant){
        if(ebMerchant == null
                || StringUtils.isEmpty(ebMerchant.getName())
                || StringUtils.isEmpty(ebMerchant.getPhone())){
            return ResponseValue.error(Constants.ERROR_ARGUMENT);
        }
        String name = ebMerchant.getName().trim().toLowerCase();
        String phone = ebMerchant.getPhone().trim().toLowerCase();
 
        if(this.getMerchantApplyService().queryApplyByName(name) != null){
            return ResponseValue.error("相同商户名称已在审核中");
        }
        if(this.getMerchantApplyService().queryApplyByPhone(phone) != null){
            return ResponseValue.error("相同商户手机号已在审核中");
        }
 
        if(this.getMerchantService().queryMerchantByName(name) != null){
            return ResponseValue.error("商户名称已存在");
        }
        if(this.getMerchantService().queryMerchantByPhone(phone) != null){
            return ResponseValue.error("商户手机号已注册");
        }
 
        String qualificationPicture = ebMerchant.getQualificationPicture();
        if(StringUtils.isNotEmpty(qualificationPicture)){
            ebMerchant.setQualificationPicture(this.clearCdnPrefix(qualificationPicture));
        }
        if(StringUtils.isEmpty(ebMerchant.getRemark())){
            ebMerchant.setRemark(ebMerchant.getKeywords());
        }
        // 2023-06-08 设置商户唯一标识uuid,外部使用
        ebMerchant.setUuid(IdUtils.randomUUID());
 
        //
        long loginId = this.getCurrentUserId();
        UserAndDeptTo userAndDeptTo = new UserAndDeptTo();
        userAndDeptTo.setCreateId(String.valueOf(loginId));
        userAndDeptTo.setDeptName(ebMerchant.getName());
        userAndDeptTo.setOrgType(OrgType.TYPE_ORG);
        userAndDeptTo.setUserName(ebMerchant.getPhone());
        userAndDeptTo.setNickName(ebMerchant.getRealName());
        userAndDeptTo.setPhone(ebMerchant.getPhone());
        userAndDeptTo.setMail(ebMerchant.getEmail());
        userAndDeptTo.setAvatar(ebMerchant.getAvatar());
        userAndDeptTo.setMenuType(MenuUtils.MENU_SCOPE_ORG);
        userAndDeptTo.setPassword(this.encryptPassword(com.ishop.merchant.Constants.INIT_PASSWORD));
 
        this.getMerchantService().execInsertMerchant(ebMerchant, com.ishop.merchant.Constants.CREATE_TYPE_ADMIN, loginId, userAndDeptTo);
        logger.info("后台创建商户成功:{}", ebMerchant);
        return ResponseValue.success();
    }
 
    @RequestMapping(value = "/close", method = RequestMethod.POST)
    public ResponseValue close(Integer id){
 
        return ResponseValue.success();
    }
 
    @RequestMapping(value = "/open", method = RequestMethod.POST)
    public ResponseValue open(Integer id){
        EbMerchant merchant = this.getMerchantService().get(new EbMerchant(id));
        if(merchant.getIsSwitch() == 1){
            return ResponseValue.error("商户已开启");
        }
        if (StringUtils.isEmpty(merchant.getAvatar())
                || StringUtils.isEmpty(merchant.getBackImage())
                || StringUtils.isEmpty(merchant.getStreetBackImage())) {
            return ResponseValue.error("请先进行商户头像、背景图配置");
        }
 
        EbMerchantInfo queryInfo = new EbMerchantInfo();
        queryInfo.setMerId(id);
        List<EbMerchantInfo> merchantInfoList = this.getMerchantService().select(queryInfo);
        if(StringUtils.isEmptyList(merchantInfoList)){
            return ResponseValue.error("商户未找到配置记录");
        }
 
        EbMerchantInfo merchantInfo = merchantInfoList.get(0);
        if (StringUtils.isEmpty(merchantInfo.getServiceLink()) && StringUtils.isEmpty(merchantInfo.getServicePhone())) {
            return ResponseValue.error("请先进行客服信息配置");
        }
 
        this.getMerchantService().execOpenMerchant(id);
        return ResponseValue.success();
    }
}