package com.stylefeng.guns.modular.system.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.stripe.exception.StripeException; import com.stripe.model.PaymentIntent; import com.stylefeng.guns.modular.system.model.ReceivableVo; import com.stylefeng.guns.modular.system.model.TGoods; import com.stylefeng.guns.modular.system.model.TOrder; import com.stylefeng.guns.modular.system.model.TPrice; import com.stylefeng.guns.modular.system.service.ITGoodsService; import com.stylefeng.guns.modular.system.service.ITOrderService; import com.stylefeng.guns.modular.system.utils.PaymentProcessor; import com.stylefeng.guns.modular.system.utils.Server; import com.stylefeng.guns.modular.system.utils.tips.SuccessTip; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @Controller @Api(tags = "用户端-财务信息") @RequestMapping("/api/tFinance") public class FinanceController { @Autowired private ITOrderService orderService; @Autowired private ITGoodsService goodsService; @ApiOperation(value = "用户端-invocie",notes="用户端-invocie") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "time", value = "时间 (时间 - 时间)", required = false, dataType = "String"), @ApiImplicitParam(name = "id", value = "订单id", required = false, dataType = "Long"), @ApiImplicitParam(name = "state", value = "状态 1支付完 2未支付完", required = false, dataType = "int"), @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "int"), }) @PostMapping(value = "/list") @ResponseBody public Object list(int pageNumber,int pageSize,String time,Long id,Integer state,int userId) { Page receivableVoPage = new Page<>(pageNumber, pageSize); List receivable = orderService.getReceivable(receivableVoPage, time, id, state, userId); receivableVoPage.setRecords(receivable); return new SuccessTip(receivableVoPage); } @ApiOperation(value = "用户端-payImmediately",notes="用户端-payImmediately") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "int"), }) @PostMapping(value = "/payImmediately") @ResponseBody public Object payImmediately(int userId) { // 找出所有未支付完成的订单 List orders = orderService.getNoPayOrder(userId); BigDecimal all = new BigDecimal(0); ArrayList goods = new ArrayList<>(); for (TOrder order : orders) { BigDecimal allTotal = order.getAllTotal(); BigDecimal paid = order.getPaid(); BigDecimal subtract = allTotal.subtract(paid); all = all.add(subtract); TGoods tGoods = goodsService.selectOne(new EntityWrapper().eq("order_id", order.getId())); goods.add(tGoods); } HashMap map = new HashMap<>(); map.put("money",all); map.put("data",goods); return new SuccessTip(map); } @ApiOperation(value = "应收款票据详情",notes="应收款票据详情") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "number", value = "订单id", required = true, dataType = "Long"), }) @GetMapping(value = "/listOfReceivablesInfo") @ResponseBody public Object listOfReceivablesInfo(Long number) { return new SuccessTip(orderService.listOfReceivablesInfo(number)); } @ApiOperation(value = "支付调用",notes="支付调用") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "id", value = "userid", required = true, dataType = "int"), @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"), }) @GetMapping(value = "/payInfo") @ResponseBody public Object payInfo(int id,Long orderId) throws StripeException { PaymentIntent paymentIntent = PaymentProcessor.charge("cus_NvFsNut8zDF9pc", 1L); Server.aaa(); return new SuccessTip(); } }