diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java index 2185f039..cfca0c7b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbPlaceController.java @@ -1,14 +1,28 @@ package cn.ysk.cashier.controller.product; +import cn.hutool.core.collection.CollUtil; import cn.ysk.cashier.annotation.AnonymousAccess; import cn.ysk.cashier.annotation.Log; import cn.ysk.cashier.config.security.security.TokenProvider; import cn.ysk.cashier.dto.shoptable.*; +import cn.ysk.cashier.mybatis.mapper.TbMerchantAccountMapper; +import cn.ysk.cashier.pojo.TbToken; import cn.ysk.cashier.pojo.order.TbCashierCart; +import cn.ysk.cashier.pojo.shop.TbMerchantAccount; +import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; +import cn.ysk.cashier.repository.TbTokenRepository; +import cn.ysk.cashier.repository.shop.TbPlussShopStaffRepository; import cn.ysk.cashier.service.product.TbProductService; import cn.ysk.cashier.service.shop.TbShopTableService; import cn.ysk.cashier.utils.RabbitMsgUtils; +import cn.ysk.cashier.utils.RedisUtils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -17,7 +31,9 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import java.util.List; +@Slf4j @RestController @RequestMapping("/api/place") public class TbPlaceController { @@ -25,7 +41,16 @@ public class TbPlaceController { private final TbProductService tbProductService; private final RabbitMsgUtils rabbitMsgUtils; @Resource + private TbPlussShopStaffRepository staffRepository; + @Resource + private TbMerchantAccountMapper tbMerchantAccountMapper; + @Resource + private TbTokenRepository tbTokenRepository; + @Resource private TokenProvider tokenProvider; + @Lazy + @Autowired + private RedisUtils redisUtils; @GetMapping("/activate") @ApiOperation("查询/product") @@ -145,7 +170,17 @@ public class TbPlaceController { @ApiOperation("代客下单 支付订单") public ResponseEntity pay(HttpServletRequest request, @Validated @RequestBody PayDTO payDTO) { String token = tokenProvider.getToken(request); - payDTO.setToken(token); + JSONObject userInfo = JSON.parseObject(JSON.toJSONString(redisUtils.get("online-token-"+token))); + String userName = userInfo.getString("userName"); + String shopId = userInfo.getString("shopId"); + TbPlussShopStaff shopStaff = staffRepository.queryByAccount(userName, shopId); + TbMerchantAccount merchantAccount = tbMerchantAccountMapper.selectOne(Wrappers.lambdaQuery().eq(TbMerchantAccount::getAccount, shopStaff.getAccount())); + Integer accountId = merchantAccount.getId(); + Integer staffId = shopStaff.getId(); + List onlineUserList = tbTokenRepository.findListByAccountIdAndStaffId(accountId, staffId); + if (CollUtil.isNotEmpty(onlineUserList)) { + payDTO.setToken(onlineUserList.get(0).getToken()); + } return ResponseEntity.ok(tbShopTableService.pay(payDTO)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/TbTokenRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/TbTokenRepository.java index 5357cbc8..bf85cd7d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/TbTokenRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/TbTokenRepository.java @@ -1,13 +1,12 @@ package cn.ysk.cashier.repository; -import javax.persistence.Tuple; -import cn.ysk.cashier.pojo.TbShopPayType; import cn.ysk.cashier.pojo.TbToken; import org.apache.ibatis.annotations.Param; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; +import javax.persistence.Tuple; import java.util.Date; import java.util.List; @@ -23,7 +22,9 @@ public interface TbTokenRepository extends JpaRepository, JpaS Tuple countByAccountId(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); @Query(value = "select count(0),DATE_FORMAT(create_time,'%Y-%m-%d')from tb_token where account_id=:shopId " + - "and create_time BETWEEN :startTime and :endTime group by DATE_FORMAT( create_time, '%Y-%m-%d') ",nativeQuery = true) + "and create_time BETWEEN :startTime and :endTime group by DATE_FORMAT( create_time, '%Y-%m-%d') ", nativeQuery = true) List countByMonth(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); + @Query("from TbToken x where x.accountId=:accountId and x.staffId=:staffId and x.status=1 order by x.id desc") + List findListByAccountIdAndStaffId(@Param("accountId") Integer accountId, @Param("staffId") Integer staffId); }