| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package com.ruoyi.app.pay;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.ruoyi.app.pay.dto.MerchantPayMethodSaveDto;
- import com.ruoyi.common.annotation.Anonymous;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.exception.ServiceException;
- import com.ruoyi.common.utils.MessageUtils;
- import com.ruoyi.system.domain.InfoUser;
- import com.ruoyi.system.mapper.InfoUserMapper;
- import com.ruoyi.system.service.PaymentMethodGateService;
- import com.ruoyi.system.utils.Auth;
- import com.ruoyi.system.utils.JwtUtil;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PutMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestHeader;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * 骑手闪送收款方式接口(031,骑手 App 接入;本期无前端页面)。
- * 未设置(NULL)=接受平台开放的全部方式,避免新单无人可见;
- * 抢单列表按此选择过滤订单支付方式(见 FlashDeliveryApplicationService.riderOrdersQuery)。
- */
- @RestController
- @RequestMapping("/system/riderFlashPayMethods")
- @Anonymous
- public class RiderFlashPayMethodController extends BaseController {
- private final PaymentMethodGateService gateService;
- private final InfoUserMapper userMapper;
- public RiderFlashPayMethodController(PaymentMethodGateService gateService, InfoUserMapper userMapper) {
- this.gateService = gateService;
- this.userMapper = userMapper;
- }
- /** 设置数据:available=平台闪送维度开放方式;selected=骑手当前选择(NULL 视为全部)。 */
- @Auth(session = true)
- @GetMapping
- public AjaxResult get(@RequestHeader String token) {
- InfoUser rider = requireRider(token);
- List<PaymentMethodGateService.PayMethodOption> available =
- gateService.listAvailable(PaymentMethodGateService.GateScope.RIDER_FLASH, null, null);
- List<String> selected = new ArrayList<>();
- String csv = rider.getFlashPayMethods();
- if (csv != null && !csv.trim().isEmpty()) {
- for (String part : csv.split(",")) {
- if (!part.trim().isEmpty()) selected.add(part.trim());
- }
- }
- Map<String, Object> data = new HashMap<>();
- data.put("available", available);
- data.put("selected", selected);
- return success(data);
- }
- /** 保存选择:空数组=清空回落"平台开放全部";值域校验闪送维度组合法。 */
- @Auth(session = true)
- @PutMapping
- public AjaxResult save(@RequestHeader String token, @RequestBody MerchantPayMethodSaveDto dto) {
- InfoUser rider = requireRider(token);
- List<String> groups = PaymentMethodGateService.groupsOf(PaymentMethodGateService.GateScope.RIDER_FLASH);
- String csv = null;
- if (dto != null && dto.getMethodCodes() != null && !dto.getMethodCodes().isEmpty()) {
- for (String code : dto.getMethodCodes()) {
- if (code == null || !groups.contains(code.trim())) {
- throw new ServiceException(MessageUtils.message("pay.method.config.invalid"));
- }
- }
- csv = String.join(",", dto.getMethodCodes());
- }
- userMapper.update(null, new UpdateWrapper<InfoUser>()
- .eq("user_id", rider.getUserId())
- .set("flash_pay_methods", csv)
- .set("update_time", new Date()));
- return success();
- }
- /** 仅 userType=2 骑手可设置;非骑手按无权限处理。 */
- private InfoUser requireRider(String token) {
- Long userId = Long.valueOf(new JwtUtil().getusid(token));
- InfoUser rider = userMapper.selectById(userId);
- if (rider == null || !"2".equals(rider.getUserType())) {
- throw new ServiceException(MessageUtils.message("no.user.stop"));
- }
- return rider;
- }
- }
|