package com.slodon.b2b2c.controller.seller.admin;

import com.slodon.b2b2c.aop.OperationLogger;
import com.slodon.b2b2c.core.constant.StoreConst;
import com.slodon.b2b2c.core.exception.MallException;
import com.slodon.b2b2c.core.response.JsonResult;
import com.slodon.b2b2c.core.response.PageVO;
import com.slodon.b2b2c.core.response.PagerInfo;
import com.slodon.b2b2c.core.response.SldResponse;
import com.slodon.b2b2c.core.util.*;
import com.slodon.b2b2c.dao.write.seller.StoreWriteMapper;
import com.slodon.b2b2c.dto.StoreApplyAuditDTO;
import com.slodon.b2b2c.enums.WebSiteConstant;
import com.slodon.b2b2c.goods.example.GoodsCategoryExample;
import com.slodon.b2b2c.goods.pojo.GoodsCategory;
import com.slodon.b2b2c.model.goods.GoodsCategoryModel;
import com.slodon.b2b2c.model.seller.*;
import com.slodon.b2b2c.model.system.SettingModel;
import com.slodon.b2b2c.seller.dto.StoreBusinessVO;
import com.slodon.b2b2c.seller.example.*;
import com.slodon.b2b2c.seller.pojo.*;
import com.slodon.b2b2c.system.pojo.Admin;
import com.slodon.b2b2c.system.pojo.Setting;
import com.slodon.b2b2c.vo.seller.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author slodon
 */
@Slf4j
@Api(tags = "admin-入驻店铺相关接口")
@RestController
@RequestMapping("v3/seller/admin/storeAudit")
public class AdminStoreAuditController {

    @Resource
    private StoreModel storeModel;
    @Resource
    private StoreApplyModel storeApplyModel;
    @Resource
    private StoreNameModel storeNameModel;
    @Resource
    private StoreGradeModel storeGradeModel;
    @Resource
    private StoreCertificateModel storeCertificateModel;
    @Resource
    private StoreBindCategoryModel storeBindCategoryModel;
    @Resource
    private GoodsCategoryModel goodsCategoryModel;
    @Resource
    private StoreWriteMapper storeWriteMapper;
    @Autowired
    private StoreSiteInfoModel storeSiteInfoModel;
    @Resource
    private SettingModel settingModel;

    @ApiOperation("入驻审核列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "webSite", value = "站点", paramType = "query"),
            @ApiImplicitParam(name = "storeName", value = "店铺名称", paramType = "query"),
            @ApiImplicitParam(name = "vendorName", value = "店主账号", paramType = "query"),
            @ApiImplicitParam(name = "storeGradeId", value = "店铺等级", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "审核状态", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = "20", paramType = "query"),
            @ApiImplicitParam(name = "current", value = "当前页面位置", defaultValue = "1", paramType = "query")
    })
    @GetMapping("list")
    public JsonResult<PageVO<StoreApplyVO>> getList(HttpServletRequest request,
                                                    @RequestParam(value = "webSite", required = false) String webSite,
                                                    @RequestParam(value = "storeName", required = false) String storeName,
                                                    @RequestParam(value = "vendorName", required = false) String vendorName,
                                                    @RequestParam(value = "storeGradeId", required = false) Integer storeGradeId,
                                                    @RequestParam(value = "state", required = false) Integer state) {
        PagerInfo pager = WebUtil.handlerPagerInfo(request);

        List<StoreApplyVO> vos = new ArrayList<>();
        List<StoreApply> storeApplyList = new ArrayList<>();

        StoreApplyExample example = new StoreApplyExample();
        example.setStoreNameLike(storeName);
        example.setStoreGradeId(storeGradeId);
        example.setVendorNameLike(vendorName);
        example.setStoreType(StoreConst.NO_OWN_STORE);
        example.setPager(pager);
        example.setOrderBy("submit_time desc");
        if (state != null) {
            example.setState(state);
        } else {
            example.setStateNotEquals(StoreConst.STATE_4_STORE_OPEN);
        }
        if (WebSiteConstant.MEMBER_OVERSEA.equals(webSite)) {
            storeApplyList = storeApplyModel.getStoreApplyList(example, pager);
        } else {
            if (pager!= null){
                storeApplyList = storeApplyModel.getStoreApplyCnList(example, pager);
            }

        }
        if (!CollectionUtils.isEmpty(storeApplyList)) {

            storeApplyList.forEach(storeApply -> {
                StoreApplyVO vo = new StoreApplyVO(storeApply);
                //根据等级id获取等级名称
                StoreGrade storeGrade = storeGradeModel.getStoreGradeByGradeId(storeApply.getStoreGradeId());
                if (storeGrade != null) {
                    vo.setStoreGradeName(storeGrade.getGradeName());
                }

                //获取联系人名称和电话
                StoreCertificateExample storeCertificateExample = new StoreCertificateExample();
                storeCertificateExample.setVendorId(storeApply.getVendorId());
                List<StoreCertificate> storeCertificateList = storeCertificateModel.getStoreCertificateList(storeCertificateExample, null);
                if (!CollectionUtils.isEmpty(storeCertificateList)) {
                    vo.setContactName(storeCertificateList.get(0).getContactName());
                    vo.setContactPhone(CommonUtil.dealMobile(storeCertificateList.get(0).getContactPhone()));
                }
                vos.add(vo);
            });
        }
        return SldResponse.success(new PageVO<>(vos, example.getPager()));
    }

    @ApiOperation("查看入驻详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applyId", value = "申请id", required = true)
    })
    @GetMapping("detail")
    public JsonResult<StoreApplyDetailVO> getDetail(HttpServletRequest request, @RequestParam("applyId") Integer applyId) {
        String logMsg = "申请id" + applyId;
        Admin admin = UserUtil.getUser(request, Admin.class);

        //获取商家申请信息
        StoreApply storeApply = storeApplyModel.getStoreApplyByApplyId(applyId);


        //获取申请资质信息
        StoreCertificateExample storeCertificateExample = new StoreCertificateExample();
        storeCertificateExample.setVendorId(storeApply.getVendorId());
        List<StoreCertificate> storeCertificateList = storeCertificateModel.getStoreCertificateList(storeCertificateExample, null);
        StoreApplyDetailVO vo = new StoreApplyDetailVO(storeApply, storeCertificateList.get(0));

        //根据等级id获取等级名称
        StoreGrade storeGrade = storeGradeModel.getStoreGradeByGradeId(storeApply.getStoreGradeId());
        vo.setStoreGradeName(storeGrade != null ? storeGrade.getGradeName() : null);

        Store store = storeModel.getStoreByStoreId(storeApply.getStoreId());

        vo.setOpenTime(store != null ? store.getOpenTime() : null);


        List<StoreBusinessVO> storeBusinessVOList = new ArrayList<>();
        StoreBusinessVO storeBusinessVO = new StoreBusinessVO();
        storeBusinessVO.setWebSite(WebSiteConstant.MEMBER_OVERSEA);
        storeBusinessVO.setStoreName(vo.getStoreName());
        storeBusinessVO.setOpenTime(vo.getOpenTime());
        storeBusinessVO.setStoreGradeId(vo.getStoreGradeId());
        storeBusinessVO.setStoreGradeName(vo.getStoreGradeName());
        storeBusinessVOList.add(storeBusinessVO);

        StoreNameExample storeNameExample = new StoreNameExample();
        storeNameExample.setStoreId(storeApply.getStoreId());
        storeNameExample.setWebSite(WebSiteConstant.MEMBER_DISTRIBUTOR);
        StoreName storeName = storeNameModel.getStoreNameByExample(storeNameExample);

        Store storeCn = storeSiteInfoModel.getStoreByStoreIdAndWebSite(storeApply.getStoreId(), WebSiteConstant.MEMBER_DISTRIBUTOR);
        storeBusinessVO = new StoreBusinessVO();
        storeBusinessVO.setWebSite(WebSiteConstant.MEMBER_DISTRIBUTOR);
        storeBusinessVO.setStoreName(storeName != null ? storeName.getStoreName() : "");
        storeBusinessVO.setOpenTime(storeCn != null ? storeCn.getOpenTime() : null);
        storeBusinessVO.setStoreGradeId(storeCn != null ? storeCn.getStoreGradeId() : null);
        storeBusinessVO.setStoreGradeName(storeCn != null ? storeCn.getStoreGradeName() : null);
        storeBusinessVOList.add(storeBusinessVO);

        vo.setStoreBusinessVOList(storeBusinessVOList);


        List<Setting> webSiteList = settingModel.getSiteSetting();
        List<StoreGoodsCateVO> storeGoodsCateVOList = new ArrayList<>();
        for (Setting setting : webSiteList) {
            bulidStoreGoodsCateVOList(storeGoodsCateVOList, storeApply, webSiteList, setting.getValue());
        }
        vo.setStoreGoodsCateVOList(storeGoodsCateVOList);
        return SldResponse.success(vo, logMsg);
    }

    /**
     * 构建不同站点经营类目信息
     * @param storeGoodsCateVOList
     * @param storeApply
     * @param webSiteList
     * @param webSite
     */
    private void bulidStoreGoodsCateVOList(List<StoreGoodsCateVO> storeGoodsCateVOList, StoreApply storeApply, List<Setting> webSiteList, String webSite) {

        //获取经营类目信息
        StoreBindCategoryExample storeBindCategoryExample = new StoreBindCategoryExample();
        storeBindCategoryExample.setWebSite(webSite);
        storeBindCategoryExample.setCreateVendorId(storeApply.getVendorId());
        List<StoreBindCategory> storeBindCategoryList = storeBindCategoryModel.getStoreBindCategoryList(storeBindCategoryExample, null);

        GoodsCategoryExample goodsCategoryExample = new GoodsCategoryExample();
        List<GoodsCategory> goodsCategoryList = goodsCategoryModel.getGoodsCategoryList(goodsCategoryExample, null);

        if (!CollectionUtils.isEmpty(storeBindCategoryList)) {
            storeBindCategoryList.forEach(storeBindCategory -> {
                StoreGoodsCateVO storeGoodsCateVO = new StoreGoodsCateVO(storeBindCategory);
                storeGoodsCateVO.setWebSiteName(webSiteList.stream().filter(setting -> setting.getValue().equals(storeBindCategory.getWebSite())).findFirst().map(Setting::getTitle).orElse(""));
                storeGoodsCateVO.setGoodsCateName1(goodsCategoryList.stream().filter(goodsCategory -> goodsCategory.getCategoryId().equals(storeBindCategory.getGoodsCategoryId1())).findFirst().map(GoodsCategory::getCategoryName).orElse(""));
                storeGoodsCateVO.setGoodsCateName2(goodsCategoryList.stream().filter(goodsCategory -> goodsCategory.getCategoryId().equals(storeBindCategory.getGoodsCategoryId2())).findFirst().map(GoodsCategory::getCategoryName).orElse(""));
                storeGoodsCateVO.setGoodsCateName3(goodsCategoryList.stream().filter(goodsCategory -> goodsCategory.getCategoryId().equals(storeBindCategory.getGoodsCategoryId3())).findFirst().map(GoodsCategory::getCategoryName).orElse(""));
                storeGoodsCateVOList.add(storeGoodsCateVO);
            });
        }
    }

    @ApiOperation("查看入驻详情所有接口")
    @GetMapping("detailList")
    public JsonResult<List<StoreApplyDetailVO>> getDetailList(HttpServletRequest request, String applyIds) {
        Admin admin = UserUtil.getUser(request, Admin.class);
        String[] split = applyIds.split(",");
        //string[]类型数组转int[]类型数组
        int[] array = Arrays.asList(split).stream().mapToInt(Integer::parseInt).toArray();

        List<StoreApplyDetailVO> vos = new ArrayList<>();
        for (Integer applyId : array) {
            //获取商家申请信息
            StoreApply storeApply = storeApplyModel.getStoreApplyByApplyId(applyId);

            //获取申请资质信息
            StoreCertificateExample storeCertificateExample = new StoreCertificateExample();
            storeCertificateExample.setVendorId(storeApply.getVendorId());
            List<StoreCertificate> storeCertificateList = storeCertificateModel.getStoreCertificateList(storeCertificateExample, null);
            StoreApplyDetailVO vo = new StoreApplyDetailVO(storeApply, storeCertificateList.get(0));

            //根据等级id获取等级名称
            StoreGrade storeGrade = storeGradeModel.getStoreGradeByGradeId(storeApply.getStoreGradeId());
            vo.setStoreGradeName(storeGrade != null ? storeGrade.getGradeName() : null);


            Store store = storeModel.getStoreByStoreId(storeApply.getStoreId());
            vo.setOpenTime(store != null ? store.getOpenTime() : null);

            List<StoreBusinessVO> storeBusinessVOList = new ArrayList<>();
            StoreBusinessVO storeBusinessVO = new StoreBusinessVO();
            storeBusinessVO.setWebSite(WebSiteConstant.MEMBER_OVERSEA);
            storeBusinessVO.setStoreName(vo.getStoreName());
            storeBusinessVO.setOpenTime(vo.getOpenTime());
            storeBusinessVO.setStoreGradeId(vo.getStoreGradeId());
            storeBusinessVO.setStoreGradeName(vo.getStoreGradeName());
            storeBusinessVOList.add(storeBusinessVO);

            StoreNameExample storeNameExample = new StoreNameExample();
            storeNameExample.setStoreId(storeApply.getStoreId());
            storeNameExample.setWebSite(WebSiteConstant.MEMBER_DISTRIBUTOR);
            StoreName storeName = storeNameModel.getStoreNameByExample(storeNameExample);

            Store storeCn = storeSiteInfoModel.getStoreByStoreIdAndWebSite(storeApply.getStoreId(), WebSiteConstant.MEMBER_DISTRIBUTOR);
            storeBusinessVO = new StoreBusinessVO();
            storeBusinessVO.setWebSite(WebSiteConstant.MEMBER_DISTRIBUTOR);
            storeBusinessVO.setStoreName(storeName != null ? storeName.getStoreName() : "");
            storeBusinessVO.setOpenTime(storeCn != null ? storeCn.getOpenTime() : null);
            storeBusinessVO.setStoreGradeId(storeCn != null ? storeCn.getStoreGradeId() : null);
            storeBusinessVO.setStoreGradeName(storeCn != null ? storeCn.getStoreGradeName() : null);
            storeBusinessVOList.add(storeBusinessVO);

            vo.setStoreBusinessVOList(storeBusinessVOList);

            List<Setting> webSiteList = settingModel.getSiteSetting();
            List<StoreGoodsCateVO> storeGoodsCateVOList = new ArrayList<>();
            for (Setting setting : webSiteList) {
                bulidStoreGoodsCateVOList(storeGoodsCateVOList, storeApply, webSiteList, setting.getValue());
            }
            vo.setStoreGoodsCateVOList(storeGoodsCateVOList);
        }

        return SldResponse.success(vos);
    }


    @ApiOperation("审核入驻申请")
    @OperationLogger(option = "审核入驻申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applyId", value = "申请id", required = true),
            @ApiImplicitParam(name = "isPass", value = "是否通过[true==通过,false==驳回]", required = true),
            @ApiImplicitParam(name = "refuseReason", value = "审核原因，驳回时必填"),
            @ApiImplicitParam(name = "remark", value = "备注，拒绝时选填"),
            @ApiImplicitParam(name = "scalingBindIds", value = "分佣比例，审核通过时必填,例：bindId1-scaling1,bindId2-scaling2,..."),
            @ApiImplicitParam(name = "storeGradeId", value = "等级id"),
            @ApiImplicitParam(name = "storeGradeIdCn", value = "国内店铺等级id"),
            @ApiImplicitParam(name = "openTime", value = "开店时长"),
            @ApiImplicitParam(name = "openTimeCn", value = "国内店铺开店时长"),
    })
    @PostMapping("audit")
    public JsonResult<Object> audit(HttpServletRequest request,
                                    @RequestBody StoreApplyAuditDTO storeApplyAuditDTO)
                                    {

        Admin admin = UserUtil.getUser(request, Admin.class);

        AssertUtil.isTrue(!storeApplyAuditDTO.getIsPass() && StringUtils.isEmpty(storeApplyAuditDTO.getRefuseReason()), "请填写审核拒绝原因");
//        AssertUtil.isTrue(isPass && StringUtils.isEmpty(scalingBindIds), "请填写分佣比例");

        StoreApply storeApply = storeApplyModel.audit(storeApplyAuditDTO.getApplyId(), storeApplyAuditDTO.getIsPass(), storeApplyAuditDTO.getRefuseReason(), storeApplyAuditDTO.getRemark(), storeApplyAuditDTO.getScalingBindIds(), admin);

//        //根据gradeId查询store_grade表
//        StoreGrade storeGrade = storeGradeModel.getStoreGradeByGradeId(storeApply.getStoreGradeId());
//
//        RegisterPayVO vo = new RegisterPayVO(storeGrade, storeApply);
//        //获取经营类目信息
//        StoreBindCategoryExample storeBindCategoryExample = new StoreBindCategoryExample();
//        storeBindCategoryExample.setCreateVendorId(storeApply.getVendorId());
//        List<StoreBindCategory> storeBindCategoryList = storeBindCategoryModel.getStoreBindCategoryList(storeBindCategoryExample, null);
//        List<StoreGoodsCateVO> storeGoodsCateVOList = new ArrayList<>();
//        if (!CollectionUtils.isEmpty(storeBindCategoryList)) {
//            for (StoreBindCategory storeBindCategory : storeBindCategoryList) {
//                StoreGoodsCateVO storeGoodsCateVO = new StoreGoodsCateVO(storeBindCategory);
//                GoodsCategory goodsCategory1 = goodsCategoryModel.getGoodsCategoryByCategoryId(storeBindCategory.getGoodsCategoryId1());
//                if (goodsCategory1 == null) {
//                    continue;
//                }
//                storeGoodsCateVO.setGoodsCateName1(goodsCategory1.getCategoryName());
//                GoodsCategory goodsCategory2 = goodsCategoryModel.getGoodsCategoryByCategoryId(storeBindCategory.getGoodsCategoryId2());
//                if (goodsCategory2 == null) {
//                    continue;
//                }
//                storeGoodsCateVO.setGoodsCateName2(goodsCategory2.getCategoryName());
//                GoodsCategory goodsCategory3 = goodsCategoryModel.getGoodsCategoryByCategoryId(storeBindCategory.getGoodsCategoryId3());
//                if (goodsCategory3 == null) {
//                    continue;
//                }
//                storeGoodsCateVO.setGoodsCateName3(goodsCategory3.getCategoryName());
//                storeGoodsCateVOList.add(storeGoodsCateVO);
//            }
//            vo.setStoreGoodsCateVOList(storeGoodsCateVOList);
//        }
        if (storeApplyAuditDTO.getIsPass()) {
            if (CollectionUtils.isEmpty(storeApplyAuditDTO.getStoreBusinessVOList())){
                throw new MallException("请选择经营信息");
            }
            // 扩展站点可重新设计
            for (StoreBusinessVO storeBusinessVO : storeApplyAuditDTO.getStoreBusinessVOList()){
                if(WebSiteConstant.MEMBER_OVERSEA.equals(storeBusinessVO.getWebSite())){
                    if (!StringUtil.isNullOrZero(storeBusinessVO.getOpenTime())){
                        storeApply.setApplyYear(storeBusinessVO.getOpenTime());
                    }else {
                        throw new MallException("请选择开店时长");
                    }
                    if (!StringUtil.isNullOrZero(storeBusinessVO.getStoreGradeId())){
                        storeApply.setStoreGradeId(storeBusinessVO.getStoreGradeId());
                    }else {
                        throw new MallException("请选择店铺等级");
                    }
                }else if (WebSiteConstant.MEMBER_DISTRIBUTOR.equals(storeBusinessVO.getWebSite())) {
                    if (!StringUtil.isNullOrZero(storeBusinessVO.getOpenTime())){
                        storeApply.setApplyYearCn(storeBusinessVO.getOpenTime());
                    }else {
                        throw new MallException("请选择开店时长");
                    }
                    if (!StringUtil.isNullOrZero(storeBusinessVO.getStoreGradeId())){
                        storeApply.setStoreGradeIdCn(storeBusinessVO.getStoreGradeId());
                    }else {
                        throw new MallException("请选择店铺等级");
                    }
                }
            }
            //todo 因业务需要暂不用此功能
//            if (storeApply.getPayAmount().compareTo(BigDecimal.ZERO) == 0) {
            storeModel.openStore(storeApply);
//            }
            storeApplyModel.sendApplyStoreOkSms(storeApply);
            return SldResponse.success("审核通过", storeApply);
        } else {
            ApplyRefuseVO applyRefuseVO = new ApplyRefuseVO(storeApply);
            storeApplyModel.sendApplyStoreFailedSms(storeApply);
            return SldResponse.success("审核拒绝", applyRefuseVO);
        }
    }


    @ApiOperation("批量审核入驻申请")
    @OperationLogger(option = "批量审核入驻申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applyIds", value = "申请id字符串", required = true),
            @ApiImplicitParam(name = "isPass", value = "是否通过[true==通过,false==驳回]", required = true),
            @ApiImplicitParam(name = "refuseReason", value = "审核原因，驳回时必填"),
            @ApiImplicitParam(name = "remark", value = "备注，拒绝时选填"),
            @ApiImplicitParam(name = "scalingBindIds", value = "分佣比例，审核通过时必填,例：bindId1-scaling1,bindId2-scaling2,..."),
            @ApiImplicitParam(name = "openTime", value = "开店时长"),
    })
    @PostMapping("batchAudit")
    public JsonResult<Object> batchAudit(HttpServletRequest request,StoreApplyAuditDTO storeApplyAuditDTO) {
        //参数校验
        String applyIds = storeApplyAuditDTO.getApplyIds();
        AssertUtil.notEmpty(applyIds, "绑定id不能为空");
        AssertUtil.notFormatFrontIds(applyIds, "applyIds格式错误,请重试");
        Admin admin = UserUtil.getUser(request, Admin.class);
        String[] split = applyIds.split(",");
        //string[]类型数组转int[]类型数组
        int[] array = Arrays.asList(split).stream().mapToInt(Integer::parseInt).toArray();
        //遍历
        int total = 0;
        RegisterPayVO vo = null;
        ApplyRefuseVO applyRefuseVO = null;
        Boolean isPass = storeApplyAuditDTO.getIsPass();
        String refuseReason = storeApplyAuditDTO.getRefuseReason();
        String remark = storeApplyAuditDTO.getRemark();
        String scalingBindIds = storeApplyAuditDTO.getScalingBindIds();
        Integer openTime = storeApplyAuditDTO.getOpenTime();
        for (Integer applyId : array) {

            AssertUtil.isTrue(!isPass && StringUtils.isEmpty(refuseReason), "请填写审核拒绝原因");
//            AssertUtil.isTrue(isPass && StringUtils.isEmpty(scalingBindIds), "请填写分佣比例");

            StoreApply storeApply = storeApplyModel.auditNew(applyId, isPass, refuseReason, remark, scalingBindIds, admin);

            //根据gradeId查询store_grade表
            StoreGrade storeGrade = storeGradeModel.getStoreGradeByGradeId(storeApply.getStoreGradeId());

            vo = new RegisterPayVO(storeGrade, storeApply);
//            //获取经营类目信息
//            StoreBindCategoryExample storeBindCategoryExample = new StoreBindCategoryExample();
//            storeBindCategoryExample.setCreateVendorId(storeApply.getVendorId());
//            List<StoreBindCategory> storeBindCategoryList = storeBindCategoryModel.getStoreBindCategoryList(storeBindCategoryExample, null);
//            List<StoreGoodsCateVO> storeGoodsCateVOList = new ArrayList<>();
//            if (!CollectionUtils.isEmpty(storeBindCategoryList)) {
//                for (StoreBindCategory storeBindCategory : storeBindCategoryList) {
//                    StoreGoodsCateVO storeGoodsCateVO = new StoreGoodsCateVO(storeBindCategory);
//                    GoodsCategory goodsCategory1 = goodsCategoryModel.getGoodsCategoryByCategoryId(storeBindCategory.getGoodsCategoryId1());
//                    if (goodsCategory1 == null) {
//                        continue;
//                    }
//                    storeGoodsCateVO.setGoodsCateName1(goodsCategory1.getCategoryName());
//                    GoodsCategory goodsCategory2 = goodsCategoryModel.getGoodsCategoryByCategoryId(storeBindCategory.getGoodsCategoryId2());
//                    if (goodsCategory2 == null) {
//                        continue;
//                    }
//                    storeGoodsCateVO.setGoodsCateName2(goodsCategory2.getCategoryName());
//                    GoodsCategory goodsCategory3 = goodsCategoryModel.getGoodsCategoryByCategoryId(storeBindCategory.getGoodsCategoryId3());
//                    if (goodsCategory3 == null) {
//                        continue;
//                    }
//                    storeGoodsCateVO.setGoodsCateName3(goodsCategory3.getCategoryName());
//                    storeGoodsCateVOList.add(storeGoodsCateVO);
//                }
//                vo.setStoreGoodsCateVOList(storeGoodsCateVOList);
//            }

            if (isPass) {
                // 店铺审核增加开店时长
                if (!StringUtil.isNullOrZero(openTime)) {
                    storeApply.setApplyYear(openTime);
                    storeApply.setApplyYearCn(openTime);
                }else{
                    throw new MallException("请选择开店时长");
                }
                storeApply.setStoreGradeIdCn(storeApply.getStoreGradeId());
                int count = storeModel.openStore(storeApply);
                total += count;
            } else {
                applyRefuseVO = new ApplyRefuseVO(storeApply);
            }
        }
        if (total == 0) {
            if (!StringUtil.isEmpty(applyIds)) {
                List<String> mobiles = storeApplyModel.getStoreApplyVendorMobile(Arrays.asList(split));
                if (!CollectionUtils.isEmpty(mobiles)) {
                    storeApplyModel.sendApplyStoreFailedSms(mobiles.stream().map(String::valueOf).collect(Collectors.joining(",")));
                }
            }
            return SldResponse.success("审核拒绝", applyRefuseVO);
        } else {
            if (!StringUtil.isEmpty(applyIds)) {
                List<String> mobiles = storeApplyModel.getStoreApplyVendorMobile(Arrays.asList(split));
                if (!CollectionUtils.isEmpty(mobiles)) {
                    storeApplyModel.sendApplyStoreOkSms(mobiles.stream().map(String::valueOf).collect(Collectors.joining(",")));
                }
            }
            return SldResponse.success("审核通过", vo);
        }

    }
}
