新增:shop端模块

This commit is contained in:
2025-02-22 13:23:24 +08:00
parent 2be6b0c125
commit 34284a66e0
39 changed files with 543 additions and 317 deletions

View File

@@ -1,17 +1,34 @@
package com.gxwebsoft.shop.controller;
import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.gxwebsoft.common.core.utils.CommonUtil;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.Company;
import com.gxwebsoft.common.system.entity.Role;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.entity.UserRole;
import com.gxwebsoft.common.system.param.MenuParam;
import com.gxwebsoft.common.system.service.CompanyService;
import com.gxwebsoft.common.system.service.MenuService;
import com.gxwebsoft.common.system.service.UserRoleService;
import com.gxwebsoft.common.system.service.UserService;
import com.gxwebsoft.shop.entity.ShopMerchant;
import com.gxwebsoft.shop.entity.ShopMerchantAccount;
import com.gxwebsoft.shop.service.ShopMerchantApplyService;
import com.gxwebsoft.shop.entity.ShopMerchantApply;
import com.gxwebsoft.shop.param.ShopMerchantApplyParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.shop.service.ShopMerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@@ -22,7 +39,7 @@ import java.util.List;
* 商户入驻申请控制器
*
* @author 科技小王子
* @since 2024-10-02 08:08:23
* @since 2024-09-10 21:05:07
*/
@Api(tags = "商户入驻申请管理")
@RestController
@@ -30,7 +47,14 @@ import java.util.List;
public class ShopMerchantApplyController extends BaseController {
@Resource
private ShopMerchantApplyService shopMerchantApplyService;
@Resource
private ShopMerchantService shopMerchantService;
@Resource
private CompanyService companyService;
@Resource
private UserService userService;
@PreAuthorize("hasAuthority('shop:shopMerchantApply:list')")
@ApiOperation("分页查询商户入驻申请")
@GetMapping("/page")
public ApiResult<PageResult<ShopMerchantApply>> page(ShopMerchantApplyParam param) {
@@ -38,6 +62,7 @@ public class ShopMerchantApplyController extends BaseController {
return success(shopMerchantApplyService.pageRel(param));
}
@PreAuthorize("hasAuthority('shop:shopMerchantApply:list')")
@ApiOperation("查询全部商户入驻申请")
@GetMapping()
public ApiResult<List<ShopMerchantApply>> list(ShopMerchantApplyParam param) {
@@ -61,22 +86,46 @@ public class ShopMerchantApplyController extends BaseController {
User loginUser = getLoginUser();
if (loginUser != null) {
shopMerchantApply.setUserId(loginUser.getUserId());
if (shopMerchantApplyService.count(new LambdaQueryWrapper<ShopMerchantApply>().eq(ShopMerchantApply::getPhone, shopMerchantApply.getPhone())) > 0) {
return fail("该手机号码已存在");
}
// 个人开发者认证材料:使用姓名+身份证号码
if (shopMerchantApply.getType().equals(0)) {
shopMerchantApply.setMerchantName(shopMerchantApply.getRealName());
shopMerchantApply.setMerchantCode(shopMerchantApply.getIdCard());
}
shopMerchantApply.setCheckStatus(true);
shopMerchantApply.setTenantId(loginUser.getTenantId());
shopMerchantApply.setPhone(loginUser.getPhone());
if (shopMerchantApplyService.save(shopMerchantApply)) {
return success("添加成功");
return success("您的申请已提交,请耐心等待工作人员的审核,非常感谢");
}
return fail("添加失败");
}
return fail("提交失败");
}
@ApiOperation("修改商户入驻申请")
@PutMapping()
public ApiResult<?> update(@RequestBody ShopMerchantApply shopMerchantApply) {
if (shopMerchantApplyService.updateById(shopMerchantApply)) {
return success("修改成功");
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
// 审核中?
shopMerchantApply.setCheckStatus(true);
// 审核状态
shopMerchantApply.setStatus(0);
// 个人开发者
if (StrUtil.isBlank(shopMerchantApply.getMerchantName())) {
shopMerchantApply.setMerchantName(shopMerchantApply.getRealName());
}
return fail("修改失败");
if (shopMerchantApplyService.updateById(shopMerchantApply)) {
return success("您的申请已提交,请耐心等待工作人员的审核,非常感谢");
}
}
return fail("操作失败");
}
@PreAuthorize("hasAuthority('shop:shopMerchantApply:remove')")
@ApiOperation("删除商户入驻申请")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
@@ -86,6 +135,7 @@ public class ShopMerchantApplyController extends BaseController {
return fail("删除失败");
}
@PreAuthorize("hasAuthority('shop:shopMerchantApply:save')")
@ApiOperation("批量添加商户入驻申请")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<ShopMerchantApply> list) {
@@ -95,6 +145,7 @@ public class ShopMerchantApplyController extends BaseController {
return fail("添加失败");
}
@PreAuthorize("hasAuthority('shop:shopMerchantApply:update')")
@ApiOperation("批量修改商户入驻申请")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<ShopMerchantApply> batchParam) {
@@ -104,6 +155,7 @@ public class ShopMerchantApplyController extends BaseController {
return fail("修改失败");
}
@PreAuthorize("hasAuthority('shop:shopMerchantApply:remove')")
@ApiOperation("批量删除商户入驻申请")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
@@ -113,4 +165,77 @@ public class ShopMerchantApplyController extends BaseController {
return fail("删除失败");
}
@ApiOperation("我的入驻信息")
@GetMapping("/getByUserId")
public ApiResult<ShopMerchantApply> getByUserId() {
final User loginUser = getLoginUser();
if (loginUser == null) {
return fail("请先登录", null);
}
final ShopMerchantApply shopMerchantApply = shopMerchantApplyService.getOne(new LambdaQueryWrapper<ShopMerchantApply>().eq(ShopMerchantApply::getUserId, getLoginUser().getUserId()).last("limit 1"));
return success(shopMerchantApply);
}
@ApiOperation("我的认证信息")
@GetMapping("/getByPhone")
public ApiResult<ShopMerchantApply> getByPhone() {
final User loginUser = getLoginUser();
if (loginUser == null) {
return fail("请先登录", null);
}
final ShopMerchantApply shopMerchantApply = shopMerchantApplyService.getOne(new LambdaQueryWrapper<ShopMerchantApply>().eq(ShopMerchantApply::getPhone, loginUser.getPhone()).last("limit 1"));
return success(shopMerchantApply);
}
@PreAuthorize("hasAuthority('shop:shopMerchantApply:update')")
@ApiOperation("入驻审核")
@PutMapping("/check")
public ApiResult<?> check(@RequestBody ShopMerchantApply shopMerchantApply) {
// 审核中?
shopMerchantApply.setCheckStatus(true);
// TODO 审核通过则创建商户
if (shopMerchantApply.getStatus().equals(1)) {
final ShopMerchant one = shopMerchantService.getOne(new LambdaQueryWrapper<ShopMerchant>().eq(ShopMerchant::getPhone, shopMerchantApply.getPhone()).last("limit 1"));
final ShopMerchantAccount merchantAccount = new ShopMerchantAccount();
BeanUtils.copyProperties(shopMerchantApply, merchantAccount);
final User user = new User();
if (ObjectUtil.isNotEmpty(one)) {
BeanUtils.copyProperties(shopMerchantApply, one);
one.setStatus(0);
shopMerchantService.updateById(one);
user.setRealName(shopMerchantApply.getRealName());
} else {
final ShopMerchant merchant = new ShopMerchant();
BeanUtils.copyProperties(shopMerchantApply, merchant);
merchant.setStatus(0);
shopMerchantService.save(merchant);
user.setRealName(shopMerchantApply.getRealName());
}
// TODO 创建商户账号
// TODO 更新用户表的商户信息
user.setUserId(shopMerchantApply.getUserId());
userService.updateById(user);
shopMerchantApplyService.updateById(shopMerchantApply);
// 更新company表的认证状态
companyService.update(new LambdaUpdateWrapper<Company>().eq(Company::getTenantId, shopMerchantApply.getTenantId()).set(Company::getAuthentication, true));
// TODO 入驻开发者中心(添加会员)
return success("操作成功");
}
// TODO 驳回
if (shopMerchantApply.getStatus().equals(2)) {
shopMerchantApply.setCheckStatus(false);
shopMerchantApplyService.updateById(shopMerchantApply);
return success("操作成功");
}
// 审核状态
shopMerchantApply.setStatus(0);
if (shopMerchantApplyService.updateById(shopMerchantApply)) {
return success("您的申请已提交,请耐心等待工作人员的审核,非常感谢");
}
return fail("操作失败");
}
}

View File

@@ -8,9 +8,7 @@ import com.gxwebsoft.shop.entity.ShopMerchant;
import com.gxwebsoft.shop.param.ShopMerchantParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -23,7 +21,7 @@ import java.util.List;
* 商户控制器
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Api(tags = "商户管理")
@RestController
@@ -32,6 +30,7 @@ public class ShopMerchantController extends BaseController {
@Resource
private ShopMerchantService shopMerchantService;
@PreAuthorize("hasAuthority('shop:shopMerchant:list')")
@ApiOperation("分页查询商户")
@GetMapping("/page")
public ApiResult<PageResult<ShopMerchant>> page(ShopMerchantParam param) {
@@ -39,6 +38,7 @@ public class ShopMerchantController extends BaseController {
return success(shopMerchantService.pageRel(param));
}
@PreAuthorize("hasAuthority('shop:shopMerchant:list')")
@ApiOperation("查询全部商户")
@GetMapping()
public ApiResult<List<ShopMerchant>> list(ShopMerchantParam param) {
@@ -47,7 +47,6 @@ public class ShopMerchantController extends BaseController {
}
@PreAuthorize("hasAuthority('shop:shopMerchant:list')")
@OperationLog
@ApiOperation("根据id查询商户")
@GetMapping("/{id}")
public ApiResult<ShopMerchant> get(@PathVariable("id") Long id) {
@@ -55,6 +54,7 @@ public class ShopMerchantController extends BaseController {
return success(shopMerchantService.getByIdRel(id));
}
@PreAuthorize("hasAuthority('shop:shopMerchant:save')")
@ApiOperation("添加商户")
@PostMapping()
public ApiResult<?> save(@RequestBody ShopMerchant shopMerchant) {
@@ -69,6 +69,7 @@ public class ShopMerchantController extends BaseController {
return fail("添加失败");
}
@PreAuthorize("hasAuthority('shop:shopMerchant:update')")
@ApiOperation("修改商户")
@PutMapping()
public ApiResult<?> update(@RequestBody ShopMerchant shopMerchant) {
@@ -78,6 +79,7 @@ public class ShopMerchantController extends BaseController {
return fail("修改失败");
}
@PreAuthorize("hasAuthority('shop:shopMerchant:remove')")
@ApiOperation("删除商户")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
@@ -87,6 +89,7 @@ public class ShopMerchantController extends BaseController {
return fail("删除失败");
}
@PreAuthorize("hasAuthority('shop:shopMerchant:save')")
@ApiOperation("批量添加商户")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<ShopMerchant> list) {
@@ -96,6 +99,7 @@ public class ShopMerchantController extends BaseController {
return fail("添加失败");
}
@PreAuthorize("hasAuthority('shop:shopMerchant:update')")
@ApiOperation("批量修改商户")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<ShopMerchant> batchParam) {
@@ -105,6 +109,7 @@ public class ShopMerchantController extends BaseController {
return fail("修改失败");
}
@PreAuthorize("hasAuthority('shop:shopMerchant:remove')")
@ApiOperation("批量删除商户")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
@@ -114,6 +119,7 @@ public class ShopMerchantController extends BaseController {
return fail("删除失败");
}
@PreAuthorize("hasAuthority('sys:auth:user')")
@ApiOperation("我的商户信息")
@GetMapping("/getByUserId")
public ApiResult<ShopMerchant> getByUserId() {
@@ -122,4 +128,16 @@ public class ShopMerchantController extends BaseController {
return success(shopMerchant);
}
@PreAuthorize("hasAuthority('sys:auth:user')")
@ApiOperation("我的开发者信息")
@GetMapping("/getByPhone")
public ApiResult<ShopMerchant> getByPhone() {
final User loginUser = getLoginUser();
if (loginUser == null) {
return fail("请先登录", null);
}
final ShopMerchant shopMerchant = shopMerchantService.getOne(new LambdaQueryWrapper<ShopMerchant>().eq(ShopMerchant::getPhone, loginUser.getPhone()).last("limit 1"));
return success(shopMerchant);
}
}

View File

@@ -22,7 +22,7 @@ import java.util.List;
* 门店销售统计表控制器
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Api(tags = "门店销售统计表管理")
@RestController
@@ -41,8 +41,11 @@ public class ShopMerchantCountController extends BaseController {
@ApiOperation("查询全部门店销售统计表")
@GetMapping()
public ApiResult<List<ShopMerchantCount>> list(ShopMerchantCountParam param) {
PageParam<ShopMerchantCount, ShopMerchantCountParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(shopMerchantCountService.list(page.getOrderWrapper()));
// 使用关联查询
return success(shopMerchantCountService.listRel(param));
//return success(shopMerchantCountService.listRel(param));
}
@PreAuthorize("hasAuthority('shop:shopMerchantCount:list')")
@@ -50,8 +53,9 @@ public class ShopMerchantCountController extends BaseController {
@ApiOperation("根据id查询门店销售统计表")
@GetMapping("/{id}")
public ApiResult<ShopMerchantCount> get(@PathVariable("id") Integer id) {
return success(shopMerchantCountService.getById(id));
// 使用关联查询
return success(shopMerchantCountService.getByIdRel(id));
//return success(shopMerchantCountService.getByIdRel(id));
}
@ApiOperation("添加门店销售统计表")

View File

@@ -22,7 +22,7 @@ import java.util.List;
* 商户类型控制器
*
* @author 科技小王子
* @since 2024-10-02 10:07:52
* @since 2024-09-10 21:05:07
*/
@Api(tags = "商户类型管理")
@RestController
@@ -41,8 +41,11 @@ public class ShopMerchantTypeController extends BaseController {
@ApiOperation("查询全部商户类型")
@GetMapping()
public ApiResult<List<ShopMerchantType>> list(ShopMerchantTypeParam param) {
PageParam<ShopMerchantType, ShopMerchantTypeParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(shopMerchantTypeService.list(page.getOrderWrapper()));
// 使用关联查询
return success(shopMerchantTypeService.listRel(param));
//return success(shopMerchantTypeService.listRel(param));
}
@PreAuthorize("hasAuthority('shop:shopMerchantType:list')")
@@ -50,8 +53,9 @@ public class ShopMerchantTypeController extends BaseController {
@ApiOperation("根据id查询商户类型")
@GetMapping("/{id}")
public ApiResult<ShopMerchantType> get(@PathVariable("id") Integer id) {
return success(shopMerchantTypeService.getById(id));
// 使用关联查询
return success(shopMerchantTypeService.getByIdRel(id));
//return success(shopMerchantTypeService.getByIdRel(id));
}
@ApiOperation("添加商户类型")

View File

@@ -1,23 +1,33 @@
package com.gxwebsoft.shop.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.gxwebsoft.common.core.exception.BusinessException;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.entity.UserBalanceLog;
import com.gxwebsoft.common.system.service.UserBalanceLogService;
import com.gxwebsoft.common.system.service.UserService;
import com.gxwebsoft.shop.service.ShopOrderGoodsService;
import com.gxwebsoft.shop.service.ShopOrderService;
import com.gxwebsoft.shop.entity.ShopOrder;
import com.gxwebsoft.shop.param.ShopOrderParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;
import static com.gxwebsoft.common.core.constants.BalanceConstants.BALANCE_USE;
/**
* 订单控制器
@@ -31,7 +41,16 @@ import java.util.List;
public class ShopOrderController extends BaseController {
@Resource
private ShopOrderService shopOrderService;
@Resource
private UserService userService;
@Resource
private UserBalanceLogService userBalanceLogService;
@Resource
private ShopOrderGoodsService shopOrderGoodsService;
@Resource
private RedisUtil redisUtil;
@PreAuthorize("hasAuthority('shop:shopOrder:list')")
@ApiOperation("分页查询订单")
@GetMapping("/page")
public ApiResult<PageResult<ShopOrder>> page(ShopOrderParam param) {
@@ -39,24 +58,20 @@ public class ShopOrderController extends BaseController {
return success(shopOrderService.pageRel(param));
}
@PreAuthorize("hasAuthority('shop:shopOrder:list')")
@ApiOperation("查询全部订单")
@GetMapping()
public ApiResult<List<ShopOrder>> list(ShopOrderParam param) {
PageParam<ShopOrder, ShopOrderParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(shopOrderService.list(page.getOrderWrapper()));
// 使用关联查询
//return success(shopOrderService.listRel(param));
return success(shopOrderService.listRel(param));
}
@PreAuthorize("hasAuthority('shop:shopOrder:list')")
@OperationLog
@ApiOperation("根据id查询订单")
@GetMapping("/{id}")
public ApiResult<ShopOrder> get(@PathVariable("id") Integer id) {
return success(shopOrderService.getById(id));
// 使用关联查询
//return success(shopOrderService.getByIdRel(id));
return success(shopOrderService.getByIdRel(id));
}
@ApiOperation("添加订单")
@@ -66,17 +81,14 @@ public class ShopOrderController extends BaseController {
User loginUser = getLoginUser();
if (loginUser != null) {
shopOrder.setUserId(loginUser.getUserId());
shopOrder.setOpenid(loginUser.getOpenid());
}
if (shopOrder.getOrderNo() == null) {
shopOrder.setOrderNo(Long.toString(IdUtil.getSnowflakeNextId()));
}
if (shopOrderService.save(shopOrder)) {
return success("下单成功", shopOrderService.createWxOrder(shopOrder));
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('shop:shopOrder:update')")
@ApiOperation("修改订单")
@PutMapping()
public ApiResult<?> update(@RequestBody ShopOrder shopOrder) {
@@ -86,6 +98,7 @@ public class ShopOrderController extends BaseController {
return fail("修改失败");
}
@PreAuthorize("hasAuthority('shop:shopOrder:remove')")
@ApiOperation("删除订单")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
@@ -95,6 +108,7 @@ public class ShopOrderController extends BaseController {
return fail("删除失败");
}
@PreAuthorize("hasAuthority('shop:shopOrder:save')")
@ApiOperation("批量添加订单")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<ShopOrder> list) {
@@ -104,6 +118,7 @@ public class ShopOrderController extends BaseController {
return fail("添加失败");
}
@PreAuthorize("hasAuthority('shop:shopOrder:update')")
@ApiOperation("批量修改订单")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<ShopOrder> batchParam) {
@@ -113,6 +128,7 @@ public class ShopOrderController extends BaseController {
return fail("修改失败");
}
@PreAuthorize("hasAuthority('shop:shopOrder:remove')")
@ApiOperation("批量删除订单")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
@@ -122,4 +138,121 @@ public class ShopOrderController extends BaseController {
return fail("删除失败");
}
@ApiOperation("统一下单")
@PostMapping("/createOrder")
public ApiResult<?> createOrder(@RequestBody ShopOrder shopOrder) {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
// 封装订单数据
shopOrder.setUserId(loginUser.getUserId());
shopOrder.setOrderNo(Long.toString(IdUtil.getSnowflakeNextId()));
shopOrder.setPhone(loginUser.getPhone());
shopOrder.setOpenid(loginUser.getOpenid());
shopOrder.setTenantId(loginUser.getTenantId());
shopOrder.setLoginUser(loginUser);
shopOrder.setRealName(loginUser.getRealName());
shopOrder.setPayTime(DateUtil.date());
// 判断支付方式
if(shopOrder.getPayType() == null){
return fail("支付方式不能为空");
}
// 商品描述(必填)
if (StrUtil.isBlank(shopOrder.getComments())) {
return fail("商品描述(必填)");
}
// 微信支付
if(shopOrder.getPayType().equals(1) || shopOrder.getPayType().equals(102)){
// 微信openid(必填)
if (StrUtil.isBlank(loginUser.getOpenid())) {
return fail("微信openid(必填)");
}
// 微信支付(商品金额不能为0)
if (shopOrder.getPayType().equals(1) && shopOrder.getPayType().equals(102)) {
if (shopOrder.getTotalPrice().compareTo(BigDecimal.ZERO) == 0) {
return fail("商品金额不能为0");
}
}
}
if (shopOrderService.save(shopOrder)) {
// 保存订单商品
if(shopOrder.getOrderProduct() != null){
shopOrder.getOrderProduct().forEach(item -> {
item.setOrderId(shopOrder.getOrderId());
item.setTenantId(shopOrder.getTenantId());
item.setOrderCode("product");
item.setMerchantId(shopOrder.getMerchantId());
item.setUserId(shopOrder.getUserId());
});
final boolean saveBatch = shopOrderGoodsService.saveBatch(shopOrder.getOrderProduct());
System.out.println("saveBatch = " + saveBatch);
}
// 调起支付
return onPay(shopOrder);
}
}
return fail("下单失败");
}
private ApiResult<?> onPay(ShopOrder order) {
// TODO 余额支付
if (order.getPayType().equals(0)) {
final User loginUser = order.getLoginUser();
if (order.getLoginUser().getBalance().compareTo(order.getTotalPrice()) < 0) {
throw new BusinessException("余额不足");
}
// 扣除余额
final BigDecimal subtract = loginUser.getBalance().subtract(order.getTotalPrice());
loginUser.setBalance(subtract);
final boolean updateUser = userService.updateById(loginUser);
System.out.println("updateUser = " + updateUser);
// 记录余额明细
UserBalanceLog userBalanceLog = new UserBalanceLog();
userBalanceLog.setUserId(loginUser.getUserId());
userBalanceLog.setTenantId(loginUser.getTenantId());
userBalanceLog.setScene(BALANCE_USE);
userBalanceLog.setMoney(order.getPayPrice());
BigDecimal balance = loginUser.getBalance().add(order.getPayPrice());
userBalanceLog.setBalance(balance);
userBalanceLog.setComments(order.getMerchantName());
userBalanceLog.setTransactionId(UUID.randomUUID().toString());
userBalanceLog.setOrderNo(order.getOrderNo());
final boolean save = userBalanceLogService.save(userBalanceLog);
System.out.println("记录余额明细 = " + save);
// 支付成功后的事务处理
shopOrderService.onPaySuccess(order);
return success("支付成功",order);
}
// TODO 微信统一下单接口
// if (order.getPayType().equals(1)) {
// // 清空购物车
// final Set<Integer> cartIds = order.getGoodsList().stream().map(OrderGoods::getGoodsId).collect(Collectors.toSet());
// cartService.remove(new LambdaQueryWrapper<Cart>().eq(Cart::getUserId,order.getUserId()).in(Cart::getGoodsId,cartIds));
// // 外卖订单
// if(!order.getMerchantId().equals(0)){
// cartService.remove(new LambdaQueryWrapper<Cart>().eq(Cart::getUserId,order.getUserId()).eq(Cart::getType,1));
// }
// return success("下单成功", orderService.createWxOrder(order));
// }
// // TODO 微信Native支付
// if(order.getPayType().equals(102)){
// order.setAccessToken(access_token);
// order.setLoginUser(loginUser);
// return success("下单成功", orderService.payByWxNative(order));
// }
// TODO 会员卡支付
// if(order.getPayType().equals(2)){
// order.setAccessToken(order.getAccessToken());
// System.out.println("getAccessToken = " + order.getAccessToken());
// return success("下单成功", orderService.payByUserCard(order));
// }
return fail("支付失败");
}
}

View File

@@ -2,12 +2,11 @@ package com.gxwebsoft.shop.entity;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableLogic;
import java.io.Serializable;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -17,7 +16,7 @@ import lombok.EqualsAndHashCode;
* 商户
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Data
@EqualsAndHashCode(callSuper = false)
@@ -27,7 +26,7 @@ public class ShopMerchant implements Serializable {
@ApiModelProperty(value = "ID")
@TableId(value = "merchant_id", type = IdType.AUTO)
private Integer merchantId;
private Long merchantId;
@ApiModelProperty(value = "商户名称")
private String merchantName;
@@ -130,6 +129,14 @@ public class ShopMerchant implements Serializable {
@ApiModelProperty(value = "租户id")
private Integer tenantId;
@ApiModelProperty(value = "应用名称")
@TableField(exist = false)
private String tenantName;
@ApiModelProperty(value = "应用图标")
@TableField(exist = false)
private String logo;
@ApiModelProperty(value = "创建时间")
private Date createTime;

View File

@@ -2,10 +2,8 @@ package com.gxwebsoft.shop.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.Date;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -15,7 +13,7 @@ import lombok.EqualsAndHashCode;
* 商户账号
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Data
@EqualsAndHashCode(callSuper = false)
@@ -34,7 +32,7 @@ public class ShopMerchantAccount implements Serializable {
private String realName;
@ApiModelProperty(value = "商户ID")
private Integer merchantId;
private Long merchantId;
@ApiModelProperty(value = "角色ID")
private Integer roleId;

View File

@@ -2,11 +2,10 @@ package com.gxwebsoft.shop.entity;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.Date;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -16,7 +15,7 @@ import lombok.EqualsAndHashCode;
* 商户入驻申请
*
* @author 科技小王子
* @since 2024-10-02 08:08:23
* @since 2024-09-10 21:05:07
*/
@Data
@EqualsAndHashCode(callSuper = false)
@@ -28,6 +27,12 @@ public class ShopMerchantApply implements Serializable {
@TableId(value = "apply_id", type = IdType.AUTO)
private Integer applyId;
@ApiModelProperty(value = "类型")
private Integer type;
@ApiModelProperty(value = "店铺类型")
private String shopType;
@ApiModelProperty(value = "商户名称")
private String merchantName;
@@ -40,13 +45,28 @@ public class ShopMerchantApply implements Serializable {
@ApiModelProperty(value = "商户姓名")
private String realName;
@ApiModelProperty(value = "社会信用代码")
private String merchantCode;
@ApiModelProperty(value = "身份证号码")
private String idCard;
@ApiModelProperty(value = "店铺类型")
private String shopType;
@ApiModelProperty(value = "身份证正面")
private String sfz1;
@ApiModelProperty(value = "商户分类")
@ApiModelProperty(value = "身份证反面")
private String sfz2;
@ApiModelProperty(value = "营业执照")
private String yyzz;
@ApiModelProperty(value = "行业父级分类")
private Integer parentId;
@ApiModelProperty(value = "行业分类ID")
private Integer categoryId;
@ApiModelProperty(value = "行业分类")
private String category;
@ApiModelProperty(value = "手续费")
@@ -76,6 +96,12 @@ public class ShopMerchantApply implements Serializable {
@ApiModelProperty(value = "驳回原因")
private String reason;
@ApiModelProperty(value = "审核完成时间")
private Date completedTime;
@ApiModelProperty(value = "审核状态")
private Boolean checkStatus;
@ApiModelProperty(value = "备注")
private String comments;
@@ -88,6 +114,14 @@ public class ShopMerchantApply implements Serializable {
@ApiModelProperty(value = "租户id")
private Integer tenantId;
@ApiModelProperty(value = "应用名称")
@TableField(exist = false)
private String tenantName;
@ApiModelProperty(value = "应用图标")
@TableField(exist = false)
private String logo;
@ApiModelProperty(value = "创建时间")
private Date createTime;

View File

@@ -2,10 +2,8 @@ package com.gxwebsoft.shop.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.Date;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -15,7 +13,7 @@ import lombok.EqualsAndHashCode;
* 门店销售统计表
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Data
@EqualsAndHashCode(callSuper = false)

View File

@@ -2,10 +2,8 @@ package com.gxwebsoft.shop.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.Date;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -15,7 +13,7 @@ import lombok.EqualsAndHashCode;
* 商户类型
*
* @author 科技小王子
* @since 2024-10-02 10:07:52
* @since 2024-09-10 21:05:07
*/
@Data
@EqualsAndHashCode(callSuper = false)

View File

@@ -7,6 +7,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableLogic;
import java.io.Serializable;
import java.util.List;
import com.gxwebsoft.common.system.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -47,9 +50,11 @@ public class ShopOrder implements Serializable {
private Long merchantId;
@ApiModelProperty(value = "商户名称")
@TableField(exist = false)
private String merchantName;
@ApiModelProperty(value = "商户编号")
@TableField(exist = false)
private String merchantCode;
@ApiModelProperty(value = "使用的优惠券id")
@@ -176,18 +181,16 @@ public class ShopOrder implements Serializable {
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "自提码")
private String selfTakeCode;
@ApiModelProperty(value = "是否已收到赠品")
private Boolean hasTakeGift;
@ApiModelProperty(value = "accessToken")
@TableField(exist = false)
private String accessToken;
@ApiModelProperty(value = "openid")
@ApiModelProperty(value = "微信OPENID,用于微信支付")
@TableField(exist = false)
private String openid;
@ApiModelProperty(value = "当前登录用户")
@TableField(exist = false)
private User loginUser;
@ApiModelProperty(value = "订单商品信息")
@TableField(exist = false)
private List<ShopOrderGoods> orderProduct;
}

View File

@@ -3,6 +3,8 @@ package com.gxwebsoft.shop.entity;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDate;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalTime;
import java.util.Date;
@@ -38,6 +40,7 @@ public class ShopOrderGoods implements Serializable {
private Long merchantId;
@ApiModelProperty(value = "商户名称")
@TableField(exist = false)
private String merchantName;
@ApiModelProperty(value = "商品封面图")

View File

@@ -12,7 +12,7 @@ import java.util.List;
* 商户账号Mapper
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
public interface ShopMerchantAccountMapper extends BaseMapper<ShopMerchantAccount> {

View File

@@ -12,7 +12,7 @@ import java.util.List;
* 商户入驻申请Mapper
*
* @author 科技小王子
* @since 2024-10-02 08:08:23
* @since 2024-09-10 21:05:07
*/
public interface ShopMerchantApplyMapper extends BaseMapper<ShopMerchantApply> {

View File

@@ -12,7 +12,7 @@ import java.util.List;
* 门店销售统计表Mapper
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
public interface ShopMerchantCountMapper extends BaseMapper<ShopMerchantCount> {

View File

@@ -12,7 +12,7 @@ import java.util.List;
* 商户Mapper
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
public interface ShopMerchantMapper extends BaseMapper<ShopMerchant> {

View File

@@ -12,7 +12,7 @@ import java.util.List;
* 商户类型Mapper
*
* @author 科技小王子
* @since 2024-10-02 10:07:52
* @since 2024-09-10 21:05:07
*/
public interface ShopMerchantTypeMapper extends BaseMapper<ShopMerchantType> {

View File

@@ -4,15 +4,22 @@
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
SELECT a.*, b.short_name as tenantName, b.company_logo as logo
FROM shop_merchant_apply a
LEFT JOIN sys_company b ON a.tenant_id = b.tenant_id and deleted = 0
<where>
<if test="param.applyId != null">
AND a.apply_id = #{param.applyId}
</if>
<if test="param.type != null">
AND a.type = #{param.type}
</if>
<if test="param.merchantName != null">
AND a.merchant_name LIKE CONCAT('%', #{param.merchantName}, '%')
</if>
<if test="param.merchantCode != null">
AND a.merchant_code #{param.merchantCode}
</if>
<if test="param.image != null">
AND a.image LIKE CONCAT('%', #{param.image}, '%')
</if>
@@ -22,9 +29,6 @@
<if test="param.realName != null">
AND a.real_name LIKE CONCAT('%', #{param.realName}, '%')
</if>
<if test="param.idCard != null">
AND a.id_card LIKE CONCAT('%', #{param.idCard}, '%')
</if>
<if test="param.shopType != null">
AND a.shop_type LIKE CONCAT('%', #{param.shopType}, '%')
</if>
@@ -34,9 +38,6 @@
<if test="param.commission != null">
AND a.commission = #{param.commission}
</if>
<if test="param.keywords != null">
AND a.keywords LIKE CONCAT('%', #{param.keywords}, '%')
</if>
<if test="param.files != null">
AND a.files LIKE CONCAT('%', #{param.files}, '%')
</if>
@@ -73,6 +74,17 @@
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.keywords != null">
AND (a.apply_id = #{param.keywords}
OR a.tenant_id = #{param.keywords}
OR a.phone = #{param.keywords}
OR a.user_id = #{param.keywords}
OR a.real_name LIKE CONCAT('%', #{param.keywords}, '%')
OR a.merchant_name LIKE CONCAT('%', #{param.keywords}, '%')
OR a.merchant_code LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
</sql>

View File

@@ -4,8 +4,9 @@
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
SELECT a.*, b.short_name as tenantName, b.company_logo as logo
FROM shop_merchant a
LEFT JOIN sys_company b ON a.tenant_id = b.tenant_id
<where>
<if test="param.merchantId != null">
AND a.merchant_id = #{param.merchantId}
@@ -37,21 +38,9 @@
<if test="param.category != null">
AND a.category LIKE CONCAT('%', #{param.category}, '%')
</if>
<if test="param.merchantCategoryId != null">
AND a.merchant_category_id = #{param.merchantCategoryId}
</if>
<if test="param.merchantCategoryTitle != null">
AND a.merchant_category_title LIKE CONCAT('%', #{param.merchantCategoryTitle}, '%')
</if>
<if test="param.lngAndLat != null">
AND a.lng_and_lat LIKE CONCAT('%', #{param.lngAndLat}, '%')
</if>
<if test="param.lng != null">
AND a.lng LIKE CONCAT('%', #{param.lng}, '%')
</if>
<if test="param.lat != null">
AND a.lat LIKE CONCAT('%', #{param.lat}, '%')
</if>
<if test="param.province != null">
AND a.province LIKE CONCAT('%', #{param.province}, '%')
</if>
@@ -67,9 +56,6 @@
<if test="param.commission != null">
AND a.commission = #{param.commission}
</if>
<if test="param.keywords != null">
AND a.keywords LIKE CONCAT('%', #{param.keywords}, '%')
</if>
<if test="param.files != null">
AND a.files LIKE CONCAT('%', #{param.files}, '%')
</if>
@@ -118,6 +104,14 @@
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.keywords != null">
AND (a.merchant_id = #{param.keywords}
OR a.phone = #{param.keywords}
OR a.tenant_id = #{param.keywords}
OR a.user_id = #{param.keywords}
OR a.merchant_name LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
</sql>

View File

@@ -4,8 +4,9 @@
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
SELECT a.*, b.merchant_name as merchantName
FROM shop_order_goods a
LEFT JOIN shop_merchant b ON a.merchant_id = b.merchant_id
<where>
<if test="param.id != null">
AND a.id = #{param.id}

View File

@@ -4,8 +4,9 @@
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
SELECT a.*, b.merchant_name as merchantName, b.merchant_code
FROM shop_order a
LEFT JOIN shop_merchant b ON a.merchant_id = b.merchant_id
<where>
<if test="param.orderId != null">
AND a.order_id = #{param.orderId}
@@ -157,6 +158,12 @@
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.keywords != null">
AND (a.order_id = #{param.keywords}
OR a.order_no = #{param.keywords}
OR a.title LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
</sql>

View File

@@ -13,7 +13,7 @@ import lombok.EqualsAndHashCode;
* 商户账号查询参数
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Data
@EqualsAndHashCode(callSuper = false)

View File

@@ -15,7 +15,7 @@ import java.math.BigDecimal;
* 商户入驻申请查询参数
*
* @author 科技小王子
* @since 2024-10-02 08:08:23
* @since 2024-09-10 21:05:07
*/
@Data
@EqualsAndHashCode(callSuper = false)
@@ -28,9 +28,15 @@ public class ShopMerchantApplyParam extends BaseParam {
@QueryField(type = QueryType.EQ)
private Integer applyId;
@ApiModelProperty(value = "入驻类型")
private Integer type;
@ApiModelProperty(value = "商户名称")
private String merchantName;
@ApiModelProperty(value = "证件号码")
private String merchantCode;
@ApiModelProperty(value = "商户图标")
private String image;
@@ -40,9 +46,6 @@ public class ShopMerchantApplyParam extends BaseParam {
@ApiModelProperty(value = "商户姓名")
private String realName;
@ApiModelProperty(value = "身份证号码")
private String idCard;
@ApiModelProperty(value = "店铺类型")
private String shopType;

View File

@@ -13,7 +13,7 @@ import lombok.EqualsAndHashCode;
* 门店销售统计表查询参数
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Data
@EqualsAndHashCode(callSuper = false)

View File

@@ -15,7 +15,7 @@ import java.math.BigDecimal;
* 商户查询参数
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Data
@EqualsAndHashCode(callSuper = false)
@@ -56,20 +56,9 @@ public class ShopMerchantParam extends BaseParam {
@ApiModelProperty(value = "商户分类")
private String category;
@ApiModelProperty(value = "商户经营分类")
@QueryField(type = QueryType.EQ)
private Integer merchantCategoryId;
@ApiModelProperty(value = "商户分类")
private String merchantCategoryTitle;
@ApiModelProperty(value = "经纬度")
private String lngAndLat;
private String lng;
private String lat;
@ApiModelProperty(value = "所在省份")
private String province;

View File

@@ -13,7 +13,7 @@ import lombok.EqualsAndHashCode;
* 商户类型查询参数
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Data
@EqualsAndHashCode(callSuper = false)

View File

@@ -11,7 +11,7 @@ import java.util.List;
* 商户账号Service
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
public interface ShopMerchantAccountService extends IService<ShopMerchantAccount> {

View File

@@ -11,7 +11,7 @@ import java.util.List;
* 商户入驻申请Service
*
* @author 科技小王子
* @since 2024-10-02 08:08:23
* @since 2024-09-10 21:05:07
*/
public interface ShopMerchantApplyService extends IService<ShopMerchantApply> {
@@ -38,5 +38,4 @@ public interface ShopMerchantApplyService extends IService<ShopMerchantApply> {
* @return ShopMerchantApply
*/
ShopMerchantApply getByIdRel(Integer applyId);
}

View File

@@ -11,7 +11,7 @@ import java.util.List;
* 门店销售统计表Service
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
public interface ShopMerchantCountService extends IService<ShopMerchantCount> {

View File

@@ -11,7 +11,7 @@ import java.util.List;
* 商户Service
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
public interface ShopMerchantService extends IService<ShopMerchant> {

View File

@@ -11,7 +11,7 @@ import java.util.List;
* 商户类型Service
*
* @author 科技小王子
* @since 2024-10-02 10:07:52
* @since 2024-09-10 21:05:07
*/
public interface ShopMerchantTypeService extends IService<ShopMerchantType> {

View File

@@ -5,7 +5,6 @@ import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.shop.entity.ShopOrder;
import com.gxwebsoft.shop.param.ShopOrderParam;
import java.util.HashMap;
import java.util.List;
/**
@@ -40,5 +39,5 @@ public interface ShopOrderService extends IService<ShopOrder> {
*/
ShopOrder getByIdRel(Integer orderId);
HashMap<String, String> createWxOrder(ShopOrder shopOrder);
void onPaySuccess(ShopOrder order);
}

View File

@@ -15,7 +15,7 @@ import java.util.List;
* 商户账号Service实现
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Service
public class ShopMerchantAccountServiceImpl extends ServiceImpl<ShopMerchantAccountMapper, ShopMerchantAccount> implements ShopMerchantAccountService {

View File

@@ -15,7 +15,7 @@ import java.util.List;
* 商户入驻申请Service实现
*
* @author 科技小王子
* @since 2024-10-02 08:08:23
* @since 2024-09-10 21:05:07
*/
@Service
public class ShopMerchantApplyServiceImpl extends ServiceImpl<ShopMerchantApplyMapper, ShopMerchantApply> implements ShopMerchantApplyService {

View File

@@ -15,7 +15,7 @@ import java.util.List;
* 门店销售统计表Service实现
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Service
public class ShopMerchantCountServiceImpl extends ServiceImpl<ShopMerchantCountMapper, ShopMerchantCount> implements ShopMerchantCountService {

View File

@@ -15,7 +15,7 @@ import java.util.List;
* 商户Service实现
*
* @author 科技小王子
* @since 2024-10-02 10:07:51
* @since 2024-09-10 21:05:07
*/
@Service
public class ShopMerchantServiceImpl extends ServiceImpl<ShopMerchantMapper, ShopMerchant> implements ShopMerchantService {

View File

@@ -15,7 +15,7 @@ import java.util.List;
* 商户类型Service实现
*
* @author 科技小王子
* @since 2024-10-02 10:07:52
* @since 2024-09-10 21:05:07
*/
@Service
public class ShopMerchantTypeServiceImpl extends ServiceImpl<ShopMerchantTypeMapper, ShopMerchantType> implements ShopMerchantTypeService {

View File

@@ -1,30 +1,16 @@
package com.gxwebsoft.shop.service.impl;
import com.alibaba.fastjson.JSONObject;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.config.ConfigProperties;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.shop.mapper.ShopOrderMapper;
import com.gxwebsoft.shop.service.ShopOrderService;
import com.gxwebsoft.shop.entity.ShopOrder;
import com.gxwebsoft.shop.param.ShopOrderParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAConfig;
import com.wechat.pay.java.core.RSAPublicKeyConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
/**
@@ -35,18 +21,8 @@ import java.util.List;
*/
@Service
public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderMapper, ShopOrder> implements ShopOrderService {
@Value("${spring.profiles.active}")
String active;
@Resource
private ConfigProperties config;
@Resource
private RedisUtil redisUtil;
public static String privateKeyPath = "/Users/gxwebsoft/Downloads/ef7f7e0430cb47019d06b93f885bf95f/apiclient_key.pem";
public static String privateCertPath = "/Users/gxwebsoft/JAVA/com.gxwebsoft.core/src/main/resources/cert/apiclient_cert.pem";
public static String wechatpayCertPath = "/Users/gxwebsoft/Downloads/ef7f7e0430cb47019d06b93f885bf95f/wechatpay_55729BDEC2502C301BA02CDC28E4CEE4DE4D1DB9.pem"; // 平台证书
private ShopOrderService shopOrderService;
@Override
public PageResult<ShopOrder> pageRel(ShopOrderParam param) {
@@ -72,95 +48,16 @@ public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderMapper, ShopOrder
return param.getOne(baseMapper.selectListRel(param));
}
/**
* 支付成功后的事务处理
* @param order
*/
@Override
public HashMap<String, String> createWxOrder(ShopOrder order) {
Integer payType = order.getPayType();
final String uploadPath = config.getUploadPath(); // 服务器本地路径
final HashMap<String, String> orderInfo = new HashMap<>();
// 微信小程序(微信支付)
String key = "mp-weixin:".concat(order.getTenantId().toString());
final String string = redisUtil.get(key);
// System.out.println("string = " + string);
final JSONObject mpWx = JSONObject.parseObject(string);
// System.out.println("mpWx = " + mpWx);
String key2 = "Payment:".concat(payType.toString()).concat(":").concat(order.getTenantId().toString());
final Payment payment = redisUtil.get(key2, Payment.class);
// System.out.println("payment = " + payment);
// 计算金额
BigDecimal decimal = order.getTotalPrice();
final BigDecimal multiply = decimal.multiply(new BigDecimal(100));
// 将 BigDecimal 转换为 Integer
Integer money = multiply.intValue();
String privateKey = uploadPath.concat("/file").concat(payment.getApiclientKey()); // 秘钥证书
String apiclientCert = uploadPath.concat("/file").concat(payment.getApiclientCert());
String pubKey = uploadPath.concat("/file").concat(payment.getPubKey()); // 公钥证书
// 开发环境配置
if (active.equals("dev")) {
privateKey = privateKeyPath;
apiclientCert = wechatpayCertPath;
}
// 兼容公钥
Config config;
if (payment.getPubKey() != null && !payment.getPubKey().isEmpty()) {
config = new RSAPublicKeyConfig.Builder()
.merchantId(payment.getMchId())
.privateKeyFromPath(privateKey)
.publicKeyFromPath(pubKey)
.publicKeyId(payment.getPubKeyId())
.merchantSerialNumber(payment.getMerchantSerialNumber())
.apiV3Key(payment.getApiKey())
.build();
} else {
config = new RSAConfig.Builder()
.merchantId(payment.getMchId())
.privateKeyFromPath(privateKey)
.merchantSerialNumber(payment.getMerchantSerialNumber())
.wechatPayCertificatesFromPath(apiclientCert)
.build();
}
// 构建service
JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
// 跟之前下单示例一样,填充预下单参数
PrepayRequest request = new PrepayRequest();
Amount amount = new Amount();
amount.setTotal(money);
amount.setCurrency("CNY");
request.setAmount(amount);
request.setAppid(mpWx.getString("appId"));
request.setMchid(payment.getMchId());
request.setDescription(order.getComments());
request.setOutTradeNo(order.getOrderNo());
request.setAttach(order.getTenantId().toString());
final Payer payer = new Payer();
payer.setOpenid(order.getOpenid());
request.setPayer(payer);
// 测试环境
if (active.equals("dev")) {
amount.setTotal(1);
request.setAmount(amount);
request.setNotifyUrl("http://jimei-api.natapp1.cc/api/shop/wx-pay/notify/" + order.getTenantId()); // 默认回调地址
}
// 生成环境
if (active.equals("prod")) {
request.setAmount(amount);
request.setNotifyUrl("https://server.gxwebsoft.com/api/system/wx-pay/notify/" + order.getTenantId()); // 默认回调地址
}
// if (StrUtil.isNotBlank(payment.getNotifyUrl())) {
// 后台配置的回调地址
// request.setNotifyUrl(payment.getNotifyUrl().concat("/").concat(order.getTenantId().toString()));
// }
System.out.println("request = " + request);
PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
orderInfo.put("provider", "wxpay");
orderInfo.put("timeStamp", response.getTimeStamp());
orderInfo.put("nonceStr", response.getNonceStr());
orderInfo.put("package", response.getPackageVal());
orderInfo.put("signType", "RSA");
orderInfo.put("paySign", response.getPaySign());
return orderInfo;
public void onPaySuccess(ShopOrder order) {
System.out.println("支付成功后的事务处理 = " + order);
order.setPayStatus(true);
order.setPayTime(DateUtil.date());
shopOrderService.updateById(order);
}
}

View File

@@ -1,6 +1,6 @@
# 端口
server:
port: 9001
port: 8000
# socketIo
socketio:
port: 30091