240401
This commit is contained in:
@@ -33,6 +33,11 @@ public class CategoryController extends BaseController {
|
||||
@Resource
|
||||
private CategoryService categoryService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ApiResult<List<Category>> listForFront() {
|
||||
return success(categoryService.list());
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:category:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询商品分类表")
|
||||
|
||||
@@ -7,8 +7,14 @@ import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.shop.entity.Goods;
|
||||
import com.gxwebsoft.shop.entity.GoodsPrice;
|
||||
import com.gxwebsoft.shop.param.GoodsParam;
|
||||
import com.gxwebsoft.shop.param.GoodsPhoneModelParam;
|
||||
import com.gxwebsoft.shop.service.GoodsPhoneModelService;
|
||||
import com.gxwebsoft.shop.service.GoodsPriceService;
|
||||
import com.gxwebsoft.shop.service.GoodsService;
|
||||
import com.gxwebsoft.vivo.entity.VivoPhoneModel;
|
||||
import com.gxwebsoft.vivo.param.VivoPhoneModelParam;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -29,17 +35,62 @@ import java.util.List;
|
||||
public class GoodsController extends BaseController {
|
||||
@Resource
|
||||
private GoodsService goodsService;
|
||||
@Resource
|
||||
private GoodsPhoneModelService goodsPhoneModelService;
|
||||
@Resource
|
||||
private GoodsPriceService goodsPriceService;
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public ApiResult<List<Goods>> listForFront(@RequestBody GoodsParam param) {
|
||||
List<Goods> goodsList = goodsService.listRel(param);
|
||||
goodsService.setData(goodsList, getLoginUser());
|
||||
return success(goodsList);
|
||||
}
|
||||
|
||||
@PostMapping("/info")
|
||||
public ApiResult<Goods> info(@RequestBody GoodsParam param) {
|
||||
Goods goods = goodsService.getById(param.getGoodsId());
|
||||
User loginUser = getLoginUser();
|
||||
GoodsPrice goodsPrice = goodsPriceService.getByGoodsIdNCity(goods.getGoodsId(), loginUser.getCityId());
|
||||
goods.setGoodsPrice(goodsPrice);
|
||||
return success(goods);
|
||||
}
|
||||
|
||||
@PostMapping("/info-by-phone-code")
|
||||
public ApiResult<?> infoByPhoneCode(@RequestBody VivoPhoneModelParam phoneModelParam) {
|
||||
List<Goods> goodsList = goodsService.getByPhoneModelCode(phoneModelParam.getCode());
|
||||
User loginUser = getLoginUser();
|
||||
if (goodsList.isEmpty()) return fail("该机型暂无碎屏宝");
|
||||
goodsList.forEach(goods -> {
|
||||
GoodsPrice goodsPrice = goodsPriceService.getByGoodsIdNCity(goods.getGoodsId(), loginUser.getCityId());
|
||||
goods.setGoodsPrice(goodsPrice);
|
||||
});
|
||||
return success(goodsList);
|
||||
}
|
||||
|
||||
@PostMapping("/info-by-phone-model")
|
||||
public ApiResult<?> infoByPhoneModel(@RequestBody VivoPhoneModelParam phoneModelParam) {
|
||||
List<Goods> goodsList = goodsService.getByPhoneModel(phoneModelParam.getName());
|
||||
User loginUser = getLoginUser();
|
||||
if (goodsList == null) return fail("该机型暂无碎屏宝");
|
||||
goodsList.forEach(goods -> {
|
||||
GoodsPrice goodsPrice = goodsPriceService.getByGoodsIdNCity(goods.getGoodsId(), loginUser.getCityId());
|
||||
goods.setGoodsPrice(goodsPrice);
|
||||
});
|
||||
return success(goodsList);
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goods:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询商品记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Goods>> page(GoodsParam param) {
|
||||
// PageParam<Goods, GoodsParam> page = new PageParam<>(param);
|
||||
// page.setDefaultOrder("create_time desc");
|
||||
// return success(goodsService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
return success(goodsService.pageRel(param));
|
||||
PageResult<Goods> page = goodsService.pageRel(param);
|
||||
goodsService.setData(page.getList(), getLoginUser());
|
||||
return success(page);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goods:list')")
|
||||
@@ -51,7 +102,9 @@ public class GoodsController extends BaseController {
|
||||
// page.setDefaultOrder("create_time desc");
|
||||
// return success(goodsService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
return success(goodsService.listRel(param));
|
||||
List<Goods> goodsList = goodsService.listRel(param);
|
||||
goodsService.setData(goodsList, getLoginUser());
|
||||
return success(goodsList);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goods:list')")
|
||||
@@ -72,9 +125,12 @@ public class GoodsController extends BaseController {
|
||||
// 记录当前登录用户id、租户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
goods.setUserId(loginUser.getUserId());
|
||||
goods.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (goodsService.save(goods)) {
|
||||
if (goods.getGoodsPhoneModelList() != null) {
|
||||
addPhoneModel(goods);
|
||||
}
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
@@ -86,11 +142,22 @@ public class GoodsController extends BaseController {
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Goods goods) {
|
||||
if (goodsService.updateById(goods)) {
|
||||
addPhoneModel(goods);
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
private void addPhoneModel(Goods goods) {
|
||||
if (goods.getGoodsPhoneModelList() != null) {
|
||||
goodsPhoneModelService.delByGoodsId(goods.getGoodsId());
|
||||
goods.getGoodsPhoneModelList().forEach(goodsPhoneModel -> {
|
||||
goodsPhoneModel.setGoodsId(goods.getGoodsId());
|
||||
});
|
||||
goodsPhoneModelService.saveBatch(goods.getGoodsPhoneModelList());
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goods:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除商品记录表")
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.shop.service.GoodsPhoneModelService;
|
||||
import com.gxwebsoft.shop.entity.GoodsPhoneModel;
|
||||
import com.gxwebsoft.shop.param.GoodsPhoneModelParam;
|
||||
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.util.List;
|
||||
|
||||
/**
|
||||
* 商品匹配机型控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-03-12 01:30:55
|
||||
*/
|
||||
@Api(tags = "商品匹配机型管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/shop/goods-phone-model")
|
||||
public class GoodsPhoneModelController extends BaseController {
|
||||
@Resource
|
||||
private GoodsPhoneModelService goodsPhoneModelService;
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPhoneModel:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询商品匹配机型")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<GoodsPhoneModel>> page(GoodsPhoneModelParam param) {
|
||||
PageParam<GoodsPhoneModel, GoodsPhoneModelParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(goodsPhoneModelService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(goodsPhoneModelService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPhoneModel:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部商品匹配机型")
|
||||
@GetMapping()
|
||||
public ApiResult<List<GoodsPhoneModel>> list(GoodsPhoneModelParam param) {
|
||||
PageParam<GoodsPhoneModel, GoodsPhoneModelParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(goodsPhoneModelService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(goodsPhoneModelService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPhoneModel:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询商品匹配机型")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<GoodsPhoneModel> get(@PathVariable("id") Integer id) {
|
||||
return success(goodsPhoneModelService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(goodsPhoneModelService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPhoneModel:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加商品匹配机型")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody GoodsPhoneModel goodsPhoneModel) {
|
||||
if (goodsPhoneModelService.save(goodsPhoneModel)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPhoneModel:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改商品匹配机型")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody GoodsPhoneModel goodsPhoneModel) {
|
||||
if (goodsPhoneModelService.updateById(goodsPhoneModel)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPhoneModel:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除商品匹配机型")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (goodsPhoneModelService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPhoneModel:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加商品匹配机型")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<GoodsPhoneModel> list) {
|
||||
if (goodsPhoneModelService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPhoneModel:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改商品匹配机型")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<GoodsPhoneModel> batchParam) {
|
||||
if (batchParam.update(goodsPhoneModelService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPhoneModel:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除商品匹配机型")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (goodsPhoneModelService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Area;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.AreaService;
|
||||
import com.gxwebsoft.shop.service.GoodsPriceService;
|
||||
import com.gxwebsoft.shop.entity.GoodsPrice;
|
||||
import com.gxwebsoft.shop.param.GoodsPriceParam;
|
||||
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.util.List;
|
||||
|
||||
/**
|
||||
* 商品价格()控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-03-12 01:35:40
|
||||
*/
|
||||
@Api(tags = "商品价格()管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/shop/goods-price")
|
||||
public class GoodsPriceController extends BaseController {
|
||||
@Resource
|
||||
private GoodsPriceService goodsPriceService;
|
||||
@Resource
|
||||
private AreaService areaService;
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询商品价格()")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<GoodsPrice>> page(GoodsPriceParam param) {
|
||||
PageParam<GoodsPrice, GoodsPriceParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(goodsPriceService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(goodsPriceService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部商品价格()")
|
||||
@GetMapping()
|
||||
public ApiResult<List<GoodsPrice>> list(GoodsPriceParam param) {
|
||||
PageParam<GoodsPrice, GoodsPriceParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(goodsPriceService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(goodsPriceService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询商品价格()")
|
||||
@GetMapping("/info-by-city/{goodsId}/{cityId}")
|
||||
public ApiResult<GoodsPrice> infoByCity(@PathVariable("goodsId") Integer goodsId, @PathVariable("cityId") Integer cityId) {
|
||||
return success(goodsPriceService.getByGoodsIdNCity(goodsId, cityId));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询商品价格()")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<GoodsPrice> get(@PathVariable("id") Integer id) {
|
||||
return success(goodsPriceService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(goodsPriceService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询商品价格()")
|
||||
@GetMapping("/by-goodsId-n-city/{id}")
|
||||
public ApiResult<GoodsPrice> getByGoodsIdNCity(@PathVariable("id") Integer id) {
|
||||
User loginUser = getLoginUser();
|
||||
return success(goodsPriceService.getByGoodsIdNCity(id, loginUser.getCityId()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加商品价格()")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody GoodsPrice goodsPrice) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
goodsPrice.setUserId(loginUser.getUserId());
|
||||
Area province = areaService.getParent(goodsPrice.getCity());
|
||||
goodsPrice.setProvince(province.getId());
|
||||
goodsPrice.setProvince(loginUser.getCityId());
|
||||
}
|
||||
if (goodsPriceService.save(goodsPrice)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改商品价格()")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody GoodsPrice goodsPrice) {
|
||||
if (goodsPriceService.updateById(goodsPrice)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除商品价格()")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (goodsPriceService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加商品价格()")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<GoodsPrice> list) {
|
||||
if (goodsPriceService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改商品价格()")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<GoodsPrice> batchParam) {
|
||||
if (batchParam.update(goodsPriceService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:goodsPrice:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除商品价格()")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (goodsPriceService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +1,57 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import cn.hutool.extra.qrcode.QrConfig;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.apps.entity.BcAgent;
|
||||
import com.gxwebsoft.apps.entity.EquipmentGoods;
|
||||
import com.gxwebsoft.apps.entity.EquipmentOrderGoods;
|
||||
import com.gxwebsoft.apps.param.BcAgentParam;
|
||||
import com.gxwebsoft.apps.service.BcAgentService;
|
||||
import com.gxwebsoft.apps.service.EquipmentGoodsService;
|
||||
import com.gxwebsoft.apps.service.EquipmentOrderGoodsService;
|
||||
import com.gxwebsoft.apps.service.EquipmentService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.Area;
|
||||
import com.gxwebsoft.common.system.entity.FileRecord;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.service.FileRecordService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.entity.UserReferee;
|
||||
import com.gxwebsoft.shop.constants.OrderConstants;
|
||||
import com.gxwebsoft.shop.entity.*;
|
||||
import com.gxwebsoft.shop.param.OrderGoodsParam;
|
||||
import com.gxwebsoft.shop.param.OrderParam;
|
||||
import com.gxwebsoft.shop.service.OrderGoodsService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import com.gxwebsoft.shop.service.UserRefereeService;
|
||||
import com.gxwebsoft.shop.service.*;
|
||||
import com.gxwebsoft.shop.service.GoodsService;
|
||||
import com.gxwebsoft.vivo.entity.VivoFixStore;
|
||||
import com.gxwebsoft.vivo.entity.VivoStore;
|
||||
import com.gxwebsoft.vivo.service.VivoFixStoreService;
|
||||
import com.gxwebsoft.vivo.service.VivoStoreService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -53,59 +70,231 @@ public class OrderController extends BaseController {
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private EquipmentGoodsService equipmentGoodsService;
|
||||
@Resource
|
||||
private EquipmentService equipmentService;
|
||||
@Resource
|
||||
private OrderGoodsService orderGoodsService;
|
||||
@Resource
|
||||
private EquipmentOrderGoodsService equipmentOrderGoodsService;
|
||||
private GoodsService goodsService;
|
||||
@Resource
|
||||
private UserRefereeService userRefereeService;
|
||||
private GoodsPriceService goodsPriceService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private BcAgentService bcAgentService;
|
||||
private VivoStoreService storeService;
|
||||
@Resource
|
||||
private VivoFixStoreService fixStoreService;
|
||||
@Resource
|
||||
private UserBalanceLogService userBalanceLogService;
|
||||
@Resource
|
||||
private OrderRefundService orderRefundService;
|
||||
@Resource
|
||||
private FileRecordService fileRecordService;
|
||||
|
||||
@Autowired
|
||||
private WxPayController wxPayController;
|
||||
|
||||
@Value("${config.upload-path}")
|
||||
private String uploadPath;
|
||||
|
||||
@Value("${config.server-url}")
|
||||
private String requestURL;
|
||||
|
||||
@PostMapping("/new")
|
||||
public ApiResult<?> addOrder(@RequestBody Order order) {
|
||||
User loginUser = getLoginUser();
|
||||
order.setUserId(loginUser.getUserId());
|
||||
order.setOrgId(loginUser.getOrganizationId());
|
||||
order.setOrderNo(makeOrderNumber(""));
|
||||
Goods goods = goodsService.getById(order.getGoodsId());
|
||||
GoodsPrice goodsPrice = goodsPriceService.getByGoodsIdNCity(goods.getGoodsId(), loginUser.getCityId());
|
||||
order.setStoreId(loginUser.getStoreId());
|
||||
order.setCityId(loginUser.getCityId());
|
||||
BigDecimal goodsAmount = goods.getLinePriceMin();
|
||||
BigDecimal commission = BigDecimal.ZERO;
|
||||
if (goodsPrice != null) {
|
||||
if (loginUser.getUserLevel().equals(5) || loginUser.getUserLevel().equals(8)) {
|
||||
goodsAmount = goods.getGoodsPriceMin();
|
||||
}
|
||||
if (loginUser.getUserLevel().equals(3)) {
|
||||
if (goodsPrice.getLevel3commissionMode().equals(1)) {
|
||||
commission = goodsAmount.multiply(goodsPrice.getLevel3commissionRate()).divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP);
|
||||
} else {
|
||||
commission = goodsPrice.getLevel3commissionRate();
|
||||
}
|
||||
order.setCommission(commission);
|
||||
} else if (loginUser.getUserLevel().equals(4)) {
|
||||
if (goodsPrice.getLevel4commissionMode().equals(1)) {
|
||||
commission = goodsAmount.multiply(goodsPrice.getLevel4commissionRate()).divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP);
|
||||
} else {
|
||||
commission = goodsPrice.getLevel4commissionRate();
|
||||
}
|
||||
order.setCommission(commission);
|
||||
} else if (loginUser.getUserLevel().equals(5) || loginUser.getUserLevel().equals(8)) {
|
||||
commission = goodsAmount.multiply(goodsPrice.getLevel5commissionRate()).divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP);
|
||||
order.setCommission(commission);
|
||||
} else if (loginUser.getUserLevel().equals(6)) {
|
||||
if (goodsPrice.getLevel6commissionMode().equals(1)) {
|
||||
commission = goodsAmount.multiply(goodsPrice.getLevel6commissionRate()).divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP);
|
||||
} else {
|
||||
commission = goodsPrice.getLevel6commissionRate();
|
||||
}
|
||||
order.setCommission(commission);
|
||||
} else if (loginUser.getUserLevel().equals(7)) {
|
||||
if (goodsPrice.getLevel7commissionMode().equals(1)) {
|
||||
commission = goodsAmount.multiply(goodsPrice.getLevel7commissionRate()).divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP);
|
||||
} else {
|
||||
commission = goodsPrice.getLevel7commissionRate();
|
||||
}
|
||||
order.setCommission(commission);
|
||||
}
|
||||
// else if (loginUser.getUserLevel().equals(8)) {
|
||||
// commission = goodsAmount.multiply(goodsPrice.getLevel8commissionRate()).divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP);
|
||||
// order.setCommission(commission);
|
||||
// }
|
||||
// if (loginUser.getUserLevel().equals(5) || loginUser.getUserLevel().equals(8)) {
|
||||
// if (loginUser.getFixStoreId() != null) {
|
||||
// BigDecimal fixStoreLeaderCommission = order.getCommission()
|
||||
// .multiply(goodsPrice.getFixStoreLeaderCommissionRate())
|
||||
// .divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP);
|
||||
// order.setFixStoreLeaderCommission(fixStoreLeaderCommission);
|
||||
// }
|
||||
// }
|
||||
if (loginUser.getUserLevel().equals(5) || loginUser.getUserLevel().equals(8)) {
|
||||
order.setAgentCommission(BigDecimal.ZERO);
|
||||
} else {
|
||||
order.setAgentCommission(goodsAmount.subtract(goods.getCost()).subtract(commission));
|
||||
}
|
||||
}
|
||||
order.setTotalPrice(goodsAmount);
|
||||
if (loginUser.getUserLevel().equals(5) || loginUser.getUserLevel().equals(8)) {
|
||||
if (loginUser.getFixStoreId() != null) {
|
||||
order.setFixStoreId(loginUser.getFixStoreId());
|
||||
}
|
||||
}
|
||||
if (orderService.save(order)) {
|
||||
OrderGoods orderGoods = order.getOrderGoods();
|
||||
orderGoods.setOrderId(order.getOrderId());
|
||||
orderGoods.setUserId(getLoginUserId());
|
||||
orderGoodsService.save(orderGoods);
|
||||
return success("下单成功", order.getOrderId());
|
||||
}
|
||||
return fail("下单失败");
|
||||
}
|
||||
|
||||
@PostMapping("/update-info")
|
||||
public ApiResult<?> updateInfo(@RequestBody Order order) {
|
||||
return success(orderService.updateById(order));
|
||||
}
|
||||
|
||||
@PostMapping("/make-pay-qr")
|
||||
public ApiResult<?> makePayQr(@RequestBody Order order) {
|
||||
Order order1 = orderService.getById(order.getOrderId());
|
||||
Goods goods = goodsService.getById(order1.getGoodsId());
|
||||
return success(wxPayController.nativePay(order1.getOrderNo(),
|
||||
order1.getTotalPrice().multiply(BigDecimal.valueOf(100)).intValue(), goods.getGoodsName()));
|
||||
}
|
||||
|
||||
@PostMapping("/set-pay-voucher")
|
||||
public ApiResult<?> setPayVoucher(@RequestBody Order order) {
|
||||
order.setOrderStatus(OrderConstants.ORDER_STATUS_PAID);
|
||||
Order order1 = orderService.getById(order.getOrderId());
|
||||
order.setReceiptAmount(order1.getTotalAmount());
|
||||
if (orderService.updateById(order)) {
|
||||
orderService.updateIncome(order1);
|
||||
return success("更新成功");
|
||||
}
|
||||
return fail("更新失败");
|
||||
}
|
||||
|
||||
@PostMapping("/set-refund")
|
||||
public ApiResult<?> setRefund(@RequestBody Order order) {
|
||||
order.setOrderStatus(OrderConstants.ORDER_STATUS_REFUNDING);
|
||||
if (orderService.updateById(order)) {
|
||||
Order order1 = orderService.getById(order.getOrderId());
|
||||
OrderRefund orderRefund = new OrderRefund();
|
||||
orderRefund.setOrderId(order1.getOrderId());
|
||||
orderRefund.setOrderGoodsId(order1.getGoodsId());
|
||||
orderRefund.setRefundMoney(order1.getReceiptAmount());
|
||||
orderRefund.setTenantId(10049);
|
||||
orderRefundService.save(orderRefund);
|
||||
return success("申请成功,请等待审核");
|
||||
}
|
||||
return fail("更新失败");
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/do-refund")
|
||||
public ApiResult<?> doRefund(@RequestBody Order order) {
|
||||
if (orderService.updateById(order)) {
|
||||
refund(order);
|
||||
return success("退款成功");
|
||||
}
|
||||
return fail("退款失败");
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public ApiResult<?> listForFront(@RequestBody OrderParam param) {
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser.getUserLevel() < 3) {
|
||||
if (loginUser.getUserLevel().equals(1)) {
|
||||
param.setCityId(loginUser.getCityId());
|
||||
param.setFixStoreId(0);
|
||||
}
|
||||
} else {
|
||||
if (loginUser.getUserLevel().equals(8)) {
|
||||
VivoFixStore fixStore = fixStoreService.getByUserId(loginUser.getUserId());
|
||||
if (fixStore != null) {
|
||||
param.setFixStoreId(fixStore.getId());
|
||||
}
|
||||
} else {
|
||||
param.setUserId(getLoginUserId());
|
||||
}
|
||||
}
|
||||
List<Order> list = orderService.listRel(param);
|
||||
list.forEach(order -> {
|
||||
if (order.getStoreId() != null) order.setStore(storeService.getById(order.getStoreId()));
|
||||
if (order.getFixStoreId() != null) order.setFixStore(fixStoreService.getById(order.getFixStoreId()));
|
||||
Goods goods = goodsService.getById(order.getGoodsId());
|
||||
goods.setGoodsPrice(goodsPriceService.getByGoodsIdNCity(goods.getGoodsId(), loginUser.getCityId()));
|
||||
order.setGoods(goods);
|
||||
order.setUser(userService.getById(order.getUserId()));
|
||||
});
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/info")
|
||||
public ApiResult<Order> info(@RequestBody OrderParam param) {
|
||||
Order order = orderService.getByIdRel(param.getOrderId());
|
||||
if (order != null) {
|
||||
if (order.getStoreId() != null) order.setStore(storeService.getById(order.getStoreId()));
|
||||
if (order.getFixStoreId() != null) order.setFixStore(fixStoreService.getById(order.getFixStore()));
|
||||
}
|
||||
return success(order);
|
||||
}
|
||||
|
||||
@PostMapping("/set-done")
|
||||
public ApiResult<Order> setDone(@RequestBody Order order) {
|
||||
order.setUseTime(DateUtil.date());
|
||||
orderService.updateById(order);
|
||||
return success(order);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询订单记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Order>> page(OrderParam param) {
|
||||
// 搜索条件
|
||||
if (getMerchantCode() != null) {
|
||||
param.setMerchantCode(getMerchantCode());
|
||||
@PostMapping("/page")
|
||||
public ApiResult<PageResult<Order>> page(@RequestBody OrderParam param) {
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser.getUserLevel().equals(1)) {
|
||||
param.setCityId(loginUser.getCityId());
|
||||
}
|
||||
// 云芯威项目查询关联设备
|
||||
if(getTenantId().equals(6)){
|
||||
// 查询订单的关联商品
|
||||
List<Order> list = orderService.listRel(param);
|
||||
// 查询订单的设备
|
||||
for (Order order : list) {
|
||||
final OrderGoodsParam orderGoodsParam = new OrderGoodsParam();
|
||||
orderGoodsParam.setOrderId(order.getOrderId());
|
||||
order.setGoodsList(orderGoodsService.listRel(orderGoodsParam));
|
||||
order.setEquipmentGoods(equipmentOrderGoodsService.getOne(new LambdaQueryWrapper<EquipmentOrderGoods>().eq(EquipmentOrderGoods::getOrderId,order.getOrderId())));
|
||||
order.setEquipment(equipmentService.getById(order.getEquipmentId()));
|
||||
}
|
||||
PageParam<Order, OrderParam> page = new PageParam<>(param);
|
||||
return success(new PageResult<>(list, page.getTotal()));
|
||||
}
|
||||
// 贵港自然资源报餐
|
||||
if(getTenantId().equals(10048) && getAppId() != null){
|
||||
final BcAgentParam bcAgentParam = new BcAgentParam();
|
||||
bcAgentParam.setParentId(getLoginUserId());
|
||||
bcAgentParam.setLimit(100L);
|
||||
final PageResult<BcAgent> result = bcAgentService.pageRel(bcAgentParam);
|
||||
final Set<Integer> collect = result.getList().stream().map(BcAgent::getUserId).collect(Collectors.toSet());
|
||||
collect.add(getLoginUserId());
|
||||
param.setUserId(null);
|
||||
param.setUserIds(collect);
|
||||
return success(orderService.pageRel(param));
|
||||
}
|
||||
|
||||
// 使用关联查询
|
||||
return success(orderService.pageRel(param));
|
||||
Page<Order> list = orderService.getByPage(param);
|
||||
list.getRecords().forEach(order -> {
|
||||
if (order.getStoreId() != null) order.setStore(storeService.getById(order.getStoreId()));
|
||||
if (order.getFixStoreId() != null) order.setFixStore(fixStoreService.getById(order.getFixStore()));
|
||||
Goods goods = goodsService.getById(order.getGoodsId());
|
||||
order.setGoods(goods);
|
||||
order.setUser(userService.getById(order.getUserId()));
|
||||
});
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:list')")
|
||||
@@ -113,8 +302,12 @@ public class OrderController extends BaseController {
|
||||
@ApiOperation("查询全部订单记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Order>> list(OrderParam param) {
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser.getUserLevel().equals(1)) {
|
||||
param.setCityId(loginUser.getCityId());
|
||||
}
|
||||
// 使用关联查询
|
||||
return success(orderService.listRel(param));
|
||||
return success(orderService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:list')")
|
||||
@@ -122,21 +315,21 @@ public class OrderController extends BaseController {
|
||||
@ApiOperation("按订单集查询")
|
||||
@PostMapping("/listByIds")
|
||||
public ApiResult<List<Order>> listByIds(@RequestBody List<Integer> orderIds) {
|
||||
System.out.println("按订单集查询 = " + orderIds);
|
||||
Integer userId = getLoginUserId();
|
||||
// 代报餐情况(未完成)
|
||||
final Order order = orderService.getById(orderIds.get(0));
|
||||
if (!order.getUserId().equals(getLoginUserId())) {
|
||||
userId = order.getUserId();
|
||||
final List<Order> list1 = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getOrderId,orderIds).eq(Order::getUserId, userId).eq(Order::getPayStatus,PAY_STATUS_NO_PAY));
|
||||
final Set<Integer> collect = list1.stream().map(Order::getOrderId).collect(Collectors.toSet());
|
||||
return success(orderService.listByIds(collect));
|
||||
}
|
||||
System.out.println("按订单集查询 = " + orderIds);
|
||||
Integer userId = getLoginUserId();
|
||||
// 代报餐情况(未完成)
|
||||
final Order order = orderService.getById(orderIds.get(0));
|
||||
if (!order.getUserId().equals(getLoginUserId())) {
|
||||
userId = order.getUserId();
|
||||
final List<Order> list1 = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getOrderId, orderIds).eq(Order::getUserId, userId).eq(Order::getPayStatus, PAY_STATUS_NO_PAY));
|
||||
final Set<Integer> collect = list1.stream().map(Order::getOrderId).collect(Collectors.toSet());
|
||||
return success(orderService.listByIds(collect));
|
||||
}
|
||||
|
||||
final List<Order> list1 = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getUserId, getLoginUserId()).eq(Order::getPayStatus,PAY_STATUS_NO_PAY));
|
||||
final List<Integer> collect = list1.stream().map(Order::getOrderId).collect(Collectors.toList());
|
||||
// 使用关联查询
|
||||
return success(orderService.listByIds(collect));
|
||||
final List<Order> list1 = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getUserId, getLoginUserId()).eq(Order::getPayStatus, PAY_STATUS_NO_PAY));
|
||||
final List<Integer> collect = list1.stream().map(Order::getOrderId).collect(Collectors.toList());
|
||||
// 使用关联查询
|
||||
return success(orderService.listByIds(collect));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:list')")
|
||||
@@ -144,14 +337,10 @@ public class OrderController extends BaseController {
|
||||
@ApiOperation("根据id查询订单记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Order> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
Order order = orderService.getByIdRel(id);
|
||||
// 云芯威关联设备查询
|
||||
if (!order.getGoodsId().equals(0) || !order.getEquipmentId().equals(0)) {
|
||||
order.setEquipmentGoods(equipmentOrderGoodsService.getOne(new LambdaQueryWrapper<EquipmentOrderGoods>().eq(EquipmentOrderGoods::getOrderId,order.getOrderId())));
|
||||
order.setEquipment(equipmentService.getById(order.getEquipmentId()));
|
||||
}
|
||||
return success(order);
|
||||
// 使用关联查询
|
||||
Order order = orderService.getByIdRel(id);
|
||||
|
||||
return success(order);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:save')")
|
||||
@@ -162,58 +351,14 @@ public class OrderController extends BaseController {
|
||||
// 记录当前登录用户id、租户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
order.setUserId(loginUser.getUserId());
|
||||
order.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (orderService.save(order)) {
|
||||
// 云芯威BMS
|
||||
if (order.getTenantId().equals(6)) {
|
||||
final EquipmentGoods eg = equipmentGoodsService.getById(order.getOrderSourceId());
|
||||
eg.setOrderId(order.getOrderId());
|
||||
// 添加订单商品
|
||||
final EquipmentOrderGoods oeg = new EquipmentOrderGoods();
|
||||
oeg.setOrderId(order.getOrderId());
|
||||
oeg.setGoodsName(eg.getGoodsName());
|
||||
oeg.setEquipmentCategory(eg.getEquipmentCategory());
|
||||
oeg.setImage(eg.getImage());
|
||||
oeg.setCategoryId(eg.getCategoryId());
|
||||
oeg.setBatteryModel(eg.getBatteryModel());
|
||||
oeg.setSellingPoint(eg.getSellingPoint());
|
||||
oeg.setStockTotal(eg.getStockTotal());
|
||||
oeg.setContent(eg.getContent());
|
||||
oeg.setBatteryPrice(eg.getBatteryPrice());
|
||||
oeg.setBatteryRent(eg.getBatteryRent());
|
||||
oeg.setBatteryInsurance(eg.getBatteryInsurance());
|
||||
oeg.setBatteryDeposit(eg.getBatteryDeposit());
|
||||
oeg.setDownPayment(eg.getDownPayment());
|
||||
oeg.setPeriods(eg.getPeriods());
|
||||
oeg.setRepayment(eg.getRepayment());
|
||||
oeg.setServiceCharges(eg.getServiceCharges());
|
||||
oeg.setPeriodsType(eg.getPeriodsType());
|
||||
oeg.setUserId(eg.getUserId());
|
||||
oeg.setComments(eg.getComments());
|
||||
oeg.setStatus(eg.getStatus());
|
||||
oeg.setMerchantCode(eg.getMerchantCode());
|
||||
oeg.setTenantId(eg.getTenantId());
|
||||
|
||||
equipmentOrderGoodsService.saveOrUpdate(oeg);
|
||||
|
||||
// 添加推荐人关系
|
||||
if (order.getDealerId() != null) {
|
||||
final User dealer = userService.getById(order.getDealerId());
|
||||
if(dealer == null){
|
||||
return fail("推荐人的用户ID不存在");
|
||||
}
|
||||
final UserReferee referee = new UserReferee();
|
||||
referee.setDealerId(order.getDealerId());
|
||||
referee.setUserId(getLoginUserId());
|
||||
userRefereeService.save(referee);
|
||||
// 是否存入星期值
|
||||
if (order.getDeliveryTime() != null) {
|
||||
order.setWeek(DateUtil.dayOfWeek(order.getDeliveryTime()) - 1);
|
||||
}
|
||||
}
|
||||
// 是否存入星期值
|
||||
if(order.getDeliveryTime() != null){
|
||||
order.setWeek(DateUtil.dayOfWeek(order.getDeliveryTime()) - 1);
|
||||
}
|
||||
return success("添加成功",order);
|
||||
return success("添加成功", order);
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
@@ -224,11 +369,91 @@ public class OrderController extends BaseController {
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Order order) {
|
||||
if (orderService.updateById(order)) {
|
||||
refund(order);
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
private void refund(Order order) {
|
||||
if (order.getOrderStatus().equals(OrderConstants.ORDER_STATUS_REFUND_SUCCESS)) {
|
||||
OrderRefund orderRefund = orderRefundService.getByOrderId(order.getOrderId());
|
||||
orderRefund.setAuditStatus(10);
|
||||
|
||||
Order order1 = orderService.getById(order.getOrderId());
|
||||
User user = userService.getById(order1.getUserId());
|
||||
user.setBalance(user.getBalance().subtract(order1.getCommission()));
|
||||
user.setTotalIncome(user.getTotalIncome().subtract(order1.getCommission()));
|
||||
userService.updateById(user);
|
||||
userBalanceLogService.save(
|
||||
new UserBalanceLog() {{
|
||||
setOrderId(order1.getOrderId());
|
||||
setUserId(user.getUserId());
|
||||
setScene(1);
|
||||
setMoney(order1.getCommission());
|
||||
setBalance(user.getBalance());
|
||||
setTenantId(10049);
|
||||
setCreateTime(DateUtil.date());
|
||||
setRemark("订单:" + order1.getOrderNo() + "退款,收回返利");
|
||||
}}
|
||||
);
|
||||
|
||||
// 售后门店
|
||||
// if (order1.getFixStoreId() != null
|
||||
// && order1.getFixStoreLeaderCommission() != null
|
||||
// && order1.getFixStoreLeaderCommission().compareTo(BigDecimal.ZERO) > 0) {
|
||||
// VivoFixStore vivoFixStore = fixStoreService.getById(order1.getFixStoreId());
|
||||
// User fixStoreLeader = userService.getById(vivoFixStore.getUserId());
|
||||
// fixStoreLeader.setBalance(fixStoreLeader.getBalance().subtract(order1.getFixStoreLeaderCommission()));
|
||||
// fixStoreLeader.setTotalIncome(fixStoreLeader.getTotalIncome().subtract(order1.getFixStoreLeaderCommission()));
|
||||
// userService.updateById(fixStoreLeader);
|
||||
// userBalanceLogService.save(
|
||||
// new UserBalanceLog() {{
|
||||
// setOrderId(order1.getOrderId());
|
||||
// setUserId(fixStoreLeader.getUserId());
|
||||
// setScene(1);
|
||||
// setMoney(order1.getFixStoreLeaderCommission());
|
||||
// setBalance(fixStoreLeader.getBalance());
|
||||
// setTenantId(10049);
|
||||
// setCreateTime(DateUtil.date());
|
||||
// setRemark("订单:" + order1.getOrderNo() + "退款,收回店长门店返利");
|
||||
// }}
|
||||
// );
|
||||
// }
|
||||
|
||||
User cityAgent = userService.getCityAgent(order1.getCityId());
|
||||
if (cityAgent != null && order1.getAgentCommission() != null && order1.getAgentCommission().compareTo(BigDecimal.ZERO) > 0) {
|
||||
cityAgent.setBalance(cityAgent.getBalance().subtract(order1.getAgentCommission()));
|
||||
cityAgent.setTotalIncome(cityAgent.getTotalIncome().subtract(order1.getAgentCommission()));
|
||||
userService.updateById(cityAgent);
|
||||
userBalanceLogService.save(
|
||||
new UserBalanceLog() {{
|
||||
setOrderId(order1.getOrderId());
|
||||
setUserId(cityAgent.getUserId());
|
||||
setScene(1);
|
||||
setMoney(order1.getAgentCommission());
|
||||
setBalance(cityAgent.getBalance());
|
||||
setTenantId(10049);
|
||||
setCreateTime(DateUtil.date());
|
||||
setRemark("订单:" + order1.getOrderNo() + "退款,收回区域返利");
|
||||
}}
|
||||
);
|
||||
}
|
||||
|
||||
if (order1.getPayMethod().equals(OrderConstants.ORDER_PAY_METHOD_WECHAT.toString())) {
|
||||
orderRefund.setOrder(orderService.getById(order1.getOrderId()));
|
||||
wxPayController.refund(orderRefund);
|
||||
} else {
|
||||
orderRefund.setRefundStatus(1);
|
||||
}
|
||||
orderRefundService.updateById(orderRefund);
|
||||
} else if (order.getOrderStatus().equals(OrderConstants.ORDER_STATUS_REFUND_FAIL)) {
|
||||
OrderRefund orderRefund = orderRefundService.getByOrderId(order.getOrderId());
|
||||
orderRefund.setAuditStatus(20);
|
||||
orderRefundService.updateById(orderRefund);
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除订单记录表")
|
||||
@@ -275,46 +500,116 @@ public class OrderController extends BaseController {
|
||||
|
||||
@ApiOperation("支付成功")
|
||||
@PostMapping("/setPayStatus")
|
||||
public ApiResult<?> setPayStatus(@RequestBody Order order){
|
||||
if (orderService.updateById(order)) {
|
||||
return success("设置成功");
|
||||
}
|
||||
return fail("设置失败");
|
||||
public ApiResult<?> setPayStatus(@RequestBody Order order) {
|
||||
if (orderService.updateById(order)) {
|
||||
return success("设置成功");
|
||||
}
|
||||
return fail("设置失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("生成核销付款码(二维码)")
|
||||
@GetMapping("/generateQrCode")
|
||||
public ApiResult<?> generateQrCode(OrderParam param) throws IOException {
|
||||
// 查询当天的报餐信息
|
||||
param.setUserId(getLoginUserId());
|
||||
param.setDeliveryTime(DateUtil.beginOfDay(DateUtil.date()).toString());
|
||||
param.setOrderStatus(ORDER_STATUS_DOING);
|
||||
param.setPayStatus(PAY_STATUS_SUCCESS);
|
||||
param.setDeleted(0);
|
||||
final List<Order> list = orderService.listRel(param);
|
||||
if(list.size() == 0){
|
||||
return fail("今日无报餐记录");
|
||||
}
|
||||
final Order order = list.get(0);
|
||||
// LOGO URL地址
|
||||
String logoUrl = "https://file.wsdns.cn/20230430/6fa31aca3b0d47af98a149cf2dd26a4f.jpeg";
|
||||
// 二维码生成图片保存路径
|
||||
String filePath = "/www/wwwroot/file.ws/file/qrcode/" + getLoginUserId() + "/payQrCode.jpg";
|
||||
// 二维码访问路径
|
||||
String qrcodeUrl = "https://file.gxwebsoft.com/qrcode/" + getLoginUserId() + "/payQrCode.jpg" + "?v=" + DateUtil.current();
|
||||
// 二维码内容
|
||||
final String orderNo = order.getOrderNo().toString();
|
||||
// 将URL转为BufferedImage
|
||||
BufferedImage bufferedImage = ImageIO.read(new URL(logoUrl));
|
||||
// 生成二维码
|
||||
QrConfig config = new QrConfig(300, 300);
|
||||
// 设置边距,既二维码和背景之间的边距
|
||||
config.setMargin(1);
|
||||
// 附带小logo
|
||||
config.setImg(bufferedImage);
|
||||
QrCodeUtil.generate(orderNo, config, FileUtil.file(filePath));
|
||||
return success("请求成功",qrcodeUrl);
|
||||
@ApiOperation("导出")
|
||||
@PostMapping("/export")
|
||||
public ApiResult<?> export(@RequestBody OrderParam param, HttpServletRequest request) throws IOException {
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser.getUserLevel().equals(1)) {
|
||||
param.setCityId(loginUser.getCityId());
|
||||
}
|
||||
String filename = "file/excel/订单表" + new Date().getTime() + ".xls";
|
||||
String path = uploadPath + filename;
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
//创建工作表单
|
||||
HSSFSheet sheet = workbook.createSheet();
|
||||
List<Order> orderList = orderService.listRel(param);
|
||||
HSSFRow row = sheet.createRow(0);
|
||||
row.createCell(0).setCellValue("订单号");
|
||||
row.createCell(1).setCellValue("下单人手机号");
|
||||
row.createCell(2).setCellValue("购买的产品");
|
||||
row.createCell(3).setCellValue("IMEI");
|
||||
row.createCell(4).setCellValue("型号");
|
||||
row.createCell(5).setCellValue("系列");
|
||||
row.createCell(6).setCellValue("上报人工号");
|
||||
row.createCell(7).setCellValue("上报人姓名");
|
||||
row.createCell(8).setCellValue("激活状态");
|
||||
row.createCell(9).setCellValue("激活时间");
|
||||
row.createCell(10).setCellValue("门店");
|
||||
row.createCell(11).setCellValue("二级区域名称");
|
||||
row.createCell(12).setCellValue("零售商名称");
|
||||
row.createCell(13).setCellValue("好/坏机");
|
||||
row.createCell(14).setCellValue("下单人信息");
|
||||
row.createCell(15).setCellValue("下单门店信息");
|
||||
row.createCell(16).setCellValue("有效期开始时间");
|
||||
row.createCell(17).setCellValue("有效期结束时间");
|
||||
row.createCell(18).setCellValue("订单金额");
|
||||
row.createCell(19).setCellValue("成本价");
|
||||
row.createCell(20).setCellValue("下单人佣金");
|
||||
row.createCell(21).setCellValue("区域代理佣金");
|
||||
row.createCell(22).setCellValue("订单状态");
|
||||
row.createCell(23).setCellValue("下单时间");
|
||||
int rowNum = 1;
|
||||
for (Order order : orderList) {
|
||||
//订单状态(0已取消1待支付2已支付3已结束4退款审核中5退款成功6退款失败)
|
||||
String orderStatus = "";
|
||||
HSSFRow orderRow = sheet.createRow(rowNum);
|
||||
Goods goods = goodsService.getById(order.getGoodsId());
|
||||
String storeName = "";
|
||||
if (order.getStoreId() != null) {
|
||||
VivoStore store = storeService.getById(order.getStoreId());
|
||||
if (store != null) storeName = store.getName();
|
||||
}
|
||||
if (order.getFixStoreId() != null) {
|
||||
VivoFixStore store = fixStoreService.getById(order.getFixStoreId());
|
||||
if (store != null) storeName = store.getName();
|
||||
}
|
||||
User user = userService.getById(order.getUserId());
|
||||
orderRow.createCell(0).setCellValue(order.getOrderNo());
|
||||
orderRow.createCell(1).setCellValue(user.getPhone());
|
||||
orderRow.createCell(2).setCellValue(goods.getGoodsName());
|
||||
orderRow.createCell(3).setCellValue(order.getImei());
|
||||
orderRow.createCell(4).setCellValue(order.getSkuName());
|
||||
orderRow.createCell(5).setCellValue(order.getModelName());
|
||||
orderRow.createCell(6).setCellValue(order.getSellerCode());
|
||||
orderRow.createCell(7).setCellValue(order.getSellerName());
|
||||
orderRow.createCell(8).setCellValue(order.getActiveState());
|
||||
orderRow.createCell(9).setCellValue(order.getActiveDate());
|
||||
orderRow.createCell(10).setCellValue(order.getStoreName());
|
||||
orderRow.createCell(11).setCellValue(order.getSecondAreaName());
|
||||
orderRow.createCell(12).setCellValue(order.getRetailerName());
|
||||
orderRow.createCell(13).setCellValue(!order.getGoodOrBad().equals("undefined") ? order.getGoodOrBad() : "");
|
||||
orderRow.createCell(14).setCellValue(user.getRealName());
|
||||
orderRow.createCell(15).setCellValue(storeName);
|
||||
orderRow.createCell(16).setCellValue(DateUtil.formatDateTime(order.getStartTime()) + " ");
|
||||
orderRow.createCell(17).setCellValue(DateUtil.formatDateTime(order.getExpirationTime()) + " ");
|
||||
orderRow.createCell(18).setCellValue(order.getTotalPrice().toString());
|
||||
orderRow.createCell(19).setCellValue(goods.getCost().toString());
|
||||
orderRow.createCell(20).setCellValue(order.getCommission() != null ? order.getCommission().toString() : "0");
|
||||
orderRow.createCell(21).setCellValue(order.getAgentCommission() != null ? order.getAgentCommission().toString() : "0");
|
||||
orderRow.createCell(22).setCellValue(OrderConstants.ORDER_STATUS_MAP.get(order.getOrderStatus()));
|
||||
orderRow.createCell(23).setCellValue(DateUtil.formatDateTime(order.getCreateTime()) + " ");
|
||||
rowNum++;
|
||||
}
|
||||
FileOutputStream output = new FileOutputStream(path);
|
||||
workbook.write(output);
|
||||
output.flush();
|
||||
|
||||
FileRecord result = new FileRecord();
|
||||
result.setCreateUserId(getLoginUserId());
|
||||
result.setName(filename);
|
||||
result.setPath(path);
|
||||
result.setUrl(requestURL + "/" + filename);
|
||||
// result.setMerchantCode(getMerchantCode());
|
||||
fileRecordService.save(result);
|
||||
return success(result);
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
protected void task() {
|
||||
// 1小时未支付的单
|
||||
orderService.update(
|
||||
new UpdateWrapper<Order>().eq("order_status", 1)
|
||||
.lt("create_time", DateUtil.offsetHour(new Date(), -1))
|
||||
.set("order_status", 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class OrderGoodsController extends BaseController {
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
orderGoods.setUserId(loginUser.getUserId());
|
||||
orderGoods.setMerchantCode(getMerchantCode());
|
||||
// orderGoods.setMerchantCode(getMerchantCode());
|
||||
}
|
||||
if (orderGoodsService.save(orderGoods)) {
|
||||
return success("添加成功");
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import com.gxwebsoft.apps.entity.Equipment;
|
||||
import com.gxwebsoft.apps.service.EquipmentService;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
@@ -38,8 +36,6 @@ public class OrderRefundController extends BaseController {
|
||||
private OrderRefundService orderRefundService;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private EquipmentService equipmentService;
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:orderRefund:list')")
|
||||
@OperationLog
|
||||
@@ -90,15 +86,6 @@ public class OrderRefundController extends BaseController {
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody OrderRefund orderRefund) {
|
||||
if (orderRefundService.updateById(orderRefund)) {
|
||||
if(orderRefund.getTenantId().equals(6)){
|
||||
final Integer orderId = orderRefund.getOrderId();
|
||||
final Order order = orderService.getById(orderId);
|
||||
System.out.println("order = " + order);
|
||||
order.setReceiptStatus(RECEIPT_STATUS_RETURN);
|
||||
final Equipment equipment = equipmentService.getById(order.getEquipmentId());
|
||||
equipment.setUserId(0);
|
||||
equipmentService.updateById(equipment);
|
||||
}
|
||||
return success("操作成功");
|
||||
}
|
||||
return fail("退租失败");
|
||||
|
||||
@@ -2,24 +2,10 @@ package com.gxwebsoft.shop.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayConstants;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.internal.util.AlipayEncrypt;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.alipay.api.request.AlipayTradeCreateRequest;
|
||||
import com.alipay.api.request.AlipayTradeQueryRequest;
|
||||
import com.alipay.api.response.AlipayTradeCreateResponse;
|
||||
import com.alipay.api.response.AlipayTradeQueryResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.apps.entity.BcTemporary;
|
||||
import com.gxwebsoft.apps.param.BcTemporaryParam;
|
||||
import com.gxwebsoft.apps.service.BcTemporaryService;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.utils.AlipayConfigUtil;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.OperationRecordService;
|
||||
@@ -44,7 +30,6 @@ import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.BalanceConstants.BALANCE_USE;
|
||||
import static com.gxwebsoft.common.core.constants.OrderConstants.*;
|
||||
@@ -72,13 +57,9 @@ public class PaymentController extends BaseController {
|
||||
@Resource
|
||||
private UserOauthService userOauthService;
|
||||
@Resource
|
||||
private AlipayConfigUtil alipayConfig;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private UserBalanceLogService userBalanceLogService;
|
||||
@Resource
|
||||
private BcTemporaryService bcTemporaryService;
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:payment:list')")
|
||||
@ApiOperation("分页查询商城支付方式记录表")
|
||||
@@ -179,157 +160,11 @@ public class PaymentController extends BaseController {
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("支付宝手机号码")
|
||||
@PostMapping("/getPhoneNumber")
|
||||
public ApiResult<?> getPhoneNumber(@RequestBody Map<String, String> params) {
|
||||
final String encryptedData = params.get("encryptedData");
|
||||
final String tenantId = params.get("tenantId");
|
||||
// 支付宝配置信息
|
||||
JSONObject config = alipayConfig.payment(Integer.valueOf(tenantId));
|
||||
|
||||
//1. 获取验签和解密所需要的参数
|
||||
JSONObject jsonObject =JSONObject.parseObject(encryptedData);
|
||||
String content = jsonObject.getString("response");
|
||||
String sign = jsonObject.getString("sign");
|
||||
String signType = "RSA2";
|
||||
String charset = "UTF-8";
|
||||
String encryptType = "AES";
|
||||
String alipayCertPublicKey = pathConfig.getUploadPath() + "file" + config.getString("alipayCertPublicKey");
|
||||
boolean isDataEncrypted = !content.startsWith("{");
|
||||
boolean signVerified = false;
|
||||
//2. 验签
|
||||
String signContent = content;
|
||||
String signVeriKey = ""; // 支付宝公钥
|
||||
String decryptKey = config.getString("decryptKey"); // 加解密密钥
|
||||
// System.out.println("decryptKey = " + decryptKey);
|
||||
// System.out.println(content);
|
||||
// System.out.println(sign);
|
||||
// System.out.println(alipayCertPublicKey);
|
||||
// System.out.println(charset);
|
||||
// System.out.println(signType);
|
||||
// System.out.println(isDataEncrypted);
|
||||
if (isDataEncrypted) {
|
||||
signContent = "\"" + signContent + "\"";
|
||||
} try {
|
||||
//验签方法
|
||||
signVerified = AlipaySignature.rsaCertCheck(signContent, sign, alipayCertPublicKey, charset, signType);
|
||||
} catch (AlipayApiException e) {
|
||||
// 验签异常, 日志
|
||||
} if (!signVerified) {
|
||||
//验签不通过(异常或者报文被篡改),终止流程(不需要做解密)
|
||||
return fail("验签失败");
|
||||
}
|
||||
//3. 解密
|
||||
String plainData = null;
|
||||
if (isDataEncrypted) {
|
||||
try {
|
||||
plainData = AlipayEncrypt.decryptContent(content, encryptType, decryptKey, charset);
|
||||
} catch (AlipayApiException e) {
|
||||
//解密异常, 记录日志
|
||||
return fail("解密异常");
|
||||
}} else {
|
||||
plainData = content;
|
||||
}
|
||||
return success("获取成功",plainData);
|
||||
}
|
||||
|
||||
@ApiModelProperty("支付宝小程序支付")
|
||||
@GetMapping("/mp-alipay/{id}")
|
||||
public ApiResult<?> mpAlipay(@PathVariable("id") Integer id) throws AlipayApiException {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 订单数据
|
||||
Order order = orderService.getByIdRel(id);
|
||||
// 实例化客户端
|
||||
DefaultAlipayClient alipayClient = alipayConfig.alipayClient(order.getTenantId());
|
||||
try {
|
||||
AlipayTradeCreateRequest request = new AlipayTradeCreateRequest();
|
||||
// 配置公共请求参数
|
||||
request.setNotifyUrl(pathConfig.getServerUrl() + "/shop/payment/mp-alipay/notify");
|
||||
// request.setNotifyUrl("https://454k72r798.goho.co/api/shop/payment/mp-alipay/notify");
|
||||
request.setReturnUrl(null);
|
||||
// 配置业务参数
|
||||
JSONObject bizContent = new JSONObject();
|
||||
System.out.println("bizContent = " + order);
|
||||
bizContent.put("out_trade_no", order.getOrderNo());
|
||||
bizContent.put("total_amount", order.getPayPrice());
|
||||
bizContent.put("subject", order.getMerchantName());
|
||||
// 拿不到手机号码??
|
||||
bizContent.put("buyer_id", userOauthService.getOauthIdByUserId(order.getUserId(), "MP-ALIPAY"));
|
||||
request.setBizContent(bizContent.toString());
|
||||
//SDK 已经封装掉了公共参数,这里只需要传入业务参数。
|
||||
AlipayTradeCreateResponse response = alipayClient.certificateExecute(request);
|
||||
String trade_no = response.getTradeNo();// 获取返回的tradeNO。
|
||||
return success("支付成功", trade_no);
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiModelProperty("异步通知")
|
||||
@OperationLog
|
||||
@PostMapping("/mp-alipay/notify")
|
||||
public String alipayNotify(@RequestParam Map<String, String> params) throws AlipayApiException {
|
||||
System.out.println("异步处理>>>>");
|
||||
System.out.println("params = " + params);
|
||||
String outTradeNo = params.get("out_trade_no");
|
||||
Order order = orderService.getByOutTradeNo(outTradeNo);
|
||||
if(order == null){
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
final JSONObject config = alipayConfig.payment(order.getTenantId());
|
||||
// 生成环境证书路径
|
||||
String alipayCertPublicKey = pathConfig.getUploadPath() + "file" + config.getString("alipayCertPublicKey");
|
||||
// TODO 验签成功后,按照支付结果异步通知中的描述,对支付结果中的业务内容进行二次校验,校验成功后在response中返回success并继续商户自身业务处理,校验失败返回failure
|
||||
boolean flag = AlipaySignature.rsaCertCheckV1(params, alipayCertPublicKey, AlipayConstants.CHARSET_UTF8, AlipayConstants.SIGN_TYPE_RSA2);
|
||||
System.out.println("flag>>>>>>>>>>>>>>>>>>>>>>>");
|
||||
System.out.println(flag);
|
||||
// 处理订单业务
|
||||
if (flag) {
|
||||
final String tradeStatus = params.get("trade_status");
|
||||
final String receipt_amount = params.get("receipt_amount");
|
||||
final String payPrice = order.getPayPrice().toString();
|
||||
final String trade_no = params.get("trade_no");
|
||||
final String subject = params.get("subject");
|
||||
|
||||
// 1. 验证appId是否一致
|
||||
final String app_id = params.get("app_id");
|
||||
if(!config.getString("alipayAppId").equals(app_id)){
|
||||
System.out.println("支付宝appId不一致 = " + app_id);
|
||||
throw new BusinessException("支付宝appId不一致");
|
||||
}
|
||||
// 2. 订单金额
|
||||
if(!payPrice.equals(receipt_amount)){
|
||||
System.out.println("订单金额是不一致 = " + receipt_amount);
|
||||
throw new BusinessException("订单金额是不一致");
|
||||
}
|
||||
// 3. 判断交易状态
|
||||
if(!"TRADE_SUCCESS".equals(tradeStatus)){
|
||||
System.out.println("支付失败 = " + tradeStatus);
|
||||
throw new BusinessException("支付失败");
|
||||
}
|
||||
// 4. 修改支付状态
|
||||
order.setPayStatus(PAY_STATUS_SUCCESS);
|
||||
order.setPayMethod(PAY_METHOD_ALIPAY);
|
||||
order.setReceiptAmount(new BigDecimal(receipt_amount));
|
||||
order.setPayTime(DateUtil.date());
|
||||
order.setTradeId(trade_no);
|
||||
order.setSubject(subject);
|
||||
System.out.println("order2 = " + order);
|
||||
final boolean b = orderService.updateByIdRel(order);
|
||||
System.out.println("bsss = " + b);
|
||||
return "success";
|
||||
}
|
||||
// TODO 验签失败则记录异常日志,并在response中返回failure.
|
||||
return "failure";
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiModelProperty("余额支付")
|
||||
@GetMapping("/balance/{id}")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public ApiResult<?> balance(@PathVariable("id") Integer id) throws AlipayApiException {
|
||||
public ApiResult<?> balance(@PathVariable("id") Integer id){
|
||||
// 1. 验证签名
|
||||
isCheckSign();
|
||||
// 订单数据
|
||||
@@ -385,15 +220,7 @@ public class PaymentController extends BaseController {
|
||||
order.setExpirationTime(nextMonthTime);
|
||||
orderService.updateById(order);
|
||||
}
|
||||
// 6. 是否是临时报餐
|
||||
final BcTemporaryParam bcTemporaryParam = new BcTemporaryParam();
|
||||
bcTemporaryParam.setUserId(getLoginUserId());
|
||||
bcTemporaryParam.setApplyStatus(1);
|
||||
final List<BcTemporary> bcTemporaries = bcTemporaryService.listRel(bcTemporaryParam);
|
||||
bcTemporaries.forEach(b -> {
|
||||
b.setStatus(1);
|
||||
bcTemporaryService.updateById(b);
|
||||
});
|
||||
|
||||
return success("支付成功",user);
|
||||
}
|
||||
|
||||
@@ -401,7 +228,7 @@ public class PaymentController extends BaseController {
|
||||
@ApiModelProperty("余额支付批量")
|
||||
@PostMapping("/balanceBatch")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public ApiResult<?> balanceBatch(@RequestBody List<Integer> orderIds) throws AlipayApiException {
|
||||
public ApiResult<?> balanceBatch(@RequestBody List<Integer> orderIds) {
|
||||
// 1. 验证签名
|
||||
isCheckSign();
|
||||
// 订单数据
|
||||
@@ -461,79 +288,8 @@ public class PaymentController extends BaseController {
|
||||
d.setExpirationTime(nextMonthTime);
|
||||
orderService.updateById(d);
|
||||
}
|
||||
// 6. 是否是临时报餐
|
||||
final BcTemporaryParam bcTemporaryParam = new BcTemporaryParam();
|
||||
bcTemporaryParam.setUserId(getLoginUserId());
|
||||
bcTemporaryParam.setApplyStatus(1);
|
||||
final List<BcTemporary> bcTemporaries = bcTemporaryService.listRel(bcTemporaryParam);
|
||||
bcTemporaries.forEach(b -> {
|
||||
b.setStatus(1);
|
||||
bcTemporaryService.updateById(b);
|
||||
});
|
||||
});
|
||||
return success("支付成功",sb);
|
||||
}
|
||||
|
||||
@ApiModelProperty("统一收单交易查询")
|
||||
@GetMapping("/mp-alipay/query/{id}")
|
||||
public ApiResult<?> query(@PathVariable("id") Integer id) throws AlipayApiException {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 订单数据
|
||||
Order order = orderService.getByIdRel(id);
|
||||
// 实例化客户端
|
||||
DefaultAlipayClient alipayClient = alipayConfig.alipayClient(order.getTenantId());
|
||||
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
||||
JSONObject bizContent = new JSONObject();
|
||||
bizContent.put("out_trade_no", order.getOrderNo());
|
||||
request.setBizContent(bizContent.toString());
|
||||
AlipayTradeQueryResponse response = alipayClient.certificateExecute(request);
|
||||
if(response.isSuccess()){
|
||||
System.out.println("调用成功");
|
||||
orderService.paySuccess(response);
|
||||
} else {
|
||||
System.out.println("调用失败");
|
||||
}
|
||||
return success("调用成功",response);
|
||||
}
|
||||
|
||||
@ApiModelProperty("测试")
|
||||
@GetMapping("/mp-alipay/test")
|
||||
public String test() {
|
||||
System.out.println("开始>>>>>");
|
||||
Order order = orderService.getByOutTradeNo("2023213225911618");
|
||||
System.out.println("order = " + order);
|
||||
order.setPayPrice(new BigDecimal("0.11"));
|
||||
order.setTotalPrice(new BigDecimal("0.11"));
|
||||
order.setPayStatus(PAY_STATUS_SUCCESS);
|
||||
final boolean b = orderService.updateByIdRel(order);
|
||||
System.out.println("b = " + b);
|
||||
|
||||
// params.put("gmt_create", "2022-12-16 21:32:33");
|
||||
// params.put("charset", "UTF-8");
|
||||
// params.put("seller_email", "zhu115289@163.com");
|
||||
// params.put("subject", "测试商品");
|
||||
// params.put("buyer_id", "2088202959044205");
|
||||
// params.put("invoice_amount", "0.01");
|
||||
// params.put("notify_id", "2022121601222213308044201435873270");
|
||||
// params.put("fund_bill_list", "");
|
||||
// params.put("notify_type", "trade_status_sync");
|
||||
// params.put("trade_status", "TRADE_SUCCESS");
|
||||
// params.put("receipt_amount", "0.01");
|
||||
// params.put("buyer_pay_amount", "0.01");
|
||||
// params.put("app_id", "2021003156628508");
|
||||
// params.put("seller_id", "2088431805524422");
|
||||
// params.put("gmt_payment", "2022-12-16 21:33:07");
|
||||
// params.put("notify_time", "2022-12-16 21:33:09");
|
||||
// params.put("version", "1.0");
|
||||
// params.put("out_trade_no", "20221116205303366");
|
||||
// params.put("total_amount", "0.01");
|
||||
// params.put("trade_no", "2022121622001444201411215463");
|
||||
// params.put("auth_app_id", "2021003156628508");
|
||||
// params.put("buyer_logon_id", "ip1***@163.com");
|
||||
// params.put("point_amount", "0.00");
|
||||
// // 处理订单业务
|
||||
// orderService.paySuccess(params);
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,11 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayConstants;
|
||||
import com.alipay.api.CertAlipayRequest;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.internal.util.AlipayEncrypt;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.alipay.api.request.AlipayTradeCreateRequest;
|
||||
import com.alipay.api.response.AlipayTradeCreateResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.service.OperationRecordService;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.entity.Payment;
|
||||
import com.gxwebsoft.shop.param.PaymentParam;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import com.gxwebsoft.shop.service.PaymentService;
|
||||
import com.gxwebsoft.shop.service.UserOauthService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 定时任务
|
||||
@@ -48,16 +20,4 @@ public class SchedulingController extends BaseController {
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
// /**
|
||||
// * 删除失效订单
|
||||
// */
|
||||
// @Scheduled(cron="0 0 */1 * * ?")
|
||||
// public void reportCurrentTime() {
|
||||
// System.out.println("定时任务开始 = " + new Date());
|
||||
// boolean remove = orderService.remove(new LambdaQueryWrapper<Order>()
|
||||
// .lt(Order::getExpirationTime, new Date())
|
||||
// .eq(Order::getPayStatus, 10)
|
||||
// .eq(Order::getOrderStatus, 10));
|
||||
// System.out.println("remove = " + remove);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.FileRecord;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.FileRecordService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.shop.constants.OrderConstants;
|
||||
import com.gxwebsoft.shop.entity.Goods;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.param.OrderParam;
|
||||
import com.gxwebsoft.shop.service.GoodsPriceService;
|
||||
import com.gxwebsoft.shop.service.GoodsService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import com.gxwebsoft.shop.service.UserBalanceLogService;
|
||||
import com.gxwebsoft.shop.entity.UserBalanceLog;
|
||||
import com.gxwebsoft.shop.param.UserBalanceLogParam;
|
||||
@@ -10,12 +21,24 @@ 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.vivo.entity.VivoFixStore;
|
||||
import com.gxwebsoft.vivo.entity.VivoStore;
|
||||
import com.gxwebsoft.vivo.service.VivoFixStoreService;
|
||||
import com.gxwebsoft.vivo.service.VivoStoreService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -30,14 +53,62 @@ import java.util.List;
|
||||
public class UserBalanceLogController extends BaseController {
|
||||
@Resource
|
||||
private UserBalanceLogService userBalanceLogService;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private VivoFixStoreService fixStoreService;
|
||||
@Resource
|
||||
private VivoStoreService storeService;
|
||||
@Resource
|
||||
private GoodsService goodsService;
|
||||
@Resource
|
||||
private GoodsPriceService goodsPriceService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private FileRecordService fileRecordService;
|
||||
|
||||
@Value("${config.upload-path}")
|
||||
private String uploadPath;
|
||||
|
||||
@Value("${config.server-url}")
|
||||
private String requestURL;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ApiResult<List<UserBalanceLog>> listForFront(@RequestBody UserBalanceLogParam param) {
|
||||
// 使用关联查询
|
||||
User loginUser = getLoginUser();
|
||||
param.setUserId(getLoginUserId());
|
||||
List<UserBalanceLog> userBalanceLogList = userBalanceLogService.listRel(param);
|
||||
userBalanceLogList.forEach(userBalanceLog -> {
|
||||
Order order = orderService.getByIdRel(userBalanceLog.getOrderId());
|
||||
if (order.getStoreId() != null && order.getStoreId() != 0) {
|
||||
VivoStore store = storeService.getById(order.getStoreId());
|
||||
if (store != null) order.setStore(store);
|
||||
}
|
||||
if (order.getFixStoreId() != null && order.getFixStoreId() != 0) {
|
||||
VivoFixStore fixStore = fixStoreService.getById(order.getFixStoreId());
|
||||
if (fixStore != null) order.setFixStore(fixStore);
|
||||
}
|
||||
Goods goods = goodsService.getById(order.getGoodsId());
|
||||
goods.setGoodsPrice(goodsPriceService.getByGoodsIdNCity(goods.getGoodsId(), loginUser.getCityId()));
|
||||
order.setGoods(goods);
|
||||
userBalanceLog.setOrder(order);
|
||||
});
|
||||
return success(userBalanceLogList);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:userBalanceLog:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询用户余额变动明细表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<UserBalanceLog>> page(UserBalanceLogParam param) {
|
||||
PageResult<UserBalanceLog> list = userBalanceLogService.pageRel(param);
|
||||
list.getList().forEach(userBalanceLog -> {
|
||||
userBalanceLog.setUser(userService.getByIdRel(userBalanceLog.getUserId()));
|
||||
});
|
||||
// 使用关联查询
|
||||
return success(userBalanceLogService.pageRel(param));
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:userBalanceLog:list')")
|
||||
@@ -70,8 +141,8 @@ public class UserBalanceLogController extends BaseController {
|
||||
// 记录当前登录用户id、租户id、商户编号
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
userBalanceLog.setUserId(loginUser.getUserId());
|
||||
userBalanceLog.setMerchantCode(getMerchantCode());
|
||||
userBalanceLog.setUserId(loginUser.getUserId());
|
||||
// userBalanceLog.setMerchantCode(getMerchantCode());
|
||||
}
|
||||
if (userBalanceLogService.save(userBalanceLog)) {
|
||||
return success("添加成功");
|
||||
@@ -134,4 +205,53 @@ public class UserBalanceLogController extends BaseController {
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:userBalanceLog:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("导出")
|
||||
@PostMapping("/export")
|
||||
public ApiResult<?> export(@RequestBody UserBalanceLogParam param, HttpServletRequest request) throws IOException {
|
||||
User loginUser = getLoginUser();
|
||||
String filename = "file/excel/佣金表" + new Date().getTime() + ".xls";
|
||||
String path = uploadPath + filename;
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
//创建工作表单
|
||||
HSSFSheet sheet = workbook.createSheet();
|
||||
List<UserBalanceLog> list = userBalanceLogService.listRel(param);
|
||||
HSSFRow row = sheet.createRow(0);
|
||||
row.createCell(0).setCellValue("订单号");
|
||||
row.createCell(1).setCellValue("手机号");
|
||||
row.createCell(2).setCellValue("姓名");
|
||||
row.createCell(3).setCellValue("订单金额");
|
||||
row.createCell(4).setCellValue("收/支");
|
||||
row.createCell(5).setCellValue("佣金");
|
||||
row.createCell(6).setCellValue("下单时间");
|
||||
int rowNum = 1;
|
||||
for (UserBalanceLog log : list) {
|
||||
HSSFRow orderRow = sheet.createRow(rowNum);
|
||||
Order order = orderService.getById(log.getOrderId());
|
||||
User user = userService.getById(order.getUserId());
|
||||
orderRow.createCell(0).setCellValue(order.getOrderNo());
|
||||
orderRow.createCell(1).setCellValue(user.getPhone());
|
||||
orderRow.createCell(2).setCellValue(user.getRealName());
|
||||
orderRow.createCell(3).setCellValue(order.getTotalPrice().toString());
|
||||
orderRow.createCell(4).setCellValue(log.getScene().equals(1) ? "退款" : "收入");
|
||||
orderRow.createCell(5).setCellValue((log.getScene().equals(1) ? "-" : "") + log.getMoney().toString());
|
||||
orderRow.createCell(6).setCellValue(DateUtil.formatDateTime(order.getCreateTime()) + " ");
|
||||
rowNum++;
|
||||
}
|
||||
FileOutputStream output = new FileOutputStream(path);
|
||||
workbook.write(output);
|
||||
output.flush();
|
||||
|
||||
FileRecord result = new FileRecord();
|
||||
result.setCreateUserId(getLoginUserId());
|
||||
result.setName(filename);
|
||||
result.setPath(path);
|
||||
result.setUrl(requestURL + "/" + filename);
|
||||
// result.setMerchantCode(getMerchantCode());
|
||||
fileRecordService.save(result);
|
||||
return success(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
//import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -26,6 +31,7 @@ import com.gxwebsoft.shop.entity.UserOauth;
|
||||
import com.gxwebsoft.shop.service.UserOauthService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxRuntimeException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -44,210 +50,230 @@ import static com.gxwebsoft.common.core.constants.RedisConstants.ACCESS_TOKEN_KE
|
||||
@RequestMapping("/api/shop/wx-login")
|
||||
@Api(tags = "微信小程序登录API")
|
||||
public class WxLoginController extends BaseController {
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private ConfigProperties configProperties;
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
@Resource
|
||||
private UserOauthService userOauthService;
|
||||
@Resource
|
||||
private LoginRecordService loginRecordService;
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
@Resource
|
||||
private WxMaProperties wxMaProperties;
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private ConfigProperties configProperties;
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
@Resource
|
||||
private UserOauthService userOauthService;
|
||||
@Resource
|
||||
private LoginRecordService loginRecordService;
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
@Resource
|
||||
private WxMaProperties wxMaProperties;
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
// @Autowired
|
||||
// private WxMaService wxMaService;
|
||||
|
||||
|
||||
@ApiOperation("获取微信openId")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PostMapping("/getOpenId")
|
||||
public ApiResult<LoginResult> getOpenId(@RequestBody UserParam userParam, HttpServletRequest request) {
|
||||
// 1.获取openid
|
||||
JSONObject result = getOpenIdByCode(userParam);
|
||||
String openid = result.getString("openid");
|
||||
String unionid = result.getString("unionid");
|
||||
if (openid == null) {
|
||||
return fail("获取openid失败", null);
|
||||
@ApiOperation("获取微信openId")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PostMapping("/getOpenId")
|
||||
public ApiResult<LoginResult> getOpenId(@RequestBody UserParam userParam, HttpServletRequest request) throws WxErrorException {
|
||||
// 1.获取openid
|
||||
JSONObject result = getOpenIdByCode(userParam);
|
||||
String openid = result.getString("openid");
|
||||
String unionid = result.getString("unionid");
|
||||
// WxMaJscode2SessionResult result = getOpenIdByCode(userParam);
|
||||
// String openid = result.getOpenid();
|
||||
// String unionid = result.getUnionid();
|
||||
if (openid == null) {
|
||||
return fail("获取openid失败", null);
|
||||
}
|
||||
// 2.通过openid查询用户是否已存在
|
||||
User user = userOauthService.getByOauthId(openid);
|
||||
// 3.存在则签发token并返回登录成功,不存在则注册新用户
|
||||
if (user == null) {
|
||||
user = addUser(userParam);
|
||||
// 添加第三方用户信息
|
||||
UserOauth uo = new UserOauth();
|
||||
uo.setUserId(user.getUserId());
|
||||
uo.setTenantId(user.getTenantId());
|
||||
uo.setOauthType("MP-WEIXIN");
|
||||
uo.setOauthId(openid);
|
||||
uo.setUnionid(unionid);
|
||||
userOauthService.save(uo);
|
||||
}
|
||||
// 4.签发token
|
||||
loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_LOGIN, null, user.getTenantId(), request);
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
// 2.通过openid查询用户是否已存在
|
||||
User user = userOauthService.getByOauthId(openid);
|
||||
// 3.存在则签发token并返回登录成功,不存在则注册新用户
|
||||
if (user == null) {
|
||||
user = addUser(userParam);
|
||||
// 添加第三方用户信息
|
||||
UserOauth uo = new UserOauth();
|
||||
uo.setUserId(user.getUserId());
|
||||
uo.setTenantId(user.getTenantId());
|
||||
uo.setOauthType("MP-WEIXIN");
|
||||
uo.setOauthId(openid);
|
||||
uo.setUnionid(unionid);
|
||||
userOauthService.save(uo);
|
||||
}
|
||||
// 4.签发token
|
||||
loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_LOGIN, null, user.getTenantId(), request);
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
|
||||
@ApiOperation("微信授权手机号码并登录")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PostMapping("/loginByMpWxPhone")
|
||||
public ApiResult<LoginResult> loginByMpWxPhone(@RequestBody UserParam userParam, HttpServletRequest request) {
|
||||
// 获取手机号码
|
||||
String phone = getPhoneByCode(userParam);
|
||||
// 查询是否存在
|
||||
User user = userService.getByPhone(phone);
|
||||
// 不存在
|
||||
if (user == null) {
|
||||
return fail("该用户不存在", new LoginResult());
|
||||
}
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_LOGIN, null, user.getTenantId(), request);
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
@ApiOperation("微信授权手机号码并登录")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PostMapping("/loginByMpWxPhone")
|
||||
public ApiResult<LoginResult> loginByMpWxPhone(@RequestBody UserParam userParam, HttpServletRequest request) throws WxErrorException {
|
||||
// 获取手机号码
|
||||
String phone = getPhoneByCode(userParam);
|
||||
System.out.println("phone:" + phone);
|
||||
|
||||
@ApiOperation("微信授权手机号码并更新")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PostMapping("/updatePhoneByMpWx")
|
||||
public ApiResult<?> updatePhoneByMpWx(@RequestBody UserParam userParam) {
|
||||
// 获取微信授权手机号
|
||||
String phone = getPhoneByCode(userParam);
|
||||
// 查询当前用户
|
||||
User user = userService.getById(userParam.getUserId());
|
||||
if (user != null && phone != null) {
|
||||
user.setPhone(phone);
|
||||
userService.updateUser(user);
|
||||
return success("更新成功",phone);
|
||||
// 查询是否存在
|
||||
User user = userService.getByPhone(phone);
|
||||
System.out.println("用户:" + user);
|
||||
// 不存在
|
||||
if (user == null) {
|
||||
return fail("该用户不存在", new LoginResult());
|
||||
}
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_LOGIN, null, user.getTenantId(), request);
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
return fail("更新失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新用户注册
|
||||
*/
|
||||
private User addUser(UserParam userParam) {
|
||||
User addUser = new User();
|
||||
// 注册用户
|
||||
addUser.setStatus(0);
|
||||
addUser.setUsername(createUsername("wx_"));
|
||||
addUser.setNickname("微信用户");
|
||||
addUser.setPassword(userService.encodePassword(CommonUtil.randomUUID16()));
|
||||
addUser.setTenantId(getTenantId());
|
||||
Role role = roleService.getOne(new QueryWrapper<Role>().eq("role_code", "user"), false);
|
||||
addUser.setRoleId(role.getRoleId());
|
||||
if (userService.saveUser(addUser)) {
|
||||
// 添加用户角色
|
||||
final UserRole userRole = new UserRole();
|
||||
userRole.setUserId(addUser.getUserId());
|
||||
userRole.setTenantId(addUser.getTenantId());
|
||||
userRole.setRoleId(addUser.getRoleId());
|
||||
userRoleService.save(userRole);
|
||||
@ApiOperation("微信授权手机号码并更新")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@PostMapping("/updatePhoneByMpWx")
|
||||
public ApiResult<?> updatePhoneByMpWx(@RequestBody UserParam userParam) throws WxErrorException {
|
||||
// 获取微信授权手机号
|
||||
String phone = getPhoneByCode(userParam);
|
||||
// 查询当前用户
|
||||
User user = userService.getById(userParam.getUserId());
|
||||
if (user != null && phone != null) {
|
||||
user.setPhone(phone);
|
||||
userService.updateUser(user);
|
||||
return success("更新成功", phone);
|
||||
}
|
||||
return fail("更新失败");
|
||||
}
|
||||
return addUser;
|
||||
}
|
||||
|
||||
// 获取openid
|
||||
private JSONObject getOpenIdByCode(UserParam userParam) {
|
||||
// 获取微信小程序配置信息
|
||||
JSONObject setting = settingService.getBySettingKey("mp-weixin");
|
||||
// 获取openId
|
||||
String apiUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + setting.getString("appId") + "&secret=" + setting.getString("appSecret") + "&js_code=" + userParam.getCode() + "&grant_type=authorization_code";
|
||||
// 执行get请求
|
||||
String result = HttpUtil.get(apiUrl);
|
||||
System.out.println("result = " + result);
|
||||
// 解析access_token
|
||||
return JSON.parseObject(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信手机号码
|
||||
*
|
||||
* @param userParam 需要传微信凭证code
|
||||
*/
|
||||
private String getPhoneByCode(UserParam userParam) {
|
||||
// 获取手机号码
|
||||
String apiUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + getAccessToken();
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("code", userParam.getCode());
|
||||
// 执行post请求
|
||||
String post = HttpUtil.post(apiUrl, JSON.toJSONString(paramMap));
|
||||
JSONObject json = JSON.parseObject(post);
|
||||
if (json.get("errcode").equals(0)) {
|
||||
JSONObject phoneInfo = JSON.parseObject(json.getString("phone_info"));
|
||||
// 微信用户的手机号码
|
||||
return phoneInfo.getString("phoneNumber");
|
||||
/**
|
||||
* 新用户注册
|
||||
*/
|
||||
private User addUser(UserParam userParam) {
|
||||
User addUser = new User();
|
||||
// 注册用户
|
||||
addUser.setStatus(0);
|
||||
addUser.setUsername(createUsername("wx_"));
|
||||
addUser.setNickname("微信用户");
|
||||
addUser.setPassword(userService.encodePassword(CommonUtil.randomUUID16()));
|
||||
addUser.setTenantId(getTenantId());
|
||||
Role role = roleService.getOne(new QueryWrapper<Role>().eq("role_code", "user"), false);
|
||||
addUser.setRoleId(role.getRoleId());
|
||||
if (userService.saveUser(addUser)) {
|
||||
// 添加用户角色
|
||||
final UserRole userRole = new UserRole();
|
||||
userRole.setUserId(addUser.getUserId());
|
||||
userRole.setTenantId(addUser.getTenantId());
|
||||
userRole.setRoleId(addUser.getRoleId());
|
||||
userRoleService.save(userRole);
|
||||
}
|
||||
return addUser;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机账号
|
||||
*
|
||||
* @return username
|
||||
*/
|
||||
private String createUsername(String type) {
|
||||
return type.concat(RandomUtil.randomString(12));
|
||||
}
|
||||
// 获取openid
|
||||
private JSONObject getOpenIdByCode(UserParam userParam) {
|
||||
// 获取微信小程序配置信息
|
||||
JSONObject setting = settingService.getBySettingKey("mp-weixin");
|
||||
// 获取openId
|
||||
String apiUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + setting.getString("appId") + "&secret=" + setting.getString("appSecret") + "&js_code=" + userParam.getCode() + "&grant_type=authorization_code";
|
||||
// 执行get请求
|
||||
String result = HttpUtil.get(apiUrl);
|
||||
System.out.println("result = " + result);
|
||||
// 解析access_token
|
||||
return JSON.parseObject(result);
|
||||
// return wxMaService.getUserService().getSessionInfo(userParam.getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口调用凭据AccessToken
|
||||
* https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getAccessToken.html
|
||||
*/
|
||||
public String getAccessToken() {
|
||||
// 获取微信小程序配置信息
|
||||
JSONObject setting = settingService.getBySettingKey("mp-weixin");
|
||||
// 从缓存获取access_token
|
||||
String value = redisTemplate.opsForValue().get(ACCESS_TOKEN_KEY.concat(getTenantId().toString()));
|
||||
if (value != null) {
|
||||
// 解析access_token
|
||||
JSONObject response = JSON.parseObject(value);
|
||||
return response.getString("access_token");
|
||||
/**
|
||||
* 获取微信手机号码
|
||||
*
|
||||
* @param userParam 需要传微信凭证code
|
||||
*/
|
||||
private String getPhoneByCode(UserParam userParam) {
|
||||
// 获取手机号码
|
||||
String apiUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + getAccessToken();
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("code", userParam.getPhoneCode());
|
||||
// 执行post请求
|
||||
String post = HttpUtil.post(apiUrl, JSON.toJSONString(paramMap));
|
||||
JSONObject json = JSON.parseObject(post);
|
||||
System.out.println("json = " + json);
|
||||
if (json.get("errcode").equals(0)) {
|
||||
JSONObject phoneInfo = JSON.parseObject(json.getString("phone_info"));
|
||||
// 微信用户的手机号码
|
||||
return phoneInfo.getString("phoneNumber");
|
||||
}
|
||||
return null;
|
||||
// 解密
|
||||
// WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(userParam.getPhoneCode());
|
||||
// WxMaConfigHolder.remove();//清理ThreadLocal
|
||||
// return phoneNoInfo.getPhoneNumber();
|
||||
}
|
||||
// 微信获取凭证接口
|
||||
String apiUrl = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
// 组装url参数
|
||||
String url = apiUrl.concat("?grant_type=client_credential").concat("&appid=").concat(setting.getString("appId")).concat("&secret=").concat(setting.getString("appSecret"));
|
||||
// 执行get请求
|
||||
String result = HttpUtil.get(url);
|
||||
// 解析access_token
|
||||
JSONObject response = JSON.parseObject(result);
|
||||
if (response.getString("access_token") != null) {
|
||||
// 存入缓存
|
||||
redisTemplate.opsForValue().set(ACCESS_TOKEN_KEY.concat(getTenantId().toString()), result);
|
||||
return response.getString("access_token");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public WxMaService wxMaService() {
|
||||
List<WxMaProperties.Config> configs = wxMaProperties.getConfigs();
|
||||
if (configs == null) {
|
||||
throw new WxRuntimeException("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!");
|
||||
/**
|
||||
* 生成随机账号
|
||||
*
|
||||
* @return username
|
||||
*/
|
||||
private String createUsername(String type) {
|
||||
return type.concat(RandomUtil.randomString(12));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口调用凭据AccessToken
|
||||
* https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getAccessToken.html
|
||||
*/
|
||||
public String getAccessToken() {
|
||||
System.out.println(getTenantId());
|
||||
// 获取微信小程序配置信息
|
||||
// JSONObject setting = settingService.getBySettingKey("mp-weixin");
|
||||
String appid = "wx7bdcb7c68d53062b";
|
||||
String secret = "8d747742fa81da3211da1d504e494531";
|
||||
// 从缓存获取access_token
|
||||
String value = redisTemplate.opsForValue().get(ACCESS_TOKEN_KEY.concat(getTenantId().toString()));
|
||||
// if (value != null) {
|
||||
// // 解析access_token
|
||||
// JSONObject response = JSON.parseObject(value);
|
||||
// return response.getString("access_token");
|
||||
// }
|
||||
// 微信获取凭证接口
|
||||
String apiUrl = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
// 组装url参数
|
||||
// String url = apiUrl.concat("?grant_type=client_credential").concat("&appid=").concat(setting.getString("appId")).concat("&secret=").concat(setting.getString("appSecret"));
|
||||
String url = apiUrl.concat("?grant_type=client_credential").concat("&appid=").concat(appid).concat("&secret=").concat(secret);
|
||||
// 执行get请求
|
||||
String result = HttpUtil.get(url);
|
||||
// 解析access_token
|
||||
JSONObject response = JSON.parseObject(result);
|
||||
return response.getString("access_token");
|
||||
// if (response.getString("access_token") != null) {
|
||||
// 存入缓存
|
||||
// redisTemplate.opsForValue().set(ACCESS_TOKEN_KEY.concat(getTenantId().toString()), result);
|
||||
// return response.getString("access_token");
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
|
||||
public WxMaService wxMaService() {
|
||||
List<WxMaProperties.Config> configs = wxMaProperties.getConfigs();
|
||||
if (configs == null) {
|
||||
throw new WxRuntimeException("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!");
|
||||
}
|
||||
WxMaService maService = new WxMaServiceImpl();
|
||||
maService.setMultiConfigs(
|
||||
configs.stream()
|
||||
.map(a -> {
|
||||
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
||||
config.setAppid(a.getAppid());
|
||||
config.setSecret(a.getSecret());
|
||||
config.setToken(a.getToken());
|
||||
config.setAesKey(a.getAesKey());
|
||||
config.setMsgDataFormat(a.getMsgDataFormat());
|
||||
return config;
|
||||
}).collect(Collectors.toMap(WxMaDefaultConfigImpl::getAppid, a -> a, (o, n) -> o)));
|
||||
return maService;
|
||||
}
|
||||
WxMaService maService = new WxMaServiceImpl();
|
||||
maService.setMultiConfigs(
|
||||
configs.stream()
|
||||
.map(a -> {
|
||||
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
||||
config.setAppid(a.getAppid());
|
||||
config.setSecret(a.getSecret());
|
||||
config.setToken(a.getToken());
|
||||
config.setAesKey(a.getAesKey());
|
||||
config.setMsgDataFormat(a.getMsgDataFormat());
|
||||
return config;
|
||||
}).collect(Collectors.toMap(WxMaDefaultConfigImpl::getAppid, a -> a, (o, n) -> o)));
|
||||
return maService;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,223 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import com.gxwebsoft.common.system.entity.DictData;
|
||||
import com.gxwebsoft.common.system.service.DictDataService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.shop.constants.OrderConstants;
|
||||
import com.gxwebsoft.shop.entity.*;
|
||||
import com.gxwebsoft.shop.service.*;
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
import com.wechat.pay.java.core.RSAConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
import com.wechat.pay.java.core.notification.RequestParam;
|
||||
import com.wechat.pay.java.service.partnerpayments.nativepay.model.Amount;
|
||||
import com.wechat.pay.java.service.partnerpayments.nativepay.model.PrepayRequest;
|
||||
import com.wechat.pay.java.service.partnerpayments.nativepay.model.Transaction;
|
||||
import com.wechat.pay.java.service.partnerpayments.model.TransactionAmount;
|
||||
import com.wechat.pay.java.service.partnerpayments.nativepay.NativePayService;
|
||||
import com.wechat.pay.java.service.partnerpayments.nativepay.model.PrepayResponse;
|
||||
import com.wechat.pay.java.service.refund.RefundService;
|
||||
import com.wechat.pay.java.service.refund.model.AmountReq;
|
||||
import com.wechat.pay.java.service.refund.model.CreateRequest;
|
||||
import com.wechat.pay.java.service.refund.model.RefundNotification;
|
||||
import com.wechat.pay.java.service.refund.model.Status;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/shop/wx-pay")
|
||||
@Api(tags = "微信支付API")
|
||||
public class WxPayController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Configuration
|
||||
public class WxPayController extends BaseController {
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private DictDataService dictDataService;
|
||||
@Resource
|
||||
private OrderRefundService orderRefundService;
|
||||
@Autowired
|
||||
private UserBalanceLogController userBalanceLogController;
|
||||
|
||||
public ApiResult<?> nativePay(@PathVariable String orderId){
|
||||
return success("支付成功");
|
||||
}
|
||||
private final Integer tenantId = 10036;
|
||||
|
||||
@Value("${wxpay.app-id}")
|
||||
public String appId;
|
||||
/**
|
||||
* 商户号
|
||||
*/
|
||||
@Value("${wxpay.mch-id}")
|
||||
public String merchantId;
|
||||
/**
|
||||
* 商户API私钥路径
|
||||
*/
|
||||
@Value("${wxpay.private-key-path}")
|
||||
public String privateKeyPath;
|
||||
/**
|
||||
* 商户证书序列号
|
||||
*/
|
||||
@Value("${wxpay.mch-serial-no}")
|
||||
public String merchantSerialNumber;
|
||||
/**
|
||||
* 商户APIV3密钥
|
||||
*/
|
||||
@Value("${wxpay.api-v3-key}")
|
||||
public String apiV3key;
|
||||
|
||||
@Value("${wxpay.notify-domain}")
|
||||
public String notifyUrl;
|
||||
|
||||
@Value("${wxpay.cert-path}")
|
||||
public String wechatPayCertificatePath;
|
||||
|
||||
private final String spAppId = "wxa67c676fc445590e";
|
||||
private final String spMerchantId = "1615739384";
|
||||
|
||||
public String nativePay(String orderNo, Integer payAmount, String title) {
|
||||
Config config = new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(spMerchantId)
|
||||
.privateKeyFromPath(privateKeyPath)
|
||||
.merchantSerialNumber(merchantSerialNumber)
|
||||
.apiV3Key(apiV3key)
|
||||
.build();
|
||||
// 构建service
|
||||
NativePayService service = new NativePayService.Builder().config(config).build();
|
||||
PrepayRequest request = new PrepayRequest();
|
||||
Amount amount = new Amount();
|
||||
DictData dictData = dictDataService.getByDictCodeAndName("PAY_TEST_MODE", "模式");
|
||||
if (Integer.valueOf(dictData.getDictDataCode()).equals(0)) {
|
||||
amount.setTotal(1);
|
||||
}else {
|
||||
amount.setTotal(payAmount);
|
||||
}
|
||||
request.setSpAppid(spAppId);
|
||||
request.setSpMchid(spMerchantId);
|
||||
request.setSubAppid(appId);
|
||||
request.setSubMchid(merchantId);
|
||||
request.setAmount(amount);
|
||||
request.setDescription(title);
|
||||
request.setNotifyUrl(notifyUrl);
|
||||
request.setOutTradeNo(orderNo);
|
||||
PrepayResponse response = service.prepay(request);
|
||||
// 调用下单方法,得到应答
|
||||
return response.getCodeUrl();
|
||||
}
|
||||
|
||||
/***
|
||||
* 退款申请
|
||||
* @param orderRefund
|
||||
*/
|
||||
public void refund(OrderRefund orderRefund) {
|
||||
Config config = new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(spMerchantId)
|
||||
.privateKeyFromPath(privateKeyPath)
|
||||
.merchantSerialNumber(merchantSerialNumber)
|
||||
.apiV3Key(apiV3key)
|
||||
.build();
|
||||
RefundService service = new RefundService.Builder().config(config).build();
|
||||
CreateRequest request = new CreateRequest();
|
||||
// 金额
|
||||
AmountReq amount = new AmountReq();
|
||||
amount.setTotal(orderRefund.getRefundMoney().multiply(BigDecimal.valueOf(100)).longValue());
|
||||
amount.setRefund(orderRefund.getRefundMoney().multiply(BigDecimal.valueOf(100)).longValue());
|
||||
amount.setCurrency("CNY");
|
||||
request.setSubMchid(merchantId);
|
||||
request.setAmount(amount);
|
||||
request.setOutTradeNo(orderRefund.getOrder().getOrderNo());
|
||||
request.setOutRefundNo("R" + orderRefund.getOrder().getOrderNo());
|
||||
String wechatRefundNotifyUrl = "https://vivo-server.gxwebsoft.com/api/shop/wx-pay/refund-notify";
|
||||
request.setNotifyUrl(wechatRefundNotifyUrl);
|
||||
service.create(request);
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/notify")
|
||||
public ApiResult<?> notify(@RequestBody String body, @RequestHeader Map<String, Object> header) throws ParseException {
|
||||
RequestParam requestParam = new RequestParam.Builder()
|
||||
.serialNumber(header.get("wechatpay-serial").toString())
|
||||
.nonce(header.get("wechatpay-nonce").toString())
|
||||
.signature(header.get("wechatpay-signature").toString())
|
||||
.timestamp(header.get("wechatpay-timestamp").toString())
|
||||
.body(body)
|
||||
.build();
|
||||
NotificationConfig config = new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(spMerchantId)
|
||||
.privateKeyFromPath(privateKeyPath)
|
||||
.merchantSerialNumber(merchantSerialNumber)
|
||||
.apiV3Key(apiV3key)
|
||||
.build();
|
||||
// 初始化 NotificationParser
|
||||
NotificationParser parser = new NotificationParser(config);
|
||||
Transaction transaction = parser.parse(requestParam, Transaction.class);
|
||||
TransactionAmount transactionAmount = transaction.getAmount();
|
||||
// 支付金额
|
||||
Integer payAmount = transactionAmount.getPayerTotal();
|
||||
float calAmount = (float) payAmount / 100f;
|
||||
BigDecimal userPaid = BigDecimal.valueOf(calAmount);
|
||||
// 订单号
|
||||
String orderNo = transaction.getOutTradeNo();
|
||||
// 微信支付订单号
|
||||
String transactionId = transaction.getTransactionId();
|
||||
// 支付状态
|
||||
Transaction.TradeStateEnum tradeStateEnum = transaction.getTradeState();
|
||||
System.out.println("支付结果:" + transaction);
|
||||
if (tradeStateEnum == Transaction.TradeStateEnum.SUCCESS) {
|
||||
Order order = orderService.getByOutTradeNo(orderNo);
|
||||
order.setOrderStatus(OrderConstants.ORDER_STATUS_PAID);
|
||||
order.setPayMethod(OrderConstants.ORDER_PAY_METHOD_WECHAT.toString());
|
||||
order.setTradeId(transactionId);
|
||||
order.setReceiptAmount(userPaid);
|
||||
order.setPayTime(DateUtil.date());
|
||||
orderService.updateById(order);
|
||||
|
||||
orderService.updateIncome(order);
|
||||
}
|
||||
return success();
|
||||
}
|
||||
|
||||
@PostMapping("/refund-notify")
|
||||
public ApiResult<?> refundNotify(@RequestBody String body, @RequestHeader Map<String, Object> header) throws ParseException {
|
||||
RequestParam requestParam = new RequestParam.Builder()
|
||||
.serialNumber(header.get("wechatpay-serial").toString())
|
||||
.nonce(header.get("wechatpay-nonce").toString())
|
||||
.signature(header.get("wechatpay-signature").toString())
|
||||
.timestamp(header.get("wechatpay-timestamp").toString())
|
||||
.body(body)
|
||||
.build();
|
||||
NotificationConfig config = new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(spMerchantId)
|
||||
.privateKeyFromPath(privateKeyPath)
|
||||
.merchantSerialNumber(merchantSerialNumber)
|
||||
.apiV3Key(apiV3key)
|
||||
.build();
|
||||
// 初始化 NotificationParser
|
||||
NotificationParser parser = new NotificationParser(config);
|
||||
RefundNotification notification = parser.parse(requestParam, RefundNotification.class);
|
||||
String orderNo = notification.getOutTradeNo();
|
||||
if (notification.getRefundStatus().equals(Status.SUCCESS)) {
|
||||
Order order = orderService.getByOutTradeNo(orderNo);
|
||||
OrderRefund orderRefund = orderRefundService.getByOrderId(order.getOrderId());
|
||||
if (orderRefund.getRefundStatus().equals(0)) {
|
||||
orderRefund.setRefundStatus(1);
|
||||
orderRefundService.updateById(orderRefund);
|
||||
}
|
||||
}
|
||||
return success();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user