|
@@ -1,920 +0,0 @@
|
|
|
-package com.caimei.modules.bulkpurchase.web;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.caimei.modules.bulkpurchase.entity.*;
|
|
|
-import com.caimei.modules.bulkpurchase.service.*;
|
|
|
-import com.caimei.modules.common.utils.ExcelUtil;
|
|
|
-import com.caimei.modules.product.dao.ProductDao;
|
|
|
-import com.caimei.modules.product.entity.BuyerProductHistoryPrice;
|
|
|
-import com.caimei.modules.product.entity.BuyerProductPrice;
|
|
|
-import com.caimei.modules.product.entity.Product;
|
|
|
-import com.caimei.modules.product.service.BuyerProductHistoryPriceService;
|
|
|
-import com.caimei.modules.product.service.BuyerProductPriceService;
|
|
|
-import com.caimei.modules.project.dao.ClubDao;
|
|
|
-import com.caimei.modules.project.model.ClubModel;
|
|
|
-import com.caimei.modules.sys.utils.MailUtils;
|
|
|
-import com.caimei.utils.AppUtils;
|
|
|
-import com.caimei.utils.MathUtil;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-import com.google.common.collect.Maps;
|
|
|
-import com.thinkgem.jeesite.common.config.Global;
|
|
|
-import com.thinkgem.jeesite.common.mapper.JsonMapper;
|
|
|
-import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
-import com.thinkgem.jeesite.common.utils.DateUtils;
|
|
|
-import com.thinkgem.jeesite.common.utils.StringUtils;
|
|
|
-import com.thinkgem.jeesite.common.web.BaseController;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.ui.Model;
|
|
|
-import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
-import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.net.URLEncoder;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * 采购订单Controller
|
|
|
- *
|
|
|
- * @author jiangjunwen
|
|
|
- * @version 2017-04-07
|
|
|
- */
|
|
|
-@Controller
|
|
|
-@RequestMapping(value = "${adminPath}/bulkpurchase/contractOrder")
|
|
|
-public class ContractOrderController extends BaseController {
|
|
|
- @Autowired
|
|
|
- private ContractService contractService;
|
|
|
- @Autowired
|
|
|
- private ContractOrderService contractOrderService;
|
|
|
- @Autowired
|
|
|
- private BpOrderUserinfoService bpOrderUserinfoService;
|
|
|
- @Autowired
|
|
|
- private OrderProductService orderProductService;
|
|
|
- @Autowired
|
|
|
- private OrderInvoiceService orderInvoiceService;
|
|
|
- @Autowired
|
|
|
- private OrderStagesService orderStagesService;
|
|
|
- @Autowired
|
|
|
- private OrderStagesProductService orderStagesProductService;
|
|
|
- @Autowired
|
|
|
- private CmFinanceChargeService cmFinanceChargeService;
|
|
|
- @Autowired
|
|
|
- private BuyerProductPriceService buyerProductPriceService;
|
|
|
- @Autowired
|
|
|
- private BuyerProductHistoryPriceService buyerProductHistoryPriceService;
|
|
|
- @Autowired
|
|
|
- private ClubDao clubDao;
|
|
|
- @Autowired
|
|
|
- private ProductDao productDao;
|
|
|
- @Autowired
|
|
|
- private BpClauseService bpClauseService;
|
|
|
-
|
|
|
- @ModelAttribute
|
|
|
- public ContractOrder get(@RequestParam(required = false) String id) {
|
|
|
- ContractOrder entity = null;
|
|
|
- if (StringUtils.isNotBlank(id)) {
|
|
|
- entity = contractOrderService.get(id);
|
|
|
- }
|
|
|
- if (entity == null) {
|
|
|
- entity = new ContractOrder();
|
|
|
- }
|
|
|
- return entity;
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("contractorder:contractOrder:export")
|
|
|
- @RequestMapping(value = "exportOrderList")
|
|
|
- public void exportOrderList(ContractOrder contractOrder, RedirectAttributes redirectAttributes, HttpServletResponse response) {
|
|
|
- //获取订单数据
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- sb.append("大宗采购订单列表(");
|
|
|
- sb.append(contractOrder.getStartTime());
|
|
|
- sb.append("-");
|
|
|
- sb.append(contractOrder.getEndTime());
|
|
|
- sb.append(").xls");
|
|
|
- String fileName = sb.toString();
|
|
|
- String template = Global.getConfig("export.template");
|
|
|
- String templateFileName = template+"/bporderlist_template.xls";
|
|
|
- // 导出订单列表
|
|
|
- contractOrder.setStartTime(contractOrder.getStartTime() + " 00:00:00");
|
|
|
- contractOrder.setEndTime(contractOrder.getEndTime() + " 23:59:59");
|
|
|
- List<BpOrderVo> orderVoList = Lists.newArrayList();
|
|
|
- try {
|
|
|
- //查询在这个时间段内的订单列表
|
|
|
- contractOrder.setConfirmFlag("1");
|
|
|
- contractOrder.setOrderStopFlag("0");
|
|
|
- List<ContractOrder> contractOrders = contractOrderService.findList(contractOrder);
|
|
|
- for (ContractOrder order : contractOrders) {
|
|
|
- BigDecimal totalPayShop = new BigDecimal(0);
|
|
|
- Double alreadyPayShop = 0d;//已支付供应商
|
|
|
- Double alreadyPayCm = 0d;//已付采美佣金
|
|
|
- //如果是分期订单 id为307,381,386,526,537 或 日期> 2018-04-16 00:00:00
|
|
|
- Date date = DateUtils.parseDate("2018-04-16 00:00:00");
|
|
|
- String stagesOrderStr = "307,381,386,526,537";
|
|
|
- if (StringUtils.equals("1", order.getStagesFlag()) && (order.getCreateDate().compareTo(date) > 0 || stagesOrderStr.lastIndexOf(order.getId() + "") != -1)) {
|
|
|
- List<OrderStages> orderStagesList = orderStagesService.findStagesByOrderId(order.getId());
|
|
|
- if (CollectionUtils.isNotEmpty(orderStagesList)) {
|
|
|
- for (OrderStages orderStages : orderStagesList) {
|
|
|
- BpOrderVo orderVo = new BpOrderVo();
|
|
|
- // 判读是否是应付审核过
|
|
|
- List<CmFinanceCharge> cmFinanceChargeList = cmFinanceChargeService.findListByStagesId(orderStages.getId());
|
|
|
- if (CollectionUtils.isNotEmpty(cmFinanceChargeList)) {
|
|
|
- CmFinanceCharge cmFinanceCharge = cmFinanceChargeList.get(0);//sql获取总已付值
|
|
|
- //没有审核通过且没收到款
|
|
|
- if (new BigDecimal(cmFinanceCharge.getTotalStagesShopPay()).compareTo(BigDecimal.ZERO) == 0 && new BigDecimal(cmFinanceCharge.getTotalStagesCmPay()).compareTo(BigDecimal.ZERO) == 0 && !StringUtils.equals("1", orderStages.getPayStatus())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- orderVo.setAlreadyPayCm(cmFinanceCharge.getTotalStagesCmPay());//本期已付采美
|
|
|
- orderVo.setShouldPayShop(orderStages.getShopFee().toString());//本期应付供应商
|
|
|
- orderVo.setUnPayShop(MathUtil.sub(orderStages.getShopFee(), cmFinanceCharge.getTotalStagesShopPay()).toString());//本期未付供应商
|
|
|
- } else {
|
|
|
- //没有申请 且没收到款
|
|
|
- if (!StringUtils.equals("1", orderStages.getPayStatus())) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- orderVo.setAlreadyPayCm("0.00");
|
|
|
- orderVo.setShouldPayShop(orderStages.getShopFee().toString());//本期应付供应商
|
|
|
- orderVo.setUnPayShop(orderStages.getShopFee().toString());//本期未付供应商
|
|
|
- }
|
|
|
- }
|
|
|
- orderVo.setStagesNum(orderStages.getNum() + "");
|
|
|
- orderVo.setName(order.getName());
|
|
|
- orderVo.setNo(order.getNo());
|
|
|
- orderVo.setOrderId(Integer.parseInt(order.getId()));
|
|
|
- orderVo.setOrderTime(order.getCreateDate());
|
|
|
- orderVo.setPayTotalFee(orderStages.getFee());
|
|
|
- orderVo.setReceived(StringUtils.equals("1", orderStages.getPayStatus()) ? orderStages.getFee() : "0.00");
|
|
|
- orderVo.setUncollected(StringUtils.equals("1", orderStages.getPayStatus()) ? "0.00" : orderStages.getFee());
|
|
|
- orderVo.setStagesFlag("1");
|
|
|
- orderVoList.add(orderVo);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- List<OrderProduct> orderProduct = orderProductService.getWithorderId(order.getId() + "");
|
|
|
- if (CollectionUtils.isNotEmpty(orderProduct)) {
|
|
|
- for (OrderProduct op : orderProduct) {
|
|
|
- List<CmFinanceCharge> cmFinanceChargeList = cmFinanceChargeService.findListByProductId(op.getId() + "");
|
|
|
- //该订单商品的总的应付供应商
|
|
|
- Double totalShopFee = Double.parseDouble(op.getShopFee());
|
|
|
- totalPayShop = MathUtil.add(totalPayShop, op.getShopFee());
|
|
|
- //该订单商品已付供应商
|
|
|
- Double shopPayFee = 0.00d;
|
|
|
- if (null != cmFinanceChargeList && cmFinanceChargeList.size() > 0) {
|
|
|
- for (CmFinanceCharge cfc : cmFinanceChargeList) {
|
|
|
- if (StringUtils.equals("3", cfc.getStatus())) {
|
|
|
- //该订单商品应付供应商全部审核通过才有采美佣金
|
|
|
- shopPayFee += Double.parseDouble(cfc.getShopFee());
|
|
|
- alreadyPayShop += Double.parseDouble(cfc.getShopFee());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Double fee = totalShopFee - shopPayFee;
|
|
|
- if (fee <= 0.01) {//使用0.01:考虑计算过程中存在小数点误差
|
|
|
- // 不存在未付供应商则参加这个商品加入采美已付计算
|
|
|
- alreadyPayCm += Double.parseDouble(op.getCmFee());//(如果这个商品的已付供应商已付完表示采美也同时已付)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //如果没有收到款、且未付给供应商 则不查询导出展示
|
|
|
- if (new BigDecimal(order.getReceived()).compareTo(BigDecimal.ZERO) == 0 && alreadyPayShop == 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- BpOrderVo orderVo = new BpOrderVo();
|
|
|
- orderVo.setStagesFlag("0");
|
|
|
- orderVo.setName(order.getName());
|
|
|
- orderVo.setNo(order.getNo());
|
|
|
- orderVo.setOrderId(Integer.parseInt(order.getId()));
|
|
|
- orderVo.setOrderTime(order.getCreateDate());
|
|
|
- orderVo.setPayTotalFee(order.getPayTotalFee());
|
|
|
- orderVo.setReceived(order.getReceived());
|
|
|
- orderVo.setUncollected(order.getUncollected());
|
|
|
- orderVo.setShouldPayShop(totalPayShop.toString());
|
|
|
- orderVo.setUnPayShop(MathUtil.sub(totalPayShop, alreadyPayShop).toString());
|
|
|
- orderVo.setAlreadyPayCm(alreadyPayCm + "");
|
|
|
- orderVoList.add(orderVo);
|
|
|
- }
|
|
|
- }
|
|
|
- new ExcelUtil().createExcel(templateFileName, orderVoList, fileName, response);
|
|
|
- } catch (Exception e) {
|
|
|
- addMessage(redirectAttributes, "订单列表信息导出失败!" + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("contractorder:contractOrder:view")
|
|
|
- @RequestMapping(value = {"list", "all", ""})
|
|
|
- public String list(ContractOrder contractOrder, HttpServletRequest request, HttpServletResponse response, Model model) {
|
|
|
- if (StringUtils.equals("null", contractOrder.getContractId())) {
|
|
|
- contractOrder.setContractId(null);
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(contractOrder.getStartTime())) {
|
|
|
- model.addAttribute("startTime", contractOrder.getStartTime());
|
|
|
- contractOrder.setStartTime(contractOrder.getStartTime() + " 00:00:00");
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(contractOrder.getEndTime())) {
|
|
|
- model.addAttribute("endTime", contractOrder.getEndTime());
|
|
|
- contractOrder.setEndTime(contractOrder.getEndTime() + " 23:59:59");
|
|
|
- }
|
|
|
- Page<ContractOrder> page = contractOrderService.findPage(new Page<ContractOrder>(request, response), contractOrder);
|
|
|
- for (ContractOrder co : page.getList()) {
|
|
|
- String received = co.getReceived();
|
|
|
- String uncollected = co.getUncollected();
|
|
|
- String stagesReceived = co.getStagesReceived();
|
|
|
- String stagesUncollected = co.getStagesUncollected();
|
|
|
- if (StringUtils.isEmpty(received)) {
|
|
|
- co.setReceived("0.00");
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(uncollected)) {
|
|
|
- co.setUncollected("0.00");
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(stagesReceived)) {
|
|
|
- co.setStagesReceived("0.00");
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(stagesUncollected)) {
|
|
|
- co.setStagesUncollected("0.00");
|
|
|
- }
|
|
|
- Double alreadyPay = 0d;//已支付
|
|
|
- Double cmShopPay = 0d;//应付采美佣金
|
|
|
- boolean flag = false;
|
|
|
-
|
|
|
- //如果是分期订单 id为307,381,386,526,537 或 日期> 2018-04-16 00:00:00
|
|
|
- Date date = DateUtils.parseDate("2018-04-16 00:00:00");
|
|
|
- String stagesOrderStr = "307,381,386,526,537";
|
|
|
- if (StringUtils.equals("1", co.getStagesFlag()) && (co.getCreateDate().compareTo(date) > 0 || stagesOrderStr.lastIndexOf(co.getId() + "") != -1)) {
|
|
|
- List<OrderStages> orderStagesList = orderStagesService.findStagesByOrderId(co.getId());
|
|
|
- if (CollectionUtils.isNotEmpty(orderStagesList)) {
|
|
|
- for (OrderStages orderStages : orderStagesList) {
|
|
|
- List<CmFinanceCharge> cmFinanceChargeList = cmFinanceChargeService.findListByStagesId(orderStages.getId());
|
|
|
- if (CollectionUtils.isNotEmpty(cmFinanceChargeList)) {
|
|
|
- CmFinanceCharge cmFinanceCharge = cmFinanceChargeList.get(0);//sql获取总已付值
|
|
|
- cmShopPay += Double.parseDouble(cmFinanceCharge.getTotalStagesCmPay());
|
|
|
- alreadyPay += (Double.parseDouble(cmFinanceCharge.getTotalStagesShopPay()) + Double.parseDouble(cmFinanceCharge.getTotalStagesOtherPay()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //总已付 = 总已付采美 + 总已付三方 + 总已供付应商
|
|
|
- alreadyPay += cmShopPay;
|
|
|
- } else {
|
|
|
- List<OrderProduct> orderProduct = orderProductService.getWithorderId(co.getId() + "");
|
|
|
- if (CollectionUtils.isNotEmpty(orderProduct)) {
|
|
|
- for (OrderProduct op : orderProduct) {
|
|
|
- List<CmFinanceCharge> cmFinanceChargeList = cmFinanceChargeService.findListByProductId(op.getId() + "");
|
|
|
- if (null != cmFinanceChargeList && cmFinanceChargeList.size() > 0) {
|
|
|
- alreadyPay = getAlreadyPay(cmFinanceChargeList, flag, alreadyPay);
|
|
|
- }
|
|
|
-
|
|
|
- //获取这个订单商品的总的应付供应商
|
|
|
- Double totalShopFee = Double.parseDouble(op.getShopFee());
|
|
|
- //已付供应商的总数
|
|
|
- Double shopPayFee = 0.00d;
|
|
|
- if (null != cmFinanceChargeList && cmFinanceChargeList.size() > 0) {
|
|
|
- for (CmFinanceCharge cfc : cmFinanceChargeList) {
|
|
|
- if (StringUtils.equals("3", cfc.getStatus())) {
|
|
|
- //应付供应商全部审核通过才有采美佣金
|
|
|
- shopPayFee += Double.parseDouble(cfc.getShopFee());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Double fee = totalShopFee - shopPayFee;
|
|
|
- if (fee <= 0.01) {//使用0.01:考虑计算过程中存在小数点误差
|
|
|
- // 不存在未付供应商则参加这个商品加入采美已付计算
|
|
|
- cmShopPay += Double.parseDouble(op.getCmFee());//(如果这个商品的已付供应商已付完表示采美也同时已付)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- co.setAlreadyPayCm(String.format("%.2f", cmShopPay));//采美总已付
|
|
|
- co.setUnPay(String.format("%.2f", Double.parseDouble(co.getPayTotalFee()) - alreadyPay));//未支付
|
|
|
- co.setAlreadyPay(String.format("%.2f", alreadyPay));//已支付
|
|
|
-
|
|
|
- }
|
|
|
- model.addAttribute("contractId", contractOrder.getContractId());
|
|
|
- model.addAttribute("page", page);
|
|
|
- return "modules/bulkpurchase/contractOrderList";
|
|
|
- }
|
|
|
-
|
|
|
- //获取已付金额
|
|
|
- private Double getAlreadyPay(List<CmFinanceCharge> cmFinanceChargeList, boolean flag, Double alreadyPay) {
|
|
|
- for (int i = 0; i < cmFinanceChargeList.size(); i++) { //一个产品多个出账记录
|
|
|
- if ("3".equals(cmFinanceChargeList.get(i).getStatus())) {
|
|
|
- flag = true;
|
|
|
- alreadyPay += Double.parseDouble(cmFinanceChargeList.get(i).getShopFee()) + Double.parseDouble(cmFinanceChargeList.get(i).getOtherFee());
|
|
|
- } else {
|
|
|
- alreadyPay += 0;
|
|
|
- }
|
|
|
- if (flag == true && i == (cmFinanceChargeList.size() - 1)) {
|
|
|
- //存在审核通过的应付金额 则+应付采美金额+税费
|
|
|
- alreadyPay += Double.parseDouble(cmFinanceChargeList.get(i).getCmFee()) + Double.parseDouble(cmFinanceChargeList.get(i).getTaxRateFee());
|
|
|
- }
|
|
|
- }
|
|
|
- return alreadyPay;
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("contractorder:contractOrder:view")
|
|
|
- @RequestMapping(value = "form")
|
|
|
- public String form(ContractOrder contractOrder, Model model, HttpServletRequest request) {
|
|
|
- if (StringUtils.isEmpty(contractOrder.getId())) {//新增
|
|
|
- contractOrder.setOrderSource("4");//来源设置为后台
|
|
|
- request.getSession().removeAttribute("orderProducts");
|
|
|
- //获取会所信息,即默认订单客户
|
|
|
- BpOrderUserinfo bpOrderUserinfo = bpOrderUserinfoService.selectUserInfoById(contractOrder.getContractId() + "");
|
|
|
- //获取采购基本信息
|
|
|
- Contract contract = contractService.get(contractOrder.getContractId().toString());
|
|
|
- contractOrder.setContract(contract);
|
|
|
- contractOrder.setFreePostFlag(contract.getFreePostFlag().toString());//设置包邮信息
|
|
|
- contractOrder.setBpOrderUserinfo(bpOrderUserinfo);
|
|
|
- contractOrder.setNo("CMBP" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSSS"));
|
|
|
-
|
|
|
- } else {//修改
|
|
|
- //获取订单客户
|
|
|
- BpOrderUserinfo bpOrderUserinfo = bpOrderUserinfoService.getWithorderId(contractOrder.getId());
|
|
|
- if (null != bpOrderUserinfo) {
|
|
|
- contractOrder.setBpOrderUserinfo(bpOrderUserinfo);
|
|
|
- }
|
|
|
- //获取订单商品
|
|
|
- List<OrderProduct> list = orderProductService.getWithorderId(contractOrder.getId());
|
|
|
- if (CollectionUtils.isNotEmpty(list)) {
|
|
|
- contractOrder.setOrderProduct(list);
|
|
|
- request.getSession().removeAttribute("orderProducts");
|
|
|
- request.getSession().setAttribute("orderProducts", list);
|
|
|
- }
|
|
|
- //获取订单发票
|
|
|
- OrderInvoice orderInvoice = orderInvoiceService.getWithorderId(contractOrder.getId());
|
|
|
- if (null != orderInvoice) {
|
|
|
- contractOrder.setOrderInvoice(orderInvoice);
|
|
|
- }
|
|
|
- String contractId = contractOrder.getContractId();
|
|
|
- if (StringUtils.isNotEmpty(contractId)) {
|
|
|
- //获取采购基本信息(针对V1.2.0之前版本存在合同订单)
|
|
|
- Contract contract = contractService.get(contractId);
|
|
|
- contractOrder.setContract(contract);
|
|
|
- }
|
|
|
- }
|
|
|
- model.addAttribute("contractOrder", contractOrder);
|
|
|
- return "modules/bulkpurchase/contractOrderForm";
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("contractorder:contractOrder:edit")
|
|
|
- @RequestMapping(value = "save")
|
|
|
- public String save(ContractOrder contractOrder, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
|
|
|
- if (!beanValidator(model, contractOrder)) {
|
|
|
- return form(contractOrder, model, request);
|
|
|
- }
|
|
|
-
|
|
|
- if (null == contractOrder.getOrderProduct()) {
|
|
|
- model.addAttribute("message", "保存失败商品不能为空");
|
|
|
- return form(contractOrder, model, request);
|
|
|
- } else {
|
|
|
- List<OrderProduct> orderProductList = Lists.newArrayList();
|
|
|
- for (OrderProduct orderProduct : contractOrder.getOrderProduct()) {
|
|
|
- if (StringUtils.isNotEmpty(orderProduct.getEnabledStatus())) {
|
|
|
- OrderProduct o = (OrderProduct) JsonMapper.fromJsonString(orderProduct.getEnabledStatus(), OrderProduct.class);
|
|
|
- orderProductList.add(o);
|
|
|
- }
|
|
|
- }
|
|
|
- if (CollectionUtils.isNotEmpty(orderProductList)) {
|
|
|
- contractOrder.setOrderProduct(orderProductList);
|
|
|
- }
|
|
|
- }
|
|
|
- //后台添加订单状态为0;未付款
|
|
|
- if (StringUtils.isEmpty(contractOrder.getStatus())) {
|
|
|
- contractOrder.setStatus("0");
|
|
|
- }
|
|
|
-
|
|
|
- //如果是[5:外单]类型则订单状态直接为交易完成
|
|
|
- if (StringUtils.equals("5", contractOrder.getOrderSource())) {
|
|
|
- contractOrder.setConfirmFlag("1");//标记为确认订单
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.equals("1", contractOrder.getStagesFlag())) {//分期信息处理
|
|
|
- List<OrderStages> list = Lists.newArrayList();
|
|
|
- for (OrderStages orderStages : contractOrder.getOrderStages()) {
|
|
|
- if (StringUtils.isNotEmpty(orderStages.getEnabledStatus())) {
|
|
|
-// OrderStages o = (OrderStages) JsonMapper.fromJsonString(orderStages.getEnabledStatus(),OrderStages.class);
|
|
|
- //未选择商品确认时 显示"" 、
|
|
|
- if ("\"\"".equals(orderStages.getEnabledStatus())) {
|
|
|
- orderStages.setEnabledStatus("[]");
|
|
|
- }
|
|
|
- List<OrderStagesProduct> orderStagesProducts = JSONArray.parseArray(orderStages.getEnabledStatus(), OrderStagesProduct.class);
|
|
|
- orderStages.setOrderStagesProductList(orderStagesProducts);
|
|
|
- list.add(orderStages);
|
|
|
- }
|
|
|
- }
|
|
|
- if (CollectionUtils.isNotEmpty(list)) {
|
|
|
- contractOrder.setOrderStages(list);
|
|
|
- }
|
|
|
- } else {
|
|
|
- contractOrder.setStagesRemarks(null);
|
|
|
- contractOrder.setStagesFlag("0");
|
|
|
- }
|
|
|
- if(StringUtils.equals("1",contractOrder.getStagesFlag()) || StringUtils.equals("1",contractOrder.getCooFreeFlag())){
|
|
|
- //如果是分期订单
|
|
|
- contractOrder.setCooFreeFlag("0");
|
|
|
- contractOrder.setCooFreeRate(0);
|
|
|
- contractOrder.setCooFreeAmount("0.00");
|
|
|
- }
|
|
|
- //保存订单
|
|
|
- contractOrderService.save(contractOrder);
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(contractOrder.getId())) {
|
|
|
- //订单重新保存后则修改订单商品需供应商确认
|
|
|
- orderProductService.updateShopConfigFlag(contractOrder.getId());
|
|
|
- }
|
|
|
-
|
|
|
- addMessage(redirectAttributes, "保存订单成功");
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder/list?contractId=" + contractOrder.getContractId();
|
|
|
- }
|
|
|
-
|
|
|
- // 非分期订单确认
|
|
|
- @RequiresPermissions("contractorder:contractOrder:edit")
|
|
|
- @RequestMapping(value = "saveConfirmFlag")
|
|
|
- public String saveConfirmFlag(ContractOrder contractOrder, Model model) {
|
|
|
- model.addAttribute("contractOrder", contractOrder);
|
|
|
-
|
|
|
- //增加快照条款内容
|
|
|
- Long clauseId = contractOrder.getClauseId();
|
|
|
- String clauseContent = contractOrder.getClauseContent();
|
|
|
- BpClause bpClause = bpClauseService.get(String.valueOf(clauseId));
|
|
|
- if(StringUtils.isEmpty(clauseContent) && null != bpClause){//第一次保存数据则按照条款表设置,后面再保存可能存在修改过快照,此时存在条款内容不允许修改
|
|
|
- contractOrder.setClauseName(bpClause.getName());
|
|
|
- contractOrder.setClauseContent(bpClause.getContent());
|
|
|
- }
|
|
|
-
|
|
|
- contractOrder.setConfirmFlag("1");//设置为已确认订单
|
|
|
- contractOrderService.saveConfirmFlag(contractOrder);
|
|
|
-
|
|
|
- //确认订单时处理买家商品价格库信息
|
|
|
- Long clubId = contractOrder.getClubId();
|
|
|
- ClubModel clubByUserId = clubDao.getClubByUserId(Integer.parseInt(clubId.toString()));
|
|
|
- List<OrderProduct> orderProduct = contractOrder.getOrderProduct();
|
|
|
- if(CollectionUtils.isNotEmpty(orderProduct) && orderProduct.size() > 0){
|
|
|
- for(OrderProduct op:orderProduct){
|
|
|
- String buyAgainFlag = op.getBuyAgainFlag();
|
|
|
- //对于可以复购的商品添加买家商品价格,提供再次购买商品使用(如果不存在没有改买家商品价格则不能购买该商品)
|
|
|
- if(StringUtils.isNotEmpty(buyAgainFlag) && StringUtils.equals("1",buyAgainFlag)){
|
|
|
- //1.买家用户最新价格(最多只存在一条表buyer_product_price)
|
|
|
- BuyerProductPrice buyerProductPrice = new BuyerProductPrice();//通过用户ID和商品ID确定唯一买家最新价格
|
|
|
- if(null != clubByUserId){
|
|
|
- buyerProductPrice.setUserId(clubByUserId.getUserID());
|
|
|
- }
|
|
|
- buyerProductPrice.setProductId(Integer.parseInt(op.getProductId().toString()));
|
|
|
- List<BuyerProductPrice> list = buyerProductPriceService.findList(buyerProductPrice);
|
|
|
- if(CollectionUtils.isNotEmpty(list) && list.size() == 1 ){
|
|
|
- //更新数据
|
|
|
- BuyerProductPrice buyerProductPrice1 = list.get(0);
|
|
|
- buyerProductPrice1.setTaxRate(op.getTaxRate());//税率
|
|
|
- buyerProductPrice1.setConfirmFlag("0");//确认标识 0否 1已确认
|
|
|
- buyerProductPrice1.setSingleShopFee(op.getShopFee1());//应付供应商成本
|
|
|
- buyerProductPrice1.setDiscountPrice(op.getDiscountPrice());
|
|
|
- buyerProductPrice1.setUpdateDate(new Date());
|
|
|
- buyerProductPriceService.save(buyerProductPrice1);
|
|
|
- }else if(CollectionUtils.isEmpty(list)){
|
|
|
- //插入新数据
|
|
|
- buyerProductPrice.setTaxRate(op.getTaxRate());//税率
|
|
|
- buyerProductPrice.setConfirmFlag("0");//确认标识 0否 1已确认
|
|
|
- buyerProductPrice.setSingleShopFee(op.getShopFee1());//应付供应商成本
|
|
|
- buyerProductPrice.setDiscountPrice(op.getDiscountPrice());
|
|
|
- buyerProductPrice.setUpdateDate(new Date());
|
|
|
- buyerProductPriceService.save(buyerProductPrice);
|
|
|
- }else{
|
|
|
- logger.info("买家价格列表信息异常");
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder";
|
|
|
- }
|
|
|
-
|
|
|
- //2.买家价格历史库(表buyer_product_history_price)
|
|
|
- //用户商品单价≤成本价/用户商品单价≤应付供应商成本(不写入历史价格,在同意价格后再添加)
|
|
|
- Product product = productDao.get(op.getProductId().toString());
|
|
|
- if(null != product){
|
|
|
- String costPrice = product.getCostPrice();//成本价
|
|
|
- String discountPrice = op.getDiscountPrice();//折后单价
|
|
|
- String singleShopFee = op.getShopFee1();//单个应付供应商
|
|
|
- //如果存在价格差并从未确认过则红色提示(用户商品单价≤成本价或用户商品单价≤应付供应商成本)
|
|
|
- double discountPriceDouble = Double.parseDouble(discountPrice);
|
|
|
- double singleShopFeeDouble = Double.parseDouble(singleShopFee);
|
|
|
- boolean isRed1 = false;//默认不显示红色
|
|
|
- boolean isRed2 = false;//默认不显示红色
|
|
|
- //1.单价≤成本价
|
|
|
- if(StringUtils.isNotEmpty(costPrice)){//如果成本价是空则不需要比
|
|
|
- double costPriceDouble = Double.parseDouble(costPrice);
|
|
|
- if(discountPriceDouble <= costPriceDouble){
|
|
|
- isRed1 = true;//列表价格差异红色警告0:无警告、1:有警告
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //2.商品单价≤应付供应商成本
|
|
|
- if(discountPriceDouble <= singleShopFeeDouble){
|
|
|
- isRed2 = true;//列表价格差异红色警告0:无警告、1:有警告
|
|
|
- }
|
|
|
-
|
|
|
- //1和2存在一个红色就发送邮件提示客服(2088892826@qq.com、512431995@qq.com)
|
|
|
- if(isRed1 || isRed2){
|
|
|
- //发送邮件提示
|
|
|
- Thread thread = new Thread(){
|
|
|
- public void run(){
|
|
|
- try {
|
|
|
- String photoServer = Global.getConfig("user.mails");//获取邮件地址
|
|
|
- String[] split = photoServer.split(",");
|
|
|
- for(String mailAdd:split) {
|
|
|
- StringBuffer info = new StringBuffer();
|
|
|
- info.append("【采美365】您好!用户(id=" + clubByUserId.getUserID() + ")");//用户(id=1001)的[]商品价格过小提示,可在采美后台中的[采美365-商品管理-新商品管理中]通过搜索对应商品ID,查看对应商品的[买家价格库]查看对应用户ID的商品价格(已标记红色提示)可以通过同意价格等操作来处理。
|
|
|
- info.append("的[" + op.getProductId() + "]商品价格过小提示,可在采美后台中的[采美365-商品管理-新商品管理中]通过搜索对应商品ID,查看对应商品的[买家价格库]查看对应用户ID的商品价格(已标记红色提示)可以通过同意价格等操作来处理。");
|
|
|
- MailUtils.sendMail(mailAdd, "用户商品价格库价格低于成本价或应付供应商", String.valueOf(info));
|
|
|
- logger.info("已发送邮件提示!!");
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- logger.info("发送邮件异常",e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- thread.start();
|
|
|
- }else{
|
|
|
- //不存在红色提示,则不需要同意价格,直接写入历史价格
|
|
|
- BuyerProductHistoryPrice buyerProductHistoryPrice = new BuyerProductHistoryPrice();
|
|
|
- buyerProductHistoryPrice.setProductId(Integer.parseInt(op.getProductId().toString()));
|
|
|
- if(null != clubByUserId){
|
|
|
- buyerProductHistoryPrice.setUserId(clubByUserId.getUserID());
|
|
|
- }
|
|
|
- BuyerProductHistoryPrice bphp = buyerProductHistoryPrice;
|
|
|
- bphp.setDelFlag("1");//禁用老的历史记录
|
|
|
- buyerProductHistoryPriceService.updateDelFlag(bphp);
|
|
|
- buyerProductHistoryPrice.setDelFlag("0");
|
|
|
- buyerProductHistoryPrice.setDiscountPrice(op.getDiscountPrice());
|
|
|
- buyerProductHistoryPrice.setSingleShopFee(op.getShopFee1());
|
|
|
- buyerProductHistoryPrice.setTaxRate(op.getTaxRate());
|
|
|
- buyerProductHistoryPriceService.save(buyerProductHistoryPrice);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // flag=1订单查询页面的订单详情,删除等入口-
|
|
|
- if (StringUtils.equals("1", contractOrder.getFlag())) {
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder";
|
|
|
- }
|
|
|
-
|
|
|
- // flag=2采购信息的页面订单详情,删除等入口
|
|
|
- if (StringUtils.equals("2", contractOrder.getFlag())) {
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder?contractId=" + contractOrder.getContractId();
|
|
|
- }
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder";
|
|
|
- }
|
|
|
-
|
|
|
- // 分期订单确认
|
|
|
- @RequiresPermissions("contractorder:contractOrder:edit")
|
|
|
- @RequestMapping(value = "saveStagesConfirmFlag")
|
|
|
- public String saveStagesConfirmFlag(ContractOrder contractOrder, RedirectAttributes redirectAttributes) {
|
|
|
-// model.addAttribute("contractOrder",contractOrder);
|
|
|
- //获取当前订单的确认订单状态(0未确认 1已确认 2买家确认 3 供应商确认)
|
|
|
- List<ContractOrder> list = contractOrderService.findList(contractOrder);
|
|
|
- if (CollectionUtils.isNotEmpty(list)) {
|
|
|
- ContractOrder order = list.get(0);//通过订单ID查询能够确定一个订单
|
|
|
- /**获取订单分期信息 获取订单商品信息 判断金额商品数量是否分配 */
|
|
|
- BigDecimal totalShouldPay = new BigDecimal(0); //订单应付金额
|
|
|
- BigDecimal stagesTotalFee = new BigDecimal(0); //分期总金额
|
|
|
- Integer num = 0;//购买数
|
|
|
- Integer presentNum = 0;//商品赠品数
|
|
|
- Integer alreadyNum = 0;//已分配商品数
|
|
|
-
|
|
|
- List<OrderStages> orderStagesList = orderStagesService.findStagesByOrderId(order.getId());
|
|
|
- OrderProduct orderProduct = new OrderProduct();
|
|
|
- orderProduct.setOrderId(Long.parseLong(order.getId()));
|
|
|
- List<OrderProduct> products = orderProductService.findAllList(orderProduct);
|
|
|
-
|
|
|
- //分期订单 判断分期金额与商品数量分配情况
|
|
|
- if ("1".equals(order.getStagesFlag())) {
|
|
|
- if (null != products && products.size() > 0) {
|
|
|
- for (int i = 0; i < products.size(); i++) {
|
|
|
- //应付总额
|
|
|
- totalShouldPay = MathUtil.add(totalShouldPay, products.get(i).getShouldPayFee());
|
|
|
- //商品购买数
|
|
|
- num += Integer.parseInt(products.get(i).getNum());
|
|
|
- //赠品数
|
|
|
- if (null != products.get(i).getPresentNum()) {
|
|
|
- presentNum += Integer.parseInt(products.get(i).getPresentNum());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (null != orderStagesList && orderStagesList.size() > 0) {
|
|
|
- for (int i = 0; i < orderStagesList.size(); i++) {
|
|
|
- //分期金额
|
|
|
- stagesTotalFee = MathUtil.add(stagesTotalFee, orderStagesList.get(i).getFee());
|
|
|
- List<OrderStagesProduct> stagesProducts = orderStagesProductService.findStagesProductBuyStagesId(orderStagesList.get(i).getId());
|
|
|
- //分期商品数
|
|
|
- if (null != stagesProducts && stagesProducts.size() > 0) {
|
|
|
- for (int j = 0; j < stagesProducts.size(); j++) {
|
|
|
- alreadyNum += stagesProducts.get(j).getProductNum();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- BigDecimal notNum = MathUtil.sub(totalShouldPay, stagesTotalFee);
|
|
|
- /**未满足 分期设置未完成*/
|
|
|
- if ((num + presentNum - alreadyNum) != 0 || notNum.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
- addMessage(redirectAttributes, order.getId() + " 剩下分期金额(¥ " + notNum + " ),商品数( " + (num + presentNum - alreadyNum) + " )未分配,不能确认订单");
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder/";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String confirmFlag = order.getConfirmFlag();
|
|
|
- if (StringUtils.equals("0", confirmFlag)) {//会所与供应商都没有确认-----设置确认状态为供应已确认
|
|
|
- contractOrder.setConfirmFlag("3");
|
|
|
- contractOrderService.saveConfirmFlag(contractOrder);
|
|
|
- }
|
|
|
- if (StringUtils.equals("2", confirmFlag)) {//会所已确认-----设置确认状态为已确认
|
|
|
- contractOrder.setConfirmFlag("1");
|
|
|
- contractOrderService.saveConfirmFlag(contractOrder);
|
|
|
- }
|
|
|
- }
|
|
|
- // flag=1订单查询页面的订单详情,删除等入口-
|
|
|
- if (StringUtils.equals("1", contractOrder.getFlag())) {
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder";
|
|
|
- }
|
|
|
-
|
|
|
- // flag=2采购信息的页面订单详情,删除等入口
|
|
|
- if (StringUtils.equals("2", contractOrder.getFlag())) {
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder?contractId=" + contractOrder.getContractId();
|
|
|
- }
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder";
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("contractorder:contractOrder:delete")
|
|
|
- @RequestMapping(value = "delete")
|
|
|
- public String delete(ContractOrder contractOrder, RedirectAttributes redirectAttributes) {
|
|
|
- contractOrder.setDelFlag(DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSSS"));
|
|
|
- contractOrderService.delete(contractOrder);
|
|
|
- addMessage(redirectAttributes, "删除订单成功");
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder/";
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresPermissions("contractorder:contractOrder:delete")
|
|
|
- @RequestMapping(value = "deleteAll")
|
|
|
- public String deleteAll(ContractOrder contractOrder, RedirectAttributes redirectAttributes) {
|
|
|
- contractOrderService.delete(contractOrder);
|
|
|
- addMessage(redirectAttributes, "删除订单成功");
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder/all?repage";
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping(value = "putProductToOrder")
|
|
|
- public String putProductToOrder(ContractOrder contractOrder, HttpServletRequest request, Model model) {
|
|
|
- List<OrderProduct> orderProducts = (List<OrderProduct>) request.getSession().getAttribute("orderProducts");//添加的商品
|
|
|
- List<OrderProduct> orderProduct = contractOrder.getOrderProduct();//传过来的订单商品
|
|
|
- if (null == orderProducts && null == orderProduct) {
|
|
|
- Double userMoney = contractService.getUserMoneyByClubId(contractOrder.getContractId());
|
|
|
- contractOrder.setBalancePayFee(userMoney + "");
|
|
|
- model.addAttribute("contractOrder", contractOrder);
|
|
|
- return "modules/bulkpurchase/contractOrderForm";
|
|
|
- }
|
|
|
- BigDecimal productCount = new BigDecimal("0");
|
|
|
- BigDecimal presentCount = new BigDecimal("0");
|
|
|
- BigDecimal addedValueTax = new BigDecimal("0");
|
|
|
- BigDecimal productTotalFee = new BigDecimal("0");
|
|
|
- BigDecimal orderProductShopFee = new BigDecimal("0");
|
|
|
- BigDecimal orderProductOtherFee = new BigDecimal("0");
|
|
|
- BigDecimal orderProductCmFee = new BigDecimal("0");
|
|
|
- for (OrderProduct product : orderProducts) {
|
|
|
- BigDecimal num = new BigDecimal(product.getNum());
|
|
|
- productCount = productCount.add(num);
|
|
|
- BigDecimal presentNum = new BigDecimal(product.getPresentNum());
|
|
|
- presentCount = presentCount.add(presentNum);
|
|
|
- BigDecimal totalFee = new BigDecimal(product.getTotalFee());
|
|
|
- productTotalFee = productTotalFee.add(totalFee);
|
|
|
- }
|
|
|
-
|
|
|
- contractOrder.setPayTotalFee(productTotalFee.doubleValue() + "");
|
|
|
- contractOrder.setProductTotalFee(productTotalFee.doubleValue() + "");
|
|
|
- contractOrder.setOrderTotalFee(productTotalFee.doubleValue() + "");
|
|
|
- contractOrder.setBalancePayFee(0 + "");
|
|
|
- contractOrder.setPresentCount(presentCount.doubleValue() + "");
|
|
|
- contractOrder.setProductCount(productCount.doubleValue() + "");
|
|
|
- //每次选择商品后折扣需要重新输入计算
|
|
|
- contractOrder.setDiscount("0");
|
|
|
-// if (null != contractOrder.getDiscount() && !contractOrder.getDiscount().equals("")) {
|
|
|
-// BigDecimal discount = new BigDecimal(contractOrder.getDiscount());
|
|
|
-// contractOrder.setPayTotalFee(productTotalFee.subtract(discount).doubleValue() + "");
|
|
|
-// } else {
|
|
|
- contractOrder.setPayTotalFee(productTotalFee.doubleValue() + "");
|
|
|
-// }
|
|
|
- contractOrder.setOrderProduct(orderProducts);
|
|
|
- Double userMoney = contractService.getUserMoneyByClubId(contractOrder.getContractId());
|
|
|
- contractOrder.setBalancePayFee(userMoney + "");
|
|
|
- model.addAttribute("contractOrder", contractOrder);
|
|
|
- return "modules/bulkpurchase/contractOrderForm";
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @RequestMapping(value = "PutSession")
|
|
|
- @ResponseBody
|
|
|
- public Map<String, Object> PutSession(@RequestParam("items") String items, HttpServletRequest request) {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- try {
|
|
|
- List<OrderProduct> orderProducts = JSONArray.parseArray(items, OrderProduct.class);
|
|
|
- request.getSession().removeAttribute("orderProducts");
|
|
|
- request.getSession().setAttribute("orderProducts", orderProducts);
|
|
|
- map.put("success", "true");
|
|
|
- map.put("msg", "添加成功");
|
|
|
- } catch (Exception e) {
|
|
|
- map.put("success", "false");
|
|
|
- map.put("msg", "添加失败");
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping(value = "setProductTotalFee")
|
|
|
- @ResponseBody
|
|
|
- public String setProductTotalFee(ContractOrder contractOrder, Model model) {
|
|
|
- String discount = contractOrder.getDiscount();
|
|
|
- int i = Integer.parseInt(discount);
|
|
|
- int pay = Integer.parseInt(contractOrder.getPayTotalFee()) - i;
|
|
|
- if (pay < 0) {
|
|
|
- model.addAttribute("message", "您输入的折扣超出了订单总额,请注意");
|
|
|
- } else {
|
|
|
- contractOrder.setPayTotalFee(pay + "");
|
|
|
- }
|
|
|
- model.addAttribute("contractOrder", contractOrder);
|
|
|
- return "";
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // 保存订单终止信息
|
|
|
- @RequiresPermissions("contractorder:contractOrder:edit")
|
|
|
- @RequestMapping(value = "saveOrderStopInfo")
|
|
|
- public String saveOrderStopInfo(ContractOrder contractOrder, Model model) {
|
|
|
- model.addAttribute("contractOrder", contractOrder);
|
|
|
-
|
|
|
- contractOrder.setOrderStopFlag("1");//设置为终止状态
|
|
|
- contractOrderService.saveOrderStopInfo(contractOrder);
|
|
|
-
|
|
|
- // flag=1订单查询页面的订单详情,删除、终止等入口-
|
|
|
- if (StringUtils.equals("1", contractOrder.getFlag())) {
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder";
|
|
|
- }
|
|
|
-
|
|
|
- // flag=2采购信息的页面订单详情,删除、终止等入口
|
|
|
- if (StringUtils.equals("2", contractOrder.getFlag())) {
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder?contractId=" + contractOrder.getContractId();
|
|
|
- }
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder";
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 导出订单信息
|
|
|
- *
|
|
|
- * @param contractOrder
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequiresPermissions("contractorder:contractOrder:export")
|
|
|
- @RequestMapping(value = "exportOrderInfo")
|
|
|
- public void exportOrderInfo(ContractOrder contractOrder, RedirectAttributes redirectAttributes, HttpServletResponse response) {
|
|
|
- //获取订单数据
|
|
|
- String fileName = contractOrder.getId() + "-" + contractOrder.getName() + "-采美365网购订单.xls";
|
|
|
- String template = Global.getConfig("export.template");
|
|
|
- String templateFileName = template+"/bpstages_template.xls";
|
|
|
- try {
|
|
|
- OrderProduct orderProduct = new OrderProduct();
|
|
|
- orderProduct.setOrderId(Long.parseLong(contractOrder.getId()));
|
|
|
- List<OrderProduct> products = orderProductService.findAllList(orderProduct);
|
|
|
- for (OrderProduct orderProduct2 : products) {
|
|
|
- //如果 =0 则设置为 0 方便页面判断
|
|
|
- BigDecimal totalPay = new BigDecimal(orderProduct2.getTotalFee());
|
|
|
- if (totalPay.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- orderProduct2.setTotalFee("0");
|
|
|
- }
|
|
|
- //设置税费
|
|
|
- if (null == orderProduct2.getAddedValueTax() || "".equals(orderProduct2.getAddedValueTax()) || new BigDecimal(orderProduct2.getAddedValueTax()).compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- orderProduct2.setAddedValueTax("0");
|
|
|
- }
|
|
|
- String image = orderProduct2.getImage();
|
|
|
- //设置图片完整路径
|
|
|
- orderProduct2.setImage(AppUtils.getProductImageURL(image, 0, Global.getConfig("wwwServer")));
|
|
|
- }
|
|
|
- List<OrderProduct> products1 = orderProductService.findByOrderIdGroupByShopId(Integer.parseInt(contractOrder.getId()));
|
|
|
- StringBuffer shopNameInfo = new StringBuffer();
|
|
|
- //设置供应商信息
|
|
|
- for (OrderProduct orderProduct1 : products1) {
|
|
|
- shopNameInfo.append(orderProduct1.getShopName() + "、");
|
|
|
- }
|
|
|
- shopNameInfo.setLength(shopNameInfo.length() - 1);
|
|
|
- contractOrder.setShopNameInfo(shopNameInfo.toString());
|
|
|
- //设置订单商品信息
|
|
|
- contractOrder.setOrderProduct(products);
|
|
|
- BigDecimal stagesTotalFee = new BigDecimal(0);
|
|
|
- StringBuffer buffer = new StringBuffer();
|
|
|
- if ("1".equals(contractOrder.getStagesFlag())) {
|
|
|
- List<OrderStages> stagesList = orderStagesService.findStagesByOrderId(contractOrder.getId());
|
|
|
- //获取商品信息
|
|
|
- for (OrderStages stages : stagesList) {
|
|
|
- List<OrderStagesProduct> stagesProducts = orderStagesProductService.findStagesProductBuyStagesId(stages.getId());
|
|
|
- if (null != stagesProducts && stagesProducts.size() > 0) {
|
|
|
- for (OrderStagesProduct stagesProduct : stagesProducts) {
|
|
|
- buffer.append(stagesProduct.getProductNum() + "-个(" + stagesProduct.getProductName() + ")、");
|
|
|
- }
|
|
|
- }
|
|
|
- //设置商品信息
|
|
|
- stages.setProductInfo(buffer.toString());
|
|
|
- //清空
|
|
|
- buffer.setLength(0);
|
|
|
- //设置分期总金额
|
|
|
- stagesTotalFee = MathUtil.round(MathUtil.add(stagesTotalFee, stages.getFee()), 2);
|
|
|
- }
|
|
|
- contractOrder.setStagesTotalFee(MathUtil.round(stagesTotalFee, 2));
|
|
|
- contractOrder.setOrderStages(stagesList);
|
|
|
- }
|
|
|
- //设置list数据
|
|
|
- List<ContractOrder> list = Lists.newArrayList();
|
|
|
- contractOrder.setClauseContent(StringUtils.replaceHtml(contractOrder.getClauseContent()));
|
|
|
- list.add(contractOrder);
|
|
|
- new ExcelUtil().createExcel(templateFileName, list, fileName, response);
|
|
|
- } catch (Exception e) {
|
|
|
- addMessage(redirectAttributes, "订单信息导出失败!" + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 保存订单条款信息
|
|
|
- @RequestMapping(value = "editclausecontent")
|
|
|
- public String editclausecontent(ContractOrder contractOrder, Model model) {
|
|
|
- model.addAttribute("contractOrder", contractOrder);
|
|
|
- return "modules/bulkpurchase/contractOrderClause";
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping(value = "saveClause")
|
|
|
- public String saveClause(ContractOrder contractOrder, RedirectAttributes redirectAttributes, HttpServletRequest request) {
|
|
|
- String clauseContent = request.getParameter("clauseContent");
|
|
|
- String clauseName = request.getParameter("clauseName");
|
|
|
- contractOrder.setClauseContent(clauseContent);
|
|
|
- contractOrder.setClauseName(clauseName);
|
|
|
- contractOrderService.updateClauseContent(contractOrder);
|
|
|
- if (StringUtils.isNotEmpty(contractOrder.getId())) {
|
|
|
- //订单重新保存后则修改订单商品需供应商确认
|
|
|
- orderProductService.updateShopConfigFlag(contractOrder.getId());
|
|
|
- }
|
|
|
- return "redirect:" + Global.getAdminPath() + "/bulkpurchase/contractOrder";
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // URL编码utf-8
|
|
|
- @RequestMapping(value = "enCode")
|
|
|
- @ResponseBody
|
|
|
- public Map<String, Object> enCode(@RequestParam("redirectUrl") String redirectUrl) {
|
|
|
- String enCodeRedirectUrl = "";
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- try {
|
|
|
- enCodeRedirectUrl = URLEncoder.encode(redirectUrl, "UTF-8");
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- logger.error("URL编码异常", e);
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- map.put("enCodeRedirectUrl", enCodeRedirectUrl);
|
|
|
- map.put("msg", "添加成功");
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //进账确认编辑
|
|
|
- @RequestMapping(value = "orderStatusEdit")
|
|
|
- public String orderStatusEdit(@RequestParam(required = true) String orderId, Model model) {
|
|
|
- model.addAttribute("orderId", orderId);
|
|
|
- ContractOrder contractOrder = contractOrderService.get(orderId);
|
|
|
- if (null != contractOrder) {
|
|
|
- model.addAttribute("orderStatus", contractOrder.getStatus());
|
|
|
- }
|
|
|
- model.addAttribute("updateDate", new Date());
|
|
|
- return "modules/bulkpurchase/updateOrderStatusForm";
|
|
|
- }
|
|
|
-
|
|
|
- //保存订单状态
|
|
|
- @ResponseBody
|
|
|
- @RequestMapping(value = "saveOrderStatus")
|
|
|
- public Map<String, Object> saveOrderStatus(String orderStatus, Date updateDate, String orderId) {
|
|
|
- Map<String, Object> map = Maps.newLinkedHashMap();
|
|
|
- try {
|
|
|
- ContractOrder contractOrder = contractOrderService.get(orderId);
|
|
|
- if (null != contractOrder) {
|
|
|
- contractOrder.setStatus(orderStatus);//设置订单状态
|
|
|
- contractOrder.setUpdateDate(updateDate);
|
|
|
- }
|
|
|
- contractOrderService.updateOrderStatusInfo(contractOrder);
|
|
|
- map.put("success", true);
|
|
|
- map.put("msg", "确认修改");
|
|
|
- } catch (Exception e) {
|
|
|
- logger.debug(e.toString(), e);
|
|
|
- map.put("success", false);
|
|
|
- map.put("msg", "修改失败");
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
-}
|