Browse Source

订单增加销售记录

周箭河 5 years ago
parent
commit
8d885ff6e6

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SellOrderDao.java

@@ -0,0 +1,8 @@
+package com.ym.mec.biz.dal.dao;
+
+import com.ym.mec.biz.dal.entity.SellOrder;
+import com.ym.mec.common.dal.BaseDAO;
+
+public interface SellOrderDao extends BaseDAO<Integer, SellOrder> {
+
+}

+ 7 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentPaymentOrderDetailDao.java

@@ -78,4 +78,11 @@ public interface StudentPaymentOrderDetailDao extends BaseDAO<Long, StudentPayme
      * @return
      * @return
      */
      */
     StudentPaymentOrderDetail findApplyOrderMusical(@Param("orderId") Long orderId);
     StudentPaymentOrderDetail findApplyOrderMusical(@Param("orderId") Long orderId);
+
+    /**
+     * 获取订单详细
+     * @param orderId
+     * @return
+     */
+    List<StudentPaymentOrderDetail> getOrderDetail(@Param("orderId") Long orderId);
 }
 }

+ 300 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SellOrder.java

@@ -0,0 +1,300 @@
+package com.ym.mec.biz.dal.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.math.BigDecimal;
+import java.util.Date;
+
+@ApiModel(value="com-ym-SellOrder")
+public class SellOrder {
+    @ApiModelProperty(value="")
+    private Integer id;
+
+    /**
+    * 分部id
+    */
+    @ApiModelProperty(value="分部id")
+    private Integer organId;
+
+    /**
+    * 学校id
+    */
+    @ApiModelProperty(value="学校id")
+    private Integer schoolId;
+
+    /**
+    * 交易流水号
+    */
+    @ApiModelProperty(value="交易流水号")
+    private String transNo;
+
+    /**
+     * 交易流水号
+     */
+    @ApiModelProperty(value="订单id")
+    private Long orderId;
+
+    /**
+    * 订单号
+    */
+    @ApiModelProperty(value="订单号")
+    private String orderNo;
+
+    /**
+    * 应付金额
+    */
+    @ApiModelProperty(value="应付金额")
+    private BigDecimal expectAmount;
+
+    /**
+    * 现金支付金额
+    */
+    @ApiModelProperty(value="现金支付金额")
+    private BigDecimal actualAmount;
+
+    /**
+    * 余额支付金额
+    */
+    @ApiModelProperty(value="余额支付金额")
+    private BigDecimal balanceAmount;
+
+    /**
+    * 销售成本
+    */
+    @ApiModelProperty(value="销售成本")
+    private BigDecimal sellCost;
+
+    /**
+     * 销售成本2
+     */
+    @ApiModelProperty(value="销售成本2")
+    private BigDecimal sellCost2;
+
+    /**
+    * 销售类型
+    */
+    @ApiModelProperty(value="销售类型")
+    private String type;
+
+    /**
+    * 商品id
+    */
+    @ApiModelProperty(value="商品id")
+    private Integer goodsId;
+
+    /**
+     * 商品名称
+     */
+    @ApiModelProperty(value="商品名称")
+    private String goodsName;
+
+    /**
+    * 数量
+    */
+    @ApiModelProperty(value="数量")
+    private Integer num;
+
+    /**
+    * 用户id
+    */
+    @ApiModelProperty(value="用户id")
+    private Integer userId;
+
+    /**
+    * 交易方式
+    */
+    @ApiModelProperty(value="交易方式")
+    private String paymentChannel;
+
+    /**
+    * 收款账户
+    */
+    @ApiModelProperty(value="收款账户")
+    private String merNo;
+
+    /**
+    * 交易时间
+    */
+    @ApiModelProperty(value="交易时间")
+    private Date sellTime;
+
+    /**
+    * 创建时间
+    */
+    @ApiModelProperty(value="创建时间")
+    private Date createIme;
+
+    /**
+    * 更新时间
+    */
+    @ApiModelProperty(value="更新时间")
+    private Date updateTime;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getOrganId() {
+        return organId;
+    }
+
+    public void setOrganId(Integer organId) {
+        this.organId = organId;
+    }
+
+    public Integer getSchoolId() {
+        return schoolId;
+    }
+
+    public void setSchoolId(Integer schoolId) {
+        this.schoolId = schoolId;
+    }
+
+    public String getTransNo() {
+        return transNo;
+    }
+
+    public void setTransNo(String transNo) {
+        this.transNo = transNo;
+    }
+
+    public String getOrderNo() {
+        return orderNo;
+    }
+
+    public void setOrderNo(String orderNo) {
+        this.orderNo = orderNo;
+    }
+
+    public BigDecimal getExpectAmount() {
+        return expectAmount;
+    }
+
+    public void setExpectAmount(BigDecimal expectAmount) {
+        this.expectAmount = expectAmount;
+    }
+
+    public BigDecimal getActualAmount() {
+        return actualAmount;
+    }
+
+    public void setActualAmount(BigDecimal actualAmount) {
+        this.actualAmount = actualAmount;
+    }
+
+    public BigDecimal getBalanceAmount() {
+        return balanceAmount;
+    }
+
+    public void setBalanceAmount(BigDecimal balanceAmount) {
+        this.balanceAmount = balanceAmount;
+    }
+
+    public BigDecimal getSellCost() {
+        return sellCost;
+    }
+
+    public void setSellCost(BigDecimal sellCost) {
+        this.sellCost = sellCost;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public Integer getGoodsId() {
+        return goodsId;
+    }
+
+    public void setGoodsId(Integer goodsId) {
+        this.goodsId = goodsId;
+    }
+
+    public Integer getNum() {
+        return num;
+    }
+
+    public void setNum(Integer num) {
+        this.num = num;
+    }
+
+    public Integer getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Integer userId) {
+        this.userId = userId;
+    }
+
+    public String getPaymentChannel() {
+        return paymentChannel;
+    }
+
+    public void setPaymentChannel(String paymentChannel) {
+        this.paymentChannel = paymentChannel;
+    }
+
+    public String getMerNo() {
+        return merNo;
+    }
+
+    public void setMerNo(String merNo) {
+        this.merNo = merNo;
+    }
+
+    public Date getSellTime() {
+        return sellTime;
+    }
+
+    public void setSellTime(Date sellTime) {
+        this.sellTime = sellTime;
+    }
+
+    public Date getCreateIme() {
+        return createIme;
+    }
+
+    public void setCreateIme(Date createIme) {
+        this.createIme = createIme;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public String getGoodsName() {
+        return goodsName;
+    }
+
+    public void setGoodsName(String goodsName) {
+        this.goodsName = goodsName;
+    }
+
+    public BigDecimal getSellCost2() {
+        return sellCost2;
+    }
+
+    public void setSellCost2(BigDecimal sellCost2) {
+        this.sellCost2 = sellCost2;
+    }
+
+    public Long getOrderId() {
+        return orderId;
+    }
+
+    public void setOrderId(Long orderId) {
+        this.orderId = orderId;
+    }
+}

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentPaymentOrderDetail.java

@@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.util.List;
 
 
 /**
 /**
  * 对应数据库表(student_payment_order_detail):
  * 对应数据库表(student_payment_order_detail):
@@ -45,6 +46,8 @@ public class StudentPaymentOrderDetail {
 	//商品成本价
 	//商品成本价
 	private String goodsPrices;
 	private String goodsPrices;
 
 
+	private List<Goods> goodsList;
+
 	public void setId(Long id){
 	public void setId(Long id){
 		this.id = id;
 		this.id = id;
 	}
 	}
@@ -121,4 +124,12 @@ public class StudentPaymentOrderDetail {
 	public void setGoodsPrices(String goodsPrices) {
 	public void setGoodsPrices(String goodsPrices) {
 		this.goodsPrices = goodsPrices;
 		this.goodsPrices = goodsPrices;
 	}
 	}
+
+	public List<Goods> getGoodsList() {
+		return goodsList;
+	}
+
+	public void setGoodsList(List<Goods> goodsList) {
+		this.goodsList = goodsList;
+	}
 }
 }

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderDetailService.java

@@ -70,4 +70,12 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
      * @return
      * @return
      */
      */
     StudentPaymentOrderDetail findApplyOrderMusical(Long orderId);
     StudentPaymentOrderDetail findApplyOrderMusical(Long orderId);
+
+
+    /**
+     * 获取订单详细
+     * @param orderId
+     * @return
+     */
+    List<StudentPaymentOrderDetail> getOrderDetail(Long orderId);
 }
 }

+ 5 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java

@@ -211,4 +211,9 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
     public StudentPaymentOrderDetail findApplyOrderMusical(Long orderId) {
     public StudentPaymentOrderDetail findApplyOrderMusical(Long orderId) {
         return studentPaymentOrderDetailDao.findApplyOrderMusical(orderId);
         return studentPaymentOrderDetailDao.findApplyOrderMusical(orderId);
     }
     }
+
+    @Override
+    public List<StudentPaymentOrderDetail> getOrderDetail(Long orderId) {
+        return studentPaymentOrderDetailDao.getOrderDetail(orderId);
+    }
 }
 }

+ 41 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -862,8 +862,48 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 rechargeDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
                 rechargeDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
                 rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
                 rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
             }
             }
-
             sysUserCashAccountDetailService.insert(paymentDetail);
             sysUserCashAccountDetailService.insert(paymentDetail);
+
+            //销售订单详情
+            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.getOrderDetail(studentPaymentOrder.getId());
+            if (orderDetails.size() > 0) {
+                List<SellOrder> sellOrders = new ArrayList<>();
+                BigDecimal remitFee = studentPaymentOrder.getRemitFee() != null ? studentPaymentOrder.getRemitFee() : BigDecimal.ZERO;
+                BigDecimal balancePaymentAmount = studentPaymentOrder.getBalancePaymentAmount() != null ? studentPaymentOrder.getBalancePaymentAmount() : BigDecimal.ZERO;
+                //总价格
+                BigDecimal totalPrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add).subtract(remitFee);
+                for (StudentPaymentOrderDetail orderDetail : orderDetails) {
+                    if (orderDetail.getType().equals(OrderDetailTypeEnum.MUSICAL) && orderDetail.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
+                        continue;
+                    }
+
+                    BigDecimal goodsTotalPrice = orderDetail.getGoodsList().stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+                    for (Goods goods : orderDetail.getGoodsList()) {
+                        BigDecimal actualAmount = goods.getGroupPurchasePrice().multiply(orderDetail.getPrice().subtract(remitFee)).multiply(studentPaymentOrder.getActualAmount()).divide(goodsTotalPrice.multiply(totalPrice), 2, BigDecimal.ROUND_HALF_UP);
+                        BigDecimal balance = goods.getGroupPurchasePrice().multiply(orderDetail.getPrice().subtract(remitFee)).multiply(balancePaymentAmount).divide(goodsTotalPrice.multiply(totalPrice), 2, BigDecimal.ROUND_HALF_UP);
+                        SellOrder sellOrder = new SellOrder();
+                        sellOrder.setOrganId(studentPaymentOrder.getOrganId());
+                        sellOrder.setSchoolId(musicGroup.getSchoolId());
+                        sellOrder.setTransNo(studentPaymentOrder.getTransNo());
+                        sellOrder.setOrderId(studentPaymentOrder.getId());
+                        sellOrder.setOrderNo(studentPaymentOrder.getOrderNo());
+                        sellOrder.setActualAmount(actualAmount);
+                        sellOrder.setBalanceAmount(balancePaymentAmount);
+                        sellOrder.setExpectAmount(actualAmount.add(balance));
+                        sellOrder.setSellCost(goods.getDiscountPrice());
+                        sellOrder.setSellCost2(goods.getAgreeCostPrice());
+                        sellOrder.setNum(1);
+                        sellOrder.setUserId(studentPaymentOrder.getUserId());
+                        sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
+                        sellOrder.setMerNo(studentPaymentOrder.getMerNos());
+                        sellOrder.setSellTime(studentPaymentOrder.getCreateTime());
+                        sellOrder.setCreateIme(new Date());
+                        sellOrder.setUpdateTime(new Date());
+                        sellOrders.add(sellOrder);
+                    }
+                }
+            }
+
             //三方乐团不发送缴费通知
             //三方乐团不发送缴费通知
             if (musicGroup.getOwnershipType() != null && musicGroup.getOwnershipType() == CooperationOrgan.OwnershipType.OWN) {
             if (musicGroup.getOwnershipType() != null && musicGroup.getOwnershipType() == CooperationOrgan.OwnershipType.OWN) {
                 //发送缴费成功通知(短信 + push)
                 //发送缴费成功通知(短信 + push)

+ 125 - 0
mec-biz/src/main/resources/config/mybatis/SellOrderMapper.xml

@@ -0,0 +1,125 @@
+<?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.ym.mec.biz.dal.dao.SellOrderDao">
+    <resultMap id="SellOrder" type="com.ym.mec.biz.dal.entity.SellOrder">
+        <!--@mbg.generated-->
+        <!--@Table sell_order-->
+        <id column="id_" property="id"/>
+        <result column="organ_id_" property="organId"/>
+        <result column="school_id_" property="schoolId"/>
+        <result column="trans_no_" property="transNo"/>
+        <result column="order_no_" property="orderNo"/>
+        <result column="order_id_" property="orderId"/>
+        <result column="expect_amount_" property="expectAmount"/>
+        <result column="actual_amount_" property="actualAmount"/>
+        <result column="balance_amount_" property="balanceAmount"/>
+        <result column="type_" property="type"/>
+        <result column="goods_id_" property="goodsId"/>
+        <result column="goods_name_" property="goodsName"/>
+        <result column="sell_cost_" property="sellCost"/>
+        <result column="sell_cost2_" property="sellCost2"/>
+        <result column="num_" property="num"/>
+        <result column="user_id_" property="userId"/>
+        <result column="payment_channel_" property="paymentChannel"/>
+        <result column="mer_no_" property="merNo"/>
+        <result column="sell_time_" property="sellTime"/>
+        <result column="create_ime_" property="createIme"/>
+        <result column="update_time_" property="updateTime"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        <!--@mbg.generated-->
+        id_, organ_id_, school_id_, trans_no_,order_id_, order_no_, expect_amount_, actual_amount_,
+        balance_amount_, sell_cost_, sell_cost2_, type_, goods_id_,goods_name_, num_, user_id_, payment_channel_,
+        mer_no_, sell_time_, create_ime_, update_time_
+    </sql>
+    <select id="get" parameterType="java.lang.Integer" resultMap="SellOrder">
+        <!--@mbg.generated-->
+        select
+        <include refid="Base_Column_List"/>
+        from sell_order
+        where id_ = #{id}
+    </select>
+    <delete id="delete" parameterType="java.lang.Integer">
+        <!--@mbg.generated-->
+        delete from sell_order
+        where id_ = #{id}
+    </delete>
+    <insert id="insert" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.biz.dal.entity.SellOrder"
+            useGeneratedKeys="true">
+        <!--@mbg.generated-->
+        insert into sell_order (organ_id_, school_id_, trans_no_,order_id_, order_no_, expect_amount_, actual_amount_,
+        balance_amount_, type_, goods_id_,goods_name_, sell_cost_, sell_cost2_, num_, user_id_, payment_channel_,
+        mer_no_, sell_time_, create_ime_, update_time_)
+        values (#{organId}, #{schoolId}, #{transNo}, #{orderNo},#{orderId}, #{expectAmount}, #{actualAmount},
+        #{balanceAmount}, #{type}, #{goodsId}, #{goodsName}, #{sellCost}, #{sellCost2}, #{num}, #{userId},
+        #{paymentChannel},
+        #{merNo}, #{sellTime}, #{createIme}, #{updateTime})
+    </insert>
+    <update id="update" parameterType="com.ym.mec.biz.dal.entity.SellOrder">
+        <!--@mbg.generated-->
+        update sell_order
+        <set>
+            <if test="organId != null">
+                organ_id_ = #{organId},
+            </if>
+            <if test="schoolId != null">
+                school_id_ = #{schoolId},
+            </if>
+            <if test="transNo != null">
+                trans_no_ = #{transNo},
+            </if>
+            <if test="orderId != null">
+                order_id_ = #{orderId},
+            </if>
+            <if test="orderNo != null">
+                order_no_ = #{orderNo},
+            </if>
+            <if test="expectAmount != null">
+                expect_amount_ = #{expectAmount},
+            </if>
+            <if test="actualAmount != null">
+                actual_amount_ = #{actualAmount},
+            </if>
+            <if test="balanceAmount != null">
+                balance_amount_ = #{balanceAmount},
+            </if>
+            <if test="type != null">
+                type_ = #{type},
+            </if>
+            <if test="goodsId != null">
+                goods_id_ = #{goodsId},
+            </if>
+            <if test="goodsName != null">
+                goods_name_ = #{goodsName},
+            </if>
+            <if test="sellCost != null">
+                sell_cost_ = #{sellCost},
+            </if>
+            <if test="sellCost2 != null">
+                sell_cost2_ = #{sellCost2},
+            </if>
+            <if test="num != null">
+                num_ = #{num},
+            </if>
+            <if test="userId != null">
+                user_id_ = #{userId},
+            </if>
+            <if test="paymentChannel != null">
+                payment_channel_ = #{paymentChannel},
+            </if>
+            <if test="merNo != null">
+                mer_no_ = #{merNo},
+            </if>
+            <if test="sellTime != null">
+                sell_time_ = #{sellTime},
+            </if>
+            <if test="createIme != null">
+                create_ime_ = #{createIme},
+            </if>
+            <if test="updateTime != null">
+                update_time_ = #{updateTime},
+            </if>
+        </set>
+        where id_ = #{id}
+    </update>
+</mapper>

+ 14 - 0
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderDetailMapper.xml

@@ -15,6 +15,14 @@
         <result column="update_time_" property="updateTime"/>
         <result column="update_time_" property="updateTime"/>
         <result column="payment_order_id_" property="paymentOrderId"/>
         <result column="payment_order_id_" property="paymentOrderId"/>
         <result column="kit_group_purchase_type_" property="kitGroupPurchaseType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
         <result column="kit_group_purchase_type_" property="kitGroupPurchaseType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
+        <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
+            <result column="goods_id_" property="id"/>
+            <result column="goods_name_" property="name"/>
+            <result column="group_purchase_price_" property="groupPurchasePrice"/>
+            <result column="discount_price_" property="discountPrice"/>
+            <result column="agree_cost_price_" property="agreeCostPrice"/>
+            <result column="goods_type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
+        </collection>
     </resultMap>
     </resultMap>
 
 
     <!-- 根据主键查询一条记录 -->
     <!-- 根据主键查询一条记录 -->
@@ -163,4 +171,10 @@
     <select id="findApplyOrderMusical" resultMap="StudentPaymentOrderDetail">
     <select id="findApplyOrderMusical" resultMap="StudentPaymentOrderDetail">
         SELECT * FROM student_payment_order_detail WHERE payment_order_id_ = #{orderId} AND type_ = 'MUSICAL' LIMIT 1
         SELECT * FROM student_payment_order_detail WHERE payment_order_id_ = #{orderId} AND type_ = 'MUSICAL' LIMIT 1
     </select>
     </select>
+
+    <select id="getOrderDetail" resultMap="StudentPaymentOrderDetail">
+        SELECT spod.*,g.id_ goods_id_,g.name_ goods_name_,g.group_purchase_price_,g.discount_price_,g.agree_cost_price_,g.type_ good_type_ FROM student_payment_order_detail spod
+                          LEFT JOIN goods g ON FIND_IN_SET(g.id_,spod.goods_id_list_)
+        WHERE spod.payment_order_id_ = #{orderId} AND spod.goods_id_list_ IS NOT null
+    </select>
 </mapper>
 </mapper>