package com.matrix.system.shopXcx.api.action; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.matrix.biz.bean.BizUser; import com.matrix.biz.dao.BizUserDao; import com.matrix.component.redis.RedisUserLoginUtils; import com.matrix.core.pojo.AjaxResult; import com.matrix.core.tools.StringUtils; import com.matrix.system.common.bean.BusParameterSettings; import com.matrix.system.common.dao.BusParameterSettingsDao; import com.matrix.system.common.interceptor.HostInterceptor; import com.matrix.system.fenxiao.constant.FenxiaoSettingConstant; import com.matrix.system.fenxiao.dao.ShopSalesmanApplyDao; import com.matrix.system.fenxiao.entity.ShopSalesmanApply; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Date; import java.util.HashMap; import java.util.Map; /** * @author wzy * @date 2021-03-10 **/ @Api(tags = "推广员接口类") @RestController @RequestMapping(value = "/wxapi/salesman") public class WxSalesmanAction { @Autowired BusParameterSettingsDao busParameterSettingsDao; @Autowired ShopSalesmanApplyDao salesmanApplyDao; @Autowired private RedisUserLoginUtils redisUserLoginUtils; @Autowired private BizUserDao bizUserDao; @ApiOperation(value = "查询推广计划", notes = "") @GetMapping(value = "/getTgPlan") public AjaxResult getTgPlan() { BusParameterSettings busParameterSettings = busParameterSettingsDao.selectCompanyParamByCode(FenxiaoSettingConstant.FX_TG_PLAN, HostInterceptor.getCompanyId()); AjaxResult ajaxResult = AjaxResult.buildSuccessInstance(""); ajaxResult.putInMap("data",busParameterSettings.getParamValue3()); return ajaxResult; } @ApiOperation(value = "申请成为推广员", notes = "传入参数invitationId 邀请人openId ,非必填 例: {invitationId:openId}") @ApiResponses({ @ApiResponse(code = 200, message = "ok", response = Map.class) }) @PostMapping(value = "/applyToBeAnSalesman") public AjaxResult applyToBeAnSalesman(@RequestBody Map param) { BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); loginUser=bizUserDao.selectById(loginUser.getUserId()); //校验审核状态,和是否重复发起 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("user_id",loginUser.getUserId()); ShopSalesmanApply checkApply = salesmanApplyDao.selectOne(queryWrapper); if(checkApply==null|| checkApply.getApplyStatus()==ShopSalesmanApply.APPLY_STATUS_WTG){ ShopSalesmanApply shopSalesmanApply=new ShopSalesmanApply(); shopSalesmanApply.setUserId(loginUser.getUserId()); shopSalesmanApply.setCreateBy(loginUser.getNickName()); shopSalesmanApply.setApplyWay(ShopSalesmanApply.APPLY_WAY_SELF); shopSalesmanApply.setApplyStatus(ShopSalesmanApply.APPLY_STATUS_DSH); shopSalesmanApply.setCompanyId(loginUser.getCompanyId()); shopSalesmanApply.setUpdateBy(loginUser.getNickName()); Date date = new Date(); shopSalesmanApply.setCreateTime(date); shopSalesmanApply.setUpdateTime(date); String invitationId = param.get("invitationId"); if(StringUtils.isNotBlank(invitationId)){ shopSalesmanApply.setParentUserId(invitationId); }else if(StringUtils.isNotBlank(loginUser.getParentOpenId())){ //如果曾经是被邀请进来的则自动绑定为之前邀请人的下级 shopSalesmanApply.setParentUserId(loginUser.getParentOpenId()); } salesmanApplyDao.insert(shopSalesmanApply); return AjaxResult.buildSuccessInstance("申请成功"); }else{ return AjaxResult.buildFailInstance("不能重复申请"); } } @ApiOperation(value = "查询推广员审核进度", notes = "") @ApiResponses({ @ApiResponse(code = 200, message = "ok", response = ShopSalesmanApply.class) }) @GetMapping(value = "/queryApplyProgress") public AjaxResult queryApplyProgress() { BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("user_id",loginUser.getUserId()); ShopSalesmanApply shopSalesmanApply = salesmanApplyDao.selectOne(queryWrapper); return AjaxResult.buildSuccessInstance(shopSalesmanApply); } @ApiOperation(value = "绑定下级客户,当客户点击分销员分销的产品时调用", notes = "传入参数invitationId 必须 分销员openId 例: {invitationId:openId}") @ApiResponses({ @ApiResponse(code = 200, message = "ok", response = Map.class) }) @PostMapping(value = "/bindingParentSalesman") public AjaxResult bindingParentSalesman(@RequestBody Map param) { String invitationId = param.get("invitationId"); if (StringUtils.isBlank(invitationId)) { return AjaxResult.buildFailInstance("请求参数错误"); } BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); loginUser = bizUserDao.selectById(loginUser.getUserId()); if (loginUser.getIsSales() == null || loginUser.getIsSales() == BizUser.NOT_SALES) { if (StringUtils.isBlank(loginUser.getParentOpenId())) { Map updateParam = new HashMap<>(); updateParam.put("userId", loginUser.getUserId()); updateParam.put("parentOpenId", invitationId); bizUserDao.updateByMap(updateParam); return AjaxResult.buildSuccessInstance("绑定成功"); } else { return AjaxResult.buildSuccessInstance("已经存在上级"); } } else { return AjaxResult.buildSuccessInstance("分销员不能被绑定"); } } }