package com.fs.store.controller;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.fs.common.core.domain.R;
import com.fs.common.utils.ParseUtils;
import com.fs.common.utils.StringUtils;
import com.fs.company.param.CompanyStoreOrderMoneyLogsListParam;
import com.fs.company.service.ICompanyMoneyLogsService;
import com.fs.company.vo.CompanyStoreOrderMoneyLogsVO;
import com.fs.erp.domain.ErpDeliverys;
import com.fs.erp.domain.ErpOrderQuery;
import com.fs.erp.dto.ErpOrderQueryRequert;
import com.fs.erp.dto.ErpOrderQueryResponse;
import com.fs.erp.service.IErpOrderService;
import com.fs.erp.utils.ErpContextHolder;
import com.fs.express.FsStoreDeliversService;
import com.fs.express.dto.DeliveryDTO;
import com.fs.store.cache.IFsStoreProductCacheService;
import com.fs.store.domain.*;
import com.fs.store.dto.*;
import com.fs.store.enums.ShipperCodeEnum;
import com.fs.store.mapper.FsStoreOrderMapper;
import com.fs.store.mapper.FsWarehousesMapper;
import com.fs.store.param.*;
import com.fs.store.service.*;
import com.fs.store.vo.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 订单Controller
 *
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/storeOrder")
public class FsStoreOrderController extends BaseController {
    @Autowired
    private IFsExpressService expressService;
    @Autowired
    private IFsStoreOrderService fsStoreOrderService;
    @Autowired
    private IFsStoreOrderItemService orderItemService;

    @Autowired
    private IFsUserService userService;

    @Autowired
    private IFsStoreOrderStatusService orderStatusService;

    @Autowired
    IErpOrderService erpOrderService;
    @Autowired
    IFsStorePaymentService paymentService;

    @Autowired
    private ICompanyMoneyLogsService moneyLogsService;

    @Autowired
    private FsStoreDeliversService fsStoreDeliversService;

    @Autowired
    private IFsStoreProductCacheService fsStoreProductCacheService;

    @Autowired
    private FsWarehousesMapper fsWarehousesMapper;

    @Autowired
    private FsStoreOrderMapper fsStoreOrderMapper;
    /**
     * 查询订单列表
     */
    @PreAuthorize("@ss.hasPermi('store:storeOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStoreOrderParam param) {
        startPage();
        if(!StringUtils.isEmpty(param.getCreateTimeRange())){
            param.setCreateTimeList(param.getCreateTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getPayTimeRange())){
            param.setPayTimeList(param.getPayTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getDeliveryImportTimeRange())){
            param.setDeliveryImportTimeList(param.getDeliveryImportTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getDeliverySendTimeRange())){
            param.setDeliverySendTimeList(param.getDeliverySendTimeRange().split("--"));
        }
        param.setNotHealth(1);
        List<FsStoreOrderVO> list = fsStoreOrderService.selectFsStoreOrderListVO(param);
        if (list != null) {
            for (FsStoreOrderVO vo : list) {
                if(vo.getPhone()!=null){
                    vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                    vo.setUserPhone(vo.getUserPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                }
            }
        }
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('store:storeOrder:payRemainList')")
    @GetMapping("/payRemainList")
    public TableDataInfo payRemainList(FsStoreOrderParam param) {
        startPage();
        if(!StringUtils.isEmpty(param.getCreateTimeRange())){
            param.setCreateTimeList(param.getCreateTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getPayTimeRange())){
            param.setPayTimeList(param.getPayTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getDeliveryImportTimeRange())){
            param.setDeliveryImportTimeList(param.getDeliveryImportTimeRange().split("--"));
        }
        List<FsStoreOrderVO> list = fsStoreOrderService.selectPayRemainListVO(param);
        if (list != null) {
            for (FsStoreOrderVO vo : list) {
                if(vo.getPhone()!=null){
                    vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                    vo.setUserPhone(vo.getUserPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                }

            }
        }
        return getDataTable(list);
    }

    /**
     * 导出付尾款订单列表
     */
    @Log(title = "付尾款订单", businessType = BusinessType.EXPORT)
    @GetMapping("/payRemainExport")
    public AjaxResult payRemainExport(FsStoreOrderParam param) {
        if(!StringUtils.isEmpty(param.getCreateTimeRange())){
            param.setCreateTimeList(param.getCreateTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getPayTimeRange())){
            param.setPayTimeList(param.getPayTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getDeliveryImportTimeRange())){
            param.setDeliveryImportTimeList(param.getDeliveryImportTimeRange().split("--"));
        }
        List<FsStorePayRemainOrderExportVO> list = fsStoreOrderService.selectFsStorePayRemainOrderListVOByExport(param);
        //对手机号脱敏
        if (list != null) {
            for (FsStorePayRemainOrderExportVO vo : list) {
                if (vo.getPhone() != null) {
                    vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                }
                if (vo.getUserPhone() != null) {
                    vo.setUserPhone(vo.getUserPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                }
                if (vo.getUserAddress()!=null){
                    vo.setUserAddress(ParseUtils.parseAddress(vo.getUserAddress()));
                }

            }
        }
        ExcelUtil<FsStorePayRemainOrderExportVO> util = new ExcelUtil<FsStorePayRemainOrderExportVO>(FsStorePayRemainOrderExportVO.class);
        return util.exportExcel(list, "付尾款订单数据");
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('store:storeOrder:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStoreOrderParam param) {
        if (param.getBeginTime().equals("") && param.getEndTime().equals("")){
            param.setBeginTime(null);
            param.setEndTime(null);
        }
        if (BeanUtil.isEmpty(param)){
            return AjaxResult.error("请筛选数据导出");
        }
        if(!StringUtils.isEmpty(param.getCreateTimeRange())){
            param.setCreateTimeList(param.getCreateTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getPayTimeRange())){
            param.setPayTimeList(param.getPayTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getDeliverySendTimeRange())){
            param.setDeliverySendTimeList(param.getDeliverySendTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getDeliveryImportTimeRange())){
            param.setDeliveryImportTimeList(param.getDeliveryImportTimeRange().split("--"));
        }
        param.setNotHealth(1);
        List<FsStoreOrderExportVO> list = fsStoreOrderService.selectFsStoreOrderListVOByExport(param);
        //对手机号脱敏
        if (list != null) {
            for (FsStoreOrderExportVO vo : list) {
                if (vo.getPhone() != null) {
                    vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                }
                if (vo.getUserPhone() != null) {
                    vo.setUserPhone(vo.getUserPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                }
                if (vo.getUserAddress()!=null){
                    vo.setUserAddress(ParseUtils.parseAddress(vo.getUserAddress()));
                }
            }
        }
        ExcelUtil<FsStoreOrderExportVO> util = new ExcelUtil<FsStoreOrderExportVO>(FsStoreOrderExportVO.class);
        return util.exportExcel(list, "订单数据");
    }



    @PreAuthorize("@ss.hasPermi('store:storeOrder:exportItems')")
    @Log(title = "订单明细导出", businessType = BusinessType.EXPORT)
    @GetMapping("/exportItems")
    public AjaxResult exportItems(FsStoreOrderParam param) {
        if (param.getBeginTime().equals("") && param.getEndTime().equals("")){
            param.setBeginTime(null);
            param.setEndTime(null);
        }
        if (BeanUtil.isEmpty(param)){
            return AjaxResult.error("请筛选数据导出");
        }
        if(!StringUtils.isEmpty(param.getCreateTimeRange())){
            param.setCreateTimeList(param.getCreateTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getPayTimeRange())){
            param.setPayTimeList(param.getPayTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getDeliveryImportTimeRange())){
            param.setDeliveryImportTimeList(param.getDeliveryImportTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getDeliverySendTimeRange())){
            param.setDeliverySendTimeList(param.getDeliverySendTimeRange().split("--"));
        }
        param.setNotHealth(1);
        List<FsStoreOrderItemExportVO> list = orderItemService.selectFsStoreOrderItemListExportVO(param);
        //对手机号脱敏
        if (list != null) {
            for (FsStoreOrderItemExportVO vo : list) {
                if (vo.getUserPhone() != null) {
                    String phone = vo.getUserPhone().replaceAll("(\\d{3})\\d*(\\d{1})", "$1****$2");
                    vo.setUserPhone(phone);
                }
                if (vo.getUserAddress()!=null){
                    vo.setUserAddress(ParseUtils.parseAddress(vo.getUserAddress()));
                }
                if (!StringUtils.isEmpty(vo.getJsonInfo())) {
                    try {
                        StoreOrderProductDTO orderProductDTO = JSONObject.parseObject(vo.getJsonInfo(), StoreOrderProductDTO.class);
                        BeanUtil.copyProperties(orderProductDTO, vo);
                    } catch (Exception e) {
                    }
                }
            }
        }
        ExcelUtil<FsStoreOrderItemExportVO> util = new ExcelUtil<FsStoreOrderItemExportVO>(FsStoreOrderItemExportVO.class);
        return util.exportExcel(list, "订单明细数据");
    }


    @GetMapping("/orderItemsNum")
    public R orderItemsNum(FsStoreOrderParam param) {

        if(!StringUtils.isEmpty(param.getCreateTimeRange())){
            param.setCreateTimeList(param.getCreateTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getPayTimeRange())){
            param.setPayTimeList(param.getPayTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getDeliveryImportTimeRange())){
            param.setDeliveryImportTimeList(param.getDeliveryImportTimeRange().split("--"));
        }
        if(!StringUtils.isEmpty(param.getDeliverySendTimeRange())){
            param.setDeliverySendTimeList(param.getDeliverySendTimeRange().split("--"));
        }
        param.setNotHealth(1);
        Long orderItemsNum = orderItemService.countFsStoreOrderItemListExportVO(param);
        return R.ok().put("orderItemsNum","订单明细数目："+orderItemsNum);
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:storeOrder:query')")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id) {
        FsStoreOrder order = fsStoreOrderService.selectFsStoreOrderById(id);
        order.setUserPhone(ParseUtils.parsePhone(order.getUserPhone()));
        order.setUserAddress(ParseUtils.parseAddress(order.getUserAddress()));
        FsUser user = userService.selectFsUserById(order.getUserId());
        if (user!=null){
            user.setPhone(ParseUtils.parsePhone(user.getPhone()));
        }

        FsStoreOrderItem itemMap = new FsStoreOrderItem();
        itemMap.setOrderId(order.getId());
        // 设置仓库代码
        List<FsStoreOrderItem> items = orderItemService.selectFsStoreOrderItemList(itemMap);
        for (FsStoreOrderItem item : items) {
            if(ObjectUtil.isNotNull(item.getProductId())){
                String warehouseCode = fsStoreProductCacheService.getWarehouseCodeByProductId(item.getProductId());
                if(StringUtils.isNotBlank(warehouseCode)){
                    item.setWarehouseCode(warehouseCode);
                }
            }
        }
        FsStoreOrderStatus statusMap = new FsStoreOrderStatus();
        statusMap.setOrderId(order.getId());
        List<FsStoreOrderStatus> logs = orderStatusService.selectFsStoreOrderStatusList(statusMap);
        List<FsStorePayment> payments=paymentService.selectFsStorePaymentByOrderId(order.getId());
        List<CompanyStoreOrderMoneyLogsVO> tuiMoneyLogs=new ArrayList<>();
        if(order.getCompanyId()!=null){
            CompanyStoreOrderMoneyLogsListParam moneyLogsMap=new CompanyStoreOrderMoneyLogsListParam();
            moneyLogsMap.setCompanyId(order.getCompanyId());
            moneyLogsMap.setBusinessId(order.getId().toString());
            tuiMoneyLogs=moneyLogsService.selectCompanyStoreOrderMoneyLogsList(moneyLogsMap);
        }
        return R.ok().put("order", order).put("items", items).put("logs", logs).put("user", user).put("payments",payments).put("tuiMoneyLogs",tuiMoneyLogs);
    }

    @GetMapping(value = "/queryAddress/{id}")
    @PreAuthorize("@ss.hasPermi('store:storeOrder:queryAddress')")
    public R getAddress(@PathVariable("id") Long id)
    {
        FsStoreOrder order = fsStoreOrderService.selectFsStoreOrderById(id);
        String address = order.getUserAddress();
        return R.ok().put("address",address);
    }

    @GetMapping(value = "/queryPhone/{id}")
    @Log(title = "查看电话", businessType = BusinessType.GRANT)
    @PreAuthorize("@ss.hasPermi('store:storeOrder:queryPhone')")
    public R getPhone(@PathVariable("id") Long id)
    {
        FsStoreOrder order = fsStoreOrderService.selectFsStoreOrderById(id);
        String userPhone = order.getUserPhone();
        return R.ok().put("userPhone",userPhone);
    }

    @PreAuthorize("@ss.hasPermi('store:storeOrder:express')")
    @GetMapping(value = "/getExpress/{id}")
    @Deprecated
    public R getExpress(@PathVariable("id") Long id) {
        logger.warn("该接口已经停止使用!");

        FsStoreOrder order = fsStoreOrderService.selectFsStoreOrderById(id);
        ExpressInfoDTO expressInfoDTO = null;
        if (StringUtils.isNotEmpty(order.getDeliveryId())) {
            String lastFourNumber = "";
            if (order.getDeliverySn().equals(ShipperCodeEnum.SF.getValue())) {
                lastFourNumber = order.getUserPhone();
                if (lastFourNumber.length() == 11) {
                    lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
                }
            }
            expressInfoDTO = expressService.getExpressInfo(order.getOrderCode(), order.getDeliverySn(), order.getDeliveryId(), lastFourNumber);
        }
        return R.ok().put("data", expressInfoDTO);
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('store:storeOrder:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStoreOrder fsStoreOrder) {
        return toAjax(fsStoreOrderService.insertFsStoreOrder(fsStoreOrder));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('store:storeOrder:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreOrder fsStoreOrder) {
        return toAjax(fsStoreOrderService.updateFsStoreOrder(fsStoreOrder));
    }

    /**
     * 修改物流
     * @param deliveryDTO
     * @return AjaxResult
     */
    @Log(title = "修改物流", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('store:storeOrder:editDeliveryId')")
    @PutMapping("/editDeliveryId")
    public AjaxResult editDeliveryId(@RequestBody FsStoreDelivers deliveryDTO) {

        fsStoreDeliversService.editDeliveryId(deliveryDTO);
        fsStoreDeliversService.syncDeliverInfo(deliveryDTO.getOrderId());
        fsStoreDeliversService.finishOrder(deliveryDTO.getOrderId());
        return AjaxResult.success();
    }

    @Log(title = "同步管易物流单号", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('store:storeOrder:updateErpOrder')")
    @PostMapping("/updateErpOrder")
    public R updateErpOrder(@Validated @RequestBody FsStoreOrderExpressEditParam param) {
        FsStoreOrder order = fsStoreOrderService.selectFsStoreOrderById(param.getOrderId());
        ErpOrderQueryRequert request = new ErpOrderQueryRequert();
        request.setCode(order.getExtendOrderId());

        // 根据仓库code找erp
        if(com.fs.common.utils.StringUtils.isNotBlank(order.getStoreHouseCode())){
            String erp = fsWarehousesMapper.selectErpByCode(order.getStoreHouseCode());
            ErpContextHolder.setErpType(erp);
        }

        ErpOrderQueryResponse response = erpOrderService.getOrder(request);
        if(response.getOrders()!=null&&response.getOrders().size()>0){
            for(ErpOrderQuery orderQuery : response.getOrders()){
                if(orderQuery.getDeliverys()!=null&&orderQuery.getDeliverys().size()>0){
                    for(ErpDeliverys delivery:orderQuery.getDeliverys()){
                        if(delivery.getDelivery()&& StringUtils.isNotEmpty(delivery.getMail_no())){
                            //更新商订单状态
                            fsStoreOrderService.updateDeliveryOrder(param.getOrderId(), delivery.getMail_no(),delivery.getExpress_code(),delivery.getExpress_name());
                            return R.ok();
                        }
                    }

                }
            }
        }
        return R.error("未查询到快递信息");
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('store:storeOrder:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fsStoreOrderService.deleteFsStoreOrderByIds(ids));
    }


    @PostMapping("/createUserOrder")
    public R createUserOrder(@Validated @RequestBody FsStoreOrderCreateUserParam param, HttpServletRequest request) {
        return fsStoreOrderService.createUserOrder(param);
    }

    @Log(title = "确认订单", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('store:storeOrder:finishOrder')")
    @PostMapping("/finishOrder")
    public R finishOrder(@Validated @RequestBody FsStoreOrderFinishParam param, HttpServletRequest request) {
        return fsStoreOrderService.finishOrder(param.getOrderId());
    }

    @PreAuthorize("@ss.hasPermi('store:storeOrder:auditPayRemain')")
    @PostMapping("/auditPayRemain")
    public R auditPayRemain(@Validated @RequestBody FsStoreOrderAuditPayRemainParam param, HttpServletRequest request) {
        return fsStoreOrderService.auditPayRemain(param.getOrderId());
    }


    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('store:storeOrder:importExpress')")
    @PostMapping("/importExpress")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<StoreOrderExpressExportDTO> util = new ExcelUtil<StoreOrderExpressExportDTO>(StoreOrderExpressExportDTO.class);
        List<StoreOrderExpressExportDTO> list = util.importExcel(file.getInputStream());
        String message = fsStoreOrderService.importExpress(list, updateSupport);
        return AjaxResult.success(message);
    }

    //下载模板
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate() {
        ExcelUtil<StoreOrderExpressExportDTO> util = new ExcelUtil<StoreOrderExpressExportDTO>(StoreOrderExpressExportDTO.class);
        return util.importTemplateExcel("物流回单数据");
    }


    @GetMapping("/getStoreOrder")
    public R getStoreOrder(@RequestParam("orderCode") String orderCode) {
        FsStoreOrderVO vo = fsStoreOrderService.selectFsStoreOrderVOByOrderCode(orderCode);
        return R.ok().put("data", vo);
    }

    @Log(title = "冻结、解冻佣金", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('store:storeOrder:editTuiMoney')")
    @PostMapping("/editTuiMoney")
    public R editTuiMoney(@Validated @RequestBody FsStoreOrderEditTuiMoneyParam param, HttpServletRequest request) {
        return fsStoreOrderService.editTuiMoney(param);
    }

    @Log(title = "退款", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('store:storeOrder:refundOrderMoney')")
    @PostMapping("/refundOrderMoney")
    public synchronized R refundOrderMoney(@Validated @RequestBody FsStoreOrderRefundParam param, HttpServletRequest request) {
        return fsStoreOrderService.refundOrderMoney(param.getOrderId());
    }
    @PreAuthorize("@ss.hasPermi('store:storeOrder:getEroOrder')")
    @GetMapping("/getEroOrder")
    public R getEroOrder(@RequestParam("extendOrderId") String extendOrderId) {
        ErpOrderQueryRequert request = new ErpOrderQueryRequert();
        request.setCode(extendOrderId);

        FsStoreOrder order = fsStoreOrderMapper.selectFsStoreOrderByExtendOrderId(extendOrderId);

        // 根据仓库code找erp
        if(com.fs.common.utils.StringUtils.isNotBlank(order.getStoreHouseCode())){
            String erp = fsWarehousesMapper.selectErpByCode(order.getStoreHouseCode());
            ErpContextHolder.setErpType(erp);
        }


        ErpOrderQueryResponse response = erpOrderService.getOrder(request);
        return R.ok().put("data",response);
    }

    @PreAuthorize("@ss.hasPermi('store:storeOrder:updateExpress')")
    @PostMapping("/updateExpress")
    public R updateExpress(@Validated @RequestBody FsStoreOrderExpressEditParam param, HttpServletRequest request) {
        return fsStoreOrderService.updateExpress(param);
    }

    @Log(title = "同步物流", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('store:storeOrder:syncExpress')")
    @PostMapping("/syncExpress")
    public R syncExpress(@Validated @RequestBody FsStoreOrderExpressEditParam param, HttpServletRequest request) {
        return fsStoreOrderService.syncExpress(param);
    }


    @Log(title = "分佣", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('store:storeOrder:addTuiMoney')")
    @PostMapping("/addTuiMoney")
    public R addTuiMoney(@Validated @RequestBody FsStoreOrderAddTuiMoneyParam param, HttpServletRequest request) {
        return fsStoreOrderService.addTuiMoney(param);
    }


    @GetMapping("/getCustomerOrderList")
    public TableDataInfo getCustomerOrderList(FsStoreOrderParam param) {
        startPage();
        List<FsStoreOrderVO> list = fsStoreOrderService.selectFsCustomerStoreOrderListVO(param);
        if (list != null) {
            for (FsStoreOrderVO vo : list) {
                if(vo.getPhone()!=null){
                    vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{1})", "$1****$2"));
                    vo.setUserPhone(vo.getUserPhone().replaceAll("(\\d{3})\\d*(\\d{1})", "$1****$2"));
                }

            }
        }
        return getDataTable(list);
    }

    @Log(title = "手动推管易", businessType = BusinessType.INSERT)
    @ApiOperation("创建ERP订单")
    @PreAuthorize("@ss.hasPermi('store:storeOrder:createErpOrder')")
    @GetMapping("/createErpOrder")
    public R createErpOrder(@RequestParam("orderCode") String orderCode) throws Exception
    {
        FsStoreOrder order=fsStoreOrderService.selectFsStoreOrderByOrderCode(orderCode);
        fsStoreOrderService.createOmsOrder(order.getId());
        return R.ok();
    }
}
