| | |
| | | package com.xinquan.order.controller.client; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xinquan.common.core.domain.R; |
| | | import com.xinquan.common.core.utils.page.BeanUtils; |
| | | import com.xinquan.common.core.utils.page.CollUtils; |
| | | import com.xinquan.common.core.utils.page.PageDTO; |
| | | import com.xinquan.common.core.web.domain.BaseModel; |
| | | import com.xinquan.common.security.utils.SecurityUtils; |
| | | import com.xinquan.course.api.feign.RemoteCourseService; |
| | | import com.xinquan.meditation.api.domain.Meditation; |
| | | import com.xinquan.meditation.api.feign.RemoteMeditationService; |
| | | import com.xinquan.order.api.domain.Order; |
| | | import com.xinquan.order.domain.OrderPaymentRecord; |
| | | import com.xinquan.order.domain.vo.ClientPlaceOrderVO; |
| | | import com.xinquan.order.service.OrderPaymentRecordService; |
| | | import com.xinquan.order.service.OrderService; |
| | | import com.xinquan.course.api.domain.OrderCourseVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2024-08-21 |
| | | */ |
| | | @RestController |
| | | @RequiredArgsConstructor |
| | | @Api(tags = {"用户端-订单相关接口"}) |
| | | @RequestMapping("/client/order/order") |
| | | public class ClientOrderController { |
| | | |
| | | @Resource |
| | | private OrderService orderService; |
| | | @Resource |
| | | private OrderPaymentRecordService orderPaymentRecordService; |
| | | @Resource |
| | | private RemoteCourseService remoteCourseService; |
| | | @Resource |
| | | private RemoteMeditationService remoteMeditationService; |
| | | @PostMapping("/myOrderCourse") |
| | | @ApiOperation(value = "我的已购",tags = "我的已购") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "state", value = "1冥想 2课程", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true) |
| | | }) |
| | | public R<PageDTO<OrderCourseVO>> balanceList(Integer state, Integer pageCurr, Integer pageSize) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId==0)return R.tokenError("登录失效"); |
| | | Page<Order> page = orderService.lambdaQuery() |
| | | .eq(Order::getAppUserId, userId) |
| | | .eq(Order::getOrderFrom, state) |
| | | .ne(Order::getPaymentStatus, 3) |
| | | .orderByDesc(BaseModel::getCreateTime).page(new Page<>(pageCurr, pageSize)); |
| | | if (CollUtils.isEmpty(page.getRecords())){ |
| | | PageDTO<OrderCourseVO> empty = PageDTO.empty(page); |
| | | return R.ok(empty); |
| | | } |
| | | PageDTO<OrderCourseVO> res = PageDTO.of(page, OrderCourseVO.class); |
| | | for (OrderCourseVO orderCourseVO : res.getList()) { |
| | | switch (orderCourseVO.getChargeType()){ |
| | | case 1: |
| | | Meditation data1 = remoteMeditationService.getMeditationById(orderCourseVO.getBusinessId()).getData(); |
| | | orderCourseVO.setCourseTitle(data1.getMeditationTitle()); |
| | | orderCourseVO.setDescription(data1.getCoverDescription()); |
| | | orderCourseVO.setCoverUrl(data1.getCoverUrl()); |
| | | orderCourseVO.setGeneralPrice(data1.getGeneralPrice()); |
| | | orderCourseVO.setIosPrice(data1.getIosPrice()); |
| | | orderCourseVO.setCount(data1.getRealLearnedNum()+data1.getVirtualLearnedNum()); |
| | | break; |
| | | case 2: |
| | | OrderCourseVO data = remoteCourseService.getCourseCategoryList(orderCourseVO).getData(); |
| | | BeanUtils.copyProperties(data, orderCourseVO); |
| | | break; |
| | | |
| | | } |
| | | |
| | | } |
| | | return R.ok(res); |
| | | } |
| | | /** |
| | | * 根据邀请用户ids 查询对应佣金 |
| | | */ |
| | | @GetMapping("/getCommissionByUserIds/{userIds}") |
| | | public R<String> getCommissionByUserIds(@PathVariable("userIds") String userIds) { |
| | | String[] split = userIds.split(","); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | for (String s : split) { |
| | | List<Order> list = orderService.lambdaQuery().eq(Order::getAppUserId, s) |
| | | .eq(Order::getPaymentStatus, 2).list(); |
| | | BigDecimal commissionAmount = list.stream() |
| | | .filter(t -> t.getCommissionAmount()!= null) |
| | | .map(Order::getCommissionAmount) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | stringBuilder.append(commissionAmount).append(","); |
| | | } |
| | | StringBuilder stringBuilder1 = stringBuilder.deleteCharAt(stringBuilder.length() - 1); |
| | | return R.ok(stringBuilder1.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 创建待支付订单 |
| | | * |
| | | * @param targetId 目标id |
| | | * @param orderFrom 订单来源 1=冥想音频 2=课程 |
| | | * @param receiverId 被赠送课程APP用户id |
| | | * @param balanceFlag 是否使用余额抵扣 1=是 2=否 |
| | | * @param payType 支付方式 1=微信 2=支付宝 |
| | | * @return 下单返回数据视图对象 |
| | | * @see com.xinquan.order.domain.vo.ClientPlaceOrderVO |
| | | */ |
| | | @PostMapping("/placeOrder") |
| | | @ApiOperation(value = "创建待支付订单", notes = "微信|支付宝") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "targetId", value = "目标id", dataType = "Long", required = true), |
| | | @ApiImplicitParam(name = "orderFrom", value = "订单来源 1=冥想音频 2=课程 3=购买会员 4充值", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(name = "receiverId", value = "被赠送课程APP用户id", dataType = "Long", required = false), |
| | | @ApiImplicitParam(name = "balanceFlag", value = "是否使用余额抵扣 1=是 2=否", dataType = "Integer", required = false), |
| | | @ApiImplicitParam(name = "payType", value = "支付方式 1=微信 2=支付宝", dataType = "Integer", required = false) |
| | | }) |
| | | public R<ClientPlaceOrderVO> placeOrder( |
| | | @RequestParam(value = "targetId") Long targetId, |
| | | @RequestParam(value = "orderFrom") Integer orderFrom, |
| | | @RequestParam(value = "receiverId", required = false) Long receiverId, |
| | | @RequestParam(value = "balanceFlag") Integer balanceFlag, |
| | | @RequestParam(value = "payType") Integer payType) { |
| | | try { |
| | | return R.ok( |
| | | orderService.placeOrder(targetId, orderFrom, receiverId, |
| | | balanceFlag, payType)); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | @ResponseBody |
| | | @PostMapping("/testCallback") |
| | | public void wechatPaymentGameCallback(HttpServletRequest request, HttpServletResponse response) throws Exception { |
| | | System.err.println("进入回调"); |
| | | |
| | | } |
| | | /** |
| | | * 远程调用 根据用户id 查询充值金额 |
| | | */ |
| | | @PostMapping("/queryChargeByUserId/{userId}") |
| | | public R<String> queryChargeByUserId(@PathVariable("userId") Long userId) { |
| | | BigDecimal reduce = orderService.lambdaQuery() |
| | | .eq(Order::getAppUserId, userId) |
| | | .eq(Order::getOrderFrom, 4) |
| | | .eq(Order::getPaymentStatus, 2) |
| | | .list().stream().filter(t -> t.getTotalAmount() != null) |
| | | .map(Order::getTotalAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | return R.ok(reduce.toString()); |
| | | } |
| | | /** |
| | | * 远程调用 根据订单id 查询订单明细 |
| | | */ |
| | | @PostMapping("/getOrderById/{orderId}") |
| | | public R<Order> getOrderById(@PathVariable("orderId") Long orderId) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId==0)return R.tokenError("登录失效"); |
| | | Order one = orderService.lambdaQuery() |
| | | .eq(Order::getId, orderId).one(); |
| | | if (one!=null){ |
| | | OrderPaymentRecord two = orderPaymentRecordService.lambdaQuery() |
| | | .eq(OrderPaymentRecord::getOrderId, orderId) |
| | | .ne(OrderPaymentRecord::getPaymentType, 4) |
| | | .eq(OrderPaymentRecord::getPaymentStatus, 2).one(); |
| | | if (two==null){ |
| | | one.setRemark("余额支付"); |
| | | }else{ |
| | | switch (two.getPaymentType()){ |
| | | case 1: |
| | | one.setRemark("微信支付"); |
| | | break; |
| | | case 2: |
| | | one.setRemark("支付宝支付"); |
| | | break; |
| | | case 3: |
| | | one.setRemark("苹果内购"); |
| | | } |
| | | one.setPayOrderNo(two.getPayOrderNo()); |
| | | } |
| | | if (one.getCommissionId()!=null){ |
| | | switch (one.getOrderFrom()){ |
| | | case 1: |
| | | one.setRemark("购买疗愈"); |
| | | break; |
| | | case 2: |
| | | one.setRemark("购买课程"); |
| | | break; |
| | | case 3: |
| | | one.setRemark("购买会员"); |
| | | case 4: |
| | | one.setRemark("充值"); |
| | | } |
| | | } |
| | | |
| | | return R.ok(one); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |