You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bsdgy-server/src/main/java/com/kiisoo/ic/activity/controller/WebAppActivityController.java

124 lines
5.6 KiB
Java

6 years ago
package com.kiisoo.ic.activity.controller;
6 years ago
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kiisoo.ic.activity.bean.PromotionSrcVO;
5 years ago
import com.kiisoo.ic.activity.bean.PushPromotionsVO;
5 years ago
import com.kiisoo.ic.activity.bean.RemoveStaffVO;
5 years ago
import com.kiisoo.ic.activity.entity.PmnPromotionSrc;
6 years ago
import com.kiisoo.ic.activity.service.IPmnPromotionSrcService;
6 years ago
import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.store.entity.PoiStoreStaff;
6 years ago
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
6 years ago
import com.kiisoo.ic.synchronous.entity.TurnBackDTO;
import io.swagger.annotations.Api;
6 years ago
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
6 years ago
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
6 years ago
import org.springframework.beans.factory.annotation.Autowired;
6 years ago
import org.springframework.web.bind.annotation.*;
5 years ago
import java.util.*;
import java.util.stream.Collectors;
6 years ago
@Api(value = "小程序-我的活动推广", tags = {"小程序-我的活动推广"})
@RestController
@RequestMapping("/webapp/my")
@Slf4j
public class WebAppActivityController extends BaseController {
6 years ago
@Autowired
6 years ago
private IPmnPromotionSrcService pmnPromotionSrcService;
5 years ago
@Autowired
private PoiStoreStaffDOMapper poiStoreStaffDOMapper;
6 years ago
6 years ago
@ApiOperation(value = "我的活动推广列表")
@GetMapping("/get/promotions")
6 years ago
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户ID", dataType = "int", paramType = "form"),
})
6 years ago
public Map<String, Object> myPromotions(long userId) {
// TODO 查询当前小程序用户,在活动有效期间的有效活动,包含活动名称,活动二维码
// TODO 从 promotion_src 获取当前导购的推广关系,并关联 activity_instance等表获取活动详情注意活动有效性
// TODO 需要附加这个活动已经推广的客户列表 promotion_friends_src
6 years ago
try {
6 years ago
List<PromotionSrcVO> codes = pmnPromotionSrcService.listUserCodes(userId);
return data(codes);
} catch (Exception e) {
log.error("获取用户信息异常", e);
6 years ago
return fail();
}
6 years ago
}
5 years ago
@ApiOperation(value = "店长-执行推广")
6 years ago
@PostMapping("/post/promotions")
6 years ago
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户ID", dataType = "int", paramType = "form"),
5 years ago
@ApiImplicitParam(name = "list", value = "选中导购staffId列表", dataType = "array", paramType = "form"),
5 years ago
@ApiImplicitParam(name = "instanceId", value = "活动ID", dataType = "array", paramType = "form"),
6 years ago
})
5 years ago
public Map<String, Object> pushPromotion(@RequestBody PushPromotionsVO vo) {
5 years ago
// TODO 将活动推广给单个或多个导购 promotion_src
6 years ago
// TODO 如果已经推广过了,则忽略
5 years ago
try {
List<PoiStoreStaff> fails = new ArrayList<>();
List<PoiStoreStaff> success = new ArrayList<>();
5 years ago
Long instanceId = vo.getInstanceId();
Long userId = vo.getUserId();
List<Long> ids = vo.getList();
if(ids.size() <= 0) {
return fail("00004", "请传入list");
}
if(instanceId == null) {
return fail("00004", "请传入实例ID");
}
List<PoiStoreStaff> staffs = poiStoreStaffDOMapper.selectBatchIds(ids);
for (PoiStoreStaff staff : staffs) {
PmnPromotionSrc create = pmnPromotionSrcService.createCode(staff, instanceId);
5 years ago
if (create == null) {
5 years ago
fails.add(staff);
} else {
success.add(staff);
}
6 years ago
}
5 years ago
/**
* ,
*/
PmnPromotionSrc up = new PmnPromotionSrc();
up.setStatus(2L);
5 years ago
pmnPromotionSrcService.update(up, Wrappers.<PmnPromotionSrc>lambdaQuery().eq(PmnPromotionSrc::getInstanceId, instanceId).notIn(PmnPromotionSrc::getPromoterId, staffs.stream().map(PoiStoreStaff::getUserId).collect(Collectors.toList())).eq(PmnPromotionSrc::getType, 1));
5 years ago
//
Map<String, Object> ret = new HashMap<>();
ret.put("success", success);
ret.put("fail", fails);
return data(ret);
} catch (Exception e) {
log.error("获取用户信息异常", e);
return fail();
6 years ago
}
6 years ago
}
5 years ago
@ApiOperation(value = "店长-移除活动导购")
@PostMapping("/removeStaff")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "当前登录用户ID", dataType = "int", paramType = "form"),
@ApiImplicitParam(name = "user", value = "要移除导购的userId", dataType = "array", paramType = "form"),
@ApiImplicitParam(name = "instanceId", value = "活动ID", dataType = "array", paramType = "form"),
})
public Map<String, Object> removeStaff(@RequestBody RemoveStaffVO removeStaffVO){
try{
boolean remove = pmnPromotionSrcService.remove(Wrappers.<PmnPromotionSrc>lambdaQuery().eq(PmnPromotionSrc::getPromoterId, removeStaffVO.getUser()).eq(PmnPromotionSrc::getType, 1).eq(PmnPromotionSrc::getInstanceId, removeStaffVO.getInstanceId()));
return remove ? success() : fail();
} catch (Exception e) {
log.error("获取用户信息异常", e);
return fail();
}
}
6 years ago
@ApiOperation(value = "好友添加回调通知")
@PostMapping("/cb")
public Map<String, Object> turnBack(@RequestBody List<TurnBackDTO> turnBackDTOS) {
// TODO 待调查
return data(null);
}
}