zyy 5 years ago
commit 3e88c52d7e

@ -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<String, Object> joinCb(TurnBackDTO turnBackDTOS){
return null;
}
}

@ -16,4 +16,5 @@ import java.util.List;
*/ */
public interface IPmnPromotionSrcService extends IService<PmnPromotionSrc> { public interface IPmnPromotionSrcService extends IService<PmnPromotionSrc> {
List<PromotionSrcVO> listUserCodes(Long userId) throws Exception; List<PromotionSrcVO> listUserCodes(Long userId) throws Exception;
String saveCodeFile(String fileUrl, String code);
} }

@ -127,7 +127,8 @@ public class PmnPromotionSrcServiceImpl extends ServiceImpl<PmnPromotionSrcDOMap
return lists; return lists;
} }
private String saveCodeFile(String fileUrl, String code) { @Override
public String saveCodeFile(String fileUrl, String code) {
try { try {
File targetPath = new File("activity"); File targetPath = new File("activity");
if (!targetPath.exists()) { if (!targetPath.exists()) {

@ -1,10 +1,17 @@
package com.kiisoo.ic.customer; package com.kiisoo.ic.customer;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.kiisoo.ic.activity.bean.ActivityInstanceVO;
import com.kiisoo.ic.activity.entity.PmnActivityInstanceConfig;
import com.kiisoo.ic.activity.entity.PmnPromotionSrc;
import com.kiisoo.ic.activity.service.IPmnActivityInstanceConfigService;
import com.kiisoo.ic.activity.service.IPmnActivityInstanceService;
import com.kiisoo.ic.activity.service.IPmnPromotionSrcService;
import com.kiisoo.ic.constants.Constants; import com.kiisoo.ic.constants.Constants;
import com.kiisoo.ic.customer.bean.CustomerDTO; import com.kiisoo.ic.customer.bean.CustomerDTO;
import com.kiisoo.ic.customer.bean.CustomerModifyDTO; import com.kiisoo.ic.customer.bean.CustomerModifyDTO;
@ -30,6 +37,7 @@ import com.kiisoo.ic.store.mapper.PoiStoreDOMapper;
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper; import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
import com.kiisoo.ic.store.mapper.PrivilageCpUserStoreDOMapper; import com.kiisoo.ic.store.mapper.PrivilageCpUserStoreDOMapper;
import com.kiisoo.ic.store.service.PoiStoreService; import com.kiisoo.ic.store.service.PoiStoreService;
import com.kiisoo.ic.store.service.StoreEmployeeService;
import com.kiisoo.ic.synchronous.entity.TurnBackDTO; import com.kiisoo.ic.synchronous.entity.TurnBackDTO;
import com.kiisoo.ic.system.entity.PrivilageUserDO; import com.kiisoo.ic.system.entity.PrivilageUserDO;
import com.kiisoo.ic.system.enums.RoleEnum; import com.kiisoo.ic.system.enums.RoleEnum;
@ -38,6 +46,7 @@ import com.kiisoo.ic.webappmy.vo.StafferInfoVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -97,6 +106,15 @@ public class CustomerService {
@Autowired @Autowired
public PrivilageUserDOMapper privilageUserDOMapper; public PrivilageUserDOMapper privilageUserDOMapper;
@Autowired
private IPmnPromotionSrcService pmnPromotionSrcService;
@Autowired
private IPmnActivityInstanceService pmnActivityInstanceService;
@Autowired
private IPmnActivityInstanceConfigService pmnActivityInstanceConfigService;
@Autowired
private StoreEmployeeService storeEmployeeService;
/** /**
* token * token
*/ */
@ -177,10 +195,10 @@ public class CustomerService {
public void turnBack(TurnBackDTO turnBackDTOS) throws Exception { public void turnBack(TurnBackDTO turnBackDTOS) throws Exception {
String eaCode = turnBackDTOS.getEaCode(); String eaCode = turnBackDTOS.getEaCode();
// 判断是否是活动扫码 // 判断是否是活动扫码
if(eaCode.contains(Constants.ACTIVITY_QR_CODE_PREFIX)){ if (eaCode.contains(Constants.ACTIVITY_QR_CODE_PREFIX)) {
// 活动码处理 // 活动码处理
handleActivity(turnBackDTOS, eaCode); handleActivity(turnBackDTOS, eaCode);
}else{ } else {
// 导购码处理 // 导购码处理
handleCustomer(turnBackDTOS); handleCustomer(turnBackDTOS);
} }
@ -188,19 +206,48 @@ public class CustomerService {
/** /**
* *
*
* @param turnBackDTOS * @param turnBackDTOS
* @param eaCode state * @param eaCode state
*/ */
private void handleActivity(TurnBackDTO turnBackDTOS, String eaCode){ private void handleActivity(TurnBackDTO turnBackDTOS, String eaCode) throws Exception {
String[] strArr = eaCode.split(Constants.LINE); String[] strArr = eaCode.split(Constants.LINE);
Long instanceId = Long.parseLong(strArr[1]); Long instanceId = Long.parseLong(strArr[1]);
int type = Integer.parseInt(strArr[2]); int type = Integer.parseInt(strArr[2]);
Long promoterId = Long.parseLong(strArr[3]); Long promoterId = Long.parseLong(strArr[3]);
// 处理逻辑 // 处理逻辑
if (type == 1) {
//导购逻辑
PmnPromotionSrc src = pmnPromotionSrcService.getOne(Wrappers.<PmnPromotionSrc>lambdaQuery().eq(PmnPromotionSrc::getInstanceId, instanceId).eq(PmnPromotionSrc::getType, type).eq(PmnPromotionSrc::getPromoterId, promoterId));
if (src == null) {
PrivilageCpUserDO cpUserDO = privilageCpUserDOMapper.selectOne(Wrappers.<PrivilageCpUserDO>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.<PmnActivityInstanceConfig>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 * @param turnBackDTOS
*/ */
private void handleCustomer(TurnBackDTO turnBackDTOS) throws Exception { private void handleCustomer(TurnBackDTO turnBackDTOS) throws Exception {
@ -210,12 +257,12 @@ public class CustomerService {
QueryWrapper<OpCustomer> customerWrapper = new QueryWrapper<>(); QueryWrapper<OpCustomer> customerWrapper = new QueryWrapper<>();
customerWrapper.eq("wechat_uni_id", null).eq("external_userid", turnBackDTOS.getWxData().getUserId()).last("limit 1"); customerWrapper.eq("wechat_uni_id", null).eq("external_userid", turnBackDTOS.getWxData().getUserId()).last("limit 1");
opCustomer = opCustomerDOMapper.selectOne(customerWrapper); opCustomer = opCustomerDOMapper.selectOne(customerWrapper);
}else if (turnBackDTOS.getWxData().getUnionId() != null && turnBackDTOS.getUserId() != null){ } else if (turnBackDTOS.getWxData().getUnionId() != null && turnBackDTOS.getUserId() != null) {
//客户信息 //客户信息
QueryWrapper<OpCustomer> customerWrapper = new QueryWrapper<>(); QueryWrapper<OpCustomer> customerWrapper = new QueryWrapper<>();
customerWrapper.eq("wechat_uni_id", turnBackDTOS.getWxData().getUnionId()).last("limit 1"); customerWrapper.eq("wechat_uni_id", turnBackDTOS.getWxData().getUnionId()).last("limit 1");
opCustomer = opCustomerDOMapper.selectOne(customerWrapper); opCustomer = opCustomerDOMapper.selectOne(customerWrapper);
}else{ } else {
log.error("turn back error: " + turnBackDTOS.toString()); log.error("turn back error: " + turnBackDTOS.toString());
return; return;
} }
@ -232,10 +279,10 @@ public class CustomerService {
if (!turnBackDTOS.getEaCode().equals("") && !turnBackDTOS.getEaCode().equals("0")) { if (!turnBackDTOS.getEaCode().equals("") && !turnBackDTOS.getEaCode().equals("0")) {
//导购信息 //导购信息
QueryWrapper<PoiStoreStaff> wrapper = new QueryWrapper<>(); QueryWrapper<PoiStoreStaff> wrapper = new QueryWrapper<>();
if (turnBackDTOS.getEaCode().matches("导购(.*)")){ if (turnBackDTOS.getEaCode().matches("导购(.*)")) {
wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status","1").last("limit 1"); wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status", "1").last("limit 1");
}else{ } else {
wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status","1").eq("store_id", poiStore.getStoreId()).last("limit 1"); wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status", "1").eq("store_id", poiStore.getStoreId()).last("limit 1");
} }
poiStoreStaff = poiStoreStaffDOMapper.selectOne(wrapper); poiStoreStaff = poiStoreStaffDOMapper.selectOne(wrapper);
} }
@ -249,11 +296,11 @@ public class CustomerService {
insertCustomer.setExternalUserid(turnBackDTOS.getWxData().getUserId()); insertCustomer.setExternalUserid(turnBackDTOS.getWxData().getUserId());
insertCustomer.setCpUserId(turnBackDTOS.getUserId()); insertCustomer.setCpUserId(turnBackDTOS.getUserId());
insertCustomer.setPhone(turnBackDTOS.getPhone()); insertCustomer.setPhone(turnBackDTOS.getPhone());
if (shop != null && StringUtils.isNotBlank(shop.getName())){ if (shop != null && StringUtils.isNotBlank(shop.getName())) {
insertCustomer.setShopName(shop.getName()); insertCustomer.setShopName(shop.getName());
} }
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (turnBackDTOS.getJoinTime() != null){ if (turnBackDTOS.getJoinTime() != null) {
insertCustomer.setCreateTime(sdf.parse(turnBackDTOS.getJoinTime())); insertCustomer.setCreateTime(sdf.parse(turnBackDTOS.getJoinTime()));
} }
if (null != opCustomer) { if (null != opCustomer) {
@ -261,23 +308,23 @@ public class CustomerService {
insertCustomer.setId(opCustomer.getId()); insertCustomer.setId(opCustomer.getId());
try { try {
opCustomerDOMapper.updateById(insertCustomer); opCustomerDOMapper.updateById(insertCustomer);
}catch (Exception e) { } catch (Exception e) {
log.error(insertCustomer.toString(),e); log.error(insertCustomer.toString(), e);
return; return;
} }
if (poiStoreStaff != null) { if (poiStoreStaff != null) {
//存在--1.处理客户导购关系。 //存在--1.处理客户导购关系。
try { try {
sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId()); sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId());
}catch (Exception e) { } catch (Exception e) {
log.error(insertCustomer.toString(),e); log.error(insertCustomer.toString(), e);
return; return;
} }
} else { } else {
try { try {
storeCustomerRelation(insertCustomer,sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId()); storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId());
}catch (Exception e) { } catch (Exception e) {
log.error(insertCustomer.toString(),e); log.error(insertCustomer.toString(), e);
return; return;
} }
} }
@ -286,8 +333,8 @@ public class CustomerService {
//不存在 //不存在
try { try {
opCustomerDOMapper.insert(insertCustomer); opCustomerDOMapper.insert(insertCustomer);
}catch (Exception e) { } catch (Exception e) {
log.error(insertCustomer.toString(),e); log.error(insertCustomer.toString(), e);
return; return;
} }
@ -295,15 +342,15 @@ public class CustomerService {
//添加关系 //添加关系
try { try {
sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId()); sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId());
}catch (Exception e) { } catch (Exception e) {
log.error(insertCustomer.toString(),e); log.error(insertCustomer.toString(), e);
return; return;
} }
} else { } else {
try { try {
storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()),poiStore.getStoreId()); storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId());
}catch (Exception e) { } catch (Exception e) {
log.error(insertCustomer.toString(),e); log.error(insertCustomer.toString(), e);
return; return;
} }
} }
@ -353,9 +400,9 @@ public class CustomerService {
opCustomer.setMemberId(opVip.getId()); opCustomer.setMemberId(opVip.getId());
} }
QueryWrapper<OpCustomer> wrapper1 = new QueryWrapper<>(); QueryWrapper<OpCustomer> wrapper1 = new QueryWrapper<>();
if (turnBackDTO.getType() == 1){ if (turnBackDTO.getType() == 1) {
wrapper1.eq("wechat_uni_id", turnBackDTO.getWxData().getUnionId()); wrapper1.eq("wechat_uni_id", turnBackDTO.getWxData().getUnionId());
}else{ } else {
wrapper1.eq("external_userid", turnBackDTO.getWxData().getUserId()); wrapper1.eq("external_userid", turnBackDTO.getWxData().getUserId());
} }
opCustomerDOMapper.update(opCustomer, wrapper1); opCustomerDOMapper.update(opCustomer, wrapper1);
@ -363,6 +410,7 @@ public class CustomerService {
/** /**
* *
*
* @param opCustomer * @param opCustomer
* @param joinTime * @param joinTime
* @param shopId * @param shopId
@ -397,7 +445,7 @@ public class CustomerService {
insertRelation.setType(2); insertRelation.setType(2);
} }
opSellerCustomerRelationDOMapper.insert(insertRelation); opSellerCustomerRelationDOMapper.insert(insertRelation);
}else{ } else {
//可能是同步过来的数据,此时已经存在的话,用有导购的代替 //可能是同步过来的数据,此时已经存在的话,用有导购的代替
opSellerCustomerRelation.setCreateTime(joinTime); opSellerCustomerRelation.setCreateTime(joinTime);
opSellerCustomerRelation.setUpdateTime(new Date()); opSellerCustomerRelation.setUpdateTime(new Date());
@ -411,7 +459,7 @@ public class CustomerService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void storeCustomerRelation(OpCustomer opCustomer, Date joinTime,long shopId) { public void storeCustomerRelation(OpCustomer opCustomer, Date joinTime, long shopId) {
QueryWrapper<OpSellerCustomerRelation> wrapper1 = new QueryWrapper<>(); QueryWrapper<OpSellerCustomerRelation> wrapper1 = new QueryWrapper<>();
wrapper1.eq("customer_id", opCustomer.getId()).eq("store_id", shopId).last("limit 1"); wrapper1.eq("customer_id", opCustomer.getId()).eq("store_id", shopId).last("limit 1");
OpSellerCustomerRelation opSellerCustomerRelation = opSellerCustomerRelationDOMapper.selectOne(wrapper1); OpSellerCustomerRelation opSellerCustomerRelation = opSellerCustomerRelationDOMapper.selectOne(wrapper1);
@ -437,13 +485,13 @@ public class CustomerService {
//无效 //无效
insertRelation.setType(2); insertRelation.setType(2);
} }
if (shopId == 0L){ if (shopId == 0L) {
QueryWrapper<PrivilageCpUserDO> cpQw = new QueryWrapper<>(); QueryWrapper<PrivilageCpUserDO> 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); PrivilageCpUserDO privilageCpUserDO = privilageCpUserDOMapper.selectOne(cpQw);
if (privilageCpUserDO!=null){ if (privilageCpUserDO != null) {
insertRelation.setUserId(privilageCpUserDO.getId()); insertRelation.setUserId(privilageCpUserDO.getId());
}else{ } else {
privilageCpUserDO = new PrivilageCpUserDO(); privilageCpUserDO = new PrivilageCpUserDO();
privilageCpUserDO.setCpUserId(opCustomer.getCpUserId()); privilageCpUserDO.setCpUserId(opCustomer.getCpUserId());
privilageCpUserDO.setStatus(1); privilageCpUserDO.setStatus(1);
@ -551,6 +599,7 @@ public class CustomerService {
/** /**
* *
*
* @param userId ID * @param userId ID
* @param sellerId ID * @param sellerId ID
* @param search * @param search
@ -576,34 +625,34 @@ public class CustomerService {
PageHelper.startPage(pageNum, pageSize); PageHelper.startPage(pageNum, pageSize);
if (roleCode.equals(RoleEnum.ROLE_CODE_DZ.getRoleCode())) { if (roleCode.equals(RoleEnum.ROLE_CODE_DZ.getRoleCode())) {
// 0、新增好友 1、累计好友 // 0、新增好友 1、累计好友
if(flag == 0){ if (flag == 0) {
thisList = opSellerCustomerRelationDOMapper.selectFriendListByShopId(shopId, sellerId, search, startDate, endDate, type); thisList = opSellerCustomerRelationDOMapper.selectFriendListByShopId(shopId, sellerId, search, startDate, endDate, type);
}else{ } else {
thisList = opSellerCustomerRelationDOMapper.selectFriendListByShopIdAndDate(shopId, sellerId, search, startDate, endDate, type); 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++) { for (int i = 0; i < thisList.size(); i++) {
// 设置导购名称 // 设置导购名称
if(!thisList.get(i).getInviteSellerId().equals(0L)){ if (!thisList.get(i).getInviteSellerId().equals(0L)) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("id", thisList.get(i).getInviteSellerId()); map.put("id", thisList.get(i).getInviteSellerId());
String userName = poiStoreStaffDOMapper.selectUserNameById(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); thisList.get(i).setInviteSellerName(userName);
}else{ } else {
thisList.get(i).setInviteSellerName(""); thisList.get(i).setInviteSellerName("");
} }
}else{ } else {
thisList.get(i).setInviteSellerName(""); thisList.get(i).setInviteSellerName("");
} }
} }
} }
} else { } else {
// 0、新增好友 1、累计好友 // 0、新增好友 1、累计好友
if(flag == 0){ if (flag == 0) {
thisList = opSellerCustomerRelationDOMapper.selectFriendListBySeller(userId, search, startDate, endDate, type); thisList = opSellerCustomerRelationDOMapper.selectFriendListBySeller(userId, search, startDate, endDate, type);
}else{ } else {
thisList = opSellerCustomerRelationDOMapper.selectFriendListBySellerAndDate(userId, search, startDate, endDate, type); thisList = opSellerCustomerRelationDOMapper.selectFriendListBySellerAndDate(userId, search, startDate, endDate, type);
} }
} }

@ -90,6 +90,21 @@ public class SynchronousController {
return DataImportUtil.fail(e); return DataImportUtil.fail(e);
} }
} }
@RequestMapping(value = "/ics/activity/event/cb", method = RequestMethod.POST, consumes = "application/json")
@ResponseBody
public String activityEventCb(@RequestBody List<TurnBackDTO> 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);
}
}
/** /**
* *

Loading…
Cancel
Save