无关风月
2024-09-14 3f481005be717250a2ea87ff9367aa84d6a3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.xinquan.order.controller.client;
 
 
import com.xinquan.common.core.domain.R;
import com.xinquan.order.api.domain.Order;
import com.xinquan.order.domain.vo.ClientPlaceOrderVO;
import com.xinquan.order.service.OrderService;
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 java.math.BigDecimal;
import java.util.List;
 
/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2024-08-21
 */
@RestController
@RequiredArgsConstructor
@Api(tags = {"用户端-订单相关接口"})
@RequestMapping("/client/order/order")
public class ClientOrderController {
 
    private OrderService orderService;
    /**
     * 根据邀请用户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=课程", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "receiverId", value = "被赠送课程APP用户id", dataType = "Long", required = false),
            @ApiImplicitParam(name = "balanceFlag", value = "是否使用余额抵扣 1=是 2=否", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "payType", value = "支付方式 1=微信 2=支付宝", dataType = "Integer", required = true)
    })
    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);
        }
    }
}