dcs 1 mesiac pred
rodič
commit
de05f79de7

+ 48 - 4
virgo.api/src/main/java/com/bosshand/virgo/api/workark/controller/OrderInfoController.java

@@ -2,9 +2,13 @@ package com.bosshand.virgo.api.workark.controller;
 
 
 import com.bosshand.virgo.api.workark.model.OrderInfo;
+import com.bosshand.virgo.api.workark.model.Proce;
+import com.bosshand.virgo.api.workark.model.Product;
 import com.bosshand.virgo.api.workark.model.ProductCoupon;
 import com.bosshand.virgo.api.workark.service.OrderInfoService;
+import com.bosshand.virgo.api.workark.service.ProceService;
 import com.bosshand.virgo.api.workark.service.ProductCouponService;
+import com.bosshand.virgo.api.workark.service.ProductService;
 import com.bosshand.virgo.core.response.Response;
 import com.bosshand.virgo.core.utils.ContextUtils;
 import com.bosshand.virgo.core.utils.StringUtil;
@@ -29,6 +33,12 @@ public class OrderInfoController {
     @Autowired
     ProductCouponService productCouponService;
 
+    @Autowired
+    ProductService productService;
+
+    @Autowired
+    ProceService proceService;
+
     @ApiOperation("创建订单")
     @RequestMapping(value = "/create/{productId}/{payOrganizationId}/{productCouponIds}", method = RequestMethod.GET)
     public Response createOrderByProductId(@PathVariable long productId, @PathVariable long payOrganizationId, @PathVariable String productCouponIds) {
@@ -64,7 +74,8 @@ public class OrderInfoController {
                 }
             }
         }
-        return Response.ok(orderInfoService.calculateDetails(productId, productCouponList));
+        Product product = productService.get(productId);
+        return Response.ok(orderInfoService.calculateDetails(product.getPrice(), productCouponList));
     }
 
     @ApiOperation("修改价格")
@@ -130,9 +141,42 @@ public class OrderInfoController {
     }
 
     @ApiOperation("创建过程订单")
-    @RequestMapping(value = "/create/proce/{proceId}/{payOrganizationId}", method = RequestMethod.GET)
-    public Response createOrderByProceId(@PathVariable long proceId, @PathVariable long payOrganizationId) {
-        return Response.ok(orderInfoService.createOrderByProceId(proceId, payOrganizationId));
+    @RequestMapping(value = "/create/proce/{proceId}/{payOrganizationId}/{productCouponIds}", method = RequestMethod.GET)
+    public Response createOrderByProceId(@PathVariable long proceId, @PathVariable long payOrganizationId, @PathVariable String productCouponIds) {
+        long userId = ContextUtils.getUserContext().getUserId();
+        List<ProductCoupon> productCouponList = new ArrayList<>();
+        if (!StringUtil.equals("-1", productCouponIds)) {
+            String[] ids = productCouponIds.split(",");
+            for (int i = 0; i < ids.length; i++) {
+                ProductCoupon productCoupon = productCouponService.getUserId(Long.parseLong(ids[i]), userId);
+                if (productCoupon == null) {
+                    return Response.fail(20000, "当前用户下没有这个优惠券!");
+                } else {
+                    productCouponList.add(productCoupon);
+                }
+            }
+        }
+        return Response.ok(orderInfoService.createOrderByProceId(proceId, payOrganizationId, productCouponList));
+    }
+
+    @ApiOperation("计算过程价格")
+    @RequestMapping(value = "/calculateProcePrice/{proceId}/{productCouponIds}", method = RequestMethod.GET)
+    public Response calculateProcePrice(@PathVariable long proceId, @PathVariable String productCouponIds) {
+        long userId = ContextUtils.getUserContext().getUserId();
+        List<ProductCoupon> productCouponList = new ArrayList<>();
+        if (!StringUtil.equals("-1", productCouponIds)) {
+            String[] ids = productCouponIds.split(",");
+            for (int i = 0; i < ids.length; i++) {
+                ProductCoupon productCoupon = productCouponService.getUserId(Long.parseLong(ids[i]), userId);
+                if (productCoupon == null) {
+                    return Response.fail(20000, "当前用户下没有这个优惠券!");
+                } else {
+                    productCouponList.add(productCoupon);
+                }
+            }
+        }
+        Proce proce = proceService.get(proceId);
+        return Response.ok(orderInfoService.calculateDetails(proce.getTotalFee(), productCouponList));
     }
 
 }

+ 27 - 1
virgo.api/src/main/java/com/bosshand/virgo/api/workark/model/Proce.java

@@ -80,10 +80,20 @@ public class Proce {
     private BigDecimal totalFee;
 
     /**
-     * 支付状态
+     * 过程订单编号
+     */
+    private String proceOrderNo;
+
+    /**
+     * 过程订单支付状态
      */
     private String payStatus;
 
+    /**
+     * 过程订单支付发票
+     */
+    private Invoice invoice;
+
     public long getId() {
         return id;
     }
@@ -212,6 +222,14 @@ public class Proce {
         this.totalFee = totalFee;
     }
 
+    public String getProceOrderNo() {
+        return proceOrderNo;
+    }
+
+    public void setProceOrderNo(String proceOrderNo) {
+        this.proceOrderNo = proceOrderNo;
+    }
+
     public String getPayStatus() {
         return payStatus;
     }
@@ -219,4 +237,12 @@ public class Proce {
     public void setPayStatus(String payStatus) {
         this.payStatus = payStatus;
     }
+
+    public Invoice getInvoice() {
+        return invoice;
+    }
+
+    public void setInvoice(Invoice invoice) {
+        this.invoice = invoice;
+    }
 }

+ 25 - 13
virgo.api/src/main/java/com/bosshand/virgo/api/workark/service/OrderInfoService.java

@@ -91,7 +91,7 @@ public class OrderInfoService {
         }
 
         //计算价格
-        BigDecimal price = calculatePrice(productId, productCouponList);
+        BigDecimal price = calculatePrice(product.getPrice(), productCouponList);
 
         //生成订单
         OrderInfo orderInfo = new OrderInfo();
@@ -212,15 +212,13 @@ public class OrderInfoService {
             Proce proce = proceDao.get(orderInfo.getProceId());
             if(!OrderStatus.SUCCESS.getType().equals(proce.getPayStatus())){
                 proce.setPayStatus(orderStatus.getType());
+                proce.setProceOrderNo(orderNo);
                 proceDao.updatePayStatus(proce);
             }
         }
     }
 
-    public JSONObject calculateDetails(long productId, List<ProductCoupon> productCouponList) {
-        // 获取商品信息
-        Product product = productDao.get(productId);
-        BigDecimal price = product.getPrice();
+    public JSONObject calculateDetails(BigDecimal price, List<ProductCoupon> productCouponList) {
         JSONObject json = new JSONObject();
         if (productCouponList.size() > 0) {
             JSONArray ja = new JSONArray();
@@ -233,20 +231,17 @@ public class OrderInfoService {
             }
             json.put("productCoupon", ja);
         }
-        json.put("totalFee", calculatePrice(productId, productCouponList));
+        json.put("totalFee", calculatePrice(price, productCouponList));
         return json;
     }
 
     /**
      * 计算最终价格
-     * @param productId
+     * @param price
      * @param productCouponList
      * @return
      */
-    public BigDecimal calculatePrice(long productId, List<ProductCoupon> productCouponList) {
-        // 获取商品信息
-        Product product = productDao.get(productId);
-        BigDecimal price = product.getPrice();
+    public BigDecimal calculatePrice(BigDecimal price, List<ProductCoupon> productCouponList) {
 
         BigDecimal lastPrice = price;
 
@@ -372,13 +367,29 @@ public class OrderInfoService {
     }
 
     @Transactional
-    public OrderInfo createOrderByProceId(long proceId, long payOrganizationId) {
+    public OrderInfo createOrderByProceId(long proceId, long payOrganizationId, List<ProductCoupon> productCouponList) {
 
         long userId = ContextUtils.getUserContext().getUserId();
 
         //获取过程支付信息
         Proce proce = proceDao.get(proceId);
 
+        String productCouponIds = null;
+
+        if (productCouponList.size() > 0) {
+            List<String> ids = new ArrayList();
+            for (ProductCoupon productCoupon : productCouponList) {
+                ids.add(String.valueOf(productCoupon.getId()));
+                // 优惠券使用
+                productCoupon.setState(2);
+                productCouponDao.update(productCoupon);
+            }
+            productCouponIds = String.join(",", ids);
+        }
+
+        //计算价格
+        BigDecimal price = calculatePrice(proce.getTotalFee(), productCouponList);
+
         Product product = productDao.get(proce.getProductId());
 
         //生成订单
@@ -386,10 +397,11 @@ public class OrderInfoService {
         orderInfo.setProceId(proce.getId());
         orderInfo.setTitle(proce.getName());
         orderInfo.setOrderNo(OrderNoUtils.getOrderNo()); //订单号
-        orderInfo.setTotalFee(proce.getTotalFee()); //元
+        orderInfo.setTotalFee(price); //元
         orderInfo.setOrderStatus(OrderStatus.NOTPAY.getType());
         orderInfo.setUserId(userId);
         orderInfo.setProductId(product.getId());
+        orderInfo.setProductCouponIds(productCouponIds);
         orderInfo.setOrganizationId(product.getOrganizationId());
         orderInfo.setProductLevelId(-1);
         orderInfo.setPayOrganizationId(payOrganizationId);

+ 34 - 9
virgo.api/src/main/resources/mapper/ProceMapper.xml

@@ -20,31 +20,56 @@
         <result column="status" property="status"/>
         <result column="type" property="type"/>
         <result column="totalFee" property="totalFee"/>
+        <result column="proceOrderNo" property="proceOrderNo"/>
         <result column="payStatus" property="payStatus"/>
+        <collection property="invoice" ofType="com.bosshand.virgo.api.workark.model.Invoice" resultMap="com.bosshand.virgo.api.workark.dao.InvoiceDao.result" columnPrefix="invoice_"/>
     </resultMap>
 
+    <sql id="query">
+        select a.*,
+               b.id                           as invoice_id,
+               b.invoiceModelId               as invoice_invoiceModelId,
+               b.organizationId               as invoice_organizationId,
+               b.userId                       as invoice_userId,
+               b.createTime                   as invoice_createTime,
+               b.updateTime                   as invoice_updateTime,
+               b.orderNo                      as invoice_orderNo,
+               b.type                         as invoice_type,
+               b.name                         as invoice_name,
+               b.taxpayerIdentificationNumber as invoice_taxpayerIdentificationNumber,
+               b.address                      as invoice_address,
+               b.phone                        as invoice_phone,
+               b.bankAccount                  as invoice_bankAccount,
+               b.bankAccountNumber            as invoice_bankAccountNumber,
+               b.content                      as invoice_content,
+               b.amount                       as invoice_amount,
+               b.file                         as invoice_file,
+               b.state                        as invoice_state
+        from workark_proce a left join workark_invoice b on a.proceOrderNo = b.orderNo
+    </sql>
+
     <select id="get" resultMap="result">
-        select * from workark_proce where id = #{id}
+        <include refid="query" /> where a.id = #{id}
     </select>
 
     <select id="getParentId" resultMap="result">
-        select * from workark_proce where parentId = #{parentId} order by sequence
+        <include refid="query" /> where a.parentId = #{parentId} order by a.sequence
     </select>
 
     <select id="getList" resultMap="result">
-        select * from workark_proce where orderId = #{orderId} order by sequence
+        <include refid="query" /> where a.orderId = #{orderId} order by a.sequence
     </select>
 
     <select id="getRoot" resultMap="result">
-        select * from workark_proce where parentId = -1 and orderId = #{orderId} order by sequence
+        <include refid="query" /> where a.parentId = -1 and a.orderId = #{orderId} order by a.sequence
     </select>
 
-    <insert id="save" parameterType="com.bosshand.virgo.api.workark.model.ProceModel" useGeneratedKeys="true" keyProperty="id">
+    <insert id="save" parameterType="com.bosshand.virgo.api.workark.model.Proce" useGeneratedKeys="true" keyProperty="id">
         INSERT into workark_proce(name, parentId, orderId, productId, productLevelId, sequence, attachment, attachmentNumber, attachmentContent, roleId, remark, type, totalFee)
         values(#{name}, #{parentId}, #{orderId}, #{productId}, #{productLevelId}, #{sequence}, #{attachment}, #{attachmentNumber}, #{attachmentContent}, #{roleId}, #{remark}, #{type}, #{totalFee})
     </insert>
 
-    <update id="update" parameterType="com.bosshand.virgo.api.workark.model.ProceModel">
+    <update id="update" parameterType="com.bosshand.virgo.api.workark.model.Proce">
         UPDATE workark_proce
         <trim prefix="set" suffixOverrides=",">
             <if test="name!=null">name=#{name},</if>
@@ -64,15 +89,15 @@
         WHERE id=#{id}
     </update>
 
-    <update id="updateStatus" parameterType="com.bosshand.virgo.api.workark.model.ProceModel">
+    <update id="updateStatus" parameterType="com.bosshand.virgo.api.workark.model.Proce">
         UPDATE workark_proce set status = #{status} WHERE id in
         <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
             #{id}
         </foreach>
     </update>
 
-    <update id="updatePayStatus" parameterType="com.bosshand.virgo.api.workark.model.ProceModel">
-        UPDATE workark_proce set payStatus = #{payStatus} WHERE id = #{id}
+    <update id="updatePayStatus" parameterType="com.bosshand.virgo.api.workark.model.Proce">
+        UPDATE workark_proce set proceOrderNo = #{proceOrderNo}, payStatus = #{payStatus} WHERE id = #{id}
     </update>
 
     <delete id="delete">