|
@@ -0,0 +1,129 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
|
|
+ *
|
|
|
+ * https://www.mall4j.com/
|
|
|
+ *
|
|
|
+ * 未经允许,不可做商业用途!
|
|
|
+ *
|
|
|
+ * 版权所有,侵权必究!
|
|
|
+ */
|
|
|
+
|
|
|
+package com.qs.mp.web.controller.api.channel;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.qs.mp.channel.domain.Channel;
|
|
|
+import com.qs.mp.channel.domain.ChannelBankCard;
|
|
|
+import com.qs.mp.channel.domain.ChannelCart;
|
|
|
+import com.qs.mp.channel.domain.ChannelWithdraw;
|
|
|
+import com.qs.mp.channel.domain.param.ChannelCartParam;
|
|
|
+import com.qs.mp.channel.domain.param.ChannelWithdrawParam;
|
|
|
+import com.qs.mp.channel.domain.vo.ChannelCartVO;
|
|
|
+import com.qs.mp.channel.domain.vo.ChannelOrderSettleVO;
|
|
|
+import com.qs.mp.channel.service.IChannelBankCardService;
|
|
|
+import com.qs.mp.channel.service.IChannelCartService;
|
|
|
+import com.qs.mp.channel.service.IChannelService;
|
|
|
+import com.qs.mp.channel.service.IChannelWithdrawService;
|
|
|
+import com.qs.mp.common.core.domain.AjaxResult;
|
|
|
+import com.qs.mp.common.core.redis.RedisCache;
|
|
|
+import com.qs.mp.common.domain.param.BatchLongIdsParam;
|
|
|
+import com.qs.mp.utils.SecurityUtils;
|
|
|
+import com.qs.mp.web.controller.common.BaseApiController;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import javax.validation.Valid;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import ma.glasnost.orika.MapperFacade;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/v1/mp/channel")
|
|
|
+@Api(tags = "渠道提现接口")
|
|
|
+@AllArgsConstructor
|
|
|
+public class ChannelWithdrawController extends BaseApiController {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IChannelWithdrawService channelWithdrawService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IChannelService channelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IChannelBankCardService channelBankCardService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
+ private final String CHANNEL_WITHDRAW_CACHE_KEY = "channel_settle_withdraw_";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 渠道提现计算手续费
|
|
|
+ */
|
|
|
+ @PostMapping("/withdraw/settle")
|
|
|
+ @ApiOperation(value = "提现" , notes = "提现计费")
|
|
|
+ public AjaxResult settle(@Valid @RequestBody ChannelWithdrawParam param) {
|
|
|
+ Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
+ ChannelWithdraw channelWithdraw = new ChannelWithdraw();
|
|
|
+ channelWithdraw.setMoney(param.getMoney());
|
|
|
+ channelWithdraw.setChargeAmt(0);
|
|
|
+ channelWithdraw.setUserName(param.getUserName());
|
|
|
+ channelWithdraw.setCardNo(param.getCardNo());
|
|
|
+ channelWithdraw.setBranchName(param.getBranchName());
|
|
|
+
|
|
|
+ // 缓存订单结算对象
|
|
|
+ redisCache.setCacheObject(CHANNEL_WITHDRAW_CACHE_KEY + channelId, channelWithdraw, 1, TimeUnit.MINUTES);
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("chargeAmt", channelWithdraw.getChargeAmt());
|
|
|
+ return AjaxResult.success(jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 渠道提现申请提交
|
|
|
+ */
|
|
|
+ @PostMapping("/withdraw/apply")
|
|
|
+ @ApiOperation(value = "提交提现申请" , notes = "确认服务费后提交")
|
|
|
+ public AjaxResult apply(@RequestBody ChannelWithdrawParam param) {
|
|
|
+ Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
+ ChannelWithdraw channelWithdraw = redisCache.getCacheObject(CHANNEL_WITHDRAW_CACHE_KEY + channelId);
|
|
|
+ if (null == channelWithdraw) {
|
|
|
+ return AjaxResult.error("申请已过期,请重新提交");
|
|
|
+ }
|
|
|
+ Channel channel = channelService.getById(channelId);
|
|
|
+ if (channelWithdraw.getMoney() > channel.getMoney() ) {
|
|
|
+ return AjaxResult.error("提现金额超出账户余额");
|
|
|
+ }
|
|
|
+
|
|
|
+ channelWithdraw.setChannelId(channelId);
|
|
|
+ channelWithdraw.setLogMoney(channel.getMoney());
|
|
|
+
|
|
|
+ channelWithdrawService.apply(channel, channelWithdraw);
|
|
|
+
|
|
|
+ // 缓存提现结算对象
|
|
|
+ redisCache.deleteObject(CHANNEL_WITHDRAW_CACHE_KEY + channelId);
|
|
|
+
|
|
|
+ return AjaxResult.success("提现申请成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 渠道提现查询银行卡
|
|
|
+ */
|
|
|
+ @PostMapping("/withdraw/card/query")
|
|
|
+ @ApiOperation(value = "查询银行卡" , notes = "查询银行卡信息")
|
|
|
+ public AjaxResult queryCard(@RequestBody ChannelWithdrawParam param) {
|
|
|
+ Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
+ ChannelBankCard bankCard = channelBankCardService.getOne(new LambdaQueryWrapper<ChannelBankCard>()
|
|
|
+ .eq(ChannelBankCard::getChannelId, channelId));
|
|
|
+
|
|
|
+ return AjaxResult.success(bankCard);
|
|
|
+ }
|
|
|
+}
|