Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
2024-09-02 14:51:05 +08:00
9 changed files with 124 additions and 227 deletions

View File

@@ -36,8 +36,9 @@ import org.springframework.web.bind.annotation.RestController;
@EnableAsync @EnableAsync
@RestController @RestController
@Api(hidden = true) @Api(hidden = true)
@SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
@SpringBootApplication
@EnableJpaAuditing(auditorAwareRef = "auditorAware") @EnableJpaAuditing(auditorAwareRef = "auditorAware")
public class AppRun { public class AppRun {

View File

@@ -1,185 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.ysk.cashier.controller;
import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.pojo.TbUserInfo;
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
import cn.ysk.cashier.repository.TbUserInfoRepository;
import cn.ysk.cashier.repository.shop.TbMerchantAccountRepository;
import cn.ysk.cashier.service.TbUserInfoService;
import cn.ysk.cashier.dto.TbUserInfoQueryCriteria;
import cn.ysk.cashier.utils.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @author lyf
* @date 2023-11-13
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "/userInfo/list管理")
@RequestMapping("/api/tbUserInfo")
public class TbUserInfoController {
private final TbUserInfoService tbUserInfoService;
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('tbUserInfo:list')")
public void exportTbUserInfo(HttpServletResponse response, TbUserInfoQueryCriteria criteria) throws IOException {
tbUserInfoService.download(tbUserInfoService.queryAll(criteria), response);
}
@GetMapping
@ApiOperation("查询/userInfo/list")
public ResponseEntity<Object> queryTbUserInfo(TbUserInfoQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(tbUserInfoService.queryAll(criteria,pageable),HttpStatus.OK);
}
@PostMapping
@ApiOperation("新增/userInfo/list")
public ResponseEntity<Object> createTbUserInfo(@Validated @RequestBody TbUserInfo resources){
return new ResponseEntity<>(tbUserInfoService.create(resources),HttpStatus.CREATED);
}
@PutMapping
@ApiOperation("修改/userInfo/list")
public ResponseEntity<Object> updateTbUserInfo(@Validated @RequestBody TbUserInfo resources){
tbUserInfoService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@DeleteMapping
@ApiOperation("删除/userInfo/list")
public ResponseEntity<Object> deleteTbUserInfo(@RequestBody Integer[] ids) {
tbUserInfoService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@Autowired
ValidateCodeUtil validateCodeUtil;
@Autowired
RedisUtils redisUtils;
@GetMapping("sendMsg")
public Object sendMsg(){
Object o= SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if(Objects.isNull(o)){
throw new BadRequestException("用户登录信息失效");
}
JSONObject object=JSON.parseObject(JSON.toJSONString(o));
if(Objects.isNull(object)){
throw new BadRequestException("用户登录信息失效");
}
String regex="^\\d{11}$";
if(!object.containsKey("username")||Objects.isNull(object.getString("username"))||
!object.getString("username").matches(regex)
){
throw new BadRequestException("用户登录信息失效");
}
String phone=object.getString("username");
String tempcode="SMS_244665149";
String random = StringUtil.random(6);
try {
validateCodeUtil.requestValidateCodeAli(phone, random,tempcode);
redisUtils.set(phone.concat("#").concat(tempcode),random,300L);
return "{\n" +
" \"code\": 0,\n" +
" \"msg\": \"成功\"\n" +
"}";
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
@Autowired
TbMerchantAccountRepository tbMerchantAccountRepository;
@RequestMapping(value = "modfiyUserInfo",method = RequestMethod.POST)
public ResponseEntity<Object> modfiyUserInfo(@RequestBody Map<String,String> map){
Object o= SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if(Objects.isNull(o)){
throw new BadRequestException("用户登录信息失效");
}
JSONObject object=JSON.parseObject(JSON.toJSONString(o));
if(Objects.isNull(object)){
throw new BadRequestException("用户登录信息失效");
}
String regex="^\\d{11}$";
if(!object.containsKey("username")||Objects.isNull(object.getString("username"))||
!object.getString("username").matches(regex)
){
throw new BadRequestException("用户登录信息失效");
}
String tempcode="SMS_244665149";
String phone=object.getString("username");
Object redisCode= redisUtils.get(phone.concat("#").concat(tempcode));
if(Objects.isNull(redisCode)){
throw new BadRequestException("短信验证码已过期");
}
String code= map.get("code");
if(!redisCode.toString().equals(code)){
throw new BadRequestException("短信验证码错误");
}
redisUtils.del(phone.concat("#").concat(tempcode));
String pwd= map.get("pwd");
TbMerchantAccount account= tbMerchantAccountRepository.findByAccount(phone);
if(Objects.isNull(account)){
throw new BadRequestException("账户不存在");
}
account.setPwd(MD5Utils.md5(pwd.concat(account.getAccount()).concat(account.getId().toString())));
account.setUpdatedAt(System.currentTimeMillis());
tbMerchantAccountRepository.save(account);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}

View File

@@ -8,6 +8,7 @@ import cn.ysk.cashier.dto.shop.TbShopRechargeListDto;
import cn.ysk.cashier.dto.shop.TbShopUserQueryCriteria; import cn.ysk.cashier.dto.shop.TbShopUserQueryCriteria;
import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.service.TbMShopUserService; import cn.ysk.cashier.mybatis.service.TbMShopUserService;
import cn.ysk.cashier.mybatis.service.TbShopUserFlowService;
import cn.ysk.cashier.pojo.shop.TbShopUser; import cn.ysk.cashier.pojo.shop.TbShopUser;
import cn.ysk.cashier.service.shop.TbShopUserService; import cn.ysk.cashier.service.shop.TbShopUserService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@@ -37,6 +38,9 @@ public class TbShopUserController {
private final TbShopUserService tbShopUserService; private final TbShopUserService tbShopUserService;
private final TbMShopUserService tbMShopUserService; private final TbMShopUserService tbMShopUserService;
private final TbShopUserFlowService tbShopUserFlowService;
@ApiOperation("导出数据") @ApiOperation("导出数据")
@GetMapping(value = "/download") @GetMapping(value = "/download")
public void exportTbShopUser(HttpServletResponse response, TbShopUserQueryCriteria criteria) throws IOException { public void exportTbShopUser(HttpServletResponse response, TbShopUserQueryCriteria criteria) throws IOException {
@@ -104,4 +108,10 @@ public class TbShopUserController {
tbShopUserService.modfiyAccount(map); tbShopUserService.modfiyAccount(map);
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
@GetMapping("queryShopUserFlow")
public ResponseEntity<Object> queryShopUserFlow(@RequestParam("userId") Integer userId,@RequestParam("page") Integer page,@RequestParam("pageSize") Integer pageSize){
return new ResponseEntity<>( tbShopUserFlowService.selectByUserId(userId, page, pageSize),HttpStatus.OK);
}
} }

View File

@@ -1,39 +1,86 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.ysk.cashier.mybatis.entity; package cn.ysk.cashier.mybatis.entity;
import com.baomidou.mybatisplus.annotation.TableName; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.activerecord.Model; import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.Entity; import javax.persistence.*;
import javax.persistence.Id; import java.io.Serializable;
import javax.persistence.Table;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.sql.Timestamp;
/** /**
* @author GYJ * @author admin
*/ * @date 2024-09-02
**/
@Entity @Entity
@Data @Data
@EqualsAndHashCode(callSuper = true)
@TableName("tb_shop_user_flow")
@Table(name="tb_shop_user_flow") @Table(name="tb_shop_user_flow")
public class TbShopUserFlow extends Model<TbShopUserFlow> { public class TbShopUserFlow implements Serializable {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "`id`")
@ApiModelProperty(value = "id")
private Integer id; private Integer id;
@Column(name = "`shop_user_id`")
@ApiModelProperty(value = "shopUserId")
private Integer shopUserId; private Integer shopUserId;
@Column(name = "`amount`")
@ApiModelProperty(value = "amount")
private BigDecimal amount; private BigDecimal amount;
@Column(name = "`balance`")
@ApiModelProperty(value = "balance")
private BigDecimal balance; private BigDecimal balance;
@Column(name = "`biz_code`")
@ApiModelProperty(value = "bizCode")
private String bizCode; private String bizCode;
@Column(name = "`biz_name`")
@ApiModelProperty(value = "bizName")
private String bizName; private String bizName;
private Date createTime; @Column(name = "`create_time`")
@ApiModelProperty(value = "createTime")
private Timestamp createTime;
@Column(name = "`type`")
@ApiModelProperty(value = "type")
private String type; private String type;
@Column(name = "`is_return`")
@ApiModelProperty(value = "是否退款 1 已退款 0 未退款")
private String isReturn;
@Column(name = "`update_time`")
@ApiModelProperty(value = "updateTime")
private Timestamp updateTime;
@Column(name = "`remark`")
@ApiModelProperty(value = "备注")
private String remark;
public void copy(TbShopUserFlow source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
} }

View File

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import javax.validation.Valid;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
@@ -41,4 +42,11 @@ public interface TbShopUserFlowMapper extends BaseMapper<TbShopUserFlow> {
@Param("endTime") String endTime); @Param("endTime") String endTime);
@Select(value = "select * from tb_shop_user_flow where shop_user_id=#{userId} order by id desc limit #{page},#{size}")
List<TbShopUserFlow> selectByUserId(@Param("userId") Integer userId,@Param("page") Integer page,@Param("size") Integer size);
@Select(value = "select count(0) from tb_shop_user_flow where shop_user_id=#{userId} ")
Integer selectCountByUserId(@Param("userId") Integer userId);
} }

View File

@@ -2,10 +2,10 @@ package cn.ysk.cashier.mybatis.service;
import cn.ysk.cashier.mybatis.entity.TbShopUserFlow; import cn.ysk.cashier.mybatis.entity.TbShopUserFlow;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author GYJ * @author GYJ
@@ -13,4 +13,9 @@ import java.util.List;
public interface TbShopUserFlowService extends IService<TbShopUserFlow> { public interface TbShopUserFlowService extends IService<TbShopUserFlow> {
BigDecimal sumUserFlowAmountByConditions(Long shopId, String startTime, String endTime); BigDecimal sumUserFlowAmountByConditions(Long shopId, String startTime, String endTime);
Map selectByUserId(Integer userId, Integer page, Integer pageSize);
Integer selectCountByUserId(Integer userId);
} }

View File

@@ -4,10 +4,13 @@ import cn.ysk.cashier.mybatis.entity.TbShopUserFlow;
import cn.ysk.cashier.mybatis.mapper.TbShopUserFlowMapper; import cn.ysk.cashier.mybatis.mapper.TbShopUserFlowMapper;
import cn.ysk.cashier.mybatis.service.TbShopUserFlowService; import cn.ysk.cashier.mybatis.service.TbShopUserFlowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author GYJ * @author GYJ
@@ -18,4 +21,29 @@ public class TbShopUserFlowServiceImpl extends ServiceImpl<TbShopUserFlowMapper,
public BigDecimal sumUserFlowAmountByConditions(Long shopId, String startTime, String endTime) { public BigDecimal sumUserFlowAmountByConditions(Long shopId, String startTime, String endTime) {
return baseMapper.sumUserFlowAmountByConditions(shopId, startTime, endTime); return baseMapper.sumUserFlowAmountByConditions(shopId, startTime, endTime);
} }
@Override
public Map selectByUserId(Integer userId, Integer page, Integer pageSize) {
Map map=new HashMap();
int count= baseMapper.selectCountByUserId(userId);
if(count>0){
Pageable pageable = PageRequest.of(page, pageSize, Sort.by("id").descending());
List<TbShopUserFlow> userFlows=baseMapper.selectByUserId(userId,pageable.getPageNumber(),pageable.getPageSize());
map.put("totalElements",count);
map.put("content",userFlows);
}else {
map.put("totalElements",0);
map.put("content",null);
}
return map;
}
@Override
public Integer selectCountByUserId(Integer userId) {
return null;
}
} }

View File

@@ -1,6 +1,5 @@
package cn.ysk.cashier.service.impl; package cn.ysk.cashier.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.ysk.cashier.dto.ScanPayDTO; import cn.ysk.cashier.dto.ScanPayDTO;
@@ -39,8 +38,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.math.BigDecimal; import java.sql.Timestamp;
import java.math.RoundingMode;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -335,7 +333,7 @@ public class TbPayServiceImpl implements TbPayService {
private final TbShopUserFlowMapper shopUserFlowMapper; private final TbShopUserFlowMapper shopUserFlowMapper;
@Override @Override
public TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId, Double discount, Integer vipUserId) { public TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId) {
TbOrderInfo orderInfo = orderInfoMapper.selectById(orderId); TbOrderInfo orderInfo = orderInfoMapper.selectById(orderId);
@@ -347,9 +345,6 @@ public class TbPayServiceImpl implements TbPayService {
throw new BadRequestException("订单非未支付状态"); throw new BadRequestException("订单非未支付状态");
} }
if (vipUserId != null) {
orderInfo.setUserId(String.valueOf(vipUserId));
}
// 扣减会员余额 // 扣减会员余额
TbShopUser shopUser = shopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>() TbShopUser shopUser = shopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
@@ -360,29 +355,22 @@ public class TbPayServiceImpl implements TbPayService {
throw new BadRequestException("用户不存在或已被禁用"); throw new BadRequestException("用户不存在或已被禁用");
} }
BigDecimal payMount = discount == null ? orderInfo.getOrderAmount() : orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(discount)).setScale(2, RoundingMode.UP); long flag = shopUserMapper.decrBalance(Integer.valueOf(orderInfo.getUserId()), orderInfo.getOrderAmount());
long flag = shopUserMapper.decrBalance(Integer.valueOf(orderInfo.getUserId()), payMount);
if (flag < 1) { if (flag < 1) {
throw new BadRequestException("余额不足或扣除余额失败"); throw new BadRequestException("余额不足或扣除余额失败");
} }
TbShopUserFlow userFlow = new TbShopUserFlow(); TbShopUserFlow userFlow = new TbShopUserFlow();
userFlow.setAmount(payMount); userFlow.setAmount(orderInfo.getOrderAmount());
userFlow.setBalance(shopUser.getAmount()); userFlow.setBalance(shopUser.getAmount());
userFlow.setShopUserId(shopUser.getId()); userFlow.setShopUserId(shopUser.getId());
userFlow.setBizCode("vipCardCash"); userFlow.setBizCode("vipCardCash");
userFlow.setBizName("余额支付"); userFlow.setBizName("代客下单会员余额支付");
userFlow.setCreateTime(DateUtil.date()); userFlow.setCreateTime(new Timestamp(System.currentTimeMillis()));
userFlow.setType("-"); userFlow.setType("-");
shopUserFlowMapper.insert(userFlow); shopUserFlowMapper.insert(userFlow);
orderInfo.setPayAmount(payMount); orderInfo.setPayAmount(orderInfo.getOrderAmount());
if (discount != null && discount != 1) {
orderInfo.setDiscountAmount(orderInfo.getOrderAmount().subtract(orderInfo.getPayAmount()));
orderInfo.setDiscountRatio(BigDecimal.valueOf(discount));
}
orderInfo.setPayType("cash"); orderInfo.setPayType("cash");
orderInfo.setStatus("closed"); orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo())); orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
@@ -421,12 +409,7 @@ public class TbPayServiceImpl implements TbPayService {
// return Result.fail(CodeEnum.PAYTYPENOEXIST); // return Result.fail(CodeEnum.PAYTYPENOEXIST);
// } // }
orderInfo.setPayAmount(payDTO.getDiscount() == null ? orderInfo.getOrderAmount() : orderInfo.getOrderAmount() orderInfo.setPayAmount(orderInfo.getOrderAmount());
.multiply(BigDecimal.valueOf(payDTO.getDiscount())).setScale(2, RoundingMode.UP));
if (payDTO.getDiscount() != null && payDTO.getDiscount() != 1) {
orderInfo.setDiscountAmount(orderInfo.getOrderAmount().subtract(orderInfo.getPayAmount()));
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
}
orderInfo.setPayType("cash"); orderInfo.setPayType("cash");
orderInfo.setStatus("closed"); orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo())); orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));

View File

@@ -32,9 +32,9 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.regex.Pattern;
/** /**
* @author lyf * @author lyf
@@ -252,7 +252,7 @@ public class TbShopUserServiceImpl implements TbShopUserService {
flow.setShopUserId(tbShopUser.getId()); flow.setShopUserId(tbShopUser.getId());
flow.setAmount(amount); flow.setAmount(amount);
flow.setBalance(tbShopUser.getAmount()); flow.setBalance(tbShopUser.getAmount());
flow.setCreateTime(new Date()); flow.setCreateTime(new Timestamp(System.currentTimeMillis()));
tbShopUserFlowMapper.insert(flow); tbShopUserFlowMapper.insert(flow);