| | |
| | | package com.ruoyi.order.controller.miniapp; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.github.binarywang.wxpay.bean.ecommerce.PartnerTransactionsResult; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.web.controller.BaseController; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.order.domain.dto.*; |
| | | import com.ruoyi.order.domain.pojo.order.Order; |
| | | import com.ruoyi.order.domain.vo.*; |
| | | import com.ruoyi.order.service.order.OrderService; |
| | | import com.ruoyi.system.api.constant.DelayTaskEnum; |
| | | import com.ruoyi.system.api.constant.SecurityConstant; |
| | | import com.ruoyi.system.api.domain.dto.AppBaseGetDto; |
| | | import com.ruoyi.system.api.domain.dto.AppMemberBindingDto; |
| | | import com.ruoyi.system.api.domain.poji.member.Member; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import com.ruoyi.system.api.service.RemoteConfigService; |
| | | import com.ruoyi.system.api.service.RemoteMemberService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | @Resource |
| | | private OrderService orderService; |
| | | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private RemoteConfigService remoteConfigService; |
| | | |
| | | |
| | | @RequestMapping(value = "/buyGoods", method = RequestMethod.POST) |
| | |
| | | Long userId = loginUser.getUserid(); |
| | | appPlaceOrderDto.setUserId(userId); |
| | | appPlaceOrderDto.setSpbillCreateIp(loginUser.getIpaddr()); |
| | | |
| | | if (userId != null) { |
| | | Member member = memberService.getMember(userId).getData(); |
| | | appPlaceOrderDto.setUserId(userId); |
| | | |
| | | if (member != null) { |
| | | appPlaceOrderDto.setOpenid(member.getMiniOpenid()); |
| | | appPlaceOrderDto.setShopId(member.getRelationShopId()); |
| | | if (member.getBindingFlag() != 1) { |
| | | //绑定商户 |
| | | AppMemberBindingDto appMemberBindingDto = new AppMemberBindingDto(); |
| | | appMemberBindingDto.setShopId(appPlaceOrderDto.getShopId()); |
| | | appMemberBindingDto.setUserId(userId); |
| | | appMemberBindingDto.setBindingFlag(1); |
| | | appMemberBindingDto.setBindingType(1); |
| | | memberService.updateMemberBinding(appMemberBindingDto); |
| | | appPlaceOrderDto.setNewMemberFlag(1); |
| | | } |
| | | } |
| | | } |
| | | AppPlaceOrderVo appPlaceOrderVo = orderService.placeOrder(appPlaceOrderDto); |
| | | return R.ok(appPlaceOrderVo); |
| | | } |
| | |
| | | public R<AppPlaceOrderVo> placeActivityOrder(@Validated @RequestBody AppPlaceActivityDto appPlaceActivityDto) { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | Long userId = loginUser.getUserid(); |
| | | appPlaceActivityDto.setUserId(userId); |
| | | appPlaceActivityDto.setSpbillCreateIp(loginUser.getIpaddr()); |
| | | if (userId != null) { |
| | | Member member = memberService.getMember(userId).getData(); |
| | | appPlaceActivityDto.setUserId(userId); |
| | | if (member != null && member.getRelationShopId() != null) { |
| | | appPlaceActivityDto.setOpenid(member.getMiniOpenid()); |
| | | appPlaceActivityDto.setShopId(member.getRelationShopId()); |
| | | } |
| | | if (member.getBindingFlag() != 1) { |
| | | //绑定商户 |
| | | AppMemberBindingDto appMemberBindingDto = new AppMemberBindingDto(); |
| | | appMemberBindingDto.setShopId(appPlaceActivityDto.getShopId()); |
| | | appMemberBindingDto.setUserId(userId); |
| | | appMemberBindingDto.setBindingFlag(1); |
| | | appMemberBindingDto.setBindingType(2); |
| | | memberService.updateMemberBinding(appMemberBindingDto); |
| | | appPlaceActivityDto.setNewMemberFlag(1); |
| | | } |
| | | } |
| | | AppPlaceOrderVo appPlaceOrderVo = orderService.placeActivityOrder(appPlaceActivityDto); |
| | | return R.ok(appPlaceOrderVo); |
| | | } |
| | |
| | | @ApiOperation(value = "分页获取用户订单") |
| | | public R<Page<AppUserOrderPageVo>> pageUserOrder(@RequestBody AppUserOrderPageDto appUserOrderPageDto) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId != null) { |
| | | Member member = memberService.getMember(userId).getData(); |
| | | appUserOrderPageDto.setUserId(userId); |
| | | if (member != null && member.getRelationShopId() != null) { |
| | | appUserOrderPageDto.setShopId(member.getRelationShopId()); |
| | | } |
| | | } |
| | | logger.info("appUserOrderPageDto:" + appUserOrderPageDto.toString()); |
| | | appUserOrderPageDto.setUserId(userId); |
| | | Page<AppUserOrderPageVo> page = new Page<>(); |
| | | page.setSize(appUserOrderPageDto.getPageSize()); |
| | | page.setCurrent(appUserOrderPageDto.getPageNum()); |
| | |
| | | } |
| | | |
| | | @RequestMapping(value = "/payOrder", method = RequestMethod.POST) |
| | | @ApiOperation(value = "支付订单(临时)") |
| | | public R<AppPlaceOrderVo> placeOrder(@RequestBody AppBaseGetDto appBaseGetDto) { |
| | | @ApiOperation(value = "支付订单") |
| | | public R<AppPlaceOrderVo> payOrder(@RequestBody AppBaseGetDto appBaseGetDto) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | AppPlaceOrderVo appPlaceOrderVo = new AppPlaceOrderVo(); |
| | | Order order = orderService.getById(appBaseGetDto.getId()); |
| | | PartnerTransactionsResult transaction = new PartnerTransactionsResult(); |
| | | transaction.setOutTradeNo(appBaseGetDto.getId()); |
| | | orderService.payBack(transaction); |
| | | appPlaceOrderVo.setOrderId(order.getOrderId()); |
| | | appPlaceOrderVo.setOrderNo(order.getOrderNo()); |
| | | appPlaceOrderVo.setPayType(order.getPayType()); |
| | | appPlaceOrderVo.setPayMoney(order.getPayMoney()); |
| | | appPlaceOrderVo.setUnpaidMoney(order.getPayMoney()); |
| | | Integer delayTime = 30; |
| | | if (redisService.hasKey(SecurityConstant.AUTO_CANCEL_ORDER_TIME)) { |
| | | delayTime = redisService.getCacheObject(SecurityConstant.AUTO_CANCEL_ORDER_TIME); |
| | | } |
| | | redisService.deleteObject(DelayTaskEnum.ORDER_AUTOMATIC_CANCEL.getCode() + "-" + order.getOrderId()); |
| | | remoteConfigService.deleteDelayTask(DelayTaskEnum.ORDER_AUTOMATIC_CANCEL.getCode() + "-" + order.getOrderId()); |
| | | appPlaceOrderVo.setEndTime(DateUtils.addMinutes(order.getCreateTime(), delayTime)); |
| | | AppPlaceOrderVo appPlaceOrderVo = orderService.payOrder(appBaseGetDto.getId()); |
| | | return R.ok(appPlaceOrderVo); |
| | | } |
| | | |