diff --git a/src/main/java/com/kiisoo/ic/activity/controller/EventController.java b/src/main/java/com/kiisoo/ic/activity/controller/EventController.java deleted file mode 100644 index b6268a6..0000000 --- a/src/main/java/com/kiisoo/ic/activity/controller/EventController.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.kiisoo.ic.activity.controller; - -import com.kiisoo.ic.synchronous.entity.TurnBackDTO; -import io.swagger.annotations.Api; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; - -@RestController -@Api(value = "活动回调事件", tags = {"活动回调事件"}) -@RequestMapping(value = "/activity/event") -@Slf4j -public class EventController { - public Map joinCb(TurnBackDTO turnBackDTOS){ - return null; - } -} diff --git a/src/main/java/com/kiisoo/ic/activity/service/IPmnPromotionSrcService.java b/src/main/java/com/kiisoo/ic/activity/service/IPmnPromotionSrcService.java index f5848e7..70e89d8 100644 --- a/src/main/java/com/kiisoo/ic/activity/service/IPmnPromotionSrcService.java +++ b/src/main/java/com/kiisoo/ic/activity/service/IPmnPromotionSrcService.java @@ -16,4 +16,5 @@ import java.util.List; */ public interface IPmnPromotionSrcService extends IService { List listUserCodes(Long userId) throws Exception; + String saveCodeFile(String fileUrl, String code); } diff --git a/src/main/java/com/kiisoo/ic/activity/service/impl/PmnPromotionSrcServiceImpl.java b/src/main/java/com/kiisoo/ic/activity/service/impl/PmnPromotionSrcServiceImpl.java index 00b5336..7d71eef 100644 --- a/src/main/java/com/kiisoo/ic/activity/service/impl/PmnPromotionSrcServiceImpl.java +++ b/src/main/java/com/kiisoo/ic/activity/service/impl/PmnPromotionSrcServiceImpl.java @@ -127,7 +127,8 @@ public class PmnPromotionSrcServiceImpl extends ServiceImpllambdaQuery().eq(PmnPromotionSrc::getInstanceId, instanceId).eq(PmnPromotionSrc::getType, type).eq(PmnPromotionSrc::getPromoterId, promoterId)); + if (src == null) { + PrivilageCpUserDO cpUserDO = privilageCpUserDOMapper.selectOne(Wrappers.lambdaQuery().eq(PrivilageCpUserDO::getCpUserId, turnBackDTOS.getWxData().getUserId())); + Long storeId = privilageCpUserStoreDOMapper.selectOneByCpUserId(turnBackDTOS.getWxData().getUserId()); + String state = Constants.ACTIVITY_QR_CODE_PREFIX + Constants.LINE + instanceId + Constants.LINE + type + Constants.LINE + promoterId; + ActivityInstanceVO instanceVO = pmnActivityInstanceService.getVO(instanceId); + PmnActivityInstanceConfig config = pmnActivityInstanceConfigService.getOne(Wrappers.lambdaQuery().eq(PmnActivityInstanceConfig::getInstanceId, instanceId)); + PmnPromotionSrc saveSrc = new PmnPromotionSrc(); + saveSrc.setCaseId(config.getCaseId()); + saveSrc.setCode(state); + saveSrc.setCreateTime(new Date()); + saveSrc.setExpiredTime(instanceVO.getEndTime()); + saveSrc.setInstanceId(instanceId); + saveSrc.setPromoterId(cpUserDO.getId()); + saveSrc.setIsAddition(2L); + saveSrc.setType(1L); + saveSrc.setUpdateTime(new Date()); + saveSrc.setStatus(1L); + PoiStore store = poiStoreDOMapper.selectById(storeId); + String url = storeEmployeeService.createActivityQrCode(turnBackDTOS.getWxData().getUserId(), store.getCode(), 1, instanceId, promoterId); + saveSrc.setQrCode(url); + pmnPromotionSrcService.saveCodeFile(url, new SimpleHash("MD5", state).toHex()); + pmnPromotionSrcService.save(saveSrc); + } + } } /** * 处理客户扫码回调的方法 + * * @param turnBackDTOS 回调对象 */ private void handleCustomer(TurnBackDTO turnBackDTOS) throws Exception { @@ -210,12 +257,12 @@ public class CustomerService { QueryWrapper customerWrapper = new QueryWrapper<>(); customerWrapper.eq("wechat_uni_id", null).eq("external_userid", turnBackDTOS.getWxData().getUserId()).last("limit 1"); opCustomer = opCustomerDOMapper.selectOne(customerWrapper); - }else if (turnBackDTOS.getWxData().getUnionId() != null && turnBackDTOS.getUserId() != null){ + } else if (turnBackDTOS.getWxData().getUnionId() != null && turnBackDTOS.getUserId() != null) { //客户信息 QueryWrapper customerWrapper = new QueryWrapper<>(); customerWrapper.eq("wechat_uni_id", turnBackDTOS.getWxData().getUnionId()).last("limit 1"); opCustomer = opCustomerDOMapper.selectOne(customerWrapper); - }else{ + } else { log.error("turn back error: " + turnBackDTOS.toString()); return; } @@ -232,10 +279,10 @@ public class CustomerService { if (!turnBackDTOS.getEaCode().equals("") && !turnBackDTOS.getEaCode().equals("0")) { //导购信息 QueryWrapper wrapper = new QueryWrapper<>(); - if (turnBackDTOS.getEaCode().matches("导购(.*)")){ - wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status","1").last("limit 1"); - }else{ - wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status","1").eq("store_id", poiStore.getStoreId()).last("limit 1"); + if (turnBackDTOS.getEaCode().matches("导购(.*)")) { + wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status", "1").last("limit 1"); + } else { + wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status", "1").eq("store_id", poiStore.getStoreId()).last("limit 1"); } poiStoreStaff = poiStoreStaffDOMapper.selectOne(wrapper); } @@ -249,11 +296,11 @@ public class CustomerService { insertCustomer.setExternalUserid(turnBackDTOS.getWxData().getUserId()); insertCustomer.setCpUserId(turnBackDTOS.getUserId()); insertCustomer.setPhone(turnBackDTOS.getPhone()); - if (shop != null && StringUtils.isNotBlank(shop.getName())){ + if (shop != null && StringUtils.isNotBlank(shop.getName())) { insertCustomer.setShopName(shop.getName()); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - if (turnBackDTOS.getJoinTime() != null){ + if (turnBackDTOS.getJoinTime() != null) { insertCustomer.setCreateTime(sdf.parse(turnBackDTOS.getJoinTime())); } if (null != opCustomer) { @@ -261,23 +308,23 @@ public class CustomerService { insertCustomer.setId(opCustomer.getId()); try { opCustomerDOMapper.updateById(insertCustomer); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } if (poiStoreStaff != null) { //存在--1.处理客户导购关系。 try { sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId()); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } } else { try { - storeCustomerRelation(insertCustomer,sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId()); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId()); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } } @@ -286,8 +333,8 @@ public class CustomerService { //不存在 try { opCustomerDOMapper.insert(insertCustomer); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } @@ -295,15 +342,15 @@ public class CustomerService { //添加关系 try { sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId()); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } } else { try { - storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()),poiStore.getStoreId()); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId()); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } } @@ -353,9 +400,9 @@ public class CustomerService { opCustomer.setMemberId(opVip.getId()); } QueryWrapper wrapper1 = new QueryWrapper<>(); - if (turnBackDTO.getType() == 1){ + if (turnBackDTO.getType() == 1) { wrapper1.eq("wechat_uni_id", turnBackDTO.getWxData().getUnionId()); - }else{ + } else { wrapper1.eq("external_userid", turnBackDTO.getWxData().getUserId()); } opCustomerDOMapper.update(opCustomer, wrapper1); @@ -363,6 +410,7 @@ public class CustomerService { /** * 处理客户和导购的关系 + * * @param opCustomer * @param joinTime * @param shopId @@ -397,7 +445,7 @@ public class CustomerService { insertRelation.setType(2); } opSellerCustomerRelationDOMapper.insert(insertRelation); - }else{ + } else { //可能是同步过来的数据,此时已经存在的话,用有导购的代替 opSellerCustomerRelation.setCreateTime(joinTime); opSellerCustomerRelation.setUpdateTime(new Date()); @@ -411,7 +459,7 @@ public class CustomerService { } @Transactional(rollbackFor = Exception.class) - public void storeCustomerRelation(OpCustomer opCustomer, Date joinTime,long shopId) { + public void storeCustomerRelation(OpCustomer opCustomer, Date joinTime, long shopId) { QueryWrapper wrapper1 = new QueryWrapper<>(); wrapper1.eq("customer_id", opCustomer.getId()).eq("store_id", shopId).last("limit 1"); OpSellerCustomerRelation opSellerCustomerRelation = opSellerCustomerRelationDOMapper.selectOne(wrapper1); @@ -437,13 +485,13 @@ public class CustomerService { //无效 insertRelation.setType(2); } - if (shopId == 0L){ + if (shopId == 0L) { QueryWrapper cpQw = new QueryWrapper<>(); - cpQw.eq("cp_user_id",opCustomer.getCpUserId()).last("limit 1"); + cpQw.eq("cp_user_id", opCustomer.getCpUserId()).last("limit 1"); PrivilageCpUserDO privilageCpUserDO = privilageCpUserDOMapper.selectOne(cpQw); - if (privilageCpUserDO!=null){ + if (privilageCpUserDO != null) { insertRelation.setUserId(privilageCpUserDO.getId()); - }else{ + } else { privilageCpUserDO = new PrivilageCpUserDO(); privilageCpUserDO.setCpUserId(opCustomer.getCpUserId()); privilageCpUserDO.setStatus(1); @@ -551,14 +599,15 @@ public class CustomerService { /** * 查询好友列表,可根据导购、日期、搜索 - * @param userId 用户ID - * @param sellerId 导购ID - * @param search 搜索内容 - * @param roleCode 角色编码 - * @param type 会员与非会员类型 + * + * @param userId 用户ID + * @param sellerId 导购ID + * @param search 搜索内容 + * @param roleCode 角色编码 + * @param type 会员与非会员类型 * @param startDate 开始日期 - * @param endDate 结束日期 - * @param flag 0、新增好友 1、累计好友 + * @param endDate 结束日期 + * @param flag 0、新增好友 1、累计好友 * @return 返回数据集合 * @throws Exception 异常 * @author dexiang.jiang @@ -576,34 +625,34 @@ public class CustomerService { PageHelper.startPage(pageNum, pageSize); if (roleCode.equals(RoleEnum.ROLE_CODE_DZ.getRoleCode())) { // 0、新增好友 1、累计好友 - if(flag == 0){ + if (flag == 0) { thisList = opSellerCustomerRelationDOMapper.selectFriendListByShopId(shopId, sellerId, search, startDate, endDate, type); - }else{ + } else { thisList = opSellerCustomerRelationDOMapper.selectFriendListByShopIdAndDate(shopId, sellerId, search, startDate, endDate, type); } - if(CollectionUtils.isNotEmpty(thisList)){ + if (CollectionUtils.isNotEmpty(thisList)) { for (int i = 0; i < thisList.size(); i++) { // 设置导购名称 - if(!thisList.get(i).getInviteSellerId().equals(0L)){ + if (!thisList.get(i).getInviteSellerId().equals(0L)) { Map map = new HashMap<>(); map.put("id", thisList.get(i).getInviteSellerId()); String userName = poiStoreStaffDOMapper.selectUserNameById(thisList.get(i).getInviteSellerId()); - if(StringUtils.isNotEmpty(userName)){ + if (StringUtils.isNotEmpty(userName)) { thisList.get(i).setInviteSellerName(userName); - }else{ + } else { thisList.get(i).setInviteSellerName(""); } - }else{ + } else { thisList.get(i).setInviteSellerName(""); } } } } else { // 0、新增好友 1、累计好友 - if(flag == 0){ + if (flag == 0) { thisList = opSellerCustomerRelationDOMapper.selectFriendListBySeller(userId, search, startDate, endDate, type); - }else{ + } else { thisList = opSellerCustomerRelationDOMapper.selectFriendListBySellerAndDate(userId, search, startDate, endDate, type); } } diff --git a/src/main/java/com/kiisoo/ic/synchronous/controller/SynchronousController.java b/src/main/java/com/kiisoo/ic/synchronous/controller/SynchronousController.java index bcc5727..a62ff71 100644 --- a/src/main/java/com/kiisoo/ic/synchronous/controller/SynchronousController.java +++ b/src/main/java/com/kiisoo/ic/synchronous/controller/SynchronousController.java @@ -90,6 +90,21 @@ public class SynchronousController { return DataImportUtil.fail(e); } } + @RequestMapping(value = "/ics/activity/event/cb", method = RequestMethod.POST, consumes = "application/json") + @ResponseBody + public String activityEventCb(@RequestBody List turnBackDTOS) { + try { + for (TurnBackDTO turnBackDTO : turnBackDTOS) { + customerService.turnBack(turnBackDTO); + } + return DataImportUtil.succ(1); + }catch (Exception e){ + log.error("扫码回调报错",e); + String str = JSON.toJSONString(turnBackDTOS); + System.out.println(str); + return DataImportUtil.fail(e); + } + } /** * 好友添加回调通知