Procházet zdrojové kódy

联合丽格改版

zhijiezhao před 2 roky
rodič
revize
ea3568da9a

+ 21 - 3
src/main/java/com/caimei/modules/order/controller/OrderPayShopController.java

@@ -52,14 +52,32 @@ public class OrderPayShopController {
 
 
     @ApiOperation("付款单详情")
+    @ApiImplicitParam(required = true, name = "id", value = "付款单Id")
     @GetMapping("/pay/form/{id}")
     public ResponseJson<OrderPayShopDetail> payDetail(@PathVariable("id") Integer id) {
         return ResponseJson.success(payShopService.getPayShopDetail(id));
     }
 
     @ApiOperation("审核付款单")
-    @PostMapping("/pay/check")
-    public ResponseJson<OrderPayShopDetail> checkPass(@PathVariable("id") Integer id) {
-        return ResponseJson.success(payShopService.getPayShopDetail(id));
+    @ApiImplicitParams({
+            @ApiImplicitParam(required = true, name = "id", value = "付款单Id"),
+            @ApiImplicitParam(required = true, name = "payType", value = "付款方式"),
+            @ApiImplicitParam(required = true, name = "passCode", value = "1审核通过/2审核不通过")
+    })
+    @GetMapping("/pay/check/{id}/{payType}/{passCode}")
+    public ResponseJson checkPass(@PathVariable("id") Integer id, @PathVariable("payType") Integer payType,
+                                  @PathVariable("passCode") Integer passCode) throws Exception {
+        return payShopService.checkPass(id, payType, passCode);
     }
+
+    @ApiOperation("付款申请")
+    @ApiImplicitParams({
+            @ApiImplicitParam(required = true, name = "id", value = "付款单Id")
+    })
+    @PostMapping("/pay/apply")
+    public ResponseJson applyPay(OrderPayShopDetail payShop) throws Exception {
+        return payShopService.applyPay(payShop);
+    }
+
+
 }

+ 2 - 0
src/main/java/com/caimei/modules/order/dao/NewOrderDao.java

@@ -13,4 +13,6 @@ public interface NewOrderDao {
     NewOrder get(String id);
 
     void update(NewOrder order);
+
+    void updatePayStatus(Integer status, Integer orderId);
 }

+ 10 - 0
src/main/java/com/caimei/modules/order/dao/NewShopOrderDao.java

@@ -13,4 +13,14 @@ public interface NewShopOrderDao {
     NewShopOrder findByShopOrderId(Integer shopOrderId);
 
     List<NewShopOrder> findListByOrderId(Integer orderId);
+
+    void update(NewShopOrder shopOrder);
+
+    Integer findUnPaidShopOrder(Integer orderId);
+
+    void outPaying(Integer id);
+
+    Integer getPayingStatus(Integer id);
+
+    void inPaying(Integer payShopId);
 }

+ 15 - 4
src/main/java/com/caimei/modules/order/dao/PayShopDao.java

@@ -1,9 +1,6 @@
 package com.caimei.modules.order.dao;
 
-import com.caimei.modules.order.entity.NewOrderProduct;
-import com.caimei.modules.order.entity.NewShopOrder;
-import com.caimei.modules.order.entity.OrderPayShop;
-import com.caimei.modules.order.entity.OrderPayShopDetail;
+import com.caimei.modules.order.entity.*;
 import org.apache.ibatis.annotations.Mapper;
 
 import java.util.List;
@@ -23,4 +20,18 @@ public interface PayShopDao {
     List<NewOrderProduct> findPayOrderProducts(Integer shopOrderId);
 
     List<String> findShopOrderNos(Integer orderId);
+
+    List<OrderPayShopRecord> findPayShopRecords(Integer id);
+
+    void updatePayRecord(OrderPayShopRecord record);
+
+    void updatePayShop(OrderPayShop orderPayShop);
+
+    void updatePayRecordById(Integer status, Integer id);
+
+    void insertPayShop(OrderPayShopDetail payShop);
+
+    void insertPayRecord(OrderPayShopRecord record);
+
+    void updatePaying(Integer shopOrderId);
 }

+ 5 - 2
src/main/java/com/caimei/modules/order/entity/NewShopOrder.java

@@ -32,7 +32,8 @@ public class NewShopOrder {
     @ApiModelProperty("付供应商运费")
     private Double shopPostFee;
     @ApiModelProperty("(付款供应商)付款状态:1待付款、2部分付款、3已付款")
-    private String payStatus;
+    private Integer payStatus;
+
 
     @ApiModelProperty("已付采美")
     private Double payCmAmount;
@@ -141,11 +142,13 @@ public class NewShopOrder {
      *  付款列表展示数据
      */
     @ApiModelProperty("是否处于给供应商状态中 0不是,1是")
-    private String paying;
+    private Integer paying;
     @ApiModelProperty("是否处于供应商退款状态中  0不是,1是")
     private String refunding;
     @ApiModelProperty("商品金额/商品费")
     private Double productAmount;
     @ApiModelProperty("已付金额")
     private Double payed;
+    @ApiModelProperty("分帐号")
+    private String splitCode;
 }

+ 7 - 3
src/main/java/com/caimei/modules/order/entity/OrderPayShop.java

@@ -24,11 +24,15 @@ public class OrderPayShop implements Serializable {
     private String name;
     @ApiModelProperty("供应商名称")
     private String shopName;
+    @ApiModelProperty("申请人Id")
+    private Integer applicant;
     @ApiModelProperty("申请人名称")
     private String applicantName;
     @ApiModelProperty("申请时间")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private String applyTime;
+    @ApiModelProperty("审核人Id")
+    private Integer reviewer;
     @ApiModelProperty("审核人名称")
     private String reviewerName;
     @ApiModelProperty("审核时间")
@@ -38,15 +42,15 @@ public class OrderPayShop implements Serializable {
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private String payTime;
     @ApiModelProperty("审核状态  0待审核,  1审核通过 2 审核不通过")
-    private String status;
+    private Integer status;
     @ApiModelProperty("审核不通过原因")
     private String reason;
     @ApiModelProperty("子订单编号")
     private String shopOrderNo;
     @ApiModelProperty("子订单Id")
-    private String shopOrderId;
+    private Integer shopOrderId;
     @ApiModelProperty("主订单Id")
-    private String orderId;
+    private Integer orderId;
     @ApiModelProperty("主订单编号")
     private String orderNo;
 

+ 9 - 3
src/main/java/com/caimei/modules/order/entity/OrderPayShopDetail.java

@@ -17,6 +17,8 @@ public class OrderPayShopDetail implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    @ApiModelProperty("shopId")
+    private Integer shopId;
     @ApiModelProperty("付款单Id")
     private Integer payShopId;
     @ApiModelProperty("付款单名称")
@@ -32,14 +34,18 @@ public class OrderPayShopDetail implements Serializable {
     @ApiModelProperty("付供应商总金额")
     private Double totalAmount;
     @ApiModelProperty("付款银行")
-    private String payType;
+    private Integer payType;
     @ApiModelProperty("付款银行名称")
     private String bankNameType;
+    @ApiModelProperty("申请人Id")
+    private Integer applicant;
     @ApiModelProperty("申请人名称")
     private String applicantName;
     @ApiModelProperty("申请时间")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private String applyTime;
+    @ApiModelProperty("审核人Id")
+    private Integer reviewer;
     @ApiModelProperty("审核人名称")
     private String reviewerName;
     @ApiModelProperty("审核时间")
@@ -49,11 +55,11 @@ public class OrderPayShopDetail implements Serializable {
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private String payTime;
     @ApiModelProperty("审核状态  0待审核,  1审核通过 2 审核不通过")
-    private String status;
+    private Integer status;
     @ApiModelProperty("审核不通过原因")
     private String reason;
     @ApiModelProperty("付款单关联的子订单")
     private List<NewShopOrder> shopOrders;
     @ApiModelProperty("付款账号的类型 0公账, 1私账")
-    private String type;
+    private Integer type;
 }

+ 41 - 0
src/main/java/com/caimei/modules/order/entity/OrderPayShopRecord.java

@@ -0,0 +1,41 @@
+package com.caimei.modules.order.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author zzj
+ */
+@ApiModel("付款记录")
+@Data
+public class OrderPayShopRecord implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private Integer id;
+    @ApiModelProperty("付款方式")
+    private Integer payType;
+    @ApiModelProperty("供应商Id")
+    private Integer shopId;
+    @ApiModelProperty("子订单Id")
+    private Integer shopOrderId;
+    @ApiModelProperty("子订单编号")
+    private String shopOrderNo;
+    @ApiModelProperty("付款金额")
+    private Double payAmount;
+    @ApiModelProperty("付采美金额")
+    private Double payCmAmount;
+    @ApiModelProperty("付款时间")
+    private Date payTime;
+    @ApiModelProperty("付款单表id")
+    private Integer payShopId;
+    @ApiModelProperty("0待审核, 1已审核")
+    private Integer status;
+    @ApiModelProperty("银行账户")
+    private String bankNameType;
+}

+ 5 - 0
src/main/java/com/caimei/modules/order/service/PayShopService.java

@@ -2,6 +2,7 @@ package com.caimei.modules.order.service;
 
 import com.caimei.modules.order.entity.OrderPayShop;
 import com.caimei.modules.order.entity.OrderPayShopDetail;
+import com.caimei.utils.ResponseJson;
 import com.github.pagehelper.PageInfo;
 
 /**
@@ -12,4 +13,8 @@ public interface PayShopService {
     PageInfo<OrderPayShop> findPayList(OrderPayShop orderPayShop, int pageNum, int pageSize);
 
     OrderPayShopDetail getPayShopDetail(Integer id);
+
+    ResponseJson checkPass(Integer id, Integer payType, Integer passCode) throws Exception;
+
+    ResponseJson applyPay(OrderPayShopDetail payShop) throws Exception;
 }

+ 1 - 1
src/main/java/com/caimei/modules/order/service/impl/CmReturnedPurchaseServiceImpl.java

@@ -100,7 +100,7 @@ public class CmReturnedPurchaseServiceImpl implements CmReturnedPurchaseService
                         NewShopOrder shopOrder = newShopOrderService.findByShopOrderId(item.getShopOrderId());
                         if (null != shopOrder) {
                             shopOrderReturned.setProductAmount(shopOrder.getProductAmount());
-                            shopOrderReturned.setPayStatus(shopOrder.getPayStatus());
+                            shopOrderReturned.setPayStatus(shopOrder.getPayStatus().toString());
                             shopOrderReturned.setSendOutStatus(shopOrder.getSendOutStatus());
                             shopOrderReturned.setShopOrderNo(shopOrder.getShopOrderNo());
                         }

+ 159 - 1
src/main/java/com/caimei/modules/order/service/impl/PayShopServiceImpl.java

@@ -1,30 +1,45 @@
 package com.caimei.modules.order.service.impl;
 
+import com.caimei.modules.order.dao.NewOrderDao;
+import com.caimei.modules.order.dao.NewShopOrderDao;
 import com.caimei.modules.order.dao.PayShopDao;
 import com.caimei.modules.order.entity.*;
 import com.caimei.modules.order.service.PayShopService;
 import com.caimei.modules.shiro.entity.CmMallAdminUser;
+import com.caimei.utils.DateUtils;
+import com.caimei.utils.MathUtil;
+import com.caimei.utils.ResponseJson;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.github.pagehelper.util.StringUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.shiro.SecurityUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
 
 /**
  * @author zzj
  */
+@Slf4j
 @Service
 public class PayShopServiceImpl implements PayShopService {
 
     @Resource
     private PayShopDao payShopDao;
+    @Resource
+    private NewShopOrderDao newShopOrderDao;
+    @Resource
+    private NewOrderDao newOrderDao;
 
     @Override
     public PageInfo<OrderPayShop> findPayList(OrderPayShop orderPayShop, int pageNum, int pageSize) {
         PageHelper.startPage(pageNum, pageSize);
-        CmMallAdminUser principal = (CmMallAdminUser) SecurityUtils.getSubject().getPrincipal();
         List<OrderPayShop> payShops = payShopDao.findPayShops(orderPayShop);
         PageInfo<OrderPayShop> pageInfo = new PageInfo(payShops);
         return pageInfo;
@@ -41,4 +56,147 @@ public class PayShopServiceImpl implements PayShopService {
         detail.setShopOrders(shopOrders);
         return detail;
     }
+
+    @Transactional(readOnly = false, rollbackFor = Exception.class)
+    @Override
+    public ResponseJson checkPass(Integer id, Integer payType, Integer passCode) throws Exception {
+        OrderPayShop orderPayShop = new OrderPayShop();
+        CmMallAdminUser user = (CmMallAdminUser) SecurityUtils.getSubject().getPrincipal();
+        orderPayShop.setReviewer(user.getId());
+        orderPayShop.setReviewTime(DateUtils.getDateTime());
+        orderPayShop.setPayShopId(id);
+        if (1 == passCode) {
+            // 通过审核
+            List<OrderPayShopRecord> records = payShopDao.findPayShopRecords(id);
+
+            //修改每一条子订单的已付款金额
+            for (OrderPayShopRecord record : records) {
+                NewShopOrder shopOrder = newShopOrderDao.get(record.getShopOrderId());
+
+                // 本次付款金额 + 付采美 + 原来已经付过的金额
+                BigDecimal payedFee = MathUtil.add(MathUtil.add(record.getPayAmount(), record.getPayAmount()), shopOrder.getPayedShopAmount());
+                // 总共要付的金额
+                BigDecimal shouldPayFee = MathUtil.add(shopOrder.getShouldPayShopAmount(), MathUtil.mul(shopOrder.getTotalAmount(), 0.03));
+
+                if (MathUtil.compare(payedFee, shouldPayFee) == -1) {
+                    // (本次付款金额 + 付采美 + 原来已经付过的金额)  < 总共要付的金额
+                    shopOrder.setPayStatus(2);
+                } else if (MathUtil.compare(payedFee, shouldPayFee) == 0) {
+                    // 本次付款金额 + 原来已经付过的金额  近似于 总共要付的金额相等
+                    shopOrder.setPayStatus(3);
+                } else {
+                    log.info("已付款金额:" + shopOrder.getPayedShopAmount() + "本次付款金额:" + record.getPayAmount() + "付供应商:" + shouldPayFee + "付款id:" + id);
+                    log.info("check ----> 付款金额异常, 付款金额大于待付款金额");
+                    throw new Exception("付款单审核金额异常, 付款金额大于待付款金额");
+                }
+                shopOrder.setPayedShopAmount(shopOrder.getPayedShopAmount() == null ? 0D : shopOrder.getPayedShopAmount() + record.getPayAmount());
+                shopOrder.setPayCmAmount(shopOrder.getPayCmAmount() == null ? 0D : shopOrder.getPayCmAmount() + record.getPayCmAmount());
+                //退出付款进行状态
+                shopOrder.setPaying(0);
+                newShopOrderDao.update(shopOrder);
+                record.setStatus(1);
+                record.setPayTime(new Date());
+                record.setPayType(payType);
+                payShopDao.updatePayRecord(record);
+                //查询未付
+                Integer count = newShopOrderDao.findUnPaidShopOrder(shopOrder.getOrderId());
+                Integer status = count > 0 ? 2 : 3;
+                newOrderDao.updatePayStatus(status, shopOrder.getOrderId());
+            }
+            orderPayShop.setPayTime(DateUtils.getDateTime());
+            orderPayShop.setStatus(1);
+            payShopDao.updatePayShop(orderPayShop);
+            return ResponseJson.success();
+        } else {
+            orderPayShop.setStatus(2);
+            payShopDao.updatePayShop(orderPayShop);
+            //付款记录 修改状态
+            payShopDao.updatePayRecordById(2, id);
+            //子订单退出付款状态
+            newShopOrderDao.outPaying(id);
+            return ResponseJson.success();
+        }
+    }
+
+    @Transactional(readOnly = false, rollbackFor = Exception.class)
+    @Override
+    public ResponseJson applyPay(OrderPayShopDetail payShop) throws Exception {
+        CmMallAdminUser user = (CmMallAdminUser) SecurityUtils.getSubject().getPrincipal();
+        payShop.setApplicant(user.getId());
+        if (null == payShop.getPayShopId()) {
+            //新增
+
+            payShop.setApplyTime(DateUtils.getDateTime());
+            payShop.setStatus(0);
+            payShopDao.insertPayShop(payShop);
+            //保存每个子订单的付款金额记录  等待审核付款
+            shop.setBankAccount(payShop.getBankAccount());
+            shop.setBankAccountName(payShop.getBankAccountName());
+            shop.setBankName(payShop.getBankName());
+            payShopDao.update(shop);
+            List<NewShopOrder> shopOrders = payShop.getShopOrders();
+            shopOrders.forEach(s -> {
+                OrderPayShopRecord record = new OrderPayShopRecord();
+                record.setShopId(payShop.getShopId());
+                record.setShopOrderId(s.getShopOrderId());
+                record.setShopOrderNo(s.getShopOrderNo());
+                record.setPayAmount(s.getWaitPayShop());
+                record.setPayCmAmount(s.getWaitPayCmAmount());
+                record.setPayType(payShop.getPayType());
+                record.setPayShopId(payShop.getPayShopId());
+                record.setStatus(0);
+                payShopDao.insertPayRecord(record);
+                //子订单发起付款申请以后 就不能同时再次发起付款申请了  直到审核操作通过或者取消
+                payShopDao.updatePaying(s.getShopOrderId());
+            });
+            // 运费付款单作用不明,暂时取消生成
+
+        } else {
+            //修改
+            if (StringUtil.isNoneEmpty(payShop.getReApply())) {
+                //查询订单的paying
+                Integer count = newShopOrderDao.getPayingStatus(payShop.getPayShopId());
+                if (count > 0) {
+                    throw new Exception("订单已经处于付款状态");
+                }
+                //付款记录 修改状态
+                payShopDao.updatePayRecordById(2, payShop.getPayShopId());
+                //子订单退出付款状态
+                newShopOrderDao.inPaying(payShop.getPayShopId());
+                payShop.setReviewer(null);
+                payShop.setReviewTime(null);
+                payShop.setReason(null);
+                payShop.setStatus(0);
+            } else {
+                if (1 == payShop.getStatus()) {
+                    throw new Exception("该付款单已被审核,无需再申请付款");
+                }
+                if (2 == payShop.getStatus()) {
+                    //付款记录 修改状态
+                    payShopDao.updatePayRecordById(2, payShop.getPayShopId());
+                    //子订单退出付款状态
+                    newShopOrderDao.inPaying(payShop.getPayShopId());
+                    payShop.setReviewer(null);
+                    payShop.setReviewTime(null);
+                    payShop.setReason(null);
+                    payShop.setStatus(0);
+                }
+
+                CmPayShop dbBean = cmPayShopDao.get(payShop.getPayShopId());
+                NewCmShop shop = newCmShopDao.get(payShop.getShopId());
+
+                for (String p : payInfo) {
+                    String shopOrderID = p.split("_")[0];
+                    Double payAmount = Double.valueOf(p.split("_")[1]);
+                    Double wipeFee = Double.valueOf(p.split("_")[2]);
+                    cmPayShopRecordDao.updateByID(payShop.getPayShopId(), shopOrderID, payAmount, wipeFee);
+                }
+
+            }
+            cmPayShopDao.update(payShop);
+        }
+
+
+        return null;
+    }
 }

+ 360 - 0
src/main/java/com/caimei/utils/MathUtil.java

@@ -0,0 +1,360 @@
+package com.caimei.utils;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+public class MathUtil {
+
+
+
+	public static int default_scale = 4;
+
+	private static final int MAX_GENERATE_COUNT = 99999;
+	private static int generateCount = 0;
+
+
+	/**
+	 * 两个实数相除,默认四舍五入到4位
+	 *
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static BigDecimal div(Object v1, Object v2) {
+		return div(v1, v2, default_scale);
+	}
+
+	/**
+	 * 两个实数相除,默认四舍五入到scale位
+	 *
+	 * @param v1
+	 * @param v2
+	 * @param scale
+	 * @return
+	 */
+	public static BigDecimal div(Object v1, Object v2, int scale) {
+		if (scale < 0) {
+			throw new IllegalArgumentException("四舍五入的位数不能为负数");
+		}
+		BigDecimal b1 = convert(v1);
+		BigDecimal b2 = convert(v2);
+		if (equal0(b2)) {
+			throw new IllegalArgumentException("除数不能为0");
+		}
+		return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP);
+	}
+
+	public static String formatDouble(double s) {
+		DecimalFormat fmt = new DecimalFormat("0.00");
+		return fmt.format(s);
+	}
+
+	public static String[] intersect(String[] arr1, String[] arr2){
+		List<String> l = new LinkedList<String>();
+		Set<String> common = new HashSet<String>();
+		for(String str:arr1){
+			if(!l.contains(str)){
+				l.add(str);
+			}
+		}
+		for(String str:arr2){
+			if(l.contains(str)){
+				common.add(str);
+			}
+		}
+		String[] result={};
+		return common.toArray(result);
+	}
+
+
+	public static synchronized String getUniqueString() {
+		if (generateCount > 99999)
+			generateCount = 0;
+		String uniqueNumber = Long.toString(System.currentTimeMillis())
+				+ Integer.toString(generateCount);
+		generateCount++;
+		return uniqueNumber;
+	}
+
+	/**
+	 * 
+	 * 构造函数
+	 */
+	private MathUtil() {
+
+	}
+
+	/**
+	 * 类型转换函数
+	 * 
+	 * @param o
+	 * @return
+	 */
+	public static BigDecimal convert(Object o) {
+		if (o == null) {
+			return BigDecimal.ZERO;
+		} else if (o instanceof BigDecimal) {
+			return (BigDecimal) o;
+		}
+		String str = o.toString();
+		if (StringUtils.isNotBlank(str)) {
+			return new BigDecimal(str);
+		} else {
+			return BigDecimal.ZERO;
+		}
+	}
+
+	/**
+	 * 两个实数相加
+	 * 
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static BigDecimal add(Object v1, Object v2) {
+		BigDecimal b1 = convert(v1);
+		BigDecimal b2 = convert(v2);
+		return b1.add(b2);
+
+	}
+
+	/**
+	 * 两个实数相减
+	 * 
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static BigDecimal sub(Object v1, Object v2) {
+		BigDecimal b1 = convert(v1);
+		BigDecimal b2 = convert(v2);
+		return b1.subtract(b2);
+
+	}
+
+	/**
+	 * 两个实数相乘
+	 * 
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static BigDecimal mul(Object v1, Object v2) {
+		BigDecimal b1 = convert(v1);
+		BigDecimal b2 = convert(v2);
+		return b1.multiply(b2);
+
+	}
+
+	/**
+	 * 相个实数相乘并四舍五入到Sacle位
+	 * 
+	 * @param v1
+	 * @param v2
+	 * @param scale
+	 * @return
+	 */
+	public static BigDecimal mul(Object v1, Object v2, int scale) {
+		if (scale < 0) {
+			throw new IllegalArgumentException("四舍五入的位数不能为负数");
+		}
+		BigDecimal b1 = convert(v1);
+		BigDecimal b2 = convert(v2);
+		return b1.multiply(b2).setScale(scale, BigDecimal.ROUND_HALF_UP);
+
+	}
+
+	/**
+	 * 两个实数比较
+	 * 
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static int compare(Object v1, Object v2) {
+		BigDecimal b1 = convert(v1);
+		BigDecimal b2 = convert(v2);
+		return b1.compareTo(b2);
+	}
+
+	public static boolean equal0(Object v1) {
+		BigDecimal b1 = convert(v1);
+		return b1.compareTo(BigDecimal.ZERO) == 0;
+	}
+
+	public static boolean notEqual0(Object v1) {
+		BigDecimal b1 = convert(v1);
+		return b1.compareTo(BigDecimal.ZERO) != 0;
+	}
+
+	/**
+	 * 两个整数比较
+	 * 
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static int compareInt(Integer v1, Integer v2) {
+
+		if (v1 == null) {
+			v1 = new Integer(0);
+		}
+		if (v2 == null) {
+			v2 = new Integer(0);
+		}
+		return v1.compareTo(v2);
+	}
+
+	/**
+	 * 判断两个整数是否相等
+	 * 
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static boolean equal(Integer v1, Integer v2) {
+
+		int result = compareInt(v1, v2);
+		return result == 0;
+	}
+
+	/**
+	 * 判断两个整数不等
+	 * 
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static boolean notEqual(Integer v1, Integer v2) {
+		int result = compareInt(v1, v2);
+		return result != 0;
+	}
+
+	/**
+	 * 实数的四舍五入函数
+	 * 
+	 * @param v
+	 * @param scale
+	 * @return
+	 */
+	public static BigDecimal round(Object v, int scale) {
+		if (scale < 0) {
+			throw new IllegalArgumentException("四舍五入的位数不能为负数");
+		}
+		BigDecimal b = convert(v);
+		return b.setScale(scale, BigDecimal.ROUND_HALF_UP);
+	}
+
+	/**
+	 * 将字符串转换成整型
+	 * 
+	 * @param value
+	 * @param defaultNum
+	 * @return
+	 */
+	public static int parsetInt(String value, int defaultNum) {
+		if (value != null && !value.equals("")) {
+			int num = defaultNum;
+			try {
+				num = Integer.parseInt(value);
+			} catch (Exception ignored) {
+			}
+			return num;
+		} else {
+			return defaultNum;
+		}
+	}
+
+	/**
+	 * 将string转换为double
+	 * 
+	 * @param value
+	 * @param defaultNum
+	 * @return
+	 */
+	public static double parseDouble(String value, double defaultNum) {
+		if (StringUtils.isBlank(value)) {
+			return defaultNum;
+		}
+
+		value = value.replaceAll(",", "");
+		value = value.replaceAll(" ", "");
+		value = value.replaceAll("¥", "");
+
+		double num = defaultNum;
+		try {
+			num = Double.parseDouble(value);
+		} catch (Exception ignored) {
+		}
+		return num;
+	}
+
+	/**
+	 * 将string 转换为double
+	 * 
+	 * @param value
+	 * @return
+	 */
+	public static double parseDouble(String value) {
+		return parseDouble(value, 0);
+	}
+
+	public static int isNullInteger(Integer v) {
+		if (v == null) {
+			return 0;
+		} else {
+			return v.intValue();
+		}
+	}
+	
+	//
+	private static double EARTH_RADIUS = 6378.137;
+
+	private static double rad(double d) {
+
+		return d * Math.PI / 180.0;
+
+	}
+
+	public static double getDistance(double lat1, double lng1, double lat2,
+
+	double lng2) {
+
+		double radLat1 = rad(lat1);
+
+		double radLat2 = rad(lat2);
+
+		double a = radLat1 - radLat2;
+
+		double b = rad(lng1) - rad(lng2);
+
+		double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
+
+		+ Math.cos(radLat1) * Math.cos(radLat2)
+
+		* Math.pow(Math.sin(b / 2), 2)));
+
+		s = s * EARTH_RADIUS;
+
+		s = Math.round(s * 10000) / 10000;
+
+		return s;
+
+	}
+	
+	public static void main(String[] args){
+		double lat1=118.105736;
+		double lng1=24.491558;
+		double lat2=118.110749;
+		double lng2=24.492824;
+		double t=getDistance(lat1,lng1,lat2,lng2);
+		System.out.println(t);
+	}
+
+}

+ 6 - 0
src/main/resources/mapper/NewOrderMapper.xml

@@ -212,6 +212,12 @@
             where orderID = #{orderId}
     </update>
 
+    <update id="updatePayStatus">
+        update cm_order
+        set payStatus = #{status}
+        where orderID = #{orderId}
+    </update>
+
     <resultMap id="orderDisplayList" type="com.caimei.modules.order.entity.NewOrder">
         <id column="orderId" property="orderId"/>
         <result column="orderNo" property="orderNo"/>

+ 189 - 13
src/main/resources/mapper/NewShopOrderMapper.xml

@@ -4,6 +4,7 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.modules.order.dao.NewShopOrderDao">
     <sql id="shopOrderColumns">
+        a.payCmAmount AS payCmAmount,
 			a.shopOrderId AS shopOrderId,
 			a.orderId AS orderId,
 			a.organizeId AS organizeId,
@@ -62,24 +63,199 @@
     		a.costType AS costType,
     		a.modifyShouldPayNote AS modifyShouldPayNote,
     		proportional AS proportional
-	</sql>
+    </sql>
+
+    <update id="update">
+        update cm_shop_order
+        <set>
+            <if test="null != payCmAmount">
+                payCmAmount = #{payCmAmount},
+            </if>
+            <if test="shopOrderNo != null and shopOrderNo != ''">
+                shopOrderNo = #{shopOrderNo},
+            </if>
+            <if test="orderNo != null and orderNo != ''">
+                orderNo = #{orderNo},
+            </if>
+            <if test="itemCount != null and itemCount != ''">
+                itemCount = #{itemCount},
+            </if>
+            <if test="townId != null and itemCount != ''">
+                townID = #{townId},
+            </if>
+            <if test="productAmount != null and productAmount != ''">
+                productAmount = #{productAmount},
+            </if>
+            <if test="accountAmount != null and accountAmount != ''">
+                accountAmount = #{accountAmount},
+            </if>
+            <if test="totalAmount != null and totalAmount != ''">
+                totalAmount = #{totalAmount},
+            </if>
+            <if test="needPayAmount != null and needPayAmount != ''">
+                needPayAmount = #{needPayAmount},
+            </if>
+            <if test="refundAmount != null and refundAmount != ''">
+                refundAmount = #{refundAmount},
+            </if>
+            <if test="clubId != null and clubId != ''">
+                clubID = #{clubId},
+            </if>
+            <if test="spId != null and itemCount != ''">
+                spID = #{spId},
+            </if>
+            <if test="canRefundFlag != null and canRefundFlag != ''">
+                canRefundFlag = #{canRefundFlag},
+            </if>
+            <if test="useBalanceFlag != null and useBalanceFlag != ''">
+                useBalanceFlag = #{useBalanceFlag},
+            </if>
+            <if test="canRefundBeans != null and canRefundBeans != ''">
+                canRefundBeans = #{canRefundBeans},
+            </if>
+            <if test="freePostageFee != null and freePostageFee != ''">
+                freePostageFee = #{freePostageFee},
+            </if>
+            <if test="brokerage != null and brokerage != ''">
+                brokerage = #{brokerage},
+            </if>
+            <if test="delFlag != null and delFlag != ''">
+                delFlag = #{delFlag},
+            </if>
+            <if test="refundsAmount != null and refundsAmount != ''">
+                refundsAmount = #{refundsAmount},
+            </if>
+            <if test="orderStatusFlag != null and orderStatusFlag != ''">
+                orderStatusFlag = #{orderStatusFlag},
+            </if>
+            <if test="orderTime != null and orderTime != ''">
+                orderTime = #{orderTime},
+            </if>
+            <if test="presentNum != null and presentNum != ''">
+                presentNum = #{presentNum},
+            </if>
+            <if test="preferential != null and preferential != ''">
+                preferential = #{preferential},
+            </if>
+            <if test="receiveGoodsTime != null and receiveGoodsTime != ''">
+                receiveGoodsTime = #{receiveGoodsTime},
+            </if>
+            <if test="totalAddedValueTax != null and totalAddedValueTax != ''">
+                totalAddedValueTax = #{totalAddedValueTax},
+            </if>
+            <if test="note != null and note != ''">
+                note = #{note},
+            </if>
+            <if test="sendOutStatus != null and sendOutStatus != ''">
+                sendOutStatus = #{sendOutStatus},
+            </if>
+            <if test="paying != null and paying != ''">
+                paying = #{paying},
+            </if>
+            <if test="shopProductAmount != null">
+                shopProductAmount = #{shopProductAmount},
+            </if>
+            <if test="shopPostFee != null">
+                shopPostFee = #{shopPostFee},
+            </if>
+            <if test="shouldPayShopAmount != null">
+                shouldPayShopAmount = #{shouldPayShopAmount},
+            </if>
+            <if test="payedShopAmount != null">
+                payedShopAmount = #{payedShopAmount},
+            </if>
+            <if test="payStatus != null">
+                payStatus = #{payStatus},
+            </if>
+            <if test="realPay != null">
+                realPay = #{realPay},
+            </if>
+            <if test="receiptStatus != null">
+                receiptStatus = #{receiptStatus},
+            </if>
+            <if test="receiptAmount != null">
+                receiptAmount = #{receiptAmount},
+            </if>
+            <if test="splitCode != null">
+                splitCode = #{splitCode},
+            </if>
+        </set>
+        <where>
+            <if test="shopOrderId != null and shopOrderId != ''">
+                AND shopOrderID = #{shopOrderId}
+            </if>
+            <if test="orderId != null and orderId != ''">
+                AND orderID = #{orderId}
+            </if>
+        </where>
+    </update>
+
+    <update id="outPaying">
+        update cm_shop_order
+        set paying = '0'
+        where shopOrderID in
+              (select cpsr.shopOrderID
+               from cm_pay_shop_record cpsr
+                        left join cm_pay_shop cps on cps.id = cpsr.payShopID
+               where cps.id = #{id}
+                 and cps.delFlag = '0'
+                 and cpsr.delFlag = '0'
+                 and cpsr.shopOrderID is not null)
+    </update>
+
+    <update id="inPaying">
+        update cm_shop_order
+        set paying = 1
+        where shopOrderID in
+              (select cpsr.shopOrderID
+               from cm_pay_shop_record cpsr
+                        left join cm_pay_shop cps on cps.id = cpsr.payShopID
+               where cps.id = #{payShopId}
+                 and cps.delFlag = '0'
+                 and cpsr.delFlag = '0'
+                 and cpsr.shopOrderID is not null)
+    </update>
 
     <select id="get" resultType="com.caimei.modules.order.entity.NewShopOrder" useCache="false" flushCache="true">
-        select <include refid="shopOrderColumns"/>
+        select
+        <include refid="shopOrderColumns"/>
         from cm_shop_order a
         where a.shopOrderId = #{shopOrderId}
     </select>
 
-	<select id="findByShopOrderId" resultType="com.caimei.modules.order.entity.NewShopOrder">
-		select <include refid="shopOrderColumns"/>
-		from cm_shop_order a
-		where a.shopOrderId = #{shopOrderId}
-	</select>
+    <select id="findByShopOrderId" resultType="com.caimei.modules.order.entity.NewShopOrder">
+        select
+        <include refid="shopOrderColumns"/>
+        from cm_shop_order a
+        where a.shopOrderId = #{shopOrderId}
+    </select>
 
-	<select id="findListByOrderId" resultType="com.caimei.modules.order.entity.NewShopOrder">
-		SELECT <include refid="shopOrderColumns"/>,
-		b.name as shopName
-		FROM cm_shop_order a left join shop b on a.shopId = b.shopId
-		WHERE a.orderId = #{orderId} ORDER BY a.shopOrderNo DESC
-	</select>
+    <select id="findListByOrderId" resultType="com.caimei.modules.order.entity.NewShopOrder">
+        SELECT<include refid="shopOrderColumns"/>,
+        b.name as shopName
+        FROM cm_shop_order a left join shop b on a.shopId = b.shopId
+        WHERE a.orderId = #{orderId} ORDER BY a.shopOrderNo DESC
+    </select>
+
+    <select id="findUnPaidShopOrder" resultType="java.lang.Integer">
+        SELECT COUNT(shopOrderId)
+        FROM cm_shop_order
+        WHERE orderID = #{orderId}
+          AND shopID != 998
+          AND payStatus != 3
+    </select>
+
+    <select id="getPayingStatus" resultType="java.lang.Integer">
+        SELECT COUNT(shopOrderId)
+        FROM cm_shop_order
+        WHERE shopOrderID IN
+              (SELECT cpsr.shopOrderID
+               FROM cm_pay_shop_record cpsr
+                        LEFT JOIN cm_pay_shop cps ON cps.id = cpsr.payShopID
+               WHERE cps.id = #{id}
+                 AND cps.delFlag = '0'
+                 AND cpsr.delFlag = '0'
+                 AND cpsr.shopOrderID IS NOT NULL)
+          AND paying = 1
+    </select>
 </mapper>

+ 142 - 41
src/main/resources/mapper/PayShopDao.xml

@@ -4,6 +4,88 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.modules.order.dao.PayShopDao">
 
+    <insert id="insertPayShop" keyProperty="payShopId" useGeneratedKeys="true"
+            parameterType="com.caimei.modules.order.entity.OrderPayShopDetail">
+        INSERT INTO cm_pay_shop(shopID,
+                                name,
+                                bankAccountName,
+                                bankAccount,
+                                bankName,
+                                type,
+                                totalAmount,
+                                balancePayFee,
+                                transferPayFee,
+                                payType,
+                                applicant,
+                                applyTime,
+                                reviewer,
+                                reviewTime,
+                                payTime,
+                                status,
+                                reason)
+        VALUES (#{shopId},
+                #{name},
+                #{bankAccountName},
+                #{bankAccount},
+                #{bankName},
+                #{type},
+                #{totalAmount},
+                #{balancePayFee},
+                #{transferPayFee},
+                #{payType},
+                #{applicant},
+                #{applyTime},
+                #{reviewer},
+                #{reviewTime},
+                #{payTime},
+                #{status},
+                #{reason})
+    </insert>
+
+    <insert id="insertPayRecord">
+        insert into cm_pay_shop_record(shopID, shopOrderID, shopOrderNo, payAmount, payCmAmount,
+                                       paymentType, payType, payShopID, status)
+        values (#{shopId}, #{shopOrderId}, #{shopOrderNo}, #{payAmount}, #{payCmAmount}, 1, #{payType},
+                #{payShopId}, #{status})
+    </insert>
+
+    <update id="updatePayRecord">
+        UPDATE cm_pay_shop_record
+        SET payAmount = #{payAmount},
+            payType   = #{payType},
+            payTime   = #{payTime},
+            status    = #{status},
+            delFlag   = #{delFlag}
+        WHERE id = #{id}
+    </update>
+
+    <update id="updatePayShop">
+        UPDATE cm_pay_shop
+        SET name        = #{name},
+            totalAmount = #{totalAmount},
+            payType     = #{payType},
+            applicant   = #{applicant},
+            applyTime   = #{applyTime},
+            reviewer    = #{reviewer},
+            reviewTime  = #{reviewTime},
+            payTime     = #{payTime},
+            status      = #{status},
+            reason      = #{reason},
+            delFlag     = #{delFlag}
+        WHERE id = #{payShopId}
+    </update>
+
+    <update id="updatePayRecordById">
+        update cm_pay_shop_record
+        set status = #{status}
+        where payShopID = #{id}
+    </update>
+
+    <update id="updatePaying">
+        update cm_shop_order
+        set paying = 1
+        where shopOrderID = #{shopOrderId}
+    </update>
 
     <select id="findPayShops" resultType="com.caimei.modules.order.entity.OrderPayShop">
         SELECT
@@ -86,7 +168,8 @@
                a.status       AS "status",
                u1.accountName AS applicantName,
                u2.accountName AS reviewerName,
-               s.name         AS shopName
+               s.name         AS shopName,
+               a.shopId
         FROM cm_pay_shop a
                  left join cm_mall_admin_user u1 on u1.id = a.applicant
                  left join cm_mall_admin_user u2 on u2.id = a.reviewer
@@ -95,32 +178,32 @@
     </select>
 
     <select id="findPayShopOrders" resultType="com.caimei.modules.order.entity.NewShopOrder">
-        SELECT DISTINCT a.shopOrderID                                       AS shopOrderId,
-                        a.orderID                                           AS orderId,
-                        a.organizeID                                        AS organizeId,
-                        a.shopOrderNo                                       AS shopOrderNo,
-                        a.orderNo                                           AS orderNo,
-                        ROUND(a.totalAmount*0.17,2)                         AS brokerage,
-                        ROUND(a.totalAmount*0.03,2)                         AS shouldPayCmAmount,
-                        a.payCmAmount                                       AS payCmAmount,
-                        ROUND(a.totalAmount*0.03,2) - a.payCmAmount         AS waitPayCmAmount,
-                        a.receiptStatus                                     AS receiptStatus,
-                        a.orderTime                                         AS orderTime,
-                        a.payStatus                                         AS payStatus,
-                        a.shopProductAmount                                 AS shopProductAmount,
-                        a.shopPostFee                                       AS shopPostFee,
-                        ROUND(a.totalAmount*0.8,2)                          AS shouldPayShopAmount,
-                        ROUND(a.totalAmount*0.8,2) - payedShopAmount        AS waitPayShop,
-                        a.payedShopAmount                                   AS payedShopAmount,
-                        co.payTotalFee                                      AS payTotalFee,
-                        bou.name                                            AS buyer,
-                        s.name                                              AS shopName
+        SELECT DISTINCT a.shopOrderID                                   AS shopOrderId,
+                        a.orderID                                       AS orderId,
+                        a.organizeID                                    AS organizeId,
+                        a.shopOrderNo                                   AS shopOrderNo,
+                        a.orderNo                                       AS orderNo,
+                        ROUND(a.totalAmount * 0.17, 2)                  AS brokerage,
+                        ROUND(a.totalAmount * 0.03, 2)                  AS shouldPayCmAmount,
+                        a.payCmAmount                                   AS payCmAmount,
+                        ROUND(a.totalAmount * 0.03, 2) - a.payCmAmount  AS waitPayCmAmount,
+                        a.receiptStatus                                 AS receiptStatus,
+                        a.orderTime                                     AS orderTime,
+                        a.payStatus                                     AS payStatus,
+                        a.shopProductAmount                             AS shopProductAmount,
+                        a.shopPostFee                                   AS shopPostFee,
+                        ROUND(a.totalAmount * 0.8, 2)                   AS shouldPayShopAmount,
+                        ROUND(a.totalAmount * 0.8, 2) - payedShopAmount AS waitPayShop,
+                        a.payedShopAmount                               AS payedShopAmount,
+                        co.payTotalFee                                  AS payTotalFee,
+                        bou.name                                        AS buyer,
+                        s.name                                          AS shopName
         FROM cm_shop_order a
-        LEFT JOIN cm_pay_shop_record cpsr ON a.shopOrderID = cpsr.shopOrderID
-        LEFT JOIN bp_order_userinfo bou ON bou.orderId = a.orderID
-        LEFT JOIN cm_order co ON co.orderID = a.orderID
-        LEFT JOIN shop s ON s.shopID = a.shopID
-        LEFT JOIN club c ON c.userID = a.userID
+                 LEFT JOIN cm_pay_shop_record cpsr ON a.shopOrderID = cpsr.shopOrderID
+                 LEFT JOIN bp_order_userinfo bou ON bou.orderId = a.orderID
+                 LEFT JOIN cm_order co ON co.orderID = a.orderID
+                 LEFT JOIN shop s ON s.shopID = a.shopID
+                 LEFT JOIN club c ON c.userID = a.userID
         WHERE a.shopOrderID IN
               (SELECT shoporderId
                FROM cm_pay_shop_record
@@ -130,27 +213,27 @@
     </select>
 
     <select id="findPayOrderProducts" resultType="com.caimei.modules.order.entity.NewOrderProduct">
-        select cop.name                    AS name,
-               cop.orderProductID          AS orderProductId,
-               cop.productID               AS productId,
-               cop.productUnit             AS unit,
-               cop.num                     AS num,
-               cop.totalFee                AS totalFee,
-               cop.costPrice               AS costPrice,
-               cop.productType             AS productType,
-               cpo.touchPrice              AS touchPrice,
+        select cop.name                 AS name,
+               cop.orderProductID       AS orderProductId,
+               cop.productID            AS productId,
+               cop.productUnit          AS unit,
+               cop.num                  AS num,
+               cop.totalFee             AS totalFee,
+               cop.costPrice            AS costPrice,
+               cop.productType          AS productType,
+               cpo.touchPrice           AS touchPrice,
                (SELECT SUM(crpp.actualReturnedNum) + SUM(crpp.actualCancelNum)
                 FROM cm_returned_purchase_product crpp
-                LEFT JOIN cm_returned_purchase rp ON rp.id = crpp.returnedID
+                         LEFT JOIN cm_returned_purchase rp ON rp.id = crpp.returnedID
                 WHERE crpp.orderProductID = cop.orderProductId
                   AND rp.status = '2'
                   AND rp.delFlag = '0') AS returnedNum
         from cm_order_product cop
-        left join cm_sku cs on cop.skuId = cs.skuId
-        left join cm_promotions_order cpo on (cop.orderPromotionsId = cpo.id and cpo.mode = 1)
-        left join product p on p.productID = cop.productID
-        left join cm_order co on co.orderID = cop.orderID
-        left join user u on u.userID = co.userID
+                 left join cm_sku cs on cop.skuId = cs.skuId
+                 left join cm_promotions_order cpo on (cop.orderPromotionsId = cpo.id and cpo.mode = 1)
+                 left join product p on p.productID = cop.productID
+                 left join cm_order co on co.orderID = cop.orderID
+                 left join user u on u.userID = co.userID
         where cop.shopOrderID = #{shopOrderId}
     </select>
 
@@ -160,4 +243,22 @@
         WHERE orderID = #{orderID}
           and shopId != 998
     </select>
+
+    <select id="findPayShopRecords" resultType="com.caimei.modules.order.entity.OrderPayShopRecord">
+        SELECT f.bankAccount AS "bankNameType",
+               a.id          AS "id",
+               a.shopID      AS "shopId",
+               a.shopOrderID AS "shopOrderId",
+               a.shopOrderNo AS "shopOrderNo",
+               a.payAmount   AS "payAmount",
+               a.payCmAmount,
+               a.payType     AS "payType",
+               a.payTime     AS "payTime",
+               a.wipeTime    AS "wipeTime",
+               a.payShopID   AS "payShopID",
+               a.status      AS "status"
+        FROM cm_pay_shop_record a
+                 LEFT JOIN cm_offline_collection f ON a.payType = f.type
+        WHERE a.payShopID = #{id}
+    </select>
 </mapper>