1.3.3新增 后台微信图文发送功能,小程序配置,增加小程序授权等,修复一些bug等
This commit is contained in:
@ -10,6 +10,7 @@ package co.yixiang.common.api;
|
||||
*/
|
||||
public enum ApiCode {
|
||||
|
||||
FAIL_AUTH(410000, "没有权限"),
|
||||
SUCCESS(200, "操作成功"),
|
||||
|
||||
UNAUTHORIZED(401, "非法访问"),
|
||||
|
||||
@ -2,10 +2,16 @@ package co.yixiang.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.validation.MessageCodesResolver;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||
import org.springframework.web.servlet.config.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* WebMvcConfigurer
|
||||
@ -41,4 +47,7 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
|
||||
registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0);
|
||||
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,161 @@
|
||||
package co.yixiang.modules.manage.web.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.common.api.ApiResult;
|
||||
import co.yixiang.common.web.controller.BaseController;
|
||||
import co.yixiang.modules.manage.web.dto.OrderTimeDataDTO;
|
||||
import co.yixiang.modules.manage.web.param.OrderDeliveryParam;
|
||||
import co.yixiang.modules.manage.web.param.OrderPriceParam;
|
||||
import co.yixiang.modules.manage.web.param.OrderRefundParam;
|
||||
import co.yixiang.modules.manage.web.param.OrderRemarkParam;
|
||||
import co.yixiang.modules.order.service.YxStoreOrderService;
|
||||
import co.yixiang.modules.order.web.dto.OrderCountDTO;
|
||||
import co.yixiang.modules.order.web.vo.YxStoreOrderQueryVo;
|
||||
import co.yixiang.utils.SecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName ShoperController
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2019/11/25
|
||||
**/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
@Api(value = "商家管理", tags = "商家管理", description = "商家管理")
|
||||
public class ShoperController extends BaseController {
|
||||
|
||||
private final YxStoreOrderService storeOrderService;
|
||||
|
||||
/**
|
||||
* 订单数据统计
|
||||
*/
|
||||
@GetMapping("/admin/order/statistics")
|
||||
@ApiOperation(value = "订单数据统计",notes = "订单数据统计")
|
||||
public ApiResult<Object> statistics(){
|
||||
int uid = SecurityUtils.getUserId().intValue();
|
||||
OrderCountDTO orderCountDTO = storeOrderService.orderData(0);
|
||||
OrderTimeDataDTO orderTimeDataDTO = storeOrderService.getOrderTimeData();
|
||||
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("orderCount",orderCountDTO);
|
||||
map.put("orderTimeCount",orderTimeDataDTO);
|
||||
return ApiResult.ok(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单每月统计数据
|
||||
*/
|
||||
@GetMapping("/admin/order/data")
|
||||
@ApiOperation(value = "订单每月统计数据",notes = "订单每月统计数据")
|
||||
public ApiResult<Object> data(@RequestParam(value = "page",defaultValue = "1") int page,
|
||||
@RequestParam(value = "limit",defaultValue = "10") int limit){
|
||||
int uid = SecurityUtils.getUserId().intValue();
|
||||
|
||||
return ApiResult.ok(storeOrderService.getOrderDataPriceCount(page,limit));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单列表
|
||||
*/
|
||||
@GetMapping("/admin/order/list")
|
||||
@ApiOperation(value = "订单列表",notes = "订单列表")
|
||||
public ApiResult<Object> orderList(@RequestParam(value = "status",defaultValue = "0") int type,
|
||||
@RequestParam(value = "page",defaultValue = "1") int page,
|
||||
@RequestParam(value = "limit",defaultValue = "10") int limit){
|
||||
int uid = SecurityUtils.getUserId().intValue();
|
||||
|
||||
return ApiResult.ok(storeOrderService.orderList(0,type,page,limit));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
*/
|
||||
@GetMapping("/admin/order/detail/{key}")
|
||||
@ApiOperation(value = "订单详情",notes = "订单详情")
|
||||
public ApiResult<Object> orderDetail(@PathVariable String key){
|
||||
int uid = SecurityUtils.getUserId().intValue();
|
||||
|
||||
if(StrUtil.isEmpty(key)) return ApiResult.fail("参数错误");
|
||||
YxStoreOrderQueryVo storeOrder = storeOrderService.getOrderInfo(key,0);
|
||||
if(ObjectUtil.isNull(storeOrder)){
|
||||
return ApiResult.fail("订单不存在");
|
||||
}
|
||||
|
||||
return ApiResult.ok(storeOrderService.handleOrder(storeOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单改价
|
||||
*/
|
||||
@PostMapping("/admin/order/price")
|
||||
@ApiOperation(value = "订单改价",notes = "订单改价")
|
||||
public ApiResult<Object> orderPrice(@Validated @RequestBody OrderPriceParam param){
|
||||
|
||||
//if(ObjectUtil.isNotNull(param)) return ApiResult.fail("演示环境禁止操作");
|
||||
int uid = SecurityUtils.getUserId().intValue();
|
||||
|
||||
storeOrderService.editOrderPrice(param);
|
||||
|
||||
return ApiResult.ok("ok");
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单发货
|
||||
*/
|
||||
@PostMapping("/admin/order/delivery/keep")
|
||||
@ApiOperation(value = "订单发货",notes = "订单发货")
|
||||
public ApiResult<Object> orderDelivery(@Validated @RequestBody OrderDeliveryParam param){
|
||||
//if(ObjectUtil.isNotNull(param)) return ApiResult.fail("演示环境禁止操作");
|
||||
|
||||
int uid = SecurityUtils.getUserId().intValue();
|
||||
|
||||
storeOrderService.orderDelivery(param);
|
||||
|
||||
return ApiResult.ok("ok");
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
*/
|
||||
@PostMapping("/admin/order/refund")
|
||||
@ApiOperation(value = "订单退款",notes = "订单退款")
|
||||
public ApiResult<Object> orderRefund(@Validated @RequestBody OrderRefundParam param){
|
||||
//if(ObjectUtil.isNotNull(param)) return ApiResult.fail("演示环境禁止操作");
|
||||
int uid = SecurityUtils.getUserId().intValue();
|
||||
|
||||
storeOrderService.orderRefund(param);
|
||||
|
||||
return ApiResult.ok("ok");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单交易额/订单数量时间chart统计
|
||||
*/
|
||||
@GetMapping("/admin/order/time")
|
||||
@ApiOperation(value = "chart统计",notes = "chart统计")
|
||||
public ApiResult<Object> chartCount(@RequestParam(value = "cate",defaultValue = "1") int cate,
|
||||
@RequestParam(value = "type",defaultValue = "1") int type){
|
||||
int uid = SecurityUtils.getUserId().intValue();
|
||||
|
||||
return ApiResult.ok(storeOrderService.chartCount(cate,type));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package co.yixiang.modules.manage.web.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName ChartDataDTO
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2019/11/25
|
||||
**/
|
||||
@Data
|
||||
public class ChartDataDTO implements Serializable {
|
||||
private Double num;
|
||||
private String time;
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package co.yixiang.modules.manage.web.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName OrderDataDTO
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2019/11/25
|
||||
**/
|
||||
@Data
|
||||
public class OrderDataDTO implements Serializable {
|
||||
private Integer count;
|
||||
private Double price;
|
||||
private String time;
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package co.yixiang.modules.manage.web.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName OrderTimeDataDTO
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2019/11/25
|
||||
**/
|
||||
@Data
|
||||
public class OrderTimeDataDTO implements Serializable {
|
||||
private Double todayPrice; //今日成交额
|
||||
private Integer todayCount; //今日订单数
|
||||
private Double proPrice; //昨日成交额
|
||||
private Integer proCount;//昨日订单数
|
||||
private Double monthPrice;//本月成交额
|
||||
private Integer monthCount;//本月订单数
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package co.yixiang.modules.manage.web.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName OrderPriceParam
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2019/11/26
|
||||
**/
|
||||
@Data
|
||||
public class OrderDeliveryParam implements Serializable {
|
||||
@NotBlank(message = "订单编号错误")
|
||||
private String orderId;
|
||||
@NotBlank(message = "快递单号必填")
|
||||
private String deliveryId;
|
||||
@NotBlank(message = "快递公司必填")
|
||||
private String deliveryName;
|
||||
@NotBlank(message = "快递方式必填")
|
||||
private String deliveryType;
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package co.yixiang.modules.manage.web.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName OrderPriceParam
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2019/11/26
|
||||
**/
|
||||
@Data
|
||||
public class OrderPriceParam implements Serializable {
|
||||
@NotBlank(message = "订单编号错误")
|
||||
private String orderId;
|
||||
@NotNull(message = "修改价格必填")
|
||||
private Double price;
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package co.yixiang.modules.manage.web.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName OrderPriceParam
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2019/11/26
|
||||
**/
|
||||
@Data
|
||||
public class OrderRefundParam implements Serializable {
|
||||
@NotBlank(message = "订单编号错误")
|
||||
private String orderId;
|
||||
@NotNull(message = "退款金额必填")
|
||||
private Double price;
|
||||
@NotNull(message = "参数错误")
|
||||
private Integer type;
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package co.yixiang.modules.manage.web.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName OrderPriceParam
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2019/11/26
|
||||
**/
|
||||
@Data
|
||||
public class OrderRemarkParam implements Serializable {
|
||||
@NotBlank(message = "订单编号错误")
|
||||
private String orderId;
|
||||
@NotBlank(message = "备注必填")
|
||||
private String remark;
|
||||
}
|
||||
@ -1,6 +1,10 @@
|
||||
package co.yixiang.modules.order.mapper;
|
||||
|
||||
import co.yixiang.modules.manage.web.dto.ChartDataDTO;
|
||||
import co.yixiang.modules.manage.web.dto.OrderDataDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import co.yixiang.modules.order.entity.YxStoreOrder;
|
||||
@ -11,6 +15,7 @@ import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -23,6 +28,33 @@ import java.io.Serializable;
|
||||
@Repository
|
||||
public interface YxStoreOrderMapper extends BaseMapper<YxStoreOrder> {
|
||||
|
||||
@Select("SELECT sum(pay_price) as num," +
|
||||
"FROM_UNIXTIME(add_time, '%m-%d') as time " +
|
||||
" FROM yx_store_order ${ew.customSqlSegment} " +
|
||||
" GROUP BY FROM_UNIXTIME(add_time,'%Y-%m-%d') " +
|
||||
" ORDER BY add_time ASC")
|
||||
List<ChartDataDTO> chartList(@Param(Constants.WRAPPER) Wrapper<YxStoreOrder> wrapper);
|
||||
|
||||
@Select("SELECT count(id) as num," +
|
||||
"FROM_UNIXTIME(add_time, '%m-%d') as time " +
|
||||
" FROM yx_store_order ${ew.customSqlSegment} " +
|
||||
" GROUP BY FROM_UNIXTIME(add_time,'%Y-%m-%d') " +
|
||||
" ORDER BY add_time ASC")
|
||||
List<ChartDataDTO> chartListT(@Param(Constants.WRAPPER) Wrapper<YxStoreOrder> wrapper);
|
||||
|
||||
@Select("SELECT sum(pay_price) as price,count(id) as count," +
|
||||
"FROM_UNIXTIME(add_time, '%m-%d') as time FROM yx_store_order" +
|
||||
" WHERE is_del = 0 AND paid = 1 AND refund_status = 0 " +
|
||||
"GROUP BY FROM_UNIXTIME(add_time,'%Y-%m-%d') ORDER BY add_time DESC")
|
||||
List<OrderDataDTO> getOrderDataPriceList(Page page);
|
||||
|
||||
|
||||
@Select("SELECT IFNULL(sum(pay_price),0) " +
|
||||
" FROM yx_store_order ${ew.customSqlSegment}")
|
||||
Double todayPrice(@Param(Constants.WRAPPER) Wrapper<YxStoreOrder> wrapper);
|
||||
|
||||
|
||||
|
||||
@Select("select IFNULL(sum(pay_price),0) from yx_store_order " +
|
||||
"where paid=1 and is_del=0 and refund_status=0 and uid=#{uid}")
|
||||
double sumPrice(@Param("uid") int uid);
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
package co.yixiang.modules.order.service;
|
||||
|
||||
import co.yixiang.modules.manage.web.dto.OrderDataDTO;
|
||||
import co.yixiang.modules.manage.web.dto.OrderTimeDataDTO;
|
||||
import co.yixiang.modules.manage.web.param.OrderDeliveryParam;
|
||||
import co.yixiang.modules.manage.web.param.OrderPriceParam;
|
||||
import co.yixiang.modules.manage.web.param.OrderRefundParam;
|
||||
import co.yixiang.modules.order.entity.YxStoreOrder;
|
||||
import co.yixiang.common.service.BaseService;
|
||||
import co.yixiang.modules.order.web.dto.*;
|
||||
@ -13,8 +18,10 @@ import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -24,8 +31,23 @@ import java.util.List;
|
||||
* @author hupeng
|
||||
* @since 2019-10-27
|
||||
*/
|
||||
//@WebService(serviceName = "YxStoreOrderService",
|
||||
// targetNamespace = "http://service.order.modules.yixiang.co"
|
||||
//)
|
||||
public interface YxStoreOrderService extends BaseService<YxStoreOrder> {
|
||||
|
||||
Map<String,Object> chartCount(int cate,int type);
|
||||
|
||||
void orderRefund(OrderRefundParam param);
|
||||
|
||||
void orderDelivery(OrderDeliveryParam param);
|
||||
|
||||
void editOrderPrice(OrderPriceParam param);
|
||||
|
||||
List<OrderDataDTO> getOrderDataPriceCount(int page, int limit);
|
||||
|
||||
OrderTimeDataDTO getOrderTimeData();
|
||||
|
||||
YxStoreOrder getOrderPink(int pid,int uid,int type);
|
||||
|
||||
void regressionCoupon(YxStoreOrderQueryVo order);
|
||||
@ -48,6 +70,7 @@ public interface YxStoreOrderService extends BaseService<YxStoreOrder> {
|
||||
|
||||
List<YxStoreOrderQueryVo> orderList(int uid,int type,int page,int limit);
|
||||
|
||||
//@WebMethod
|
||||
OrderCountDTO orderData(int uid);
|
||||
|
||||
YxStoreOrderQueryVo handleOrder(YxStoreOrderQueryVo order);
|
||||
|
||||
@ -1,11 +1,20 @@
|
||||
package co.yixiang.modules.order.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.*;
|
||||
import co.yixiang.common.constant.CacheKey;
|
||||
import co.yixiang.common.constant.CommonConstant;
|
||||
import co.yixiang.exception.ErrorRequestException;
|
||||
import co.yixiang.modules.activity.service.YxStoreCombinationService;
|
||||
import co.yixiang.modules.activity.service.YxStorePinkService;
|
||||
import co.yixiang.modules.manage.web.dto.ChartDataDTO;
|
||||
import co.yixiang.modules.manage.web.dto.OrderDataDTO;
|
||||
import co.yixiang.modules.manage.web.dto.OrderTimeDataDTO;
|
||||
import co.yixiang.modules.manage.web.param.OrderDeliveryParam;
|
||||
import co.yixiang.modules.manage.web.param.OrderPriceParam;
|
||||
import co.yixiang.modules.manage.web.param.OrderRefundParam;
|
||||
import co.yixiang.modules.monitor.service.RedisService;
|
||||
import co.yixiang.modules.order.entity.YxStoreOrder;
|
||||
import co.yixiang.modules.order.entity.YxStoreOrderCartInfo;
|
||||
@ -44,11 +53,13 @@ import co.yixiang.modules.user.web.vo.YxWechatUserQueryVo;
|
||||
import co.yixiang.redisson.DelayJob;
|
||||
import co.yixiang.redisson.DelayJobService;
|
||||
import co.yixiang.utils.OrderUtil;
|
||||
import co.yixiang.utils.RedisUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
||||
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -56,7 +67,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
//import org.redisson.api.RDelayedQueue;
|
||||
//import org.redisson.api.RQueue;
|
||||
//import org.redisson.api.RedissonClient;
|
||||
//import org.apache.webservice.config.annotation.Service;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -64,13 +77,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import javax.jws.WebService;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Array;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
@ -82,6 +95,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author hupeng
|
||||
* @since 2019-10-27
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@ -147,6 +161,111 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
||||
// @Value("${job.unpayorder}")
|
||||
// private String overtime;
|
||||
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
* @param param
|
||||
*/
|
||||
@Override
|
||||
public void orderRefund(OrderRefundParam param) {
|
||||
|
||||
YxStoreOrderQueryVo orderQueryVo = getOrderInfo(param.getOrderId(),0);
|
||||
if(ObjectUtil.isNull(orderQueryVo)) throw new ErrorRequestException("订单不存在");
|
||||
|
||||
YxUserQueryVo userQueryVo = userService.getYxUserById(orderQueryVo.getUid());
|
||||
if(ObjectUtil.isNull(userQueryVo)) throw new ErrorRequestException("用户不存在");
|
||||
|
||||
if(param.getPrice() > orderQueryVo.getPayPrice().doubleValue()) throw new ErrorRequestException("退款金额不正确");
|
||||
|
||||
YxStoreOrder storeOrder = new YxStoreOrder();
|
||||
//修改状态
|
||||
storeOrder.setId(orderQueryVo.getId());
|
||||
storeOrder.setRefundStatus(2);
|
||||
storeOrder.setRefundPrice(BigDecimal.valueOf(param.getPrice()));
|
||||
yxStoreOrderMapper.updateById(storeOrder);
|
||||
|
||||
//退款到余额
|
||||
userService.incMoney(orderQueryVo.getUid(),param.getPrice());
|
||||
|
||||
//增加流水
|
||||
YxUserBill userBill = new YxUserBill();
|
||||
userBill.setUid(orderQueryVo.getUid());
|
||||
userBill.setLinkId(orderQueryVo.getId().toString());
|
||||
userBill.setPm(1);
|
||||
userBill.setTitle("商品退款");
|
||||
userBill.setCategory("now_money");
|
||||
userBill.setType("pay_product_refund");
|
||||
userBill.setNumber(BigDecimal.valueOf(param.getPrice()));
|
||||
userBill.setBalance(NumberUtil.add(param.getPrice(),userQueryVo.getNowMoney()));
|
||||
userBill.setMark("订单退款到余额");
|
||||
userBill.setAddTime(OrderUtil.getSecondTimestampTwo());
|
||||
userBill.setStatus(1);
|
||||
billService.save(userBill);
|
||||
|
||||
|
||||
orderStatusService.create(orderQueryVo.getId(),"order_edit","退款给用户:"+param.getPrice() +"元");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单发货
|
||||
* @param param
|
||||
*/
|
||||
@Override
|
||||
public void orderDelivery(OrderDeliveryParam param) {
|
||||
YxStoreOrderQueryVo orderQueryVo = getOrderInfo(param.getOrderId(),0);
|
||||
if(ObjectUtil.isNull(orderQueryVo)) throw new ErrorRequestException("订单不存在");
|
||||
|
||||
if(orderQueryVo.getStatus() != 0 || orderQueryVo.getPaid() == 0) throw new ErrorRequestException("订单状态错误");
|
||||
|
||||
YxStoreOrder storeOrder = new YxStoreOrder();
|
||||
storeOrder.setId(orderQueryVo.getId());
|
||||
storeOrder.setStatus(1);
|
||||
storeOrder.setDeliveryId(param.getDeliveryId());
|
||||
storeOrder.setDeliveryName(param.getDeliveryName());
|
||||
storeOrder.setDeliveryType(param.getDeliveryType());
|
||||
|
||||
yxStoreOrderMapper.updateById(storeOrder);
|
||||
|
||||
//增加状态
|
||||
orderStatusService.create(storeOrder.getId(),"delivery_goods",
|
||||
"已发货 快递公司:"+param.getDeliveryName()+"快递单号:" +param.getDeliveryId());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单价格
|
||||
* @param param
|
||||
*/
|
||||
@Override
|
||||
public void editOrderPrice(OrderPriceParam param) {
|
||||
YxStoreOrderQueryVo orderQueryVo = getOrderInfo(param.getOrderId(),0);
|
||||
if(ObjectUtil.isNull(orderQueryVo)) throw new ErrorRequestException("订单不存在");
|
||||
|
||||
if(orderQueryVo.getPayPrice().doubleValue() == param.getPrice()) return;
|
||||
|
||||
if(orderQueryVo.getPaid() > 0) throw new ErrorRequestException("订单状态错误");
|
||||
|
||||
|
||||
YxStoreOrder storeOrder = new YxStoreOrder();
|
||||
storeOrder.setId(orderQueryVo.getId());
|
||||
storeOrder.setPayPrice(BigDecimal.valueOf(param.getPrice()));
|
||||
|
||||
yxStoreOrderMapper.updateById(storeOrder);
|
||||
|
||||
//增加状态
|
||||
orderStatusService.create(storeOrder.getId(),"order_edit","修改实际支付金额");
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取拼团订单
|
||||
* @param pid
|
||||
* @param uid
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public YxStoreOrder getOrderPink(int pid, int uid,int type) {
|
||||
QueryWrapper<YxStoreOrder> wrapper = new QueryWrapper<>();
|
||||
@ -427,7 +546,8 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
||||
@Override
|
||||
public List<YxStoreOrderQueryVo> orderList(int uid, int type, int page, int limit) {
|
||||
QueryWrapper<YxStoreOrder> wrapper= new QueryWrapper<>();
|
||||
wrapper.eq("is_del",0).eq("uid",uid).orderByDesc("add_time");
|
||||
if(uid > 0) wrapper.eq("uid",uid);
|
||||
wrapper.eq("is_del",0).orderByDesc("add_time");
|
||||
|
||||
switch (type){
|
||||
case 0://未支付
|
||||
@ -470,8 +590,110 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
||||
return newList;
|
||||
}
|
||||
|
||||
/**
|
||||
* chart图标统计
|
||||
* @param cate
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String,Object> chartCount(int cate,int type) {
|
||||
int today = OrderUtil.dateToTimestampT(DateUtil.beginOfDay(new Date()));
|
||||
int yesterday = OrderUtil.dateToTimestampT(DateUtil.beginOfDay(DateUtil.
|
||||
yesterday()));
|
||||
int lastWeek = OrderUtil.dateToTimestampT(DateUtil.beginOfDay(DateUtil.lastWeek()));
|
||||
int nowMonth = OrderUtil.dateToTimestampT(DateUtil
|
||||
.beginOfMonth(new Date()));
|
||||
double price = 0d;
|
||||
List<ChartDataDTO> list = null;
|
||||
QueryWrapper<YxStoreOrder> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("paid",1).eq("refund_status",0).eq("is_del",0);
|
||||
|
||||
switch (cate){
|
||||
case 1: //今天
|
||||
wrapper.ge("pay_time",today);
|
||||
break;
|
||||
case 2: //昨天
|
||||
wrapper.lt("pay_time",today).ge("pay_time",yesterday);
|
||||
break;
|
||||
case 3: //上周
|
||||
wrapper.ge("pay_time",lastWeek);
|
||||
break;
|
||||
case 4: //本月
|
||||
wrapper.ge("pay_time",nowMonth);
|
||||
break;
|
||||
}
|
||||
if(type == 1){
|
||||
list = yxStoreOrderMapper.chartList(wrapper);
|
||||
price = yxStoreOrderMapper.todayPrice(wrapper);
|
||||
}else{
|
||||
list = yxStoreOrderMapper.chartListT(wrapper);
|
||||
price = yxStoreOrderMapper.selectCount(wrapper).doubleValue();
|
||||
}
|
||||
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("chart",list);
|
||||
map.put("time",price);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 今日 昨日 本月 订单金额
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public OrderTimeDataDTO getOrderTimeData() {
|
||||
|
||||
int today = OrderUtil.dateToTimestampT(DateUtil.beginOfDay(new Date()));
|
||||
int yesterday = OrderUtil.dateToTimestampT(DateUtil.beginOfDay(DateUtil.
|
||||
yesterday()));
|
||||
int nowMonth = OrderUtil.dateToTimestampT(DateUtil
|
||||
.beginOfMonth(new Date()));
|
||||
OrderTimeDataDTO orderTimeDataDTO = new OrderTimeDataDTO();
|
||||
|
||||
//今日成交额
|
||||
QueryWrapper<YxStoreOrder> wrapperOne = new QueryWrapper<>();
|
||||
wrapperOne.ge("pay_time",today).eq("paid",1)
|
||||
.eq("refund_status",0).eq("is_del",0);
|
||||
orderTimeDataDTO.setTodayPrice(yxStoreOrderMapper.todayPrice(wrapperOne));
|
||||
//今日订单数
|
||||
orderTimeDataDTO.setTodayCount(yxStoreOrderMapper.selectCount(wrapperOne));
|
||||
|
||||
//昨日成交额
|
||||
QueryWrapper<YxStoreOrder> wrapperTwo = new QueryWrapper<>();
|
||||
wrapperTwo.lt("pay_time",today).ge("pay_time",yesterday).eq("paid",1)
|
||||
.eq("refund_status",0).eq("is_del",0);
|
||||
orderTimeDataDTO.setProPrice(yxStoreOrderMapper.todayPrice(wrapperTwo));
|
||||
//昨日订单数
|
||||
orderTimeDataDTO.setProCount(yxStoreOrderMapper.selectCount(wrapperTwo));
|
||||
|
||||
//本月成交额
|
||||
QueryWrapper<YxStoreOrder> wrapperThree = new QueryWrapper<>();
|
||||
wrapperThree.ge("pay_time",nowMonth).eq("paid",1)
|
||||
.eq("refund_status",0).eq("is_del",0);
|
||||
orderTimeDataDTO.setMonthPrice(yxStoreOrderMapper.todayPrice(wrapperThree));
|
||||
//本月订单数
|
||||
orderTimeDataDTO.setMonthCount(yxStoreOrderMapper.selectCount(wrapperThree));
|
||||
|
||||
|
||||
return orderTimeDataDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单每月统计数据
|
||||
* @param page
|
||||
* @param limit
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<OrderDataDTO> getOrderDataPriceCount(int page, int limit) {
|
||||
Page<YxStoreOrder> pageModel = new Page<>(page, limit);
|
||||
return yxStoreOrderMapper.getOrderDataPriceList(pageModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个用户的订单统计数据
|
||||
* @param uid uid>0 取用户 否则取所有
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@ -480,8 +702,8 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
||||
OrderCountDTO countDTO = new OrderCountDTO();
|
||||
//订单支付没有退款 数量
|
||||
QueryWrapper<YxStoreOrder> wrapperOne = new QueryWrapper<>();
|
||||
wrapperOne.eq("is_del",0).eq("paid",1)
|
||||
.eq("uid",uid).eq("refund_status",0);
|
||||
if(uid > 0 ) wrapperOne.eq("uid",uid);
|
||||
wrapperOne.eq("is_del",0).eq("paid",1).eq("refund_status",0);
|
||||
countDTO.setOrderCount(yxStoreOrderMapper.selectCount(wrapperOne));
|
||||
|
||||
//订单支付没有退款 支付总金额
|
||||
@ -489,39 +711,45 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
||||
|
||||
//订单待支付 数量
|
||||
QueryWrapper<YxStoreOrder> wrapperTwo = new QueryWrapper<>();
|
||||
if(uid > 0 ) wrapperTwo.eq("uid",uid);
|
||||
wrapperTwo.eq("is_del",0).eq("paid",0)
|
||||
.eq("uid",uid).eq("refund_status",0).eq("status",0);
|
||||
.eq("refund_status",0).eq("status",0);
|
||||
countDTO.setUnpaidCount(yxStoreOrderMapper.selectCount(wrapperTwo));
|
||||
|
||||
//订单待发货 数量
|
||||
QueryWrapper<YxStoreOrder> wrapperThree = new QueryWrapper<>();
|
||||
if(uid > 0 ) wrapperThree.eq("uid",uid);
|
||||
wrapperThree.eq("is_del",0).eq("paid",1)
|
||||
.eq("uid",uid).eq("refund_status",0).eq("status",0);
|
||||
.eq("refund_status",0).eq("status",0);
|
||||
countDTO.setUnshippedCount(yxStoreOrderMapper.selectCount(wrapperThree));
|
||||
|
||||
//订单待收货 数量
|
||||
QueryWrapper<YxStoreOrder> wrapperFour = new QueryWrapper<>();
|
||||
if(uid > 0 ) wrapperFour.eq("uid",uid);
|
||||
wrapperFour.eq("is_del",0).eq("paid",1)
|
||||
.eq("uid",uid).eq("refund_status",0).eq("status",1);
|
||||
.eq("refund_status",0).eq("status",1);
|
||||
countDTO.setReceivedCount(yxStoreOrderMapper.selectCount(wrapperFour));
|
||||
|
||||
//订单待评价 数量
|
||||
QueryWrapper<YxStoreOrder> wrapperFive = new QueryWrapper<>();
|
||||
if(uid > 0 ) wrapperFive.eq("uid",uid);
|
||||
wrapperFive.eq("is_del",0).eq("paid",1)
|
||||
.eq("uid",uid).eq("refund_status",0).eq("status",2);
|
||||
.eq("refund_status",0).eq("status",2);
|
||||
countDTO.setEvaluatedCount(yxStoreOrderMapper.selectCount(wrapperFive));
|
||||
|
||||
//订单已完成 数量
|
||||
QueryWrapper<YxStoreOrder> wrapperSix= new QueryWrapper<>();
|
||||
if(uid > 0 ) wrapperSix.eq("uid",uid);
|
||||
wrapperSix.eq("is_del",0).eq("paid",1)
|
||||
.eq("uid",uid).eq("refund_status",0).eq("status",3);
|
||||
.eq("refund_status",0).eq("status",3);
|
||||
countDTO.setCompleteCount(yxStoreOrderMapper.selectCount(wrapperSix));
|
||||
|
||||
//订单退款
|
||||
QueryWrapper<YxStoreOrder> wrapperSeven= new QueryWrapper<>();
|
||||
if(uid > 0 ) wrapperSeven.eq("uid",uid);
|
||||
String[] strArr = {"1","2"};
|
||||
wrapperSeven.eq("is_del",0).eq("paid",1)
|
||||
.eq("uid",uid).in("refund_status",Arrays.asList(strArr));
|
||||
.in("refund_status",Arrays.asList(strArr));
|
||||
countDTO.setRefundCount(yxStoreOrderMapper.selectCount(wrapperSeven));
|
||||
|
||||
|
||||
@ -656,6 +884,20 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
||||
public WxPayMpOrderResult wxPay(String orderId) throws WxPayException {
|
||||
String apiUrl = systemConfigService.getData("api_url");
|
||||
if(StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
|
||||
|
||||
//读取redis配置
|
||||
String appId = RedisUtil.get("wxpay_appId");
|
||||
String mchId = RedisUtil.get("wxpay_mchId");
|
||||
String mchKey = RedisUtil.get("wxpay_mchKey");
|
||||
if(StrUtil.isBlank(appId) || StrUtil.isBlank(mchId) || StrUtil.isBlank(mchKey)){
|
||||
throw new ErrorRequestException("请配置微信支付");
|
||||
}
|
||||
WxPayConfig wxPayConfig = new WxPayConfig();
|
||||
wxPayConfig.setAppId(appId);
|
||||
wxPayConfig.setMchId(mchId);
|
||||
wxPayConfig.setMchKey(mchKey);
|
||||
wxPayService.setConfig(wxPayConfig);
|
||||
|
||||
YxStoreOrderQueryVo orderInfo = getOrderInfo(orderId,0);
|
||||
if(ObjectUtil.isNull(orderInfo)) throw new ErrorRequestException("订单不存在");
|
||||
if(orderInfo.getPaid() == 1) throw new ErrorRequestException("该订单已支付");
|
||||
|
||||
@ -262,10 +262,10 @@ public class StoreOrderController extends BaseController {
|
||||
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
* 订单列表
|
||||
*/
|
||||
@GetMapping("/order/list")
|
||||
@ApiOperation(value = "订单详情",notes = "订单详情")
|
||||
@ApiOperation(value = "订单列表",notes = "订单列表")
|
||||
public ApiResult<List<YxStoreOrderQueryVo>> orderList(@RequestParam(value = "type",defaultValue = "0") int type,
|
||||
@RequestParam(value = "page",defaultValue = "1") int page,
|
||||
@RequestParam(value = "limit",defaultValue = "10") int limit){
|
||||
|
||||
@ -107,6 +107,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.antMatchers("/register").anonymous()
|
||||
.antMatchers("/user/activity").anonymous()
|
||||
.antMatchers("/combination/list").anonymous()
|
||||
.antMatchers("/webservice/**").anonymous()
|
||||
//微信相关
|
||||
.antMatchers("/wechat/config").anonymous()
|
||||
.antMatchers("/wechat/auth").anonymous()
|
||||
|
||||
@ -48,8 +48,7 @@ public class IndexController {
|
||||
map.put("menus",systemGroupDataService.getDatas("routine_home_menus"));
|
||||
//首页活动区域图片
|
||||
map.put("activity",systemGroupDataService.getDatas("routine_home_activity"));
|
||||
//logo
|
||||
map.put("logoUrl",systemConfigService.getData("wechat_logo"));
|
||||
|
||||
|
||||
//精品推荐
|
||||
map.put("bastList",storeProductService.getList(1,6,1));
|
||||
@ -63,9 +62,7 @@ public class IndexController {
|
||||
//滚动
|
||||
map.put("roll",systemGroupDataService.getDatas("routine_home_roll_news"));
|
||||
|
||||
//todo 优惠券
|
||||
List list = new ArrayList();
|
||||
map.put("couponList",list);
|
||||
|
||||
|
||||
|
||||
return ApiResult.ok(map);
|
||||
|
||||
@ -56,6 +56,10 @@ public interface YxUserMapper extends BaseMapper<YxUser> {
|
||||
" where uid=#{uid}")
|
||||
int incPayCount(@Param("uid") int uid);
|
||||
|
||||
@Update("update yx_user set now_money=now_money+#{price}" +
|
||||
" where uid=#{uid}")
|
||||
int incMoney(@Param("uid") int uid,double price);
|
||||
|
||||
@Update("update yx_user set integral=integral-#{integral}" +
|
||||
" where uid=#{uid}")
|
||||
int decIntegral(@Param("integral") double integral,@Param("uid") int uid);
|
||||
|
||||
@ -23,6 +23,8 @@ import java.util.List;
|
||||
*/
|
||||
public interface YxUserService extends BaseService<YxUser> {
|
||||
|
||||
void incMoney(int uid,double price);
|
||||
|
||||
void incIntegral(int uid,double integral);
|
||||
|
||||
YxUserQueryVo getNewYxUserById(Serializable id);
|
||||
|
||||
@ -62,6 +62,16 @@ public class YxUserServiceImpl extends BaseServiceImpl<YxUserMapper, YxUser> imp
|
||||
private YxUserBillService billService;
|
||||
|
||||
|
||||
/**
|
||||
* 更新用户余额
|
||||
* @param uid
|
||||
* @param price
|
||||
*/
|
||||
@Override
|
||||
public void incMoney(int uid, double price) {
|
||||
yxUserMapper.incMoney(uid,price);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incIntegral(int uid, double integral) {
|
||||
yxUserMapper.incIntegral(integral,uid);
|
||||
|
||||
@ -3,6 +3,7 @@ package co.yixiang.modules.wechat.web.controller;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.common.api.ApiCode;
|
||||
import co.yixiang.common.api.ApiResult;
|
||||
import co.yixiang.common.web.controller.BaseController;
|
||||
import co.yixiang.modules.order.service.YxStoreOrderService;
|
||||
@ -39,6 +40,11 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -110,18 +116,27 @@ public class WechatController extends BaseController {
|
||||
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.oauth2getAccessToken(code);
|
||||
WxMpUser wxMpUser = wxService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
|
||||
String openid = wxMpUser.getOpenId();
|
||||
YxWechatUser wechatUser = wechatUserService.getUserInfo(openid);;
|
||||
YxUserQueryVo yxUserQueryVo = userService.getYxUserById(wechatUser.getUid());
|
||||
YxWechatUser wechatUser = wechatUserService.getUserInfo(openid);
|
||||
|
||||
|
||||
JwtUser jwtUser = null;
|
||||
if(ObjectUtil.isNotNull(wechatUser) && ObjectUtil.isNotNull(yxUserQueryVo)){
|
||||
jwtUser = (JwtUser) userDetailsService.loadUserByUsername(wechatUser.getOpenid());
|
||||
}else{
|
||||
if(ObjectUtil.isNotNull(wechatUser)){
|
||||
wechatUserService.removeById(wechatUser.getUid());
|
||||
}
|
||||
if(ObjectUtil.isNotNull(wechatUser)){
|
||||
YxUserQueryVo yxUserQueryVo = userService.getYxUserById(wechatUser.getUid());
|
||||
if(ObjectUtil.isNotNull(yxUserQueryVo)){
|
||||
userService.removeById(yxUserQueryVo.getUid());
|
||||
jwtUser = (JwtUser) userDetailsService.loadUserByUsername(wechatUser.getOpenid());
|
||||
}else{
|
||||
if(ObjectUtil.isNotNull(wechatUser)){
|
||||
wechatUserService.removeById(wechatUser.getUid());
|
||||
}
|
||||
if(ObjectUtil.isNotNull(yxUserQueryVo)){
|
||||
userService.removeById(yxUserQueryVo.getUid());
|
||||
}
|
||||
return ApiResult.fail(ApiCode.FAIL_AUTH,"授权失败");
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
//用户保存
|
||||
YxUser user = new YxUser();
|
||||
user.setAccount(wxMpUser.getNickname());
|
||||
@ -245,14 +260,17 @@ public class WechatController extends BaseController {
|
||||
return "fail";
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/wechat/serve")
|
||||
public String post(@RequestBody String requestBody,
|
||||
public void post(@RequestBody String requestBody,
|
||||
@RequestParam("signature") String signature,
|
||||
@RequestParam("timestamp") String timestamp,
|
||||
@RequestParam("nonce") String nonce,
|
||||
@RequestParam("openid") String openid,
|
||||
@RequestParam(name = "encrypt_type", required = false) String encType,
|
||||
@RequestParam(name = "msg_signature", required = false) String msgSignature) {
|
||||
@RequestParam(name = "msg_signature", required = false) String msgSignature,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) throws IOException {
|
||||
|
||||
|
||||
if (!wxService.checkSignature(timestamp, nonce, signature)) {
|
||||
@ -264,25 +282,21 @@ public class WechatController extends BaseController {
|
||||
// 明文传输的消息
|
||||
WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(requestBody);
|
||||
WxMpXmlOutMessage outMessage = this.route(inMessage);
|
||||
if (outMessage == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
out = outMessage.toXml();
|
||||
System.out.println("xml:"+out);
|
||||
} else if ("aes".equalsIgnoreCase(encType)) {
|
||||
// aes加密的消息
|
||||
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, wxService.getWxMpConfigStorage(),
|
||||
timestamp, nonce, msgSignature);
|
||||
WxMpXmlOutMessage outMessage = this.route(inMessage);
|
||||
if (outMessage == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
out = outMessage.toEncryptedXml(wxService.getWxMpConfigStorage());
|
||||
}
|
||||
|
||||
|
||||
return out;
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.print(out);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private WxMpXmlOutMessage route(WxMpXmlMessage message) {
|
||||
|
||||
@ -0,0 +1,198 @@
|
||||
package co.yixiang.modules.wechat.web.controller;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
||||
import cn.binarywang.wx.miniapp.config.WxMaConfig;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.common.api.ApiCode;
|
||||
import co.yixiang.common.api.ApiResult;
|
||||
import co.yixiang.exception.ErrorRequestException;
|
||||
import co.yixiang.modules.order.service.YxStoreOrderService;
|
||||
import co.yixiang.modules.security.security.JwtUser;
|
||||
import co.yixiang.modules.security.utils.JwtTokenUtil;
|
||||
import co.yixiang.modules.user.entity.YxUser;
|
||||
import co.yixiang.modules.user.entity.YxWechatUser;
|
||||
import co.yixiang.modules.user.service.YxUserService;
|
||||
import co.yixiang.modules.user.service.YxWechatUserService;
|
||||
import co.yixiang.modules.user.web.vo.YxUserQueryVo;
|
||||
import co.yixiang.mp.utils.JsonUtils;
|
||||
import co.yixiang.utils.EncryptUtils;
|
||||
import co.yixiang.utils.OrderUtil;
|
||||
import co.yixiang.utils.RedisUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
/**
|
||||
* 微信小程序用户接口
|
||||
*
|
||||
* @author xuwenbo
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class WxMaUserController {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final WxMaService wxMaService;
|
||||
private final YxWechatUserService wechatUserService;
|
||||
private final YxUserService userService;
|
||||
private final JwtTokenUtil jwtTokenUtil;
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("jwtUserDetailsService")
|
||||
private UserDetailsService userDetailsService;
|
||||
|
||||
/**
|
||||
* 小程序登陆接口
|
||||
*/
|
||||
@PostMapping("/wechat/mp_auth")
|
||||
public ApiResult<Object> login(@RequestParam(value = "code") String code,
|
||||
@RequestParam(value = "spread") String spread,
|
||||
@RequestParam(value = "encryptedData") String encryptedData,
|
||||
@RequestParam(value = "iv") String iv ) {
|
||||
if (StringUtils.isBlank(code)) {
|
||||
return ApiResult.fail("empty jscode");
|
||||
}
|
||||
try {
|
||||
//读取redis配置
|
||||
String appId = RedisUtil.get("wxapp_appId");
|
||||
String secret = RedisUtil.get("wxapp_secret");
|
||||
if(StrUtil.isBlank(appId) || StrUtil.isBlank(secret)){
|
||||
throw new ErrorRequestException("请先配置小程序");
|
||||
}
|
||||
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
|
||||
wxMaConfig.setAppid(appId);
|
||||
wxMaConfig.setSecret(secret);
|
||||
|
||||
|
||||
wxMaService.setWxMaConfig(wxMaConfig);
|
||||
WxMaJscode2SessionResult session = wxMaService.getUserService().getSessionInfo(code);
|
||||
YxWechatUser wechatUser = wechatUserService.getUserInfo(session.getOpenid());;
|
||||
JwtUser jwtUser = null;
|
||||
if(ObjectUtil.isNotNull(wechatUser)){
|
||||
YxUserQueryVo yxUserQueryVo = userService.getYxUserById(wechatUser.getUid());
|
||||
if(ObjectUtil.isNotNull(yxUserQueryVo)){
|
||||
jwtUser = (JwtUser) userDetailsService.loadUserByUsername(wechatUser.getOpenid());
|
||||
}else{
|
||||
if(ObjectUtil.isNotNull(wechatUser)){
|
||||
wechatUserService.removeById(wechatUser.getUid());
|
||||
}
|
||||
if(ObjectUtil.isNotNull(yxUserQueryVo)){
|
||||
userService.removeById(yxUserQueryVo.getUid());
|
||||
}
|
||||
return ApiResult.fail(ApiCode.FAIL_AUTH,"授权失败");
|
||||
}
|
||||
|
||||
}else{
|
||||
WxMaUserInfo wxMpUser = wxMaService.getUserService()
|
||||
.getUserInfo(session.getSessionKey(), encryptedData, iv);
|
||||
//用户保存
|
||||
YxUser user = new YxUser();
|
||||
user.setAccount(wxMpUser.getNickName());
|
||||
user.setUsername(wxMpUser.getOpenId());
|
||||
user.setPassword(EncryptUtils.encryptPassword("123456"));
|
||||
user.setPwd(EncryptUtils.encryptPassword("123456"));
|
||||
user.setPhone("");
|
||||
user.setUserType("wechat");
|
||||
user.setAddTime(OrderUtil.getSecondTimestampTwo());
|
||||
user.setLastTime(OrderUtil.getSecondTimestampTwo());
|
||||
user.setNickname(wxMpUser.getNickName());
|
||||
user.setAvatar(wxMpUser.getAvatarUrl());
|
||||
user.setNowMoney(BigDecimal.ZERO);
|
||||
user.setBrokeragePrice(BigDecimal.ZERO);
|
||||
user.setIntegral(BigDecimal.ZERO);
|
||||
|
||||
userService.save(user);
|
||||
|
||||
|
||||
//保存微信用户
|
||||
YxWechatUser yxWechatUser = new YxWechatUser();
|
||||
// System.out.println("wxMpUser:"+wxMpUser);
|
||||
yxWechatUser.setAddTime(OrderUtil.getSecondTimestampTwo());
|
||||
yxWechatUser.setNickname(wxMpUser.getNickName());
|
||||
yxWechatUser.setOpenid(wxMpUser.getOpenId());
|
||||
int sub = 0;
|
||||
yxWechatUser.setSubscribe(sub);
|
||||
yxWechatUser.setSex(Integer.valueOf(wxMpUser.getGender()));
|
||||
yxWechatUser.setLanguage(wxMpUser.getLanguage());
|
||||
yxWechatUser.setCity(wxMpUser.getCity());
|
||||
yxWechatUser.setProvince(wxMpUser.getProvince());
|
||||
yxWechatUser.setCountry(wxMpUser.getCountry());
|
||||
yxWechatUser.setHeadimgurl(wxMpUser.getAvatarUrl());
|
||||
if(StrUtil.isNotEmpty(wxMpUser.getUnionId())){
|
||||
yxWechatUser.setUnionid(wxMpUser.getUnionId());
|
||||
}
|
||||
yxWechatUser.setUid(user.getUid());
|
||||
|
||||
wechatUserService.save(yxWechatUser);
|
||||
|
||||
|
||||
jwtUser = (JwtUser) userDetailsService.loadUserByUsername(wxMpUser.getOpenId());
|
||||
}
|
||||
|
||||
|
||||
//设置推广关系
|
||||
if(StrUtil.isNotEmpty(spread) && !spread.equals("NaN")){
|
||||
//System.out.println("spread:"+spread);
|
||||
userService.setSpread(Integer.valueOf(spread),
|
||||
jwtUser.getId().intValue());
|
||||
}
|
||||
|
||||
// 生成令牌
|
||||
final String token = jwtTokenUtil.generateToken(jwtUser);
|
||||
Date expiresTime = jwtTokenUtil.getExpirationDateFromToken(token);
|
||||
String expiresTimeStr = DateUtil.formatDateTime(expiresTime);
|
||||
Map<String,String> map = new LinkedHashMap<>();
|
||||
map.put("token",token);
|
||||
map.put("expires_time",expiresTimeStr);
|
||||
|
||||
// 返回 token
|
||||
return ApiResult.ok(map);
|
||||
} catch (WxErrorException e) {
|
||||
this.logger.error(e.getMessage(), e);
|
||||
return ApiResult.fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * <pre>
|
||||
// * 获取用户绑定手机号信息
|
||||
// * </pre>
|
||||
// */
|
||||
// @GetMapping("/phone")
|
||||
// public String phone(@PathVariable String appid, String sessionKey, String signature,
|
||||
// String rawData, String encryptedData, String iv) {
|
||||
//
|
||||
// // 用户信息校验
|
||||
// if (!wxMaService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
|
||||
// return "user check failed";
|
||||
// }
|
||||
//
|
||||
// // 解密
|
||||
// WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
|
||||
//
|
||||
// return JsonUtils.toJson(phoneNoInfo);
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user