瀏覽代碼

呵呵商城改版part3

Aslee 3 年之前
父節點
當前提交
7cc8557486

+ 15 - 4
src/main/java/com/caimei/controller/OrderApi.java

@@ -13,10 +13,7 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 import java.util.Map;
@@ -211,4 +208,18 @@ public class OrderApi {
         }
         return orderService.collageDetails(collageId, userId);
     }
+
+    @ApiOperation("订单分享")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "orderId", required = false, value = "订单id"),
+            @ApiImplicitParam(name = "userId", required = false, value = "用户id")
+    })
+    @PostMapping("/share")
+    public ResponseJson shareOrder(Integer orderId, Integer userId) {
+        if (null == orderId || null == userId) {
+            return ResponseJson.error("参数异常");
+        }
+        return orderService.shareOrder(orderId, userId);
+    }
+
 }

+ 2 - 0
src/main/java/com/caimei/mapper/CouponMapper.java

@@ -168,4 +168,6 @@ public interface CouponMapper {
      * @return
      */
     ReceiveCouponPo getReceiveCouponById(Integer receiveCouponId);
+
+    Integer getShareRecordCount(Integer orderId);
 }

+ 8 - 0
src/main/java/com/caimei/model/po/CouponSharePo.java

@@ -25,4 +25,12 @@ public class CouponSharePo implements Serializable {
      * 分享得到的好友分享/消费券id
      */
     private Integer shareCouponId;
+    /**
+     * 消费分享券的订单id(唯一)
+     */
+    private Integer orderId;
+    /**
+     * 优惠券类型:1好友分享券,2好友消费券,3消费分享券
+     */
+    private Integer type;
 }

+ 8 - 0
src/main/java/com/caimei/service/OrderService.java

@@ -131,4 +131,12 @@ public interface OrderService {
      * @return
      */
     ResponseJson<CollageDetailsVo> collageDetails(Integer collageId, Integer userId);
+
+    /**
+     * 分享订单
+     * @param orderId
+     * @param userId
+     * @return
+     */
+    ResponseJson shareOrder(Integer orderId, Integer userId);
 }

+ 20 - 0
src/main/java/com/caimei/service/impl/OrderServiceImpl.java

@@ -7,6 +7,7 @@ import com.caimei.mapper.OrderMapper;
 import com.caimei.mapper.ProductMapper;
 import com.caimei.model.ResponseJson;
 import com.caimei.model.po.CmPayShopRecordPo;
+import com.caimei.model.po.CouponSharePo;
 import com.caimei.model.po.ReceiveCouponPo;
 import com.caimei.model.po.UserSearchHistoryPo;
 import com.caimei.model.vo.*;
@@ -459,6 +460,25 @@ public class OrderServiceImpl implements OrderService {
         return ResponseJson.success(collageDetails);
     }
 
+    @Override
+    public ResponseJson shareOrder(Integer orderId, Integer userId) {
+        // 查询该订单是否已有分享记录
+        Integer shareRecordCount = couponMapper.getShareRecordCount(orderId);
+        if (0 == shareRecordCount) {
+            // 只能获得一次优惠券领取资格
+            List<Integer> couponIds = couponMapper.getCurrentCouponIds(5);
+            CouponSharePo couponSharePo = new CouponSharePo();
+            couponSharePo.setShareUserId(userId);
+            couponSharePo.setOrderId(orderId);
+            couponSharePo.setType(3);
+            couponIds.forEach(couponId->{
+                couponSharePo.setShareCouponId(couponId);
+                couponMapper.insertCouponShare(couponSharePo);
+            });
+        }
+        return ResponseJson.success("分享成功");
+    }
+
     /**
      * 支付金额,待付金额
      */

+ 7 - 2
src/main/java/com/caimei/service/impl/OrderSubmitServiceImpl.java

@@ -276,7 +276,6 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                     // 机构税费(单)
                     BigDecimal addedValueTax = new BigDecimal(0);
                     int priceType = 0;
-                    //不含税可开票商品计算税费
                     Integer activityId = productMapper.getActivityIdByProductId(product.getProductId());
                     if (activityId != null && activityId > 0) {
                         //活动阶梯
@@ -297,15 +296,21 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                             productPrice = collageProduct.getPrice();
                         }
                     }
+
                     Integer discount = productMapper.findProductDiscount(product.getProductId(), userId);
                     if (null != discount && discount > 0) {
                         productPrice = MathUtil.div(MathUtil.mul(productPrice, discount), 100);
                     }
-                    //税费
+                    //不含税可开票商品计算税费
                     boolean addTaxFlag = (0 == product.getIncludedTax()) && (1 == product.getInvoiceType() || 2 == product.getInvoiceType());
                     if (addTaxFlag) {
                         addedValueTax = MathUtil.div(MathUtil.mul(productPrice, product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
                         productPrice = MathUtil.add(productPrice, addedValueTax);
+                        BigDecimal normalPrice = product.getNormalPrice();
+                        if (null != normalPrice) {
+                            BigDecimal normalPriceTax = MathUtil.div(MathUtil.mul(normalPrice, product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
+                            product.setNormalPrice(MathUtil.add(normalPrice,normalPriceTax));
+                        }
                         product.setPrice(productPrice);
                     }
                     if (MathUtil.compare(productPrice, BigDecimal.ZERO) == 0) {

+ 2 - 0
src/main/java/com/caimei/service/impl/PayOrderServiceImpl.java

@@ -221,10 +221,12 @@ public class PayOrderServiceImpl implements PayOrderService {
             /*
              * 保存好友消费券赠送记录
              */
+            // 查询好友邀请记录
             CouponSharePo couponShare = couponMapper.getCouponShareId(order.getUserId());
             if (null != couponShare) {
                 List<Integer> couponIds = couponMapper.getCurrentCouponIds(5);
                 couponIds.forEach(couponId->{
+                    couponShare.setType(2);
                     couponShare.setShareCouponId(couponId);
                     couponMapper.insertCouponShare(couponShare);
                     BigDecimal couponAmount = couponMapper.getCouponAmount(couponId);

+ 5 - 2
src/main/resources/mapper/CouponMapper.xml

@@ -12,8 +12,8 @@
         values (#{userId}, #{couponId}, #{couponShareId}, #{source}, #{status}, #{receiveTime}, #{delFlag})
     </insert>
     <insert id="insertCouponShare">
-        insert into cm_hehe_coupon_share (shareUserId, receiveUserId, type, shareCouponId, createTime)
-        values (#{shareUserId}, #{receiveUserId}, 2, #{shareCouponId}, NOW())
+        insert into cm_hehe_coupon_share (shareUserId, receiveUserId, orderId, type, shareCouponId, createTime)
+        values (#{shareUserId}, #{receiveUserId}, #{orderId}, #{type}, #{shareCouponId}, NOW())
     </insert>
     <update id="updateSmsSendCount">
         UPDATE cm_sms_statistics SET sendNum = (sendNum + #{count}) WHERE markId = #{markId}
@@ -241,5 +241,8 @@
         from cm_hehe_receive_coupon
         where id = #{receiveCouponId} and delFlag = 0
     </select>
+    <select id="getShareRecordCount" resultType="java.lang.Integer">
+        select count(*) from cm_hehe_coupon_share where orderId = #{orderId}
+    </select>
 
 </mapper>