935090232@qq.com
2021-03-14 99e77740b6b2c5a9e774e365bc136910e1b59793
zq-erp/src/main/java/com/matrix/system/fenxiao/action/FenXiaoUserAction.java
@@ -1,14 +1,26 @@
package com.matrix.system.fenxiao.action;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.matrix.biz.bean.BizUser;
import com.matrix.biz.dao.BizUserDao;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.fenxiao.dao.ShopSalesmanApplyDao;
import com.matrix.system.fenxiao.dto.AddSaleManApplyDto;
import com.matrix.system.fenxiao.dto.ExamineSaleManApplyDto;
import com.matrix.system.fenxiao.dto.ShopSalesmanAppliingDto;
import com.matrix.system.fenxiao.dto.ShopSalesmanApplyDto;
import com.matrix.system.fenxiao.entity.ShopSalesmanApply;
import com.matrix.system.fenxiao.service.ShopSalesmanApplyService;
import com.matrix.system.fenxiao.vo.ShopSalesmanAppliingVo;
import com.matrix.system.fenxiao.vo.ShopSalesmanApplyVo;
import com.matrix.system.fenxiao.vo.ShopSalesmanGradeVo;
import com.matrix.system.hive.action.util.QueryUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
@@ -16,12 +28,18 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/fenXiao/fenXiaoUser")
public class FenXiaoUserAction {
   
   @Autowired
    private ShopSalesmanApplyService shopSalesmanApplyService;
   @Autowired
    private ShopSalesmanApplyDao shopSalesmanApplyDao;
   @Autowired
   private BizUserDao bizUserDao;
   /**
     * 查询分销员审核记录
@@ -40,24 +58,12 @@
           shopSalesmanApplyDto.setSort("create_time");
           shopSalesmanApplyDto.setOrder("desc");
        }
        Page<ShopSalesmanApplyVo> page = new Page(shopSalesmanApplyDto.getPageNum(), shopSalesmanApplyDto.getPageSize());
        IPage<ShopSalesmanApplyVo> rows = shopSalesmanApplyService.findShopSalesmanApplyList(page,shopSalesmanApplyDto);
        AjaxResult result = AjaxResult.buildSuccessInstance(rows.getRecords(),rows.getTotal());
        return result;
    }
    /**
     * 跳转 分销员待审核记录页面
     *
    @RequestMapping(value = "/shopSalesmanAppliing")
    public String shopSalesmanAppliing() {
        return "admin/fenxiao/fenxiao-apply";
    }
     */
    
   /**
     *获取分销员待审核记录
@@ -71,8 +77,6 @@
    AjaxResult findShopSalesmanAppliingList(@RequestBody ShopSalesmanAppliingDto shopSalesmanAppliingDto) {
        //设置用户公司ID
        QueryUtil.setQueryLimitCom(shopSalesmanAppliingDto);
        //查询条件待审核状态
        shopSalesmanAppliingDto.setApplyStatus(1);
        //排序
        if(StringUtils.isBlank(shopSalesmanAppliingDto.getSort())){
           shopSalesmanAppliingDto.setSort("create_time");
@@ -80,9 +84,72 @@
        }
        Page<ShopSalesmanAppliingVo> page = new Page(shopSalesmanAppliingDto.getPageNum(), shopSalesmanAppliingDto.getPageSize());
        IPage<ShopSalesmanAppliingVo> rows = shopSalesmanApplyService.findShopSalesmanAppliingList(page,shopSalesmanAppliingDto);
        IPage<ShopSalesmanAppliingVo> rows = shopSalesmanApplyService.selectBizUserApplyList(page,shopSalesmanAppliingDto);
        //IPage<ShopSalesmanAppliingVo> rows = shopSalesmanApplyService.findShopSalesmanAppliingList(page,shopSalesmanAppliingDto);
        AjaxResult result = AjaxResult.buildSuccessInstance(rows.getRecords(),rows.getTotal());
        return result;
    }
    /**
     *获取对应的分销员等级
     */
    @RequestMapping(value = "/getShopSalesmanGrade")
    private @ResponseBody AjaxResult getShopSalesmanGradeVo(){
       AjaxResult result= AjaxResult.buildSuccessInstance("查询成功");
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        List<ShopSalesmanGradeVo> dataList = shopSalesmanApplyService.getShopSalesmanGradeVo(user.getCompanyId());
        result.putInMap("salesGrade", dataList);
        return result;
    }
    /**
     *新增分销员
     */
    @ApiOperation(value = "新增分销员")
    @PostMapping(value = "/addSaleManApply")
    public @ResponseBody
    AjaxResult findShopSalesmanAppliingList(@RequestBody AddSaleManApplyDto addSaleManApplyDto) {
        //设置用户公司ID
        QueryUtil.setQueryLimitCom(addSaleManApplyDto);
        AjaxResult result= AjaxResult.buildSuccessInstance("设置成功");
        shopSalesmanApplyService.addSaleManApply(addSaleManApplyDto.getUserId(),addSaleManApplyDto.getGradeId());
      return result;
    }
    /**
     *审核分销员
     */
    @ApiOperation(value = "审核分销员")
    @PostMapping(value = "/examineSaleManApply")
    public @ResponseBody
    AjaxResult examineSaleManApply(@RequestBody ExamineSaleManApplyDto examineSaleManApplyDto) {
        //设置用户公司ID
        QueryUtil.setQueryLimitCom(examineSaleManApplyDto);
        String userId = examineSaleManApplyDto.getUserId();
        //待审核状态才允许提交
        QueryWrapper<ShopSalesmanApply> queryWrapperOrepool = new QueryWrapper<>();
        queryWrapperOrepool.eq("user_id", userId);
        queryWrapperOrepool.eq("company_id", examineSaleManApplyDto.getCompanyId());
      ShopSalesmanApply shopSalesmanApply = shopSalesmanApplyDao.selectOne(queryWrapperOrepool);
      if(ObjectUtil.isEmpty(shopSalesmanApply)) {
         return  AjaxResult.buildFailInstance("当前记录有误");
      }
      BizUser bizUser = bizUserDao.findByOpenId(userId);
      if(ObjectUtil.isEmpty(bizUser)) {
         return  AjaxResult.buildFailInstance("当前记录有误");
      }
      Integer applyStatus = shopSalesmanApply.getApplyStatus();
        if(ObjectUtil.isNotEmpty(applyStatus) && ShopSalesmanApply.APPLY_STATUS_DSH == applyStatus) {
           Integer applyState = examineSaleManApplyDto.getApplyState();
            shopSalesmanApplyService.examineSaleManApply(shopSalesmanApply,applyState);
            return AjaxResult.buildSuccessInstance("审核成功");
        }else{
            return  AjaxResult.buildFailInstance("当前记录不是待审核状态");
        }
    }
}