zhijiezhao 1 год назад
Родитель
Сommit
85c2a4f78b

+ 16 - 0
src/main/java/com/caimei/modules/bulkpurchase/dao/CommissionsDao.java

@@ -0,0 +1,16 @@
+package com.caimei.modules.bulkpurchase.dao;
+
+import com.caimei.modules.bulkpurchase.entity.Commissions;
+import com.thinkgem.jeesite.common.persistence.CrudDao;
+import com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2022/3/25
+ */
+@MyBatisDao
+public interface CommissionsDao extends CrudDao<Commissions> {
+
+}

+ 29 - 0
src/main/java/com/caimei/modules/bulkpurchase/dao/PurchaseProductDao.java

@@ -0,0 +1,29 @@
+package com.caimei.modules.bulkpurchase.dao;
+
+import com.caimei.modules.product.entity.CmSku;
+import com.caimei.modules.svip.entity.CmSvipProduct;
+import com.caimei.po.ProductLadderPrice;
+import com.thinkgem.jeesite.common.persistence.CrudDao;
+import com.thinkgem.jeesite.common.persistence.Page;
+import com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao;
+import com.caimei.modules.bulkpurchase.entity.PurchaseProduct;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 大宗采购商品信息DAO接口
+ * @author jiangjunwen
+ * @version 2017-03-28
+ */
+@MyBatisDao
+public interface PurchaseProductDao extends CrudDao<PurchaseProduct> {
+
+    List<PurchaseProduct> findSencondProductPage(PurchaseProduct purchaseProduct);
+
+    List<ProductLadderPrice> findLadderPriceList(Long productId);
+
+    CmSvipProduct getSvipProduct(@Param("productId")Long productId, @Param("userId") Integer userId);
+
+    CmSku findVipSku(Long productId);
+}

+ 74 - 0
src/main/java/com/caimei/modules/bulkpurchase/entity/Commissions.java

@@ -0,0 +1,74 @@
+package com.caimei.modules.bulkpurchase.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.thinkgem.jeesite.common.persistence.DataEntity;
+
+import java.util.Date;
+
+public class Commissions extends DataEntity<Commissions> {
+    private String id;
+    //订单表id
+    private String orderId;
+    //记录人
+    private String name;
+    //创建时间
+    private Date addTime;
+    //提成情况
+    private String sales;
+    //备注
+    private String script;
+
+    @Override
+    public String getId() {
+        return id;
+    }
+
+    @Override
+    public void setId(String id) {
+        this.id = id;
+    }
+
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+
+
+    public String getSales() {
+        return sales;
+    }
+
+    public void setSales(String sales) {
+        this.sales = sales;
+    }
+
+    public String getScript() {
+        return script;
+    }
+
+    public void setScript(String script) {
+        this.script = script;
+    }
+
+    public String getOrderId() {
+        return orderId;
+    }
+
+    public void setOrderId(String orderId) {
+        this.orderId = orderId;
+    }
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    public Date getAddTime() {
+        return addTime;
+    }
+
+    public void setAddTime(Date addTime) {
+        this.addTime = addTime;
+    }
+}

+ 36 - 0
src/main/java/com/caimei/modules/bulkpurchase/service/CommissionsService.java

@@ -0,0 +1,36 @@
+package com.caimei.modules.bulkpurchase.service;
+
+import com.caimei.modules.bulkpurchase.dao.CommissionsDao;
+import com.caimei.modules.bulkpurchase.entity.Commissions;
+import com.thinkgem.jeesite.common.service.CrudService;
+import com.thinkgem.jeesite.common.web.BaseController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2022/3/25
+ */
+@Service
+@Transactional(readOnly = true)
+public class CommissionsService extends CrudService<CommissionsDao,Commissions> {
+
+    @Autowired
+    private CommissionsDao commissionsDao;
+
+
+   public List<Commissions> findList(Commissions commissions){
+        return commissionsDao.findList(commissions);
+    }
+
+    @Transactional(readOnly = false)
+    public int insert(Commissions commissions){
+       return commissionsDao.insert(commissions);
+    }
+
+}

+ 76 - 0
src/main/java/com/caimei/modules/bulkpurchase/service/PurchaseProductService.java

@@ -0,0 +1,76 @@
+package com.caimei.modules.bulkpurchase.service;
+
+import java.util.List;
+
+import com.caimei.modules.svip.entity.CmSvipProduct;
+import com.caimei.po.ProductLadderPrice;
+import com.thinkgem.jeesite.common.utils.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.thinkgem.jeesite.common.persistence.Page;
+import com.thinkgem.jeesite.common.service.CrudService;
+import com.caimei.modules.bulkpurchase.entity.PurchaseProduct;
+import com.caimei.modules.bulkpurchase.dao.PurchaseProductDao;
+
+
+@Service
+@Transactional(readOnly = true)
+public class PurchaseProductService extends CrudService<PurchaseProductDao, PurchaseProduct> {
+
+    @Autowired
+    private PurchaseProductDao purchaseProductDao;
+
+
+    public PurchaseProduct get(String id) {
+        return super.get(id);
+    }
+
+    public List<PurchaseProduct> findList(PurchaseProduct purchaseProduct) {
+        return super.findList(purchaseProduct);
+    }
+
+    public Page<PurchaseProduct> findPage(Page<PurchaseProduct> page, PurchaseProduct purchaseProduct) {
+        return super.findPage(page, purchaseProduct);
+    }
+
+    public List<PurchaseProduct> findSencondProductPage(PurchaseProduct purchaseProduct) {
+        return purchaseProductDao.findSencondProductPage(purchaseProduct);
+    }
+
+
+    @Transactional(readOnly = false)
+    public void save(PurchaseProduct purchaseProduct) {
+        if(StringUtils.isEmpty(purchaseProduct.getDelFlag())){
+            purchaseProduct.setDelFlag(0 + "");
+        }
+        if (StringUtils.isEmpty(purchaseProduct.getTaxRate())) {
+            purchaseProduct.setTaxRate(0 + "");
+            purchaseProduct.setAddedValueTax(0 + "");
+        }
+        if (StringUtils.isEmpty(purchaseProduct.getCmFee())) {
+            purchaseProduct.setCmFee(0 + "");
+        }
+        if (StringUtils.isEmpty(purchaseProduct.getShopFee())) {
+            purchaseProduct.setShopFee(0 + "");
+        }
+        if (StringUtils.isEmpty(purchaseProduct.getOtherFee())) {
+            purchaseProduct.setOtherFee(0 + "");
+        }
+        super.save(purchaseProduct);
+    }
+
+    @Transactional(readOnly = false)
+    public void delete(PurchaseProduct purchaseProduct) {
+        super.delete(purchaseProduct);
+    }
+
+    public List<ProductLadderPrice> findLadderPriceList(Long productId){
+        return purchaseProductDao.findLadderPriceList(productId);
+    }
+
+    public CmSvipProduct getSvipProduct(Long productId, Integer userId) {
+        return purchaseProductDao.getSvipProduct(productId, userId);
+    }
+}

+ 63 - 0
src/main/java/com/caimei/modules/bulkpurchase/web/CommissionsController.java

@@ -0,0 +1,63 @@
+package com.caimei.modules.bulkpurchase.web;
+
+import com.caimei.modules.bulkpurchase.entity.Commissions;
+import com.caimei.modules.bulkpurchase.service.CommissionsService;
+
+import com.thinkgem.jeesite.common.config.Global;
+import com.thinkgem.jeesite.common.web.BaseController;
+
+import com.thinkgem.jeesite.modules.sys.security.SystemAuthorizingRealm;
+import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2022/3/25
+ */
+@Controller
+@RequestMapping(value = "${adminPath}/bulkpurchase/commissions")
+public class CommissionsController extends BaseController {
+
+    @Autowired
+    CommissionsService commissionsService;
+
+
+    @RequestMapping(value = {""})
+    public String list(Commissions commissions, HttpServletRequest request, HttpServletResponse response, Model model) {
+        List<Commissions> list = commissionsService.findList(commissions);
+        model.addAttribute("list", list);
+        model.addAttribute("orderId", commissions.getOrderId());
+        return "/modules/bulkpurchase/cmCommissionsForm";
+    }
+
+    @RequestMapping(value = "form")
+    public String form(Commissions commissions, Model model, HttpServletRequest request, HttpServletResponse response) {
+        String orderId = request.getParameter("orderId");
+        model.addAttribute("OrderId", orderId);
+        return "modules/bulkpurchase/addCommissionsForm";
+    }
+
+
+    @RequestMapping(value = "save")
+    public String save(Commissions commissions, Model model, HttpServletRequest request) {
+        SystemAuthorizingRealm.Principal principal = UserUtils.getPrincipal();
+        commissions.setName(principal.getName());
+        String orderId = request.getParameter("orderId");
+        commissions.setOrderId(orderId);
+        commissionsService.insert(commissions);
+        model.addAttribute("commissions", commissions);
+        return "redirect:" + Global.getAdminPath() + "/bulkpurchase/commissions?orderId=" + orderId;
+    }
+
+}
+

+ 415 - 0
src/main/java/com/caimei/modules/bulkpurchase/web/PurchaseProductController.java

@@ -0,0 +1,415 @@
+package com.caimei.modules.bulkpurchase.web;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.caimei.modules.bulkpurchase.entity.ProductPrivilege;
+import com.caimei.modules.bulkpurchase.entity.PurchaseProduct;
+import com.caimei.modules.bulkpurchase.service.PurchaseProductService;
+import com.caimei.modules.coupon.service.CmCouponService;
+import com.caimei.modules.product.dao.ProductDao;
+import com.caimei.modules.product.entity.*;
+import com.caimei.modules.product.service.CmPromotionService;
+import com.caimei.modules.svip.entity.CmSvipProduct;
+import com.caimei.utils.MathUtil;
+import com.foxinmy.weixin4j.util.StringUtil;
+import com.thinkgem.jeesite.common.config.Global;
+import com.thinkgem.jeesite.common.persistence.Page;
+import com.thinkgem.jeesite.common.utils.StringUtils;
+import com.thinkgem.jeesite.common.web.BaseController;
+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 javax.servlet.http.HttpSession;
+import java.math.BigDecimal;
+import java.util.*;
+
+
+@Controller
+@RequestMapping(value = "${adminPath}/bulkpurchase/purchaseProduct")
+public class PurchaseProductController extends BaseController {
+
+    @Autowired
+    private PurchaseProductService purchaseProductService;
+    @Autowired
+    private ProductDao productDao;
+    @Autowired
+    private CmPromotionService cmPromotionService;
+    @Autowired
+    private CmCouponService cmCouponService;
+
+    @ModelAttribute
+    public PurchaseProduct get(@RequestParam(required = false) String id) {
+        PurchaseProduct entity = null;
+        if (StringUtils.isNotBlank(id)) {
+            entity = purchaseProductService.get(id);
+        }
+        if (entity == null) {
+            entity = new PurchaseProduct();
+        }
+        return entity;
+    }
+
+    @RequestMapping(value = {"list", ""})
+    public String list(PurchaseProduct purchaseProduct, HttpServletRequest request, HttpServletResponse response, Model model) {
+        Page<PurchaseProduct> page = purchaseProductService.findPage(new Page<PurchaseProduct>(request, response), purchaseProduct);
+        List<PurchaseProduct> list = page.getList();
+        // 是否取普通用户的价格
+        boolean priceFlag = "normal".equals(purchaseProduct.getPriceType());
+        //通过用户id判断当前会所是否存在价格库价格,存在则使用价格库价格
+        Integer userId = purchaseProduct.getUserId();
+        model.addAttribute("userId", userId);
+        if (priceFlag) {
+            model.addAttribute("priceType", "normal");
+        }
+        for (PurchaseProduct p : list) {
+            if (p != null) {
+                //是否有优惠券可以查看
+                Boolean couponsLogo = cmCouponService.setCouponsLogo(userId, p.getProductId().intValue(), Integer.valueOf(p.getShopId()), p.getCommodityType());
+                if (couponsLogo) {
+                    p.setCouponsLogo(2);
+                } else {
+                    p.setCouponsLogo(1);
+                }
+                List<CmSku> skuList = productDao.findSkuList(p.getProductId().intValue());
+                skuList.forEach(s -> {
+                    if (1 == s.getLadderPriceFlag()) {
+                        s.setLadderPriceList(productDao.findLadderPriceBySku(s.getSkuId()));
+                    }
+                });
+                // 超级会员价赋值
+                if (null != skuList.get(0).getPriceType()) {
+                    p.setSvipPriceType(skuList.get(0).getPriceType());
+                    if (1 == skuList.get(0).getPriceType()) {
+                        p.setSvipDiscount(skuList.get(0).getDiscount());
+                    } else {
+                        p.setSvipDiscountPrice(skuList.get(0).getDiscountPrice());
+                    }
+                }
+                p.setSkuId(skuList.get(0).getSkuId());
+                p.setPrice(skuList.get(0).getPrice().toString());
+                if (1 == skuList.get(0).getLadderPriceFlag()) {
+                    p.setLadderPriceFlag(1);
+                    p.setLadderPriceList(productDao.findLadderPrice(skuList.get(0).getSkuId()));
+                }
+                p.setSkuList(skuList);
+                if (priceFlag) {
+                    p.setPrice(p.getNormalPrice());
+                }
+                //1固定成本 2 比例成本
+                String costCheckFlag = p.getCostCheckFlag();
+                if (StringUtils.equals("1", costCheckFlag)) {
+                    //固定成本价
+                    String costPrice = p.getCostPrice();
+                    //只有固定成本,应付供应商的金额=添加商品时的成本价
+                    p.setShopFee1(costPrice);
+                }
+                if (StringUtils.equals("2", costCheckFlag)) {
+                    //比例成本价
+                    String costProportional = p.getCostProportional();
+                    String price = p.getPrice();
+                    if (StringUtils.isNotEmpty(costProportional)) {
+                        BigDecimal shopFee1 = (MathUtil.div(MathUtil.mul(costProportional, price), 100)).setScale(2, BigDecimal.ROUND_UP);
+                        p.setShopFee1(String.valueOf(shopFee1));
+                    }
+                }
+                //查询该商品的促销活动
+                CmPromotion cmPromotion = cmPromotionService.findProductPromotion(p.getShopId(), p.getProductId());
+                //设置商品的税率
+                if ("2".equals(p.getIncludedTax()) || StringUtils.isEmpty(p.getIncludedTax()) || ("0".equals(p.getIncludedTax()) && "3".equals(p.getInvoiceType()))) {
+                    p.setTaxRate("0");
+                    p.setSupplierTaxRate("0");
+                }
+                if (StringUtils.isEmpty(p.getTaxRate())) {
+                    p.setTaxRate("0");
+                }
+                if (StringUtils.isEmpty(p.getSupplierTaxRate())) {
+                    p.setSupplierTaxRate(p.getTaxRate());
+                    p.setOldProductFlag("1");
+                }
+                // 初始化超级会员优惠
+                p.setSvipReduction(0d);
+                if (1 == p.getSvipPriceFlag()) {
+                    if (1 == p.getSvipPriceType()) {
+                        p.setSvipDiscountPrice(MathUtil.div(MathUtil.mul(new Double(p.getPrice()), p.getSvipDiscount()), 100, 2).doubleValue());
+                    }
+                    // 商品的超级会员优惠=原价-超级会员优惠价
+                    p.setSvipReduction(MathUtil.sub(p.getPrice(), p.getSvipDiscountPrice()).doubleValue());
+                    if ("0".equals(p.getIncludedTax()) && ("1".equals(p.getInvoiceType()) || "2".equals(p.getInvoiceType()))) {
+                        // 计算优惠的税费
+                        BigDecimal taxReduction = MathUtil.div(MathUtil.mul(p.getSvipReduction(), p.getTaxRate()), 100);
+                        p.setSvipReduction(MathUtil.add(p.getSvipReduction(), taxReduction).doubleValue());
+                        p.setSvipTaxReduction(taxReduction.doubleValue());
+                    }
+                } else if (null != cmPromotion) {
+                    if ("1".equals(cmPromotion.getMode())) {
+                        // 优惠价取sku优惠价
+                        cmPromotion.setTouchPrice(skuList.get(0).getTouchPrice());
+                    }
+                    p.setCmPromotion(cmPromotion);
+                    p.setLadderPriceFlag(0);
+                }
+//                else {
+//                    if (p.getLadderPriceFlag().equals(1)) {
+//                        // 查询阶梯价格
+//                        List<ProductLadderPrice> ladderPriceList = purchaseProductService.findLadderPriceList(p.getProductId());
+//                        if (null != ladderPriceList && ladderPriceList.size() > 0) {
+//                            p.setPrice(ladderPriceList.get(0).getBuyPrice().toString());
+//                            p.setNum(ladderPriceList.get(0).getBuyNum().toString());
+//                            IntStream.range(0, ladderPriceList.size()).forEach(i -> {
+//                                if (i == ladderPriceList.size() - 1) {
+//                                    ladderPriceList.get(i).setBuyNumRangeShow("≥" + ladderPriceList.get(i).getBuyNum());
+//                                } else {
+//                                    String buyNumRangeShow = ladderPriceList.get(i).getBuyNum() + "~" + (ladderPriceList.get(i + 1).getBuyNum() - 1);
+//                                    ladderPriceList.get(i).setBuyNumRangeShow(buyNumRangeShow);
+//                                }
+//                            });
+//                            p.setLadderPriceList(ladderPriceList);
+//                        } else {
+//                            p.setLadderPriceFlag(0);
+//                        }
+//                    } else {
+//                        // 复购价
+//                        if (null != userId) {
+//                            String priceProductList = repeatPurchasePriceService.findPriceProductList(userId);
+//                            boolean contains = false;
+//                            if (StringUtils.isNotEmpty(priceProductList)) {
+//                                contains = priceProductList.contains(String.valueOf(productId));
+//                            }
+//                            if (contains) {//该商品存在价格库商品---修改价格为价格库价格
+//                                p.setBuyAgainPriceFlag("1");//商品是否使用复购价格购买标识 0否 1是
+//                                RepeatPurchasePrice lastBuyPrice = repeatPurchasePriceService.getLastBuyPrice(null, userId, Integer.parseInt(String.valueOf(productId)));
+//                                if (null != lastBuyPrice && MathUtil.compare(p.getPrice(), lastBuyPrice.getCurrentPrice()) > 0) {
+//                                    discountPrice = lastBuyPrice.getCurrentPrice();
+//                                    p.setDiscountPrice(discountPrice);
+//                                    // 计算折扣(折扣=折后单价/单价)[取值1-100]---四舍五入保留6位百分比小数,例如12.341234%
+//                                    BigDecimal discount = MathUtil.round((MathUtil.mul((MathUtil.div(discountPrice, p.getPrice(), 8)), 100)), 6);
+//                                    p.setDiscount(String.valueOf(discount));
+//                                }
+//                            }
+//                        }
+//                    }
+//                }
+            }
+        }
+        model.addAttribute("page", page);
+        if (StringUtils.equals(purchaseProduct.getFlag(), "1")) {
+            //直接生成订单中的添加商品
+            return "modules/bulkpurchase/orderPurchaseProductList";
+        }
+        // 合同中的添加商品
+        return "modules/bulkpurchase/purchaseProductList";
+    }
+
+    /**
+     * 二手商品添加列表
+     *
+     * @param purchaseProduct
+     * @param request
+     * @param response
+     * @param model
+     * @return
+     */
+    @RequestMapping(value = {"secondProductList"})
+    public String secondProductList(PurchaseProduct purchaseProduct, HttpServletRequest request, Page<PurchaseProduct> page, HttpServletResponse response, Model model) {
+        int pageNo = page.getPageNo();
+        if (0 == pageNo) {
+            page.setPageNo(1);
+        }
+        page.setPageSize(10);
+        purchaseProduct.setPage(page);
+        List<PurchaseProduct> list = purchaseProductService.findSencondProductPage(purchaseProduct);
+        //通过用户id判断当前会所是否存在价格库价格,存在则使用价格库价格
+        Integer userId = purchaseProduct.getUserId();
+        model.addAttribute("userId", userId);
+        for (PurchaseProduct p : list) {
+            //1固定成本 2比例成本
+            String costCheckFlag = p.getCostCheckFlag();
+            if (StringUtils.equals("1", costCheckFlag)) {
+                //固定成本价
+                String costPrice = p.getCostPrice();
+                //只有固定成本,应付供应商的金额=添加商品时的成本价
+                p.setShopFee1(costPrice);
+            }
+            if (StringUtils.equals("2", costCheckFlag)) {
+                //比例成本价
+                String costProportional = p.getCostProportional();
+                String price = p.getPrice();
+                if (StringUtils.isNotEmpty(costProportional)) {
+                    BigDecimal shopFee1 = (MathUtil.div(MathUtil.mul(costProportional, price), 100)).setScale(2, BigDecimal.ROUND_UP);
+                    p.setShopFee1(String.valueOf(shopFee1));
+                }
+            }
+            p.setTaxRate("0");
+            p.setSupplierTaxRate("0");
+        }
+        page.setList(list);
+        model.addAttribute("page", page);
+        return "modules/bulkpurchase/secondProductList";
+    }
+
+
+    @RequestMapping(value = "editProduct")
+    public String editProduct(PurchaseProduct purchaseProduct, HttpServletRequest request, HttpServletResponse response, Model model) {
+
+        HttpSession session = request.getSession();
+        PurchaseProduct purchaseProduct1 = (PurchaseProduct) session.getAttribute("purchaseProduct");
+        session.removeAttribute("purchaseProduct");
+        model.addAttribute("purchaseProduct", purchaseProduct1);
+        return "modules/bulkpurchase/purchaseProductEdit";
+    }
+
+    @RequestMapping(value = "form")
+    public String form(PurchaseProduct purchaseProduct, Model model) {
+        model.addAttribute("purchaseProduct", purchaseProduct);
+        return "modules/bulkpurchase/purchaseProductForm";
+    }
+
+    @RequestMapping(value = "save")
+    public String save(PurchaseProduct purchaseProduct, Model model, RedirectAttributes redirectAttributes) {
+        if (!beanValidator(model, purchaseProduct)) {
+            return form(purchaseProduct, model);
+        }
+        purchaseProductService.save(purchaseProduct);
+        addMessage(redirectAttributes, "保存大宗采购商品信息成功");
+        return "redirect:" + Global.getAdminPath() + "/bulkpurchase/purchaseProduct/?repage";
+    }
+
+    @RequestMapping(value = "delete")
+    public String delete(PurchaseProduct purchaseProduct, RedirectAttributes redirectAttributes) {
+        purchaseProductService.delete(purchaseProduct);
+        addMessage(redirectAttributes, "删除大宗采购商品信息成功");
+        return "redirect:" + Global.getAdminPath() + "/bulkpurchase/purchaseProduct/?repage";
+    }
+
+    @RequestMapping(value = "returnProduct")
+    @ResponseBody
+    public Map<String, Object> returnProduct(@RequestParam("product") String product, @RequestParam(value = "test", defaultValue = "") String test, HttpServletRequest request) {
+        JSONObject object = JSONObject.parseObject(product);
+        Map<String, Object> map = new HashMap();
+        PurchaseProduct purchaseProduct = JSONObject.toJavaObject(object, PurchaseProduct.class);
+        if (StringUtils.isBlank(purchaseProduct.getDiscount())) {
+            //如果商品折扣为空,则设置为100%
+            purchaseProduct.setDiscount(100 + "");
+            purchaseProduct.setDiscountPrice(purchaseProduct.getPrice());
+        }
+        List<ProductPrivilege> list = new ArrayList<>();
+        if (!test.equals("")) {
+            List<ProductPrivilege> productPrivileges = JSONArray.parseArray(test, ProductPrivilege.class);
+            purchaseProduct.setProductPrivilege(productPrivileges);
+        }
+        map.put("purchaseProduct", purchaseProduct);
+        return map;
+    }
+
+    @RequestMapping(value = "putProductToSession")
+    @ResponseBody
+    public Map<String, Object> putProductToSession(@RequestParam("product") String product, HttpServletRequest request) {
+        Map<String, Object> map = new HashMap();
+        try {
+            JSONObject object = JSONObject.parseObject(product);
+            PurchaseProduct purchaseProduct = JSONObject.toJavaObject(object, PurchaseProduct.class);
+            HttpSession session = request.getSession();
+            session.setAttribute("purchaseProduct", purchaseProduct);
+        } catch (Exception e) {
+            map.put("message", "后台错误");
+            e.printStackTrace();
+        }
+        return map;
+    }
+
+    @RequestMapping(value = "formOrderProduct")
+    public String formOrderProduct(PurchaseProduct purchaseProduct, Model model) {
+        if (purchaseProduct != null) {
+            purchaseProduct.setLadderPriceFlag(0);
+            Product product = productDao.get(purchaseProduct.getProductId().toString());
+            if (product != null) {
+                List<CmSku> skus = productDao.findSkuList(product.getProductID());
+                purchaseProduct.setSkuId(skus.get(0).getSkuId());
+                purchaseProduct.setPrice(skus.get(0).getPrice().toString());
+                skus.forEach(s -> {
+                    if (1 == s.getLadderPriceFlag()) {
+                        s.setLadderPriceList(productDao.findLadderPriceBySku(s.getSkuId()));
+                    }
+                });
+                // 超级会员价赋值
+                if (null != skus.get(0).getPriceType()) {
+                    purchaseProduct.setPriceType(skus.get(0).getPriceType().toString());
+                    if (1 == skus.get(0).getPriceType()) {
+                        purchaseProduct.setDiscount(skus.get(0).getDiscount().toString());
+                    } else {
+                        purchaseProduct.setDiscountPrice(skus.get(0).getDiscountPrice().toString());
+                    }
+                }
+                purchaseProduct.setSkuList(skus);
+                CmSvipProduct svipProduct = purchaseProductService.getSvipProduct(purchaseProduct.getProductId(), purchaseProduct.getUserId());
+                CmPromotion productPromotion = cmPromotionService.findProductPromotion(product.getShopID().toString(), Long.parseLong(product.getProductID().toString()));
+                if (null != svipProduct && 1 == svipProduct.getSvipPriceFlag()) {
+                    purchaseProduct.setSvipPriceFlag(1);
+                    purchaseProduct.setSvipPriceType(svipProduct.getPriceType());
+                } else if (productPromotion != null) {
+                    // 优惠价的时候给赋值优惠价
+                    if("1".equals(productPromotion.getMode())){
+                        productPromotion.setTouchPrice(skus.get(0).getTouchPrice());
+                    }
+                    purchaseProduct.setCmPromotion(productPromotion);
+                } else {
+                    if (1 == skus.get(0).getLadderPriceFlag()) {
+                        purchaseProduct.setLadderPriceFlag(1);
+                        purchaseProduct.setLadderPriceList(productDao.findLadderPrice(skus.get(0).getSkuId()));
+                    } else {
+                        purchaseProduct.setLadderPriceFlag(0);
+                    }
+                }
+            }
+        }
+        model.addAttribute("purchaseProduct", purchaseProduct);
+        return "modules/bulkpurchase/orderPurchaseProductForm";
+    }
+
+    /**
+     * 订单设置二手商品
+     *
+     * @param purchaseProduct
+     * @param model
+     * @return
+     */
+    @RequestMapping(value = "orderSecondHandProductForm")
+    public String orderSecondHandProductForm(PurchaseProduct purchaseProduct, Model model) {
+        model.addAttribute("purchaseProduct", purchaseProduct);
+        return "modules/bulkpurchase/orderSecondHandProductForm";
+    }
+
+
+    @RequiresPermissions("orderproduct:orderProduct:edit")
+    @RequestMapping(value = "promotionDetail")
+    public String formShopFee(@RequestParam("promotionId") String promotionId, Model model) {
+        CmPromotion cmPromotion = cmPromotionService.get(promotionId);
+        List<Product> promotionProducts = new ArrayList<>();
+        List<Product> giftProducts = new ArrayList<>();
+        List<Shop> promotionShops = new ArrayList<>();
+        if (cmPromotion != null && StringUtil.isNotBlank(promotionId)) {
+            if (!"3".equals(cmPromotion.getType())) {
+                promotionProducts.addAll(cmPromotionService.findPromotionProduct(cmPromotion));
+            } else {
+                promotionShops.addAll(cmPromotionService.findPromotionShops(cmPromotion));
+            }
+            if ("3".equals(cmPromotion.getMode())) {
+                giftProducts.addAll(cmPromotionService.findGiftProduct(cmPromotion.getId()));
+            }
+            cmPromotion.setPromotionProducts(promotionProducts);
+            cmPromotion.setGiftProducts(giftProducts);
+            cmPromotion.setPromotionShops(promotionShops);
+        }
+        model.addAttribute("cmPromotion", cmPromotion);
+        return "modules/bulkpurchase/productPromotionDetail";
+    }
+}

+ 2 - 0
src/main/java/com/caimei/modules/product/dao/ProductDao.java

@@ -1,7 +1,9 @@
 package com.caimei.modules.product.dao;
 
 import com.caimei.modules.brand.entity.BrandAndProductType;
+import com.caimei.modules.bulkpurchase.entity.PurchaseProduct;
 import com.caimei.modules.product.entity.*;
+import com.caimei.modules.svip.entity.CmSvipProduct;
 import com.caimei.po.ProductLadderPrice;
 import com.caimei.po.Shop;
 import com.thinkgem.jeesite.common.persistence.CrudDao;

+ 28 - 0
src/main/resources/mappings/modules/bulkpurchase/CommissionsMapper.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.caimei.modules.bulkpurchase.dao.CommissionsDao">
+
+	<select id="findList" resultType="com.caimei.modules.bulkpurchase.entity.Commissions">
+		SELECT id,orderid,`name`,`addtime`,sales,script
+		FROM `sales_commissions`
+		WHERE orderid=#{orderId}
+		ORDER BY `addtime` DESC
+	</select>
+
+
+	<insert id="insert" parameterType="com.caimei.modules.bulkpurchase.entity.Commissions" keyProperty="id"
+			useGeneratedKeys="true">
+		INSERT INTO `sales_commissions`
+		(orderid,
+		 name,
+		 `addtime`,
+		 `sales`,
+		 script)
+		VALUES (#{orderId},
+				#{name},
+				now(),
+				#{sales},
+				#{script})
+	</insert>
+
+</mapper>

+ 90 - 0
src/main/resources/mappings/modules/bulkpurchase/PurchaseProductMapper.xml

@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.caimei.modules.bulkpurchase.dao.PurchaseProductDao">
+
+	<select id="findList" resultType="PurchaseProduct">
+		SELECT b.name shopName ,b.`shopID` shopId,a.name purchaseProductName,
+		a.`productID` productId,a.productCode productNo,a.mainImage image,a.includedTax AS includedTax,a.machineType,
+		a.invoiceType AS invoiceType, a.taxPoint AS taxRate, a.supplierTaxPoint AS supplierTaxRate, a.commodityType,
+		if(csp.id is not null and csu.id is not null and csp.status=0,1,0) as svipPriceFlag
+		FROM product a LEFT JOIN shop b ON b.shopID=a.shopID
+		left join cm_svip_product csp on a.productID = csp.productId
+		left join cm_svip_user csu on csu.userId = #{userId} and csu.delFlag = '0' and now() <![CDATA[ < ]]> csu.endTime
+		<where>
+			<if test="purchaseProductName != null and purchaseProductName != ''">
+				AND a.name LIKE concat('%',#{purchaseProductName},'%')
+			</if>
+			<if test="productId != null and productId != ''">
+				AND a.productID = #{productId}
+			</if>
+			<if test="shopName != null and shopName != ''">
+				AND b.name like concat('%',#{shopName},'%')
+			</if>
+			and (a.validFlag=2 or a.validFlag = 9)
+			AND a.productID != 999
+			and a.productCategory = 1
+		</where>
+		<choose>
+			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
+				ORDER BY ${page.orderBy}
+			</when>
+			<otherwise>
+			</otherwise>
+		</choose>
+	</select>
+
+	<select id="findSencondProductPage" resultType="com.caimei.modules.bulkpurchase.entity.PurchaseProduct">
+		SELECT b.name as shopName ,b.`shopID` as shopId,a.name purchaseProductName,
+		cs.price,a.`productID` as productId,a.productCode productNo,a.mainImage image
+		,cs.costCheckFlag,cs.costPrice,cs.costProportional, cs.normalPrice
+		,a.productCategory as "productCategory",cshd.secondHandType as "secondHandType",cs.ladderPriceFlag
+		,a.includedTax,a.invoiceType
+		FROM product a LEFT JOIN shop b ON b.shopID=a.shopID
+		left join cm_sku cs on a.productID=cs.productId
+		left join cm_second_hand_detail cshd on cshd.productID = a.productID
+		<where>
+			<if test="purchaseProductName != null and purchaseProductName != ''">
+				AND a.name LIKE concat('%',#{purchaseProductName},'%')
+			</if>
+			<if test="productId != null and productId != ''">
+				AND a.productID = #{productId}
+			</if>
+			<if test="shopName != null and shopName != ''">
+				AND b.name like concat('%',#{shopName},'%')是否含税
+			</if>
+			and a.validFlag=2
+			AND a.productID != 999
+			and a.productCategory = 2
+			and cshd.sold != 1
+		</where>
+	</select>
+
+	<select id="findLadderPriceList" resultType="com.caimei.po.ProductLadderPrice">
+		SELECT *
+		FROM product_ladder_price
+		WHERE productId = #{productId}
+		  AND buyNum is NOT null
+		  AND buyPrice is NOT null
+		  AND delFlag = 0
+		ORDER BY ladderNum ASC
+	</select>
+
+	<select id="getSvipProduct" resultType="com.caimei.modules.svip.entity.CmSvipProduct">
+		select ccs.priceType,
+			   if(csp.id is not null and csu.id is not null and csp.status=0, 1, 0) as svipPriceFlag
+		from cm_svip_product csp
+				 left join cm_svip_user csu
+						   on csu.userId = #{userId} and csu.delFlag = '0' and now() <![CDATA[ < ]]> csu.endTime
+				 left join (select csps.productId,csps.priceType from cm_svip_product_sku csps left join cm_sku cs on csps.skuId=cs.skuId
+							where csps.productId=#{productId} order by cs.price asc limit 1) ccs on csp.productId=ccs.productId
+		where csp.productId = #{productId};
+	</select>
+
+	<select id="findVipSku" resultType="com.caimei.modules.product.entity.CmSku">
+		select discountPrice,discount,priceType
+		from cm_svip_product_sku csps
+				 left join cm_sku cs on csps.productId = cs.productId
+		where csps.productId=#{productId}
+		order by cs.price asc limit 1
+	</select>
+</mapper>

+ 27 - 24
src/main/resources/mappings/modules/product/ProductMapper.xml

@@ -578,7 +578,7 @@
             AND p.newvalidFlag = 1
             AND p.newProductType=1
             AND p.validFlag = 2
-#             AND p.showFlag!=2
+            # AND p.showFlag!=2
 
         </where>
         # 在设置重点关注时给排序值1000为了让重点关注始终在列表前端
@@ -1091,7 +1091,8 @@
     <delete id="deleteLadderPriceById">
         DELETE
         FROM product_ladder_price
-        where productId = #{productId} and skuId = #{skuId}
+        where productId = #{productId}
+          and skuId = #{skuId}
     </delete>
     <delete id="deleteSkus">
         delete
@@ -1119,7 +1120,9 @@
     </delete>
 
     <select id="findProductIdBySku" resultType="java.lang.String">
-        select productId from cm_sku where skuId=#{productId}
+        select productId
+        from cm_sku
+        where skuId = #{productId}
     </select>
 
     <select id="toAddProductList" resultType="product">
@@ -1559,8 +1562,8 @@
             <if test="qualificationLink !=null and qualificationLink!=''">
                 qualificationLink=#{qualificationLink},
             </if>
-                labelIds=#{labelIds},
-                relatedLabels=#{relatedLabels},
+            labelIds=#{labelIds},
+            relatedLabels=#{relatedLabels},
             newProductType=#{newProductType},
             showFlag=#{showFlag},
             announType=#{announType},
@@ -1708,14 +1711,13 @@
         where productID = #{productID}
     </select>
     <select id="shopKeyword" resultType="java.lang.String">
-        SELECT DISTINCT cusf.keyword FROM
-            cm_user_search_frequency cusf
-            LEFT JOIN cm_shop_label csl ON csl.keywordId = cusf.Id
-            LEFT JOIN cm_shop_relevance csr ON csr.id = csl.relevanceId
-            LEFT JOIN shop s ON s.shopID = csr.shopID
-            LEFT JOIN product p ON p.shopID = s.shopID
-        WHERE
-            csl.delFlag = 0
+        SELECT DISTINCT cusf.keyword
+        FROM cm_user_search_frequency cusf
+                 LEFT JOIN cm_shop_label csl ON csl.keywordId = cusf.Id
+                 LEFT JOIN cm_shop_relevance csr ON csr.id = csl.relevanceId
+                 LEFT JOIN shop s ON s.shopID = csr.shopID
+                 LEFT JOIN product p ON p.shopID = s.shopID
+        WHERE csl.delFlag = 0
           AND csr.delFlag = 0
           AND p.productID = #{productID}
     </select>
@@ -1882,8 +1884,8 @@
                csps.discountPrice,
                csps.priceType
         from cm_sku cs
-        left join cm_promotion_sku cps on cs.skuId = cps.skuId
-        left join cm_svip_product_sku csps on cs.skuId = csps.skuId
+                 left join cm_promotion_sku cps on cs.skuId = cps.skuId
+                 left join cm_svip_product_sku csps on cs.skuId = csps.skuId
         where cs.productId = #{productID}
     </select>
     <select id="findSkuListProduct" resultType="com.caimei.modules.product.entity.CmSku">
@@ -1902,7 +1904,7 @@
                csps.discountPrice,
                csps.priceType
         from cm_sku cs
-        left join cm_svip_product_sku csps on cs.skuId = csps.skuId
+                 left join cm_svip_product_sku csps on cs.skuId = csps.skuId
         where cs.productId = #{productID}
     </select>
     <select id="findLadderPriceBySku" resultType="com.caimei.modules.product.entity.CmLadderPrice">
@@ -1971,19 +1973,20 @@
         where promotionsId = #{promotionsId}
     </select>
     <select id="getTouchPriceBySku" resultType="java.lang.Double">
-        select touchPrice from cm_promotion_sku
-        where skuId=#{skuId}
+        select touchPrice
+        from cm_promotion_sku
+        where skuId = #{skuId}
     </select>
     <select id="findSkuByPromotion" resultType="com.caimei.modules.product.entity.CmSku">
-        SELECT cs.price,cps.skuId,cps.touchPrice,cs.unit
+        SELECT cs.price, cps.skuId, cps.touchPrice, cs.unit
         FROM cm_promotion_sku cps
-        LEFT JOIN cm_sku cs ON cps.skuId=cs.skuId
-        WHERE promotionId=#{id}
+                 LEFT JOIN cm_sku cs ON cps.skuId = cs.skuId
+        WHERE promotionId = #{id}
     </select>
     <select id="getSkuByPromotionId" resultType="com.caimei.modules.product.entity.CmSku">
-        SELECT cs.price,cpp.productId,cs.skuId,cs.unit
+        SELECT cs.price, cpp.productId, cs.skuId, cs.unit
         FROM cm_promotions_product cpp
-        LEFT JOIN cm_sku cs ON cpp.productId=cs.productId
-        WHERE promotionsId= #{id}
+                 LEFT JOIN cm_sku cs ON cpp.productId = cs.productId
+        WHERE promotionsId = #{id}
     </select>
 </mapper>