| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- package modules.deposit;
- import com.alibaba.fastjson.JSONObject;
- import com.jfinal.aop.Before;
- import com.jfinal.aop.Inject;
- import common.interceptor.LoginInterceptor;
- import common.interceptor.empty.EmptyInterface;
- import common.interceptor.role.RequiredRoleInterface;
- import common.model.User;
- import common.utils.http.MyController;
- import common.utils.http.MyRet;
- import modules.user.UserController;
- import modules.user.UserService;
- public class DepositController extends MyController {
- @Inject
- DepositService service;
- @Inject
- UserService userService;
-
- public void hello() {
- renderJson(MyRet.ok(service.hello()));
- }
- // // 微信充值回调地址
- // public void deposited() {
- // String originalBody = HttpKit.readData(getRequest());
- // AppConfig.LOGGER.info("wechat notify {}", originalBody);
- //
- // // 保证每条回调都保存到数据库
- // Deposit deposit = new Deposit();
- // deposit.setCreateTime(System.currentTimeMillis());
- // deposit.setWxOriginal(originalBody);
- // deposit.setIsDeleted(0);
- //
- // // 获取回调通知中的相关数据
- // String wechatPaySerial = getRequest().getHeader("Wechatpay-Serial");
- // String wechatpayNonce = getRequest().getHeader("Wechatpay-Nonce");
- // String wechatSignature = getRequest().getHeader("Wechatpay-Signature");
- // String wechatTimestamp = getRequest().getHeader("Wechatpay-Timestamp");
- //
- // try {
- // // 解析完成
- // Transaction tx = WeChatService.parseTransaction(originalBody, wechatPaySerial, wechatpayNonce, wechatSignature, wechatTimestamp);
- // Json json = Json.getJson();
- // String txJson = json.toJson(tx);
- //
- // // 商户下单时传入的商户系统内部订单号。
- // String orderNo = tx.getOutTradeNo();
- // // 获取库中存放的tx
- // Deposit dbDeposit = service.findDepositByWxOrderNo(orderNo);
- // // 付款数量
- // Integer paymentAmount = tx.getAmount().getTotal();
- // // 状态描述
- // String status = tx.getTradeState().toString();
- //
- // if (dbDeposit == null) {
- // deposit.setWxDecrypted(txJson);
- // deposit.setWxOrderStatus(status);
- // deposit.setDescription("未提前入库的订单,wx:" + tx.getTradeStateDesc());
- // deposit.setAmount(paymentAmount);
- // deposit.save();
- //
- // AppConfig.LOGGER.warn("未提前入库的订单 {}", deposit);
- // } else {
- // deposit = dbDeposit;
- //
- // // 记录解密后的信息
- // deposit.setAmount(paymentAmount);
- // deposit.setWxDecrypted(txJson);
- //
- // // 不要重复处理已存在的充值单号,并且要加款成功
- // if (StrKit.isBlank(deposit.getWxOrderStatus())) {
- // User user = userService.findUserById(deposit.getUserId() + "");
- //
- // // 记录订单状态
- // deposit.setWxOrderStatus(tx.getTradeState().toString());
- //
- // // 有充值信息但是未找到充值者
- // if (user == null) {
- // deposit.setDescription("未找到充值者,wx:" + tx.getTradeStateDesc());
- // } else {
- // // 判断订单状态
- // if (tx.getTradeState() == Transaction.TradeStateEnum.SUCCESS) {
- // // 如果充值成功,对用户进行充值
- // user.setBalance(user.getBalance() + paymentAmount);
- // user.update();
- //
- // deposit.setDescription("用户充值成功,wx:" + tx.getTradeStateDesc());
- // } else {
- // deposit.setDescription("用户充值失败,wx:" + tx.getTradeStateDesc());
- // }
- // }
- // }
- //
- // // 充值记录入库
- // deposit.update();
- //
- // AppConfig.LOGGER.info("入库成功 {}", deposit);
- // }
- //
- // // 成功入库后给微信的回调信息
- // getResponse().setStatus(200);
- // renderText("");
- // } catch (Exception e) {
- // // 回调日志入库
- // if (StrKit.notBlank(wechatPaySerial, wechatpayNonce, wechatSignature, wechatTimestamp)) {
- // deposit.save();
- // }
- //
- // Map<String, Object> responseJson = new HashMap<>();
- // responseJson.put("code", "FAIL");
- // responseJson.put("message", "回调失败 " + e.getMessage());
- //
- // AppConfig.LOGGER.error("回调失败 {}", e.getMessage());
- //
- // // 返回500错误码
- // getResponse().setStatus(500);
- // renderJson(responseJson);
- // }
- // }
-
- // // 创建微信支付订单
- // @Before(LoginInterceptor.class)
- // @EmptyInterface({"amount"})
- // public void create() {
- // JSONObject requestBodyJson = MyController.getJsonModelByRequestAndType(getRequest(), JSONObject.class);
- //
- // // 获取支付数量(分)
- // String amountStr = requestBodyJson.getString("amount");
- // int amount;
- // try {
- // amount = Integer.parseInt(amountStr);
- //
- // if (amount <= 0) {
- // renderJson(MyRet.fail("支付数量(amount)期待是正整数,你传的是: " + amountStr));
- // return;
- // }
- // } catch (Exception e) {
- // renderJson(MyRet.fail("支付数量(amount)格式不正确: " + e.getMessage()));
- // return;
- // }
- //
- // // 获取公网ip地址
- // String ip = IpAddressUtil.getClientIpAddress(this);
- //
- // // 获取当前用户
- // User user = userService.findUserByMobileNumber(getSessionAttr("mobile_number"));
- //
- // // 创建并返回支付链接给前端
- // renderJson(service.createDepositOrder(amount, ip, user.getId()));
- // }
- @Before(LoginInterceptor.class)
- @EmptyInterface({"page_size", "page_number"})
- public void list() {
- JSONObject requestBodyJson = MyController.getJsonModelByRequestAndType(getRequest(), JSONObject.class);
- // 页面大小
- String pageSizeStr = requestBodyJson.getString("page_size");
- int pageSizeInt;
- try {
- pageSizeInt = Integer.parseInt(pageSizeStr);
- if (pageSizeInt <= 0) {
- renderJson(MyRet.fail("页面大小(page_size)期待是正整数,你传的是: " + pageSizeStr));
- return;
- }
- } catch (Exception e) {
- renderJson(MyRet.fail("页面大小(page_size)格式不正确: " + e.getMessage()));
- return;
- }
- // 页码
- String pageNumberStr = requestBodyJson.getString("page_number");
- int pageNumberInt;
- try {
- pageNumberInt = Integer.parseInt(pageNumberStr);
- if (pageNumberInt <= 0) {
- renderJson(MyRet.fail("页码(page_number)期待是正整数,你传的是: " + pageNumberStr));
- return;
- }
- } catch (Exception e) {
- renderJson(MyRet.fail("页码(page_number)格式不正确: " + e.getMessage()));
- return;
- }
- User user = userService.findUserByMobileNumber(getSessionAttr("mobile_number"));
- renderJson(service.list(pageNumberInt, pageSizeInt, user.getId()));
- }
- @Before(LoginInterceptor.class)
- @RequiredRoleInterface({UserController.ROLE_CHECK_ADMIN, UserController.ROLE_SUPER_ADMIN})
- @EmptyInterface({"page_size", "page_number"})
- public void listByAdmin() {
- JSONObject requestBodyJson = MyController.getJsonModelByRequestAndType(getRequest(), JSONObject.class);
- // 页面大小
- String pageSizeStr = requestBodyJson.getString("page_size");
- int pageSizeInt;
- try {
- pageSizeInt = Integer.parseInt(pageSizeStr);
- if (pageSizeInt <= 0) {
- renderJson(MyRet.fail("页面大小(page_size)期待是正整数,你传的是: " + pageSizeStr));
- return;
- }
- } catch (Exception e) {
- renderJson(MyRet.fail("页面大小(page_size)格式不正确: " + e.getMessage()));
- return;
- }
- // 页码
- String pageNumberStr = requestBodyJson.getString("page_number");
- int pageNumberInt;
- try {
- pageNumberInt = Integer.parseInt(pageNumberStr);
- if (pageNumberInt <= 0) {
- renderJson(MyRet.fail("页码(page_number)期待是正整数,你传的是: " + pageNumberStr));
- return;
- }
- } catch (Exception e) {
- renderJson(MyRet.fail("页码(page_number)格式不正确: " + e.getMessage()));
- return;
- }
- renderJson(service.list(pageNumberInt, pageSizeInt, null));
- }
- }
|