diff --git a/pom.xml b/pom.xml
index 6c09948..c5adaeb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,6 +21,10 @@
+
+ org.springframework.boot
+ spring-boot-starter-test
+
org.apache.commons
commons-lang3
@@ -196,6 +200,11 @@
+
+ p6spy
+ p6spy
+ 3.8.2
+
com.baomidou
mybatis-plus-boot-starter
@@ -212,6 +221,14 @@
+
+
+
+ com.alipay.sdk
+ alipay-sdk-java
+ 4.39.208.ALL
+
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java
index aed11ff..1bbec3e 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java
@@ -1,5 +1,15 @@
package com.chaozhanggui.system.cashierservice.controller;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.AlipayClient;
+import com.alipay.api.AlipayConfig;
+import com.alipay.api.DefaultAlipayClient;
+import com.alipay.api.request.AlipaySystemOauthTokenRequest;
+import com.alipay.api.request.AlipayUserInfoShareRequest;
+import com.alipay.api.response.AlipaySystemOauthTokenResponse;
+import com.alipay.api.response.AlipayUserInfoShareResponse;
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
@@ -9,15 +19,21 @@ import com.chaozhanggui.system.cashierservice.service.PayService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.IpUtil;
+import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.RedisCst;
+import com.chaozhanggui.system.cashierservice.util.WechatUtil;
+import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
+import java.time.LocalDate;
import java.util.List;
+import java.util.Objects;
@CrossOrigin(origins = "*")
@RestController
@@ -278,4 +294,143 @@ public class PayController {
){
return payService.getOrderDiscount(staffId, orderId, token);
}
+
+
+ @RequestMapping("pcscanpay")
+ @LimitSubmit(key = "pcscanpay:%s")
+ public Result pcscanpay(HttpServletRequest request,@RequestBody PaymentReq paymentReq){
+ try {
+ return payService.pcscanpay(paymentReq.getOrderId(),IpUtil.getIpAddr(request),paymentReq.getUserId(),paymentReq.getPayType());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return Result.fail(CodeEnum.FAIL);
+ }
+
+
+
+
+
+
+ @RequestMapping("createOrder")
+ public Result createOrder(HttpServletRequest request,@RequestBody PaymentReq paymentReq){
+ try {
+ return payService.createOrder(IpUtil.getIpAddr(request),paymentReq.getUserId(),paymentReq.getPayType(),paymentReq.getShopId(),paymentReq.getPayAmount());
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+ return Result.fail(CodeEnum.FAIL);
+
+ }
+
+ @GetMapping("queryOrderPay")
+ public Result queryOrderPay(String orderId){
+ return payService.queryOrderPay(orderId);
+ }
+
+
+
+
+
+
+
+ @Value("${wx.ysk.appId}")
+ private String appId;
+
+ @Value("${wx.ysk.secrete}")
+ private String secrete;
+
+
+
+ @Value("${ali.appId}")
+ private String aliAppId;
+
+ @Value("${ali.privateKey}")
+ private String privateKey;
+
+ @Value("${ali.publicKey}")
+ private String publicKey;
+
+
+
+ /**
+ * 获取支付宝或微信openId
+ * @param code
+ * @return
+ */
+ @GetMapping("/openId")
+ public Result getOpenId(
+ @RequestParam String code,
+ @RequestParam String payType
+ ) throws AlipayApiException {
+
+ if("WECHAT".equals(payType)){
+ JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(code, appId, secrete);
+ log.info("SessionKeyOpenId:{}",SessionKeyOpenId.toString());
+ String openid = SessionKeyOpenId.getString("openid");
+ if(Objects.isNull(openid)){
+ return Result.fail("获取微信id失败");
+ }
+
+ return Result.success(CodeEnum.SUCCESS,openid);
+ }else if("ALIPAY".equals(payType)){
+
+
+ // 初始化SDK
+ AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());
+
+ // 构造请求参数以调用接口
+ AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
+
+ // 设置刷新令牌
+// request.setRefreshToken("201208134b203fe6c11548bcabd8da5bb087a83b");
+
+ // 设置授权码
+ request.setCode(code);
+
+ // 设置授权方式
+ request.setGrantType("authorization_code");
+
+ AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
+
+ log.info("AlipaySystemOauthTokenResponse:{}", JSONUtil.toJSONString(response));
+
+ response.setAccessToken(response.getRefreshToken());
+ if (!response.isSuccess()) {
+ return Result.fail("获取支付宝userId失败");
+ }
+
+ return Result.success(CodeEnum.SUCCESS, ObjectUtil.isNull(response.getUserId())?response.getOpenId():response.getUserId());
+ }
+
+ return Result.fail(CodeEnum.FAIL);
+ }
+
+
+
+ private AlipayConfig getAlipayConfig() {
+ AlipayConfig alipayConfig = new AlipayConfig();
+ alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
+ alipayConfig.setAppId(aliAppId);
+ alipayConfig.setPrivateKey(privateKey);
+ alipayConfig.setFormat("json");
+ alipayConfig.setAlipayPublicKey(publicKey);
+ alipayConfig.setCharset("UTF-8");
+ alipayConfig.setSignType("RSA2");
+ return alipayConfig;
+ }
+
+
+ public static void main(String[] args){
+ LocalDate date=LocalDate.now();
+ if(date.isLeapYear()){
+ System.out.println();
+ }
+ }
+
+
+
+
+
+
}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ShopInfoController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ShopInfoController.java
index a6fb4e1..522c1a7 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ShopInfoController.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ShopInfoController.java
@@ -17,6 +17,11 @@ public class ShopInfoController {
@Autowired
ShopInfoService shopInfoService;
+ @GetMapping("/queryShopInfo")
+ public Result queryShopInfo(@RequestParam Integer shopId){
+ return shopInfoService.queryShopInfo(shopId);
+ }
+
@GetMapping("queryShopArea")
public Result queryShopArea(@RequestHeader("token") String token,
@RequestHeader("loginName") String loginName,
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/StaffPermissionController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/StaffPermissionController.java
new file mode 100644
index 0000000..98a2b89
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/StaffPermissionController.java
@@ -0,0 +1,25 @@
+package com.chaozhanggui.system.cashierservice.controller;
+
+import com.chaozhanggui.system.cashierservice.service.TbShopPermissionService;
+import com.chaozhanggui.system.cashierservice.service.TbShopStaffPermissionService;
+import com.chaozhanggui.system.cashierservice.sign.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@Slf4j
+@RequestMapping("staffPermission")
+public class StaffPermissionController {
+
+ @Autowired
+ private TbShopPermissionService permissionService;
+
+ @GetMapping
+ public Result getStaffPermission(String staffId, String code) {
+ return permissionService.getStaffPermission(staffId, code);
+ }
+
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/VersionController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/VersionController.java
new file mode 100644
index 0000000..73247ed
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/VersionController.java
@@ -0,0 +1,40 @@
+package com.chaozhanggui.system.cashierservice.controller;
+
+import com.chaozhanggui.system.cashierservice.entity.TbVersion;
+import com.chaozhanggui.system.cashierservice.service.LoginService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author yijiegong
+ */
+@RestController
+@RequestMapping("/version")
+public class VersionController {
+
+ @Autowired
+ LoginService loginService;
+
+ @GetMapping("pcDownload")
+ public ResponseEntity pcDownload(HttpServletRequest request, HttpServletResponse response) {
+ TbVersion pcVersion = loginService.getCurrentPcVersion();
+
+ if (pcVersion == null) {
+ throw new RuntimeException("未找到PC版本信息");
+ }
+
+ // 重定向到下载地址
+ HttpHeaders headers = new HttpHeaders();
+ headers.setLocation(java.net.URI.create(pcVersion.getUrl()));
+ return new ResponseEntity<>(headers, HttpStatus.FOUND);
+ }
+
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopPermissionDao.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopPermissionDao.java
new file mode 100644
index 0000000..664e64c
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopPermissionDao.java
@@ -0,0 +1,15 @@
+package com.chaozhanggui.system.cashierservice.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.chaozhanggui.system.cashierservice.entity.TbShopPermission;
+
+/**
+ * (TbShopPermission)表数据库访问层
+ *
+ * @author makejava
+ * @since 2024-09-14 17:08:48
+ */
+public interface TbShopPermissionDao extends BaseMapper {
+
+}
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopStaffPermissionDao.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopStaffPermissionDao.java
new file mode 100644
index 0000000..a536686
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopStaffPermissionDao.java
@@ -0,0 +1,15 @@
+package com.chaozhanggui.system.cashierservice.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.chaozhanggui.system.cashierservice.entity.TbShopStaffPermission;
+
+/**
+ * 店铺员工权限关联表(TbShopStaffPermission)表数据库访问层
+ *
+ * @author makejava
+ * @since 2024-09-14 17:07:33
+ */
+public interface TbShopStaffPermissionDao extends BaseMapper {
+
+}
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/OrderVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/OrderVo.java
index 6eafc7b..8a0b924 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/OrderVo.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/OrderVo.java
@@ -15,4 +15,6 @@ public class OrderVo {
private String tableId;
private Integer vipUserId;
private Integer type;
+
+ private String sendType;
}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java
index f190219..deacaf4 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java
@@ -1,5 +1,6 @@
package com.chaozhanggui.system.cashierservice.entity;
+import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.io.Serializable;
@@ -37,7 +38,8 @@ public class TbOrderDetail implements Serializable {
private BigDecimal priceAmount;
private BigDecimal packAmount;
+ @TableField(exist = false)
private String remark;
private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintMachine.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintMachine.java
index e07c140..47111fb 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintMachine.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintMachine.java
@@ -1,7 +1,10 @@
package com.chaozhanggui.system.cashierservice.entity;
+import lombok.ToString;
+
import java.io.Serializable;
+@ToString
public class TbPrintMachine implements Serializable {
private Integer id;
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintMachineWithBLOBs.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintMachineWithBLOBs.java
index c13b47f..3f61c1f 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintMachineWithBLOBs.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPrintMachineWithBLOBs.java
@@ -1,7 +1,10 @@
package com.chaozhanggui.system.cashierservice.entity;
+import lombok.ToString;
+
import java.io.Serializable;
+@ToString
public class TbPrintMachineWithBLOBs extends TbPrintMachine implements Serializable {
private String config;
@@ -24,4 +27,4 @@ public class TbPrintMachineWithBLOBs extends TbPrintMachine implements Serializa
public void setCategoryList(String categoryList) {
this.categoryList = categoryList == null ? null : categoryList.trim();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java
index b1a62cc..9ec0ae2 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java
@@ -105,9 +105,16 @@ public class TbShopInfo implements Serializable {
private String isMemberReturn;
-
-
-
+ //是否开启桌位费 0否1是
+ private Integer isTableFee;
+ //桌位费
+ private BigDecimal tableFee;
+ //就餐模式 堂食 dine-in 外带 take-out
+ private String eatModel;
+ //程序码(零点八零首页)
+ private String smallQrcode;
+ //店铺收款码
+ private String paymentQrcode;
private static final long serialVersionUID = 1L;
@@ -495,4 +502,44 @@ public class TbShopInfo implements Serializable {
public void setIsMemberReturn(String isMemberReturn) {
this.isMemberReturn = isMemberReturn;
}
+
+ public Integer getIsTableFee() {
+ return isTableFee;
+ }
+
+ public void setIsTableFee(Integer isTableFee) {
+ this.isTableFee = isTableFee;
+ }
+
+ public BigDecimal getTableFee() {
+ return tableFee;
+ }
+
+ public void setTableFee(BigDecimal tableFee) {
+ this.tableFee = tableFee;
+ }
+
+ public String getEatModel() {
+ return eatModel;
+ }
+
+ public void setEatModel(String eatModel) {
+ this.eatModel = eatModel;
+ }
+
+ public String getSmallQrcode() {
+ return smallQrcode;
+ }
+
+ public void setSmallQrcode(String smallQrcode) {
+ this.smallQrcode = smallQrcode;
+ }
+
+ public String getPaymentQrcode() {
+ return paymentQrcode;
+ }
+
+ public void setPaymentQrcode(String paymentQrcode) {
+ this.paymentQrcode = paymentQrcode;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopPermission.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopPermission.java
new file mode 100644
index 0000000..380a643
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopPermission.java
@@ -0,0 +1,129 @@
+package com.chaozhanggui.system.cashierservice.entity;
+
+import java.util.Date;
+
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+
+import java.io.Serializable;
+
+/**
+ * (TbShopPermission)表实体类
+ *
+ * @author makejava
+ * @since 2024-09-14 17:08:48
+ */
+@SuppressWarnings("serial")
+public class TbShopPermission extends Model {
+
+ private Integer id;
+ //权限类型:staff 员工,
+ private String type;
+ //权限名称
+ private String label;
+ //权限code,为了区分采用汉语拼音
+ private String code;
+ //层级
+ private Integer level;
+ //上级ID
+ private Integer parentId;
+ //是否重要: 重要对应页面红色
+ private Integer isImportant;
+ //排序
+ private Integer sort;
+
+ private Date createTime;
+
+ private Date updateTime;
+
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public Integer getLevel() {
+ return level;
+ }
+
+ public void setLevel(Integer level) {
+ this.level = level;
+ }
+
+ public Integer getParentId() {
+ return parentId;
+ }
+
+ public void setParentId(Integer parentId) {
+ this.parentId = parentId;
+ }
+
+ public Integer getIsImportant() {
+ return isImportant;
+ }
+
+ public void setIsImportant(Integer isImportant) {
+ this.isImportant = isImportant;
+ }
+
+ public Integer getSort() {
+ return sort;
+ }
+
+ public void setSort(Integer sort) {
+ this.sort = sort;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public Date getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(Date updateTime) {
+ this.updateTime = updateTime;
+ }
+
+ /**
+ * 获取主键值
+ *
+ * @return 主键值
+ */
+ @Override
+ protected Serializable pkVal() {
+ return this.id;
+ }
+}
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopStaffPermission.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopStaffPermission.java
new file mode 100644
index 0000000..46c4a31
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopStaffPermission.java
@@ -0,0 +1,77 @@
+package com.chaozhanggui.system.cashierservice.entity;
+
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+
+import java.io.Serializable;
+
+/**
+ * 店铺员工权限关联表(TbShopStaffPermission)表实体类
+ *
+ * @author makejava
+ * @since 2024-09-14 17:07:33
+ */
+@SuppressWarnings("serial")
+public class TbShopStaffPermission extends Model {
+
+ private Integer id;
+ //权限ID
+ private Integer permissionId;
+ //员工ID
+ private Integer staffId;
+ //店铺ID
+ private Integer shopId;
+ //用户ID
+ private Integer userId;
+
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Integer getPermissionId() {
+ return permissionId;
+ }
+
+ public void setPermissionId(Integer permissionId) {
+ this.permissionId = permissionId;
+ }
+
+ public Integer getStaffId() {
+ return staffId;
+ }
+
+ public void setStaffId(Integer staffId) {
+ this.staffId = staffId;
+ }
+
+ public Integer getShopId() {
+ return shopId;
+ }
+
+ public void setShopId(Integer shopId) {
+ this.shopId = shopId;
+ }
+
+ public Integer getUserId() {
+ return userId;
+ }
+
+ public void setUserId(Integer userId) {
+ this.userId = userId;
+ }
+
+ /**
+ * 获取主键值
+ *
+ * @return 主键值
+ */
+ @Override
+ protected Serializable pkVal() {
+ return this.id;
+ }
+}
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java
index f0fae54..3b6fe93 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java
@@ -86,13 +86,6 @@ public class LimitSubmitAspect {
Object[] args= joinPoint.getArgs();
String orderId=orderId(method,args);
-
-
-
-
-
-
-
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
String redisKey = limitSubmit.key();
String key = getRedisKey1(joinPoint, redisKey,orderId);
@@ -205,6 +198,13 @@ public class LimitSubmitAspect {
if(o instanceof List){
orderId= ((List)o).get(0).getOrderId().toString();
}
+ }else if("pcscanpay".equals(method.getName())){
+ Object o=args[1];
+
+ if(o instanceof PaymentReq){
+ orderId=((PaymentReq)o).getOrderId();
+ }
+
}
return orderId;
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/SignInterceptor.java b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/SignInterceptor.java
index ad1dba3..acf8bf3 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/SignInterceptor.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/SignInterceptor.java
@@ -37,7 +37,7 @@ public class SignInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
- String requestURI = request.getRequestURI();
+ String requestUri = request.getRequestURI();
if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
@@ -45,6 +45,10 @@ public class SignInterceptor implements HandlerInterceptor {
return true;
}
+ if (requestUri.contains("/version/pcDownload")) {
+ return true;
+ }
+
String token=request.getHeader("token");
String loginName=request.getHeader("loginName");
String clientType=request.getHeader("clientType");
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/WebAppConfigurer.java b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/WebAppConfigurer.java
index ff4c376..7a8f40a 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/WebAppConfigurer.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/WebAppConfigurer.java
@@ -28,6 +28,10 @@ public class WebAppConfigurer implements WebMvcConfigurer {
.excludePathPatterns("/order/sendMessage")
.excludePathPatterns("/order/getOrderById")
.excludePathPatterns("/data/handoverprint")
+ .excludePathPatterns("/pay/pcscanpay")
+ .excludePathPatterns("/pay/openId")
+ .excludePathPatterns("/pay/createOrder")
+ .excludePathPatterns("/pay/queryOrderPay")
;
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/model/PaymentReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/model/PaymentReq.java
index e04a67b..dc8b2df 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/model/PaymentReq.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/model/PaymentReq.java
@@ -22,5 +22,12 @@ public class PaymentReq implements Serializable {
private String memberCode;
+ private String payType;
+
+ private String userId;
+
+ private String shopId;
+
+
}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mybatis/MPOrderDetailMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/mybatis/MPOrderDetailMapper.java
new file mode 100644
index 0000000..695611b
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/mybatis/MPOrderDetailMapper.java
@@ -0,0 +1,8 @@
+package com.chaozhanggui.system.cashierservice.mybatis;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
+import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
+
+public interface MPOrderDetailMapper extends BaseMapper {
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/BalanceConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/BalanceConsumer.java
index 8532993..dfd6096 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/BalanceConsumer.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/BalanceConsumer.java
@@ -37,11 +37,11 @@ public class BalanceConsumer {
- @Value("${wx.balance.appId}")
+// @Value("${wx.balance.appId}")
private static String appId="wxd88fffa983758a30" ;
- @Value("${wx.balance.secrete}")
+// @Value("${wx.balance.secrete}")
private static String secrete="a34a61adc0602118b49400baa8812454" ;
- @Value("${wx.balance.warnMsgTmpId}")
+// @Value("${wx.balance.warnMsgTmpId}")
private static String msgTmpId = "AV-KybUHaK3KtFVLqpy6PHccHBS7XeX__mOM4RbufnQ";
static LinkedHashMap linkedHashMap=new LinkedHashMap<>();
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintConsumer.java
new file mode 100644
index 0000000..c46e148
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintConsumer.java
@@ -0,0 +1,460 @@
+package com.chaozhanggui.system.cashierservice.rabbit;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.chaozhanggui.system.cashierservice.dao.*;
+import com.chaozhanggui.system.cashierservice.entity.*;
+import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
+import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
+import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper;
+import com.chaozhanggui.system.cashierservice.mybatis.MpPrintMachineMapper;
+import com.chaozhanggui.system.cashierservice.rabbit.print.PrinterHandler;
+import com.chaozhanggui.system.cashierservice.util.*;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+@Slf4j
+@Component
+@Service
+public class PrintConsumer {
+
+
+ @Autowired
+ TbShopUserMapper tbShopUserMapper;
+ @Autowired
+ private TbOrderInfoMapper tbOrderInfoMapper;
+ @Autowired
+ private TbPrintMachineMapper tbPrintMachineMapper;
+ @Autowired
+ private TbCashierCartMapper tbCashierCartMapper;
+ @Autowired
+ private TbProductSkuMapper tbProductSkuMapper;
+ @Autowired
+ private TbShopInfoMapper tbShopInfoMapper;
+
+ @Autowired
+ private TbProductMapper tbProductMapper;
+
+ @Autowired
+ private TbOrderDetailMapper tbOrderDetailMapper;
+ @Autowired
+
+ private RedisUtil redisUtils;
+
+ private final RedisTemplate redisTemplate;
+ @Autowired
+ private MpPrintMachineMapper mpPrintMachineMapper;
+ @Autowired
+ private MPOrderDetailMapper mPOrderDetailMapper;
+
+ private final PrinterHandler printerHandler;
+
+ public PrintConsumer(RedisTemplate redisTemplate, PrinterHandler printerHandler) {
+ this.redisTemplate = redisTemplate;
+ this.printerHandler = printerHandler;
+ }
+
+ @RabbitListener(queues = {RabbitConstants.QUEUE_PRINT_DISHES})
+ public void printDishesListener(String msg) {
+ try {
+ log.info("打印消息mq 接收到打印菜品消息,消息内容: {}", msg);
+ JSONObject jsonObject = JSONObject.parseObject(msg);
+ Integer orderId = jsonObject.getInteger("orderId");
+ JSONArray orderDetailIds = jsonObject.getJSONArray("orderDetailIds");
+ Boolean isReturn = jsonObject.getBoolean("isReturn");
+
+ TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
+ Utils.checkValueUnReturn(orderInfo, "订单信息不存在");
+
+
+ List orderDetails = new ArrayList<>();
+ for (Object orderDetail : orderDetailIds) {
+ orderDetails.add(JSONObject.parseObject(orderDetail.toString(), TbOrderDetail.class));
+ }
+ if (orderDetails.isEmpty()) {
+ return;
+ }
+ getPrintMachine(Integer.valueOf(orderInfo.getShopId()), "cash").forEach(machine -> {
+ log.info("打印机信息: {}", machine);
+ printerHandler.handleRequest(machine, isReturn, orderInfo, orderDetails);
+ });
+
+ } catch (Exception e) {
+ log.warn("打印菜品失败", e);
+ }
+
+ }
+
+ @RabbitListener(queues = {RabbitConstants.QUEUE_PRINT_PLACE})
+ public void printPlaceListener(JSONObject jsonObject) {
+ try {
+ log.info("打印消息mq 接收到打印结算单消息,消息内容: {}", jsonObject);
+ Integer orderId = jsonObject.getInteger("orderId");
+ Boolean isReturn = jsonObject.getBoolean("isReturn");
+
+ TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
+ Utils.checkValueUnReturn(orderInfo, "订单信息不存在");
+ TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
+ Utils.checkValueUnReturn(shopInfo, "店铺信息不存在");
+
+ getPrintMachine(shopInfo.getId(), "cash").forEach(machine -> {
+ List tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(orderInfo.getId());
+ printerHandler.handleRequest(machine, isReturn, orderInfo, tbOrderDetails);
+
+// printPlaceTicket(isReturn, machine, orderInfo, shopInfo);
+ });
+
+ } catch (Exception e) {
+ log.warn("打印菜品失败", e);
+ }
+ }
+
+ private boolean checkMachineModel(String type, TbPrintMachine machine) {
+ Utils.checkValueUnReturn(machine, "打印机为null");
+ JSONObject config = JSONObject.parseObject(machine.getConfig());
+ String model = config.getString("model");
+ return type.equals(model);
+ }
+
+
+ private List getPrintMachine(Integer shopId, String subType) {
+ TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(shopId);
+ if (ObjectUtil.isEmpty(shopInfo)) {
+ log.error("店铺信息不存在");
+ return new ArrayList<>();
+ }
+
+ List list = mpPrintMachineMapper.selectList(new LambdaQueryWrapper()
+ .eq(TbPrintMachine::getStatus, 1)
+ .eq(TbPrintMachine::getShopId, shopId)
+ .eq(TbPrintMachine::getSubType, subType)
+ .eq(TbPrintMachine::getConnectionType, "network"));
+ if (list.isEmpty()) {
+ log.error("店铺未配置打印机,店铺id: {}", shopId);
+ return list;
+ }
+ log.info("打印机列表: {}", list);
+ return list;
+
+ }
+
+
+ /**
+ * 打印菜品单
+ *
+ * @param isReturn 是否退款单
+ */
+ private void printDishesTicket(boolean isReturn, TbPrintMachine tbPrintMachineWithBLOBs, TbOrderDetail item, TbOrderInfo orderInfo, List categoryInfos) {
+ log.info("开始打印一菜一品票据,商品名:{}", item.getProductName());
+ if (item.getProductId().equals(-999)) {
+ return;
+ }
+ String categoryId = tbProductMapper.selectByPrimaryKey(item.getProductId()).getCategoryId();
+ TbProductSkuWithBLOBs sku = tbProductSkuMapper.selectByPrimaryKey(item.getProductSkuId());
+ if (sku == null) {
+ log.error("商品不存在, id: {}", item.getProductSkuId());
+ return;
+ }
+
+ long count = categoryInfos.stream().filter(c ->
+ c.getId().toString().equals(categoryId)
+ ).count();
+
+ if (count == 0) {
+ log.warn("分类未添加菜品: {} : {}", item.getProductName(), sku.getSpecSnap());
+ return;
+ }
+
+ String remark = StrUtil.isNotBlank(sku.getSpecSnap()) ? sku.getSpecSnap() : "";
+ item.setRemark(remark);
+
+ String data;
+ String voiceJson;
+ if (isReturn) {
+
+ data = PrinterUtils.getPrintData("return",
+ StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getMasterId() : orderInfo.getTableName(),
+ DateUtils.getTime(new Date(orderInfo.getCreatedAt())), item.getProductName(), Math.abs(item.getNum()), remark);
+ voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
+ PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
+
+ } else {
+ data = PrinterUtils.getPrintData("", orderInfo.getMasterId(),
+ DateUtils.getTime(new Date(orderInfo.getCreatedAt())), item.getProductName(),
+ item.getNum(), remark);
+ voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
+ PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
+ }
+ }
+
+ /**
+ * 打印结算单
+ */
+ private void printPlaceTicket(boolean isReturn, TbPrintMachine printMachine, TbOrderInfo orderInfo, TbShopInfo shopInfo) {
+ log.info("打印机信息: {}", printMachine);
+ JSONObject config = JSONObject.parseObject(printMachine.getConfig());
+ String model = config.getString("model");
+ if (!"normal".equals(model)) {
+ log.info("当前打印机非小票打印机, {}", printMachine);
+ return;
+ }
+
+ List tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(orderInfo.getId());
+ if (!tbOrderDetails.isEmpty()) {
+ List detailList = new ArrayList<>();
+ tbOrderDetails.parallelStream().forEach(it -> {
+
+ TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
+ String remark = "";
+ if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
+ remark = tbProductSkuWithBLOBs.getSpecSnap();
+ }
+ OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), it.getPriceAmount().toPlainString(), remark);
+ detailList.add(detail);
+
+ });
+ String balance = "0";
+
+ if ("deposit".equals(orderInfo.getPayType())) {
+ TbShopUser user = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMemberId()));
+ if (ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getAmount())) {
+ balance = user.getAmount().toPlainString();
+ }
+ }
+
+
+ if (!detailList.isEmpty()) {
+ if (isReturn) {
+ OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印",
+ ObjectUtil.isEmpty(orderInfo.getMasterId()) ||
+ ObjectUtil.isNull(orderInfo.getMasterId()) ? orderInfo.getTableName() : orderInfo.getMasterId(),
+ orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
+ "【POS-1】001", orderInfo.getPayAmount().toPlainString(), balance, orderInfo.getPayType(),
+ "0", detailList, orderInfo.getRemark(), null, null);
+
+ String printType = "退款单";
+
+ String data = PrinterUtils.getCashPrintData(detailPO, printType, "return");
+ String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
+ PrinterUtils.printTickets(voiceJson, 1, 1, printMachine.getAddress(), data);
+ } else {
+ OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印",
+ orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(),
+ orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
+ "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance,
+ (ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()),
+ "0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() != null ? orderInfo.getDiscountAmount().toPlainString() : null,
+ orderInfo.getDiscountRatio() != null ? orderInfo.getDiscountRatio().toPlainString() : null);
+ detailPO.setOutNumber(orderInfo.getOutNumber());
+ String printType = "结算单";
+ String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType());
+ String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
+ PrinterUtils.printTickets(voiceJson, 3, 1, printMachine.getAddress(), data);
+ }
+ }
+ }
+ }
+
+
+ private void fePrinter(TbPrintMachine tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List categoryInfos) {
+ String orderId = orderInfo.getId().toString();
+ switch (tbPrintMachineWithBLOBs.getSubType()) {
+ case "label": //标签打印机
+ List cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
+ if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
+ cashierCarts.parallelStream().forEach(it -> {
+
+ String categoryId;
+ if (ObjectUtil.isEmpty(it.getCategoryId())) {
+ categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
+ } else {
+ categoryId = it.getCategoryId();
+ }
+
+
+ Long count = categoryInfos.stream().filter(c ->
+ c.getId().toString().equals(categoryId)
+ ).count();
+
+ log.info("获取当前类别是否未打印类别:{}", count);
+
+
+ if (count > 0) {
+ TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
+ String remark = "";
+ if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
+ remark = tbProductSkuWithBLOBs.getSpecSnap();
+ }
+ for (int i = 0; i < it.getNumber(); i++) {
+ FeieyunPrintUtil.printLabelMsg(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getTableName(), it.getName(), 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), it.getSalePrice().toPlainString(), remark);
+ }
+ }
+ });
+ }
+
+ break;
+ case "cash": //小票打印机
+ switch (model) {
+ case "normal": //普通出单
+
+ if ("return".equals(orderInfo.getOrderType())) {
+ List tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
+ if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) {
+ List detailList = new ArrayList<>();
+ tbOrderDetails.parallelStream().forEach(it -> {
+ String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
+
+ Long count = categoryInfos.stream().filter(c ->
+ c.getId().toString().equals(categoryId)
+ ).count();
+ log.info("获取当前类别是否未打印类别:{}", count);
+
+
+ TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
+ String remark = "";
+ if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
+ remark = tbProductSkuWithBLOBs.getSpecSnap();
+ }
+ OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), it.getPriceAmount().toPlainString(), remark);
+ detailList.add(detail);
+
+ });
+ String balance = "0";
+
+ if ("deposit".equals(orderInfo.getPayType())) {
+ TbShopUser user = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMemberId()));
+ if (ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getAmount())) {
+ balance = user.getAmount().toPlainString();
+ }
+ }
+
+
+ if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
+// OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList);
+ OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", ObjectUtil.isEmpty(orderInfo.getMasterId()) || ObjectUtil.isNull(orderInfo.getMasterId()) ? orderInfo.getTableName() : orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio().toPlainString());
+
+ String printType = "退款单";
+
+ String data = PrinterUtils.getCashPrintData(detailPO, printType, "return");
+// String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
+// PrinterUtils.printTickets(voiceJson,1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
+ }
+ }
+
+
+ } else {
+ cashierCarts = cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
+
+ if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
+ List detailList = new ArrayList<>();
+ cashierCarts.parallelStream().forEach(it -> {
+ String categoryId;
+ if (ObjectUtil.isEmpty(it.getCategoryId())) {
+ categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
+ } else {
+ categoryId = it.getCategoryId();
+ }
+
+
+ Long count = categoryInfos.stream().filter(c ->
+ c.getId().toString().equals(categoryId)
+ ).count();
+
+ if (count > 0) {
+ TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
+ String remark = "";
+ if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
+ remark = tbProductSkuWithBLOBs.getSpecSnap();
+ }
+ OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), it.getTotalAmount().toPlainString(), remark);
+ detailList.add(detail);
+ }
+
+ });
+
+ String balance = "0";
+
+ if ("deposit".equals(orderInfo.getPayType())) {
+ TbShopUser user = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMemberId()));
+ if (ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getAmount())) {
+ balance = user.getAmount().toPlainString();
+ }
+ }
+ if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
+ OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, (ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()), "0", detailList, orderInfo.getRemark(), null, null);
+ String printType = "结算单";
+
+ if ("return".equals(orderInfo.getOrderType())) {
+ printType = "退款单";
+ }
+
+
+ FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(), printType, printType);
+ }
+
+ }
+ }
+
+ break;
+ case "one": //一菜一品
+
+ if (!orderInfo.getStatus().equals("unpaid")) {
+ return;
+ }
+
+ cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final");
+ if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
+
+ cashierCarts.parallelStream().forEach(it -> {
+
+ String categoryId;
+ if (ObjectUtil.isEmpty(it.getCategoryId())) {
+ categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
+ } else {
+ categoryId = it.getCategoryId();
+ }
+
+
+ Long count = categoryInfos.stream().filter(c ->
+ c.getId().toString().equals(categoryId)
+ ).count();
+
+ if (count > 0) {
+ TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
+ String remark = "";
+ if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
+ remark = tbProductSkuWithBLOBs.getSpecSnap();
+ }
+
+
+ FeieyunPrintUtil.getPrintData(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber(), remark);
+ }
+ });
+ }
+ break;
+ case "category": //分类出单
+ break;
+ }
+
+ break;
+ case "kitchen": //出品打印机
+ break;
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintMechineConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintMechineConsumer.java
index e867773..616eb0d 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintMechineConsumer.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/PrintMechineConsumer.java
@@ -607,13 +607,20 @@ public class PrintMechineConsumer {
if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
// OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList);
- OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", ObjectUtil.isEmpty(orderInfo.getMasterId()) || ObjectUtil.isNull(orderInfo.getMasterId()) ? orderInfo.getTableName() : orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio().toPlainString());
+ OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(),
+ "普通打印", ObjectUtil.isEmpty(orderInfo.getMasterId()) || ObjectUtil.isNull(orderInfo.getMasterId())
+ ? orderInfo.getTableName() : orderInfo.getMasterId(), orderInfo.getOrderNo(),
+ DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
+ "【POS-1】001", orderInfo.getOrderAmount().toPlainString(),
+ balance, orderInfo.getPayType(), "0",
+ detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() == null ? null : orderInfo.getDiscountAmount().toPlainString(),
+ orderInfo.getDiscountRatio() == null ? null : orderInfo.getDiscountRatio().toPlainString());
String printType = "退款单";
String data = PrinterUtils.getCashPrintData(detailPO, printType, "return");
-// String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
-// PrinterUtils.printTickets(voiceJson,1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
+ String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
+ PrinterUtils.printTickets(voiceJson,1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java
index b5e93f3..25a4ef5 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java
@@ -15,20 +15,20 @@ import org.springframework.context.annotation.Scope;
@Configuration
public class RabbitConfig {
-
+
@Value("${spring.rabbitmq.host}")
private String host;
-
+
@Value("${spring.rabbitmq.port}")
private int port;
-
+
@Value("${spring.rabbitmq.username}")
private String username;
-
+
@Value("${spring.rabbitmq.password}")
private String password;
-
-
+
+
@Bean
public ConnectionFactory connectionFactory() {
@@ -39,7 +39,7 @@ public class RabbitConfig {
connectionFactory.setPublisherConfirms(true);
return connectionFactory;
}
-
+
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
//必须是prototype类型
@@ -51,12 +51,12 @@ public class RabbitConfig {
public DirectExchange defaultExchange_Register() {
return new DirectExchange(RabbitConstants.CART_ORDER_COLLECT_PUT);
}
-
+
@Bean
public Queue queuePut_Register() {
return new Queue(RabbitConstants.CART_ORDER_COLLECT_QUEUE_PUT, true); //队列持久
}
-
+
@Bean
public Binding bindingPut_Register() {
return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT);
@@ -142,7 +142,28 @@ public class RabbitConfig {
}
+ // 打印出票
+ @Bean
+ DirectExchange printExchange() {
+ return new DirectExchange(RabbitConstants.EXCHANGE_PRINT);
+ }
+ @Bean
+ Queue printDishesQueue() {
+ return new Queue(RabbitConstants.QUEUE_PRINT_DISHES);
+ }
+ @Bean
+ Binding bindingDishedPrint(Queue printDishesQueue, DirectExchange printExchange) {
+ return BindingBuilder.bind(printDishesQueue).to(printExchange).with(RabbitConstants.ROUTING_KEY_PRINT_DISHES);
+ }
+ @Bean
+ Queue printPlaceQueue() {
+ return new Queue(RabbitConstants.QUEUE_PRINT_PLACE);
+ }
+ @Bean
+ Binding bindingPlacePrint(Queue printPlaceQueue, DirectExchange printExchange) {
+ return BindingBuilder.bind(printPlaceQueue).to(printExchange).with(RabbitConstants.ROUTING_KEY_PRINT_PLACE);
+ }
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java
index e0e1a0f..c506f13 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java
@@ -58,4 +58,13 @@ public interface RabbitConstants {
public static final String BALANCE_QUEUE_PUT="balance_queue_put";
public static final String BALANCE_ROUTINGKEY_PUT="balance_routingkey_put";
+
+ // 打印出票
+ String EXCHANGE_PRINT = "exchange.print";
+ // 菜品打印
+ String QUEUE_PRINT_DISHES = "queue.dishes.print";
+ String ROUTING_KEY_PRINT_DISHES = "routing.dishes.print";
+ // 下单打印
+ String QUEUE_PRINT_PLACE = "queue.place.order.print";
+ String ROUTING_KEY_PRINT_PLACE = "routing.place.order.print";
}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/FeiPrinter.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/FeiPrinter.java
new file mode 100644
index 0000000..2af3f0f
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/FeiPrinter.java
@@ -0,0 +1,40 @@
+package com.chaozhanggui.system.cashierservice.rabbit.print;
+
+import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
+import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
+import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
+import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
+import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
+import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
+import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class FeiPrinter extends PrinterHandler{
+
+ public FeiPrinter(TbProductMapper productMapper, TbProductSkuMapper tbProductSkuMapper, TbShopUserMapper tbShopUserMapper) {
+ super("Feie", productMapper, tbProductSkuMapper, tbShopUserMapper);
+ }
+
+ @Override
+ protected void returnDishesPrint(TbOrderInfo orderInfo, TbOrderDetail orderDetail, TbPrintMachine machine) {
+
+ }
+
+ @Override
+ protected void normalDishesPrint(TbOrderInfo orderInfo, TbOrderDetail orderDetail, TbPrintMachine machine) {
+
+ }
+
+ @Override
+ protected void returnOrderPrint(TbOrderInfo orderInfo, TbPrintMachine machine, String balance, List detailList) {
+
+ }
+
+ @Override
+ protected void normalOrderPrint(TbOrderInfo orderInfo, TbPrintMachine machine, String balance, List detailList) {
+
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/PrintConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/PrintConfig.java
new file mode 100644
index 0000000..614aeaf
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/PrintConfig.java
@@ -0,0 +1,35 @@
+package com.chaozhanggui.system.cashierservice.rabbit.print;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+
+@Configuration
+public class PrintConfig {
+
+ private final YxyPrinter yxyPrinter;
+ private final FeiPrinter feiPrinter;
+
+ public PrintConfig(YxyPrinter yxyPrinter, FeiPrinter feiPrinter) {
+ this.yxyPrinter = yxyPrinter;
+ this.feiPrinter = feiPrinter;
+ }
+
+ // 初始化责任链
+ @PostConstruct
+ public void initChain() {
+ yxyPrinter.setNextPrinter(feiPrinter);
+ feiPrinter.setNextPrinter(null);
+ }
+
+ @Bean
+ @Primary
+ public PrinterHandler printerHandler() {
+ return yxyPrinter;
+ }
+
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/PrinterHandler.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/PrinterHandler.java
new file mode 100644
index 0000000..9008941
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/PrinterHandler.java
@@ -0,0 +1,153 @@
+package com.chaozhanggui.system.cashierservice.rabbit.print;
+
+import cn.hutool.core.lang.func.Func0;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
+import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
+import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
+import com.chaozhanggui.system.cashierservice.entity.*;
+import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
+import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
+import com.chaozhanggui.system.cashierservice.util.DateUtils;
+import com.chaozhanggui.system.cashierservice.util.JSONUtil;
+import com.chaozhanggui.system.cashierservice.util.PrinterUtils;
+import com.chaozhanggui.system.cashierservice.util.Utils;
+import lombok.Setter;
+import lombok.ToString;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@ToString
+public abstract class PrinterHandler {
+ @Setter
+ protected PrinterHandler nextPrinter;
+ protected String printerBrand;
+
+ private final TbProductMapper tbProductMapper;
+ private final TbProductSkuMapper tbProductSkuMapper;
+ private final TbShopUserMapper tbShopUserMapper;
+
+ public PrinterHandler(String printerBrand, TbProductMapper productMapper, TbProductSkuMapper tbProductSkuMapper, TbShopUserMapper tbShopUserMapper) {
+ this.printerBrand = printerBrand;
+ this.tbProductMapper = productMapper;
+ this.tbProductSkuMapper = tbProductSkuMapper;
+ this.tbShopUserMapper = tbShopUserMapper;
+ }
+
+ protected void print(TbPrintMachine machine, boolean isReturn, TbOrderInfo orderInfo, List tbOrderDetailList) {
+ String configStr = machine.getConfig();
+ Utils.checkValueUnReturn(configStr, "打印机配置为空");
+ JSONObject config = JSONObject.parseObject(configStr);
+ String model = JSONObject.parseObject(configStr).getString("model");
+
+ List categoryInfos = JSONUtil.parseJSONStr2TList(config.getJSONArray("categoryList").toString(), CategoryInfo.class);
+
+ switch (model) {
+ case "one":
+ tbOrderDetailList.forEach(item -> {
+ log.info("开始打印退单菜品,商品名:{}", item.getProductName());
+ // 台位费不打印
+ if (item.getProductId().equals(-999)) {
+ log.info("台位费商品,不打印");
+ return;
+ }
+ String categoryId = tbProductMapper.selectByPrimaryKey(item.getProductId()).getCategoryId();
+ TbProductSkuWithBLOBs sku = tbProductSkuMapper.selectByPrimaryKey(item.getProductSkuId());
+ if (sku == null) {
+ log.error("商品不存在, id: {}", item.getProductSkuId());
+ return;
+ }
+
+ long count = categoryInfos.stream().filter(c ->
+ c.getId().toString().equals(categoryId)
+ ).count();
+
+ if (count == 0) {
+ log.warn("分类未添加菜品: {} : {}", item.getProductName(), sku.getSpecSnap());
+ return;
+ }
+
+ String remark = StrUtil.isNotBlank(sku.getSpecSnap()) ? sku.getSpecSnap() : "";
+ item.setRemark(remark);
+ String data;
+ String voiceJson;
+ if (isReturn) {
+ returnDishesPrint(orderInfo, item, machine);
+ } else {
+ normalDishesPrint(orderInfo, item, machine);
+ }
+ });
+ break;
+ case "normal":
+ if (tbOrderDetailList.isEmpty()) {
+ log.info("待打印列表为空");
+ return;
+ }
+ List detailList = new ArrayList<>();
+ tbOrderDetailList.forEach(it -> {
+ TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(it.getProductSkuId());
+ String remark = "";
+ if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
+ remark = tbProductSkuWithBLOBs.getSpecSnap();
+ }
+ OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), it.getPriceAmount().toPlainString(), remark);
+ detailList.add(detail);
+
+ });
+ String balance = "0";
+
+ if ("deposit".equals(orderInfo.getPayType())) {
+ TbShopUser user = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMemberId()));
+ if (ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getAmount())) {
+ balance = user.getAmount().toPlainString();
+ }
+ }
+
+ if (!detailList.isEmpty()) {
+ if (isReturn) {
+ returnOrderPrint(orderInfo, machine, balance, detailList);
+
+ } else {
+ normalOrderPrint(orderInfo, machine, balance, detailList);
+
+ }
+ }
+ default:
+ log.warn("未知打印类型: {}", model);
+ }
+ }
+
+ public void handleRequest(TbPrintMachine machine, boolean isReturn, TbOrderInfo orderInfo, List tbOrderDetailList) {
+ if (canHandleRequest(machine.getContentType(), machine.getConnectionType())) {
+ log.info("打印机: {}, 是否退款单: {}, 订单信息: {}, 订单详情信息: {}", machine, isReturn, orderInfo, tbOrderDetailList);
+ print(machine, isReturn, orderInfo, tbOrderDetailList);
+ } else if (nextPrinter != null) {
+ log.info("当前打印机无法处理: {},将请求传递给下一个打印机:{}...", this, nextPrinter);
+ nextPrinter.handleRequest(machine, isReturn, orderInfo, tbOrderDetailList);
+ } else {
+ log.warn("未找到匹配打印机");
+ }
+ }
+
+ protected abstract void returnDishesPrint(TbOrderInfo orderInfo, TbOrderDetail orderDetail, TbPrintMachine machine);
+
+ protected abstract void normalDishesPrint(TbOrderInfo orderInfo, TbOrderDetail orderDetail, TbPrintMachine machine);
+
+ protected abstract void returnOrderPrint(TbOrderInfo orderInfo, TbPrintMachine machine, String balance, List detailList);
+
+ protected abstract void normalOrderPrint(TbOrderInfo orderInfo, TbPrintMachine machine, String balance, List detailList);
+
+ // 抽象方法,子类实现判断能否处理请求
+ boolean canHandleRequest(String currentBrand, String connectType) {
+ log.info("handle判断是否可处理: {}, 连接类型: {}, handler类型: {}", currentBrand, connectType, printerBrand);
+ Utils.checkValueUnReturn(printerBrand, "打印机品牌未赋值");
+ return printerBrand.equals(currentBrand) && "network".equals(connectType);
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/YxyPrinter.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/YxyPrinter.java
new file mode 100644
index 0000000..2c317fc
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/print/YxyPrinter.java
@@ -0,0 +1,86 @@
+package com.chaozhanggui.system.cashierservice.rabbit.print;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
+import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
+import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
+import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
+import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
+import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
+import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
+import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
+import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
+import com.chaozhanggui.system.cashierservice.util.DateUtils;
+import com.chaozhanggui.system.cashierservice.util.PrinterUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@Component
+public class YxyPrinter extends PrinterHandler{
+ private final TbShopInfoMapper shopInfoMapper;
+
+ public YxyPrinter(TbShopInfoMapper shopInfoMapper, TbProductMapper productMapper, TbProductSkuMapper productSkuMapper, TbShopUserMapper shopUserMapper) {
+ super("yxyPrinter", productMapper, productSkuMapper, shopUserMapper);
+ this.shopInfoMapper = shopInfoMapper;
+ }
+
+
+ @Override
+ protected void returnDishesPrint(TbOrderInfo orderInfo, TbOrderDetail orderDetail, TbPrintMachine machine) {
+ String data = PrinterUtils.getPrintData("return",
+ StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getMasterId() : orderInfo.getTableName(),
+ DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), Math.abs(orderDetail.getNum()), orderDetail.getRemark());
+ String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
+ PrinterUtils.printTickets(voiceJson, 3, 1, machine.getAddress(), data);
+ }
+
+ @Override
+ protected void normalDishesPrint(TbOrderInfo orderInfo, TbOrderDetail orderDetail, TbPrintMachine machine) {
+ String data = PrinterUtils.getPrintData("", orderInfo.getMasterId(),
+ DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(),
+ orderDetail.getNum(), orderDetail.getRemark());
+ String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
+ PrinterUtils.printTickets(voiceJson, 3, 1, machine.getAddress(), data);
+ }
+
+ @Override
+ protected void returnOrderPrint(TbOrderInfo orderInfo, TbPrintMachine machine, String balance, List detailList) {
+ TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
+ OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印",
+ ObjectUtil.isEmpty(orderInfo.getMasterId()) ||
+ ObjectUtil.isNull(orderInfo.getMasterId()) ? orderInfo.getTableName() : orderInfo.getMasterId(),
+ orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
+ "【POS-1】001", orderInfo.getPayAmount().toPlainString(), balance, orderInfo.getPayType(),
+ "0", detailList, orderInfo.getRemark(), null, null);
+
+ String printType = "退款单";
+
+ String data = PrinterUtils.getCashPrintData(detailPO, printType, "return");
+ String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
+ PrinterUtils.printTickets(voiceJson, 1, 1, machine.getAddress(), data);
+ }
+
+ @Override
+ protected void normalOrderPrint(TbOrderInfo orderInfo, TbPrintMachine machine, String balance, List detailList) {
+ TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
+
+ OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印",
+ orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(),
+ orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
+ "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance,
+ (ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()),
+ "0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() != null ? orderInfo.getDiscountAmount().toPlainString() : null,
+ orderInfo.getDiscountRatio() != null ? orderInfo.getDiscountRatio().toPlainString() : null);
+ detailPO.setOutNumber(orderInfo.getOutNumber());
+ String printType = "结算单";
+ String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType());
+ String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
+ PrinterUtils.printTickets(voiceJson, 3, 1, machine.getAddress(), data);
+ }
+
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java
index dcc52f1..709dffa 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java
@@ -146,14 +146,17 @@ public class LoginService {
}
public Result findVersion() {
+ TbVersion pcVersion = getCurrentPcVersion();
+ return new Result(SUCCESS, pcVersion);
+ }
+
+ public TbVersion getCurrentPcVersion() {
LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TbVersion::getSource,"PC");
queryWrapper.eq(TbVersion::getSel,1);
- return new Result(SUCCESS,versionMapper.selectOne(queryWrapper));
+ return versionMapper.selectOne(queryWrapper);
}
-
-
public Result logout(String loginName, String clientType, String token, String status) {
String key = RedisCst.ONLINE_USER.concat(":").concat(clientType).concat(":").concat(loginName);
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java
index 8e13866..375dd52 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java
@@ -717,15 +717,27 @@ public class OrderService {
for (TbCashierCart cashierCart : list) {
+
+ TbOrderDetail orderDetail = new TbOrderDetail();
+ TbProductWithBLOBs product=tbProductMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getProductId()));
+ if("takeaway".equals(orderVo.getSendType())||"takeself".equals(orderVo.getSendType())){
+ if(Objects.nonNull(product.getPackFee())){
+ packAMount = packAMount.add(product.getPackFee());
+ orderDetail.setPackAmount(product.getPackFee());
+ }
+ }
+
+
+
TbProductSkuWithBLOBs tbProduct = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getSkuId()));
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
- packAMount = packAMount.add(cashierCart.getPackFee());
+
feeAmount = cashierCart.getPackFee();
if (Objects.nonNull(tbProduct)) {
saleAmount = saleAmount.add(tbProduct.getSalePrice());
}
skuMap.put(tbProduct.getId(), tbProduct);
- TbOrderDetail orderDetail = new TbOrderDetail();
+
orderDetail.setCreateTime(new Date());
orderDetail.setNum(cashierCart.getNumber());
orderDetail.setPrice(cashierCart.getSalePrice());
@@ -739,7 +751,6 @@ public class OrderService {
orderDetail.setProductSkuName(tbProduct.getSpecSnap());
orderDetail.setProductName(cashierCart.getName());
orderDetail.setShopId(orderVo.getShopId());
- orderDetail.setPackAmount(cashierCart.getPackFee());
orderDetail.setStatus("unpaid");
orderDetail.setProductImg(cashierCart.getCoverImg());
masterId = cashierCart.getMasterId();
@@ -774,10 +785,11 @@ public class OrderService {
orderInfo.setTradeDay(DateUtils.getDay());
orderInfo.setUserId(orderVo.getUserId());
orderInfo.setUseType(StrUtil.isNotBlank(orderVo.getTableId()) ? "postPay" : "afterPay");
+ orderInfo.setPackFee(packAMount);
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
} else {
orderInfo = new TbOrderInfo(orderNo, totalAmount, packAMount, totalAmount, saleAmount, totalAmount, feeAmount, "",
- "table", "cash", orderVo.getMerchantId().toString(), orderVo.getShopId().toString(),
+ orderVo.getSendType(), "cash", orderVo.getMerchantId().toString(), orderVo.getShopId().toString(),
"", (byte) 1, day, masterId);
orderInfo.setMasterId(orderVo.getMasterId());
orderInfo.setRemark(orderVo.getRemark());
@@ -826,6 +838,9 @@ public class OrderService {
for (TbOrderDetail orderDetail : orderDetails) {
orderDetail.setOrderId(orderId);
+ if (orderDetail.getPackAmount() == null) {
+ orderDetail.setPackAmount(BigDecimal.ZERO);
+ }
orderDetailMapper.insert(orderDetail);
}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java
index 1dedc66..00373d7 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java
@@ -24,6 +24,8 @@ import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.thirdpay.resp.*;
import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService;
import com.chaozhanggui.system.cashierservice.util.*;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,7 +40,6 @@ import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
-import java.util.concurrent.atomic.AtomicReference;
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.ACCOUNTEIXST;
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS;
@@ -48,43 +49,27 @@ import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS;
public class PayService {
+ private final RedisTemplate redisTemplate;
@Autowired
TbOrderInfoMapper tbOrderInfoMapper;
-
@Autowired
TbMerchantThirdApplyMapper tbMerchantThirdApplyMapper;
-
@Autowired
TbOrderPaymentMapper tbOrderPaymentMapper;
-
@Autowired
TbShopPayTypeMapper tbShopPayTypeMapper;
-
@Autowired
TbCashierCartMapper tbCashierCartMapper;
-
@Autowired
TbShopUserMapper tbShopUserMapper;
-
-
@Autowired
TbShopUserFlowMapper tbShopUserFlowMapper;
-
@Autowired
TbOrderDetailMapper tbOrderDetailMapper;
-
@Autowired
RestTemplate restTemplate;
-
-
@Autowired
RabbitProducer producer;
- @Resource
- private TbGroupOrderInfoMapper tbGroupOrderInfoMapper;
- @Resource
- private TbGroupOrderCouponMapper couponMapper;
-
-
@Autowired
TbUserInfoMapper tbUserInfoMapper;
@Autowired
@@ -93,22 +78,24 @@ public class PayService {
TbShopInfoMapper tbShopInfoMapper;
@Autowired
TbQuickPayMapper tbQuickPayMapper;
-
+ @Autowired
+ TbmerchantAccountMapper tbmerchantAccountMapper;
+ @Autowired
+ TbPlussShopStaffMapper tbPlussShopStaffMapper;
+ @Resource
+ private TbGroupOrderInfoMapper tbGroupOrderInfoMapper;
+ @Resource
+ private TbGroupOrderCouponMapper couponMapper;
@Autowired
private TbProductSkuMapper productSkuMapper;
-
@Autowired
private TbProductMapper productMapper;
-
@Autowired
private TbShopUnitMapper shopUnitMapper;
-
@Autowired
private TbProductStockDetailMapper productStockDetailMapper;
-
@Autowired
private RedisUtils redisUtil;
-
@Value("${gateway.url}")
private String gateWayUrl;
@Value("${client.backUrl}")
@@ -119,14 +106,6 @@ public class PayService {
private String url;
@Value("${thirdPay.callBack}")
private String callBack;
-
-
- @Autowired
- TbmerchantAccountMapper tbmerchantAccountMapper;
-
-
- @Autowired
- TbPlussShopStaffMapper tbPlussShopStaffMapper;
@Autowired
private MpShopUserMapper mpShopUserMapper;
@Autowired
@@ -134,12 +113,13 @@ public class PayService {
@Autowired
private MpShopTableMapper mpShopTableMapper;
- private final RedisTemplate redisTemplate;
-
public PayService(RedisTemplate redisTemplate) {
this.redisTemplate = redisTemplate;
}
+ public static void main(String[] args) {
+ System.out.println(MD5Util.encrypt("123456".concat("13718478323").concat("10")));
+ }
public Result queryPayType(String shopId) {
return Result.success(CodeEnum.SUCCESS, tbShopPayTypeMapper.selectByShopId(shopId));
@@ -303,7 +283,7 @@ public class PayService {
log.info("更新购物车:{}", cartCount);
//更新子单状态
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", token);
@@ -385,10 +365,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
log.info("更新购物车:{}", cartCount);
- if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
- }else {
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
+ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
+ } else {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
}
JSONObject jsonObject = new JSONObject();
@@ -507,10 +487,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
log.info("更新购物车:{}", cartCount);
- if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
- }else {
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
+ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
+ } else {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", token);
@@ -593,7 +573,7 @@ public class PayService {
if (ObjectUtil.isNotEmpty(memberAccount)) {
- if (!memberAccount.substring(0, 2).equals("46")) {
+ if (!memberAccount.startsWith("46")) {
return Result.fail(CodeEnum.ERRORQR);
}
@@ -645,10 +625,10 @@ public class PayService {
//更新购物车状态
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
- if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
- }else {
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
+ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
+ } else {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
}
log.info("更新购物车:{}", cartCount);
@@ -669,14 +649,13 @@ public class PayService {
producer.sendStockSaleMsg(mqData);
-
- JSONObject baObj=new JSONObject();
- baObj.put("userId",user.getUserId());
- baObj.put("shopId",user.getShopId());
- baObj.put("amount",orderInfo.getPayAmount());
- baObj.put("balance",user.getAmount());
- baObj.put("type","消费");
- baObj.put("time",flow.getCreateTime());
+ JSONObject baObj = new JSONObject();
+ baObj.put("userId", user.getUserId());
+ baObj.put("shopId", user.getShopId());
+ baObj.put("amount", orderInfo.getPayAmount());
+ baObj.put("balance", user.getAmount());
+ baObj.put("type", "消费");
+ baObj.put("time", flow.getCreateTime());
producer.balance(baObj.toString());
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
@@ -736,7 +715,7 @@ public class PayService {
}
- TbShopUser user = tbShopUserMapper.selectByShopId(orderInfo.getShopId(), tbUserInfo.getId().toString(),"2").get(0);
+ TbShopUser user = tbShopUserMapper.selectByShopId(orderInfo.getShopId(), tbUserInfo.getId().toString(), "2").get(0);
if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) {
return Result.fail(CodeEnum.MEMBERNOEXIST);
}
@@ -776,11 +755,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
-
- if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
- }else {
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
+ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
+ } else {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
}
@@ -802,14 +780,13 @@ public class PayService {
producer.sendStockSaleMsg(mqData);
-
- JSONObject baObj=new JSONObject();
- baObj.put("userId",user.getUserId());
- baObj.put("shopId",user.getShopId());
- baObj.put("amount",orderInfo.getPayAmount());
- baObj.put("balance",user.getAmount());
- baObj.put("type","消费");
- baObj.put("time",flow.getCreateTime());
+ JSONObject baObj = new JSONObject();
+ baObj.put("userId", user.getUserId());
+ baObj.put("shopId", user.getShopId());
+ baObj.put("amount", orderInfo.getPayAmount());
+ baObj.put("balance", user.getAmount());
+ baObj.put("type", "消费");
+ baObj.put("time", flow.getCreateTime());
producer.balance(baObj.toString());
clearTableInfoCache(orderInfo);
@@ -821,7 +798,7 @@ public class PayService {
return Result.fail(CodeEnum.PARAM);
}
- TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
+ TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
if (ObjectUtil.isEmpty(orderInfo)) {
return Result.fail(CodeEnum.ORDERNOEXIST);
@@ -857,8 +834,6 @@ public class PayService {
}
-
-
TbShopUserFlow userFlow = new TbShopUserFlow();
userFlow.setAmount((payAmount != null && discountAmount != null) ? payAmount : orderInfo.getOrderAmount());
userFlow.setBalance(shopUser.getAmount().subtract((payAmount != null && discountAmount != null) ? payAmount : orderInfo.getOrderAmount()));
@@ -888,10 +863,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(String.valueOf(orderId), "final");
- if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
- }else {
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
+ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
+ tbOrderDetailMapper.updateStatusByOrderId(orderId, "closed", orderInfo.getDiscountRatio());
+ } else {
+ tbOrderDetailMapper.updateStatusByOrderId(orderId, "closed", null);
}
log.info("更新购物车:{}", cartCount);
@@ -978,10 +953,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
- if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
- }else {
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
+ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
+ } else {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
}
log.info("更新购物车:{}", cartCount);
@@ -1072,10 +1047,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
log.info("更新购物车:{}", cartCount);
- if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio());
- }else {
- tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
+ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
+ } else {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
}
JSONObject jsonObject = new JSONObject();
@@ -1214,7 +1189,7 @@ public class PayService {
detailPo.setStatus("closed");
}
- BigDecimal returnAmount = it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, RoundingMode.DOWN).multiply(new BigDecimal(map1.get(it.getId())));;
+ BigDecimal returnAmount = it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, RoundingMode.DOWN).multiply(new BigDecimal(map1.get(it.getId())));
detailPo.setReturnNum(map1.get(it.getId()));
detailPos.add(detailPo);
@@ -1264,7 +1239,7 @@ public class PayService {
}
} else {
- TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId + "");
+ TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(String.valueOf(orderId));
PublicResp publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), newOrderInfo.getOrderNo(), payment.getTradeNumber(), null, "订单退款", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
@@ -1316,13 +1291,13 @@ public class PayService {
tbShopUserFlowMapper.insert(flow);
- JSONObject baObj=new JSONObject();
- baObj.put("userId",user.getUserId());
- baObj.put("shopId",user.getShopId());
- baObj.put("amount",newOrderInfo.getPayAmount());
- baObj.put("balance",user.getAmount());
- baObj.put("type","退款");
- baObj.put("time",flow.getCreateTime());
+ JSONObject baObj = new JSONObject();
+ baObj.put("userId", user.getUserId());
+ baObj.put("shopId", user.getShopId());
+ baObj.put("amount", newOrderInfo.getPayAmount());
+ baObj.put("balance", user.getAmount());
+ baObj.put("type", "退款");
+ baObj.put("time", flow.getCreateTime());
producer.balance(baObj.toString());
}
@@ -1363,13 +1338,9 @@ public class PayService {
producer.putOrderCollect(jsonObject.toJSONString());
-
producer.printMechine(newOrderInfo.getId().toString());
-
-
-
//修改耗材数据
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("orderId", newOrderInfo.getId());
@@ -1690,7 +1661,6 @@ public class PayService {
return Result.success(CodeEnum.SUCCESS);
}
-
public Result getOrderDiscount(String staffId, String orderId, String token) {
if (ObjectUtil.isNull(staffId) || ObjectUtil.isNull(orderId) || ObjectUtil.isEmpty(staffId) || ObjectUtil.isEmpty(orderId)) {
return Result.fail(CodeEnum.PARAM);
@@ -1717,7 +1687,7 @@ public class PayService {
}
if ("master".equals(staff.getType())) {
- return Result.success(SUCCESS, new BigDecimal(0.1));
+ return Result.success(SUCCESS, new BigDecimal("0.1"));
}
if (ObjectUtil.isEmpty(staff.getMaxDiscountAmount()) || ObjectUtil.isNull(staff.getMaxDiscountAmount())) {
@@ -1727,7 +1697,7 @@ public class PayService {
if ("0".equals(staff.getDiscountType())) {
if (staff.getMaxDiscountAmount().compareTo(tbOrderInfo.getOrderAmount()) >= 0) {
- staff.setMaxDiscountAmount(new BigDecimal(0.1));
+ staff.setMaxDiscountAmount(new BigDecimal("0.1"));
} else {
staff.setMaxDiscountAmount(BigDecimal.ONE.subtract(staff.getMaxDiscountAmount().divide(tbOrderInfo.getOrderAmount(), 2, RoundingMode.HALF_DOWN).setScale(2, RoundingMode.HALF_DOWN)));
}
@@ -1737,9 +1707,372 @@ public class PayService {
return Result.success(SUCCESS, staff.getMaxDiscountAmount());
}
+ public Result pcscanpay(String orderId, String ip, String userId, String payType) throws JsonProcessingException {
+ if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(ip)) {
+ return Result.fail(CodeEnum.PARAM);
+ }
+
+ TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
+
+ if (ObjectUtil.isEmpty(orderInfo)) {
+ return Result.fail(CodeEnum.ORDERNOEXIST);
+ }
+
+
+ if (!"unpaid".equals(orderInfo.getStatus()) && !"paying".equals(orderInfo.getStatus())) {
+ return Result.fail(CodeEnum.ORDERSTATUSERROR);
+ }
+
+
+ List cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, null);
+ if (ObjectUtil.isEmpty(cashierCarts) || ObjectUtil.isNull(cashierCarts)) {
+ return Result.fail(CodeEnum.CARTEXIST);
+ }
+
+ StringBuffer body = new StringBuffer();
+ for (TbCashierCart cashierCart : cashierCarts) {
+ body.append(cashierCart.getName());
+ }
+ if (ObjectUtil.isNull(orderInfo.getMerchantId()) || ObjectUtil.isEmpty(orderInfo.getMerchantId())) {
+ return Result.fail(CodeEnum.NOCUSTOMER);
+ }
+
+
+ TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
+ if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
+ return Result.fail(CodeEnum.NOCUSTOMER);
+ }
+
+
+ TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
+ if (ObjectUtil.isEmpty(payment) || payment == null) {
+ payment = new TbOrderPayment();
+ payment.setPayTypeId("ysk");
+ payment.setAmount(orderInfo.getOrderAmount());
+ payment.setPaidAmount(orderInfo.getPayAmount());
+ payment.setHasRefundAmount(BigDecimal.ZERO);
+ payment.setReceived(payment.getAmount());
+ payment.setChangeFee(BigDecimal.ZERO);
+ payment.setMemberId(orderInfo.getMemberId());
+ payment.setShopId(orderInfo.getShopId());
+ payment.setOrderId(orderInfo.getId().toString());
+ payment.setCreatedAt(System.currentTimeMillis());
+ payment.setAuthCode("");
+ tbOrderPaymentMapper.insert(payment);
+ } else {
+ payment.setAuthCode("");
+ payment.setUpdatedAt(System.currentTimeMillis());
+ tbOrderPaymentMapper.updateByPrimaryKey(payment);
+ }
+
+
+ orderInfo.setPayAmount(orderInfo.getOrderAmount());
+ orderInfo.setUpdatedAt(System.currentTimeMillis());
+ tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
+
+
+ String reqbody = "";
+
+ if (body.length() > 15) {
+ reqbody = body.substring(0, 6).concat("....").concat(body.substring(body.length() - 6, body.length()));
+ } else {
+ reqbody = body.toString();
+ }
+
+ PublicResp publicResp = thirdPayService.jspay(url, thirdApply.getAppId(), thirdApply.getAppToken(), reqbody, reqbody, orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(), payType, "WECHAT".equals(payType) ? thirdApply.getSmallAppid() : null, userId, ip, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), backUrl, backUrl);
+
+
+ if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
+ if ("000000".equals(publicResp.getCode())) {
+ JspayResp scanpayResp = publicResp.getObjData();
+ if ("TRADE_SUCCESS".equals(scanpayResp.getState())) {
+
+ payment.setTradeNumber(scanpayResp.getPayOrderId());
+ payment.setUpdatedAt(System.currentTimeMillis());
+ tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
+
+ //处理支付成功的订单
+ orderInfo.setStatus("closed");
+ orderInfo.setPayOrderNo(scanpayResp.getPayOrderId());
+ tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
+
+ //更新购物车状态
+ int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
+ log.info("更新购物车:{}", cartCount);
+
+ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
+ } else {
+ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
+ }
+
+// JSONObject jsonObject = new JSONObject();
+// jsonObject.put("token", token);
+// jsonObject.put("type", "create");
+// jsonObject.put("orderId", orderId);
+//
+// producer.putOrderCollect(jsonObject.toJSONString());
+//
+// producer.printMechine(orderId);
+
+
+ ObjectMapper mapper = new ObjectMapper();
+ return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo()));
+
+ } else if ("TRADE_AWAIT".equals(scanpayResp.getState())) {
+ orderInfo.setStatus("paying");
+ orderInfo.setPayOrderNo(payment.getTradeNumber());
+ tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
+
+ payment.setTradeNumber(scanpayResp.getPayOrderId());
+ payment.setUpdatedAt(System.currentTimeMillis());
+ tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
+
+
+ if ("WECHAT".equals(scanpayResp.getPayType())) {
+ orderInfo.setPayType("WECHAT");
+ } else if ("ALIPAY".equals(scanpayResp.getPayType())) {
+ orderInfo.setPayType("ALIPAY");
+ } else if ("UNIONPAY".equals(scanpayResp.getPayType())) {
+ orderInfo.setPayType("UNIONPAY");
+ }
+
+
+ tbOrderInfoMapper.updateByPrimaryKey(orderInfo);
+
+
+ ObjectMapper mapper = new ObjectMapper();
+ return Result.success(CodeEnum.PAYING, mapper.readTree(scanpayResp.getPayInfo()));
+ }
+ }
+ }
+
+ return Result.fail(CodeEnum.FAIL);
+
+ }
+
+ public String generateOrderNumber() {
+ String date = DateUtils.getSdfTimes();
+ Random random = new Random();
+ int randomNum = random.nextInt(900) + 100;
+ return "QR" + date + randomNum;
+ }
+
+ public Result createOrder(String ip, String userId, String payType, String shopId, BigDecimal amount) throws JsonProcessingException {
+
+ if (ObjectUtil.isNull(userId) || ObjectUtil.isEmpty(userId) || ObjectUtil.isEmpty(payType) || ObjectUtil.isNull(payType)
+
+ || ObjectUtil.isNull(shopId) || ObjectUtil.isEmpty(shopId) || ObjectUtil.isNull(shopId) || ObjectUtil.isNull(amount) || ObjectUtil.isEmpty(amount)
+ ) {
+ return Result.fail(CodeEnum.PARAM);
+ }
+
+ TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
+
+ if (ObjectUtil.isNull(shopInfo)) {
+ return Result.fail(CodeEnum.SHOPINFONOEXIST);
+ }
+
+
+ TbOrderInfo orderInfo = new TbOrderInfo();
+
+ String orderNo = generateOrderNumber();
+ orderInfo.setOrderNo(orderNo);
+ orderInfo.setSettlementAmount(amount);
+ orderInfo.setPackFee(BigDecimal.ZERO);
+ orderInfo.setOriginAmount(amount);
+ orderInfo.setPayAmount(amount);
+ orderInfo.setAmount(amount);
+ orderInfo.setRefundAmount(BigDecimal.ZERO);
+ orderInfo.setPayType(payType);
+ orderInfo.setPayAmount(amount);
+ orderInfo.setOrderAmount(amount);
+ orderInfo.setSendType("QR");
+ orderInfo.setStatus("WAIT_PAY");
+ orderInfo.setMerchantId(shopInfo.getMerchantId());
+ orderInfo.setShopId(shopId);
+ orderInfo.setRefundAble(Byte.valueOf("1"));
+ orderInfo.setSystemTime(System.currentTimeMillis());
+ orderInfo.setCreatedAt(System.currentTimeMillis());
+ orderInfo.setIsAccepted(Byte.valueOf("1"));
+ orderInfo.setTradeDay(DateUtils.getDay());
+
+ tbOrderInfoMapper.insert(orderInfo);
+
+
+ TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderInfo.getId().toString());
+ if (ObjectUtil.isEmpty(payment) || payment == null) {
+ payment = new TbOrderPayment();
+ payment.setPayTypeId("ysk");
+ payment.setAmount(orderInfo.getOrderAmount());
+ payment.setPaidAmount(orderInfo.getPayAmount());
+ payment.setHasRefundAmount(BigDecimal.ZERO);
+ payment.setReceived(payment.getAmount());
+ payment.setChangeFee(BigDecimal.ZERO);
+ payment.setMemberId(orderInfo.getMemberId());
+ payment.setShopId(orderInfo.getShopId());
+ payment.setOrderId(orderInfo.getId().toString());
+ payment.setCreatedAt(System.currentTimeMillis());
+ payment.setAuthCode("");
+ tbOrderPaymentMapper.insert(payment);
+ } else {
+ payment.setAuthCode("");
+ payment.setUpdatedAt(System.currentTimeMillis());
+ tbOrderPaymentMapper.updateByPrimaryKey(payment);
+ }
+
+
+ TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
+ if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
+ return Result.fail(CodeEnum.NOCUSTOMER);
+ }
+
+ String reqbody = "店铺收款码";
+
+ if("WECHAT".equals(payType)){
+ PublicResp publicResp = thirdPayService.jspay(url, thirdApply.getAppId(), thirdApply.getAppToken(), reqbody, reqbody, orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(), payType, "WECHAT".equals(payType) ? thirdApply.getSmallAppid() : null, userId, ip, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), backUrl, backUrl);
+
+
+ if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
+ if ("000000".equals(publicResp.getCode())) {
+ JspayResp scanpayResp = publicResp.getObjData();
+ if ("TRADE_SUCCESS".equals(scanpayResp.getState())) {
+
+ payment.setTradeNumber(scanpayResp.getPayOrderId());
+ payment.setUpdatedAt(System.currentTimeMillis());
+ tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
+
+ //处理支付成功的订单
+ orderInfo.setStatus("closed");
+ orderInfo.setPayOrderNo(scanpayResp.getPayOrderId());
+ tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
+
+
+ ObjectMapper mapper = new ObjectMapper();
+ return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo()));
+
+ } else if ("TRADE_AWAIT".equals(scanpayResp.getState())) {
+ orderInfo.setStatus("paying");
+ orderInfo.setPayOrderNo(payment.getTradeNumber());
+ tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
+
+ payment.setTradeNumber(scanpayResp.getPayOrderId());
+ payment.setUpdatedAt(System.currentTimeMillis());
+ tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
+
+
+ if ("WECHAT".equals(scanpayResp.getPayType())) {
+ orderInfo.setPayType("WECHAT");
+ } else if ("ALIPAY".equals(scanpayResp.getPayType())) {
+ orderInfo.setPayType("ALIPAY");
+ } else if ("UNIONPAY".equals(scanpayResp.getPayType())) {
+ orderInfo.setPayType("UNIONPAY");
+ }
+
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ Map map=new HashMap<>();
+
+ map.put("orderInfo",orderInfo);
+ map.put("payInfo",mapper.readTree(scanpayResp.getPayInfo()));
+ return Result.success(CodeEnum.PAYING, map);
+ }
+ }
+ }
+ }else if("ALIPAY".equals(payType)){
+ PublicResp publicResp= thirdPayService.apppay(url,thirdApply.getAppId(),thirdApply.getAppToken(),reqbody,reqbody,orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(),payType,ip,DateUtils.getSsdfTimes(),thirdApply.getStoreId(),backUrl,backUrl);
+
+ if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
+ if ("000000".equals(publicResp.getCode())) {
+ ApppayResp scanpayResp = publicResp.getObjData();
+ if ("TRADE_SUCCESS".equals(scanpayResp.getState())) {
+
+ payment.setTradeNumber(scanpayResp.getPayOrderId());
+ payment.setUpdatedAt(System.currentTimeMillis());
+ tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
+
+ //处理支付成功的订单
+ orderInfo.setStatus("closed");
+ orderInfo.setPayOrderNo(scanpayResp.getPayOrderId());
+ tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
+
+
+ ObjectMapper mapper = new ObjectMapper();
+ return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo()));
+
+ } else if ("TRADE_AWAIT".equals(scanpayResp.getState())) {
+ orderInfo.setStatus("paying");
+ orderInfo.setPayOrderNo(payment.getTradeNumber());
+ tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
+
+ payment.setTradeNumber(scanpayResp.getPayOrderId());
+ payment.setUpdatedAt(System.currentTimeMillis());
+ tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
+
+
+ if ("WECHAT".equals(scanpayResp.getPayType())) {
+ orderInfo.setPayType("WECHAT");
+ } else if ("ALIPAY".equals(scanpayResp.getPayType())) {
+ orderInfo.setPayType("ALIPAY");
+ } else if ("UNIONPAY".equals(scanpayResp.getPayType())) {
+ orderInfo.setPayType("UNIONPAY");
+ }
+
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ Map map=new HashMap<>();
+
+ map.put("orderInfo",orderInfo);
+ map.put("payInfo",mapper.readTree(scanpayResp.getPayInfo()));
+ return Result.success(CodeEnum.PAYING, map);
+ }
+ }
+ }
+ }
+
+
+ return Result.fail(CodeEnum.FAIL);
+ }
+
+ public Result queryOrderPay(String orderId) {
+ if (ObjectUtil.isEmpty(orderId)) {
+ return Result.fail(CodeEnum.PARAM);
+ }
+
+ TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
+
+ if (ObjectUtil.isEmpty(orderInfo)) {
+ return Result.fail(CodeEnum.ORDERNOEXIST);
+ }
+
+
+ if ("unpaid".equals(orderInfo.getStatus()) || "paying".equals(orderInfo.getStatus())) {
+ TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
+ if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
+ return Result.fail(CodeEnum.NOCUSTOMER);
+ }
+
+ TbOrderPayment tbOrderPayment = tbOrderPaymentMapper.selectByOrderId(orderId);
+ if (ObjectUtil.isNotEmpty(tbOrderPayment)) {
+
+ PublicResp orderstatus = thirdPayService.queryOrder(url, thirdApply.getAppId(), tbOrderPayment.getTradeNumber(), null, thirdApply.getAppToken());
+ if (ObjectUtil.isNotNull(orderstatus) && ObjectUtil.isNotEmpty(orderstatus)) {
+ if ("000000".equals(orderstatus.getCode())) {
+ if ("TRADE_SUCCESS".equals(orderstatus.getObjData().getState())) {
+ orderInfo.setStatus("closed");
+ orderInfo.setPayOrderNo(tbOrderPayment.getTradeNumber());
+ tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
+
+ }
+ }
+ }
+ }
+ }
+
+ return Result.success(CodeEnum.SUCCESS, orderInfo);
- public static void main(String[] args) {
- System.out.println(MD5Util.encrypt("123456".concat("13718478323").concat("10")));
}
}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ShopInfoService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ShopInfoService.java
index 48db52d..14e6f74 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ShopInfoService.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ShopInfoService.java
@@ -53,6 +53,10 @@ public class ShopInfoService {
this.orderInfoMapper = orderInfoMapper;
}
+ public Result queryShopInfo(Integer shopId) {
+ return new Result(CodeEnum.SUCCESS,tbShopInfoMapper.selectByPrimaryKey(shopId));
+ }
+
public Result queryShopArea(String shopId){
List list= tbShopAreaMapper.selectByShopId(shopId);
return Result.success(CodeEnum.SUCCESS,list);
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopPermissionService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopPermissionService.java
new file mode 100644
index 0000000..9fb6a38
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopPermissionService.java
@@ -0,0 +1,21 @@
+package com.chaozhanggui.system.cashierservice.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.chaozhanggui.system.cashierservice.entity.TbShopPermission;
+import com.chaozhanggui.system.cashierservice.sign.Result;
+
+/**
+ * (TbShopPermission)表服务接口
+ *
+ * @author makejava
+ * @since 2024-09-14 17:08:48
+ */
+public interface TbShopPermissionService extends IService {
+
+ /**
+ * 查询员工是否拥有某个权限
+ */
+ Result getStaffPermission(String staffId, String code);
+
+}
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopStaffPermissionService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopStaffPermissionService.java
new file mode 100644
index 0000000..e6da0ac
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopStaffPermissionService.java
@@ -0,0 +1,15 @@
+package com.chaozhanggui.system.cashierservice.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.chaozhanggui.system.cashierservice.entity.TbShopStaffPermission;
+
+/**
+ * 店铺员工权限关联表(TbShopStaffPermission)表服务接口
+ *
+ * @author makejava
+ * @since 2024-09-14 17:07:33
+ */
+public interface TbShopStaffPermissionService extends IService {
+
+}
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopPermissionServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopPermissionServiceImpl.java
new file mode 100644
index 0000000..686eac0
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopPermissionServiceImpl.java
@@ -0,0 +1,46 @@
+package com.chaozhanggui.system.cashierservice.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.chaozhanggui.system.cashierservice.dao.TbShopPermissionDao;
+import com.chaozhanggui.system.cashierservice.entity.TbShopPermission;
+import com.chaozhanggui.system.cashierservice.entity.TbShopStaffPermission;
+import com.chaozhanggui.system.cashierservice.service.TbShopPermissionService;
+import com.chaozhanggui.system.cashierservice.service.TbShopStaffPermissionService;
+import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
+import com.chaozhanggui.system.cashierservice.sign.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Service;
+
+/**
+ * (TbShopPermission)表服务实现类
+ *
+ * @author makejava
+ * @since 2024-09-14 17:08:49
+ */
+@Service
+@Primary
+public class TbShopPermissionServiceImpl extends ServiceImpl implements TbShopPermissionService {
+
+ @Autowired
+ private TbShopStaffPermissionService shopStaffPermissionService;
+
+ @Override
+ public Result getStaffPermission(String staffId, String code) {
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("code", code);
+ TbShopPermission permission = this.getOne(queryWrapper);
+ if (permission == null) {
+ return Result.fail("权限不存在");
+ }
+
+ QueryWrapper staffPermissionQueryWrapper = new QueryWrapper<>();
+ staffPermissionQueryWrapper.eq("staff_id", staffId);
+ staffPermissionQueryWrapper.eq("permission_id", permission.getId());
+ TbShopStaffPermission staffPermission = shopStaffPermissionService.getOne(staffPermissionQueryWrapper);
+
+ return Result.success(CodeEnum.SUCCESS, staffPermission != null);
+ }
+}
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopStaffPermissionServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopStaffPermissionServiceImpl.java
new file mode 100644
index 0000000..19af549
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopStaffPermissionServiceImpl.java
@@ -0,0 +1,21 @@
+package com.chaozhanggui.system.cashierservice.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.chaozhanggui.system.cashierservice.dao.TbShopStaffPermissionDao;
+import com.chaozhanggui.system.cashierservice.entity.TbShopStaffPermission;
+import com.chaozhanggui.system.cashierservice.service.TbShopStaffPermissionService;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Service;
+
+/**
+ * 店铺员工权限关联表(TbShopStaffPermission)表服务实现类
+ *
+ * @author makejava
+ * @since 2024-09-14 17:07:33
+ */
+@Service
+@Primary
+public class TbShopStaffPermissionServiceImpl extends ServiceImpl implements TbShopStaffPermissionService {
+
+}
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/ApppayReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/ApppayReq.java
new file mode 100644
index 0000000..663dca6
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/ApppayReq.java
@@ -0,0 +1,48 @@
+package com.chaozhanggui.system.cashierservice.thirdpay.req;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ApppayReq implements Serializable {
+
+
+ private String subject;
+
+ private String body;
+
+ private Long amount;
+
+ private String currency="cny";
+
+ /**
+ * 微信 WECHAT;
+ * 支付宝 ALIPAY
+ */
+ private String payType;
+
+ private String clientIp;
+
+ private String mchOrderNo;
+
+ private String storeId;
+
+ private String notifyUrl;
+
+ private String returnUrl;
+
+
+ public ApppayReq(String subject, String body, Long amount, String currency, String payType, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl) {
+ this.subject = subject;
+ this.body = body;
+ this.amount = amount;
+ this.currency = currency;
+ this.payType = payType;
+ this.clientIp = clientIp;
+ this.mchOrderNo = mchOrderNo;
+ this.storeId = storeId;
+ this.notifyUrl = notifyUrl;
+ this.returnUrl = returnUrl;
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/ChrpayReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/ChrpayReq.java
new file mode 100644
index 0000000..7eac5aa
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/ChrpayReq.java
@@ -0,0 +1,45 @@
+package com.chaozhanggui.system.cashierservice.thirdpay.req;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ChrpayReq implements Serializable {
+
+
+
+ private String subject;
+
+ private String body;
+
+ private Long amount;
+
+ private String currency="cny";
+
+ private String payType;
+
+
+ private String clientIp;
+
+ private String mchOrderNo;
+
+ private String storeId;
+
+ private String notifyUrl;
+
+ private String returnUrl;
+
+ public ChrpayReq(String subject, String body, Long amount, String currency, String payType, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl) {
+ this.subject = subject;
+ this.body = body;
+ this.amount = amount;
+ this.currency = currency;
+ this.payType = payType;
+ this.clientIp = clientIp;
+ this.mchOrderNo = mchOrderNo;
+ this.storeId = storeId;
+ this.notifyUrl = notifyUrl;
+ this.returnUrl = returnUrl;
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/H5payReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/H5payReq.java
new file mode 100644
index 0000000..3d0e7bd
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/H5payReq.java
@@ -0,0 +1,47 @@
+package com.chaozhanggui.system.cashierservice.thirdpay.req;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class H5payReq implements Serializable {
+
+ private String subject;
+
+ private String body;
+
+ private Long amount;
+
+ private String currency="cny";
+
+ /**
+ * 微信 WECHAT;
+ * 支付宝 ALIPAY
+ */
+ private String payType;
+
+ private String clientIp;
+
+ private String mchOrderNo;
+
+ private String storeId;
+
+ private String notifyUrl;
+
+ private String returnUrl;
+
+
+ public H5payReq(String subject, String body, Long amount, String currency, String payType, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl) {
+ this.subject = subject;
+ this.body = body;
+ this.amount = amount;
+ this.currency = currency;
+ this.payType = payType;
+ this.clientIp = clientIp;
+ this.mchOrderNo = mchOrderNo;
+ this.storeId = storeId;
+ this.notifyUrl = notifyUrl;
+ this.returnUrl = returnUrl;
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/JspayReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/JspayReq.java
new file mode 100644
index 0000000..fa23350
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/JspayReq.java
@@ -0,0 +1,53 @@
+package com.chaozhanggui.system.cashierservice.thirdpay.req;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class JspayReq implements Serializable {
+
+ private String subject;
+
+ private String body;
+
+ private Long amount;
+
+ private String currency="cny";
+
+ /**
+ * 微信 WECHAT;
+ * 支付宝 ALIPAY
+ */
+ private String payType;
+
+
+ private String subAppid;
+
+ private String userId;
+
+ private String clientIp;
+
+ private String mchOrderNo;
+
+ private String storeId;
+
+ private String notifyUrl;
+
+ private String returnUrl;
+
+ public JspayReq(String subject, String body, Long amount, String currency, String payType, String subAppid, String userId, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl) {
+ this.subject = subject;
+ this.body = body;
+ this.amount = amount;
+ this.currency = currency;
+ this.payType = payType;
+ this.subAppid = subAppid;
+ this.userId = userId;
+ this.clientIp = clientIp;
+ this.mchOrderNo = mchOrderNo;
+ this.storeId = storeId;
+ this.notifyUrl = notifyUrl;
+ this.returnUrl = returnUrl;
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/ScanpayReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/ScanpayReq.java
new file mode 100644
index 0000000..a2d1c4b
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/ScanpayReq.java
@@ -0,0 +1,35 @@
+package com.chaozhanggui.system.cashierservice.thirdpay.req;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ScanpayReq implements Serializable {
+
+ private String subject;
+
+ private String body;
+
+ private Long amount;
+
+ private String currency="cny";
+
+ private String clientIp;
+
+ private String mchOrderNo;
+
+ private String storeId;
+
+
+
+ public ScanpayReq(String subject, String body, Long amount, String currency, String clientIp, String mchOrderNo, String storeId) {
+ this.subject = subject;
+ this.body = body;
+ this.amount = amount;
+ this.currency = currency;
+ this.clientIp = clientIp;
+ this.mchOrderNo = mchOrderNo;
+ this.storeId = storeId;
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/ApppayResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/ApppayResp.java
new file mode 100644
index 0000000..6ce4f11
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/ApppayResp.java
@@ -0,0 +1,51 @@
+package com.chaozhanggui.system.cashierservice.thirdpay.resp;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ApppayResp implements Serializable {
+
+ private Long amount;
+
+ private String mchOrderNo;
+
+ private String payOrderId;
+
+ private String mercNo;
+
+ private String channelSendNo;
+
+ private String channelTradeNo;
+
+ private String state;
+
+ private String payType;
+
+ private String ifCode;
+
+ private String extParam;
+
+ private String payInfo;
+
+ private String liteInfo;
+
+ private String note;
+
+ private String tradeFee;
+
+ private String storeId;
+
+ private String subject;
+
+ private String drType;
+
+ private String refundAmt;
+
+ private String refundState;
+
+ private String cashFee;
+
+ private String settlementType;
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/ChrpayResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/ChrpayResp.java
new file mode 100644
index 0000000..84bdfa3
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/ChrpayResp.java
@@ -0,0 +1,51 @@
+package com.chaozhanggui.system.cashierservice.thirdpay.resp;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ChrpayResp implements Serializable {
+
+ private Long amount;
+
+ private String mchOrderNo;
+
+ private String payOrderId;
+
+ private String mercNo;
+
+ private String channelSendNo;
+
+ private String channelTradeNo;
+
+ private String state;
+
+ private String payType;
+
+ private String ifCode;
+
+ private String extParam;
+
+ private String payInfo;
+
+ private String liteInfo;
+
+ private String note;
+
+ private String tradeFee;
+
+ private String storeId;
+
+ private String subject;
+
+ private String drType;
+
+ private String refundAmt;
+
+ private String refundState;
+
+ private String cashFee;
+
+ private String settlementType;
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/H5payResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/H5payResp.java
new file mode 100644
index 0000000..b825b91
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/H5payResp.java
@@ -0,0 +1,50 @@
+package com.chaozhanggui.system.cashierservice.thirdpay.resp;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class H5payResp implements Serializable {
+
+
+ private Long amount;
+
+ private String mchOrderNo;
+
+ private String payOrderId;
+
+ private String mercNo;
+
+ private String channelSendNo;
+
+ private String channelTradeNo;
+
+ private String state;
+
+ private String payType;
+
+ private String ifCode;
+
+ private String extParam;
+
+ private String payInfo;
+
+ private String note;
+
+ private String tradeFee;
+
+ private String storeId;
+
+ private String subject;
+
+ private String drType;
+
+ private String refundAmt;
+
+ private String refundState;
+
+ private String cashFee;
+
+ private String settlementType;
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/JspayResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/JspayResp.java
new file mode 100644
index 0000000..1627d68
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/JspayResp.java
@@ -0,0 +1,50 @@
+package com.chaozhanggui.system.cashierservice.thirdpay.resp;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class JspayResp implements Serializable {
+
+
+ private Long amount;
+
+ private String mchOrderNo;
+
+ private String payOrderId;
+
+ private String mercNo;
+
+ private String channelSendNo;
+
+ private String channelTradeNo;
+
+ private String state;
+
+ private String payType;
+
+ private String ifCode;
+
+ private String extParam;
+
+ private String payInfo;
+
+ private String note;
+
+ private String tradeFee;
+
+ private String storeId;
+
+ private String subject;
+
+ private String drType;
+
+ private String refundAmt;
+
+ private String refundState;
+
+ private String cashFee;
+
+ private String settlementType;
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/ScanpayResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/ScanpayResp.java
new file mode 100644
index 0000000..a7aac73
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/ScanpayResp.java
@@ -0,0 +1,49 @@
+package com.chaozhanggui.system.cashierservice.thirdpay.resp;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ScanpayResp implements Serializable {
+
+ private Long amount;
+
+ private String mchOrderNo;
+
+ private String payOrderId;
+
+ private String mercNo;
+
+ private String channelSendNo;
+
+ private String channelTradeNo;
+
+ private String state;
+
+ private String payType;
+
+ private String ifCode;
+
+ private String extParam;
+
+ private String payInfo;
+
+ private String note;
+
+ private String tradeFee;
+
+ private String storeId;
+
+ private String subject;
+
+ private String drType;
+
+ private String refundAmt;
+
+ private String refundState;
+
+ private String cashFee;
+
+ private String settlementType;
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java
index d65d07e..e588ff6 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java
@@ -29,6 +29,15 @@ public class ThirdPayService {
private static String refund="/api/open/order/refund";
+ private static String scanpay="/api/open/payment/scanpay";
+
+ private static String h5pay="/api/open/payment/h5pay";
+
+ private static String jspay="/api/open/payment/jspay";
+
+ private static String apppay="/api/open/payment/apppay";
+
+ private static String chrpay="/api/open/payment/chrpay";
/**
* 被扫接口
* @param url
@@ -47,14 +56,14 @@ public class ThirdPayService {
public PublicResp mainScan(String url,String appId, String subject, String body, Long amount, String subAppId, String authCode, String orderNo, String storeId, String notifyUrl,
String key
) {
- MainScanReq mainScanReq=null;
- if("66bab943ae82f63b50ae3cff".equals(appId)){
-
- mainScanReq = new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl,1,"TA1824003985261588482",null);
- url="https://paymentweb.sxczgkj.cn";
- }else {
- mainScanReq = new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl,0,null,null);
- }
+ MainScanReq mainScanReq= new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl,0,null,null);;
+// if("66bab943ae82f63b50ae3cff".equals(appId)){
+//
+// mainScanReq = new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl,1,"TA1824003985261588482",null);
+// url="https://paymentweb.sxczgkj.cn";
+// }else {
+// mainScanReq = new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl,0,null,null);
+// }
@@ -108,13 +117,13 @@ public class ThirdPayService {
String clinetIp,String orderNo, String storeId, String notifyUrl,String returnUrl,
String key){
- WxScanPayReq scanPayReq=null;
- if("66bab943ae82f63b50ae3cff".equals(appId)){
- scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,1,null,"TA1824003985261588482",notifyUrl,returnUrl);
- url="https://paymentweb.sxczgkj.cn";
- }else {
- scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,0,null,null,notifyUrl,returnUrl);
- }
+ WxScanPayReq scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,0,null,null,notifyUrl,returnUrl);
+// if("66bab943ae82f63b50ae3cff".equals(appId)){
+// scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,1,null,"TA1824003985261588482",notifyUrl,returnUrl);
+// url="https://paymentweb.sxczgkj.cn";
+// }else {
+// scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,0,null,null,notifyUrl,returnUrl);
+// }
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(),null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis()));
@@ -247,6 +256,218 @@ public class ThirdPayService {
}
+ /**
+ * Pc 扫码支付
+ * @param url
+ * @param appId
+ * @param key
+ * @param subject
+ * @param body
+ * @param amount
+ * @param clientIp
+ * @param mchOrderNo
+ * @param storeId
+ * @param notifyUrl
+ * @param returnUrl
+ * @return
+ */
+ public PublicResp pcscanpay(String url,String appId,String key,String subject, String body, Long amount, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl ){
+ ScanpayReq scanpayReq=new ScanpayReq(subject, body, amount, "cny", clientIp, mchOrderNo, storeId);
+ PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(),"1.0",String.valueOf(System.currentTimeMillis()));
+ try {
+ String str=JSONUtil.toJSONString(sortFields(scanpayReq));
+ param.setBizData(str);
+ String tt = sortFieldsAndPrint(param);
+ String MD5 = tt.concat("appSecret=" + key);
+ log.info("加签原传:{}", MD5);
+ String sign = MD5Util.encrypt(MD5);
+ param.setSign(sign);
+ String reqbody = JSONUtil.toJSONString(param);
+ log.info("请求参数:{}", reqbody);
+ String response = HttpRequest.post(url.concat(scanpay)).body(reqbody).execute().body();
+ log.info("返回结果:{}", response);
+ PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
+ resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),ScanpayResp.class));
+ return resp;
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ /**
+ * 手机网页支付
+ * @param url
+ * @param appId
+ * @param key
+ * @param subject
+ * @param body
+ * @param amount
+ * @param payType
+ * @param clientIp
+ * @param mchOrderNo
+ * @param storeId
+ * @param notifyUrl
+ * @param returnUrl
+ * @return
+ */
+ public PublicResp h5Pay(String url,String appId,String key,String subject, String body, Long amount, String payType, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl){
+ H5payReq h5payReq=new H5payReq(subject, body, amount, "cny", payType, clientIp, mchOrderNo, storeId, notifyUrl, returnUrl);
+
+ PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(),"1.0",String.valueOf(System.currentTimeMillis()));
+ try {
+ String str=JSONUtil.toJSONString(sortFields(h5payReq));
+ param.setBizData(str);
+ String tt = sortFieldsAndPrint(param);
+ String MD5 = tt.concat("appSecret=" + key);
+ log.info("加签原传:{}", MD5);
+ String sign = MD5Util.encrypt(MD5);
+ param.setSign(sign);
+ String reqbody = JSONUtil.toJSONString(param);
+ log.info("请求参数:{}", reqbody);
+ String response = HttpRequest.post(url.concat(h5pay)).body(reqbody).execute().body();
+ log.info("返回结果:{}", response);
+ PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
+ resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),H5payResp.class));
+ return resp;
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ /**
+ * 公众号/生活号/银联js支付
+ * @param url
+ * @param appId
+ * @param key
+ * @param subject
+ * @param body
+ * @param amount
+ * @param payType
+ * @param subAppid
+ * @param userId
+ * @param clientIp
+ * @param mchOrderNo
+ * @param storeId
+ * @param notifyUrl
+ * @param returnUrl
+ * @return
+ */
+ public PublicResp jspay(String url,String appId,String key,String subject, String body, Long amount, String payType, String subAppid, String userId, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl){
+ JspayReq jspayReq=new JspayReq(subject, body, amount, "cny", payType, subAppid, userId, clientIp, mchOrderNo, storeId, notifyUrl, returnUrl);
+
+ PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(),"1.0",String.valueOf(System.currentTimeMillis()));
+ try {
+ String str=JSONUtil.toJSONString(sortFields(jspayReq));
+ param.setBizData(str);
+ String tt = sortFieldsAndPrint(param);
+ String MD5 = tt.concat("appSecret=" + key);
+ log.info("加签原传:{}", MD5);
+ String sign = MD5Util.encrypt(MD5);
+ param.setSign(sign);
+ String reqbody = JSONUtil.toJSONString(param);
+ log.info("请求参数:{}", reqbody);
+ String response = HttpRequest.post(url.concat(jspay)).body(reqbody).execute().body();
+ log.info("返回结果:{}", response);
+ PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
+ resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),JspayResp.class));
+ return resp;
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ /***
+ * app 支付
+ * @param url
+ * @param appId
+ * @param key
+ * @param subject
+ * @param body
+ * @param amount
+ * @param payType
+ * @param clientIp
+ * @param mchOrderNo
+ * @param storeId
+ * @param notifyUrl
+ * @param returnUrl
+ * @return
+ */
+
+ public PublicResp apppay(String url,String appId,String key,String subject, String body, Long amount, String payType, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl){
+ ApppayReq apppayReq=new ApppayReq(subject, body, amount, "cny", payType, clientIp, mchOrderNo, storeId, notifyUrl, returnUrl);
+
+
+ PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(),"1.0",String.valueOf(System.currentTimeMillis()));
+ try {
+ String str=JSONUtil.toJSONString(sortFields(apppayReq));
+ param.setBizData(str);
+ String tt = sortFieldsAndPrint(param);
+ String MD5 = tt.concat("appSecret=" + key);
+ log.info("加签原传:{}", MD5);
+ String sign = MD5Util.encrypt(MD5);
+ param.setSign(sign);
+ String reqbody = JSONUtil.toJSONString(param);
+ log.info("请求参数:{}", reqbody);
+ String response = HttpRequest.post(url.concat(apppay)).body(reqbody).execute().body();
+ log.info("返回结果:{}", response);
+ PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
+ resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),ApppayResp.class));
+ return resp;
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ /**
+ * 聚合收银台
+ * @param url
+ * @param appId
+ * @param key
+ * @param subject
+ * @param body
+ * @param amount
+ * @param clientIp
+ * @param mchOrderNo
+ * @param storeId
+ * @param notifyUrl
+ * @param returnUrl
+ * @return
+ */
+ public PublicResp chrpay(String url,String appId,String key,String subject, String body, Long amount, String payType, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl){
+ ChrpayReq chrpayReq=new ChrpayReq(subject, body, amount, "cny",payType,clientIp, mchOrderNo, storeId, notifyUrl, returnUrl);
+
+
+ PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(),"1.0",String.valueOf(System.currentTimeMillis()));
+ try {
+ String str=JSONUtil.toJSONString(sortFields(chrpayReq));
+ param.setBizData(str);
+ String tt = sortFieldsAndPrint(param);
+ String MD5 = tt.concat("appSecret=" + key);
+ log.info("加签原传:{}", MD5);
+ String sign = MD5Util.encrypt(MD5);
+ param.setSign(sign);
+ String reqbody = JSONUtil.toJSONString(param);
+ log.info("请求参数:{}", reqbody);
+ String response = HttpRequest.post(url.concat(chrpay)).body(reqbody).execute().body();
+ log.info("返回结果:{}", response);
+ PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
+ resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),ChrpayResp.class));
+ return resp;
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+
+
+
+
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/Utils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/Utils.java
new file mode 100644
index 0000000..c15a1d7
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/Utils.java
@@ -0,0 +1,131 @@
+package com.chaozhanggui.system.cashierservice.util;
+
+import cn.hutool.core.lang.func.Func0;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.chaozhanggui.system.cashierservice.exception.MsgException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.data.redis.core.StringRedisTemplate;
+
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+public class Utils {
+ public static int retryCount = 5;
+ private static final Logger log = LoggerFactory.getLogger(Utils.class);
+
+ public static void catchErrNoReturn(Supplier supplier) {
+ try {
+ supplier.get();
+ }catch (Exception e) {
+ log.error("执行方法出现异常", e);
+ }
+ }
+
+ public static void runFunAndRetryNoReturn(
+ Supplier function,
+ Function check, Consumer errFun) {
+ log.info("工具类开始执行函数");
+ R result = function.get();
+ boolean flag = check.apply(result);
+
+ log.info("执行结果: {}", result);
+
+ while (flag && retryCount-- > 0) {
+ log.info("执行函数失败, 剩余尝试次数{}", retryCount);
+ result = function.get();
+ log.info("执行结果: {}", result);
+ flag = check.apply(result);
+ }
+
+ if (flag) {
+ errFun.accept(result);
+ }
+ }
+
+ public static T runFunAndCheckKey(Supplier supplier, StringRedisTemplate redisTemplate, String lockKey) {
+ try{
+ // 创建线程id, 用作判断
+ String clientId = UUID.randomUUID().toString();
+ // 设置分布式锁
+ boolean lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.MILLISECONDS));
+ int count = 0;
+ while (!lock) {
+ if (count++ > 100) {
+ throw new MsgException("系统繁忙, 稍后再试");
+ }
+ Thread.sleep(20);
+ lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.MILLISECONDS));
+ }
+ return supplier.get();
+ } catch (RuntimeException e){
+ log.info("执行出错:{}", e.getMessage());
+ throw e;
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ } finally{
+ redisTemplate.delete(lockKey);
+ }
+ }
+
+ public static R runFunAndRetry(
+ Supplier function,
+ Function check, Consumer errFun) {
+ log.info("工具类开始执行函数");
+ R result = function.get();
+ boolean flag = check.apply(result);
+
+ log.info("执行结果: {}", result);
+
+ while (flag && retryCount-- > 0) {
+ log.info("执行函数失败, 剩余尝试次数{}", retryCount);
+ result = function.get();
+ log.info("执行结果: {}", result);
+ flag = check.apply(result);
+ }
+
+ if (flag) {
+ errFun.accept(result);
+ }
+ return result;
+ }
+
+ public static T checkValue(T data, String msg, Func0... errFunc) {
+ if (ObjectUtil.isEmpty(data)) {
+ for (Func0 tFunc0 : errFunc) {
+ try {
+ return tFunc0.call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ throw new MsgException(msg);
+ }
+ return data;
+ }
+
+ public static void checkValueUnReturn(Object data, String msg, Func0>... errFunc) {
+ if(data == null) {
+ throw new MsgException(msg);
+ }
+
+ if (data instanceof String && StrUtil.isBlank((String)data)) {
+ throw new MsgException(msg);
+ }
+ if (ObjectUtil.isEmpty(data)) {
+ for (Func0> tFunc0 : errFunc) {
+ try {
+ tFunc0.call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ throw new MsgException(msg);
+ }
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/WechatUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/WechatUtil.java
index e778af7..6bb4a48 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/util/WechatUtil.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/WechatUtil.java
@@ -101,4 +101,23 @@ public class WechatUtil {
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
}
+
+
+ public static JSONObject getSessionKeyOrOpenId(String code, String appId, String secrete) {
+ String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?";
+ Map requestUrlParam = new HashMap<>();
+ // https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN
+ //小程序appId
+ requestUrlParam.put("appid", appId);
+ //小程序secret
+ requestUrlParam.put("secret", secrete);
+ //小程序端返回的code
+ requestUrlParam.put("code", code);
+ //默认参数
+ requestUrlParam.put("grant_type", "authorization_code");
+ //发送post请求读取调用微信接口获取openid用户唯一标识
+ log.info("请求参数:{}",JSONUtil.toJSONString(requestUrlParam));
+ JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doPost(requestUrl,requestUrlParam));
+ return jsonObject;
+ }
}
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
index ba41bd9..e5b3d3e 100644
--- a/src/main/resources/application-dev.yml
+++ b/src/main/resources/application-dev.yml
@@ -4,10 +4,10 @@ spring:
application:
name: cashierService
datasource:
- url: jdbc:mysql://rm-bp1kn7h89nz62cno1ro.mysql.rds.aliyuncs.com:3306/fycashier_test?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true
+ url: jdbc:p6spy:mysql://rm-bp1kn7h89nz62cno1ro.mysql.rds.aliyuncs.com:3306/fycashier_test?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true
username: cashier
password: Cashier@1@
- driver-class-name: com.mysql.cj.jdbc.Driver
+ driver-class-name: com.p6spy.engine.spy.P6SpyDriver
initialSize: 5
minIdle: 5
maxActive: 20
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 7c61761..f2b9a7b 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -60,6 +60,10 @@ wx:
appId: wxd88fffa983758a30
secrete: a34a61adc0602118b49400baa8812454
warnMsgTmpId: AV-KybUHaK3KtFVLqpy6PHccHBS7XeX__mOM4RbufnQ
+ali:
+ appId: 2021004174605036
+ privateKey: MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQD48HaUoV7OH7os+9L01kHgxzwIhJick4OkFq4aHsntsXEJJ3gedhuEZtV8oHKZ30DPW12IJ4S8NXtpr8OWaqrAPFonf4wVaRY1d0yIAea57kfLEn9oOEEy4FzARgMNDkyxC+/3OUdGbLHpTjfVX3gusXsEhUDy1/WewihAkoNYF37+W3W/uVLzeWoPq0EcUbRv/G/t/p6gL69ltsMAiVFG4Q/Yk24YAN6lYgBPNLXUEwQ1Q+T+1omjfavHgvarKOp33z3JOUH+aGOmDsJ5Y9gyGtJzOCipAd8Zcv+T1ygsEzZYO1/gzcbPnfO1ShqStCHzssuw8FBVx2JdfQKXKMMNAgMBAAECggEAVTrO/pg5Q00titU1Jspsh67u6OOs9H605Ws2dI7yB8VmtAGlaJh7V1t14FN2qSP8poHbhhAxq9aLyGV7C3a9u09udnN+3J28EtYjh7VO732bavWMVXxdJjQWzWWrCb9JlpxFrlkYBA6W4w/6ob0sAqCVQ7jzwbEa0R4cde8ztOa5nysKSfr4YTSs0gqvoiC6fmg8eiRJraEQBoYz9VkKFtOhhh/4w5FhVcYQ2gQvZ3kK3QVuD1eJIQKlCtz8qaox9lXKDiZT4SCmnKshdUL0u5TYIcYeBjZmhJz0Q50KHcpZrCs5y7I0+vRBH3hU+TKSQt7ureymwhbwWMHScLV2gQKBgQD+58SHXhr5M8NGagAmTdsgmCnNv2kOYMd4STyPMY10SVwCv1Bk808ZuP+7e558J1b5/OuDLI5dLq6xrZ/1wLv1G++XqxI00hlFuWS5mUGJVcXotT1mw20rVeUILc7Qe3mLvbMGgfyKf4A7Qa5SSZ4bDeDTJYaFxyiQ281hMzDuPQKBgQD6AiL/Na2/uPH4CG6juwpjYvYVUcjK+7gbRwf3wWsWMpk90Z4ju2iUiP5c1J/oK9P+1T3PIr6M4Xjza8JJj+r9KC/PVB0gBv6vVM96cDpKUEy/UMpcn/T81vqj/Z+WEOODU8Ms6NiTTm+u9ldvpCjbu0u8M+9c0JeIyadJvSTFEQKBgQCsxmFyM3nq8YfpgU2qqNjfBeRH3faSVUy+nj1a/YZYjKS+A/i1BCnYUImeBVNN6chNV342ggvY4xxruDiU9Vcw8wd58O09Oi8BEIFSP6upL6cebUI6Fjo3xlegLJRiwV6INkNTJOYM5hD/mSxUACwXQFfkJipBINXBIgraWD1RLQKBgQCj49axWq0F6+WjZVOyPaD3uh37p9trRUxRhWTxw3fB23WdktaKMgbCqHOmwzP4bRLSEVQtf2dOz1gMqu14b8HqJvgAf/F/11YJ9hz09LEhmjZVjE68HZfqT7uK2W5OX8/lfXmK7TFcj6SjG5YB96lZMhTZ0WnufEd6QkdKDZYXIQKBgQD9GDTcIMbFwbEaKHnfZaTD3f876EGRgsgrCxwdEk7LBCRPwWo7yI929M4psIlpNwNeiyjBkBunWIVkpznp6qPtJqagIPUYesU4f5v6/okq5wcpaNKSkWbIvWVLaLGOiA1aeGJtbpMpyClbSr52puHpRRdvAiIEQ74yYh0JX8q96g==
+ publicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiQkrz+emAuS1mB3KKDOMmAZRd/BlPbh7fAIHAqAj1+QCZNcV3o2BTLIIqnuKpSlFXDG3uDzp2VsBxcizXuBbFyPGylnD9CgCj5abyh3+FIHPAZ2IM3TtpqImZ0TSPGXrMli4Nir7MvZktgccCqQKCC4o6iaDGz+UwWwJUIPna8fm2tiTZ+KH150CZbKVj4ZGNpBh5XSV/1dRgyQIV9D/EwSbkZ0n6VgKQLJBi0C2UE3QB17aL1Ir6+gDXIDbknN8O7GUD3aMGdThYdSRUb5wp9CZ5qfV7vCS/CgaRo38nhH3NOzkTL+7v0m1ZDHPmqEkn9VzZN6sCQdL7PoAOjHOCwIDAQAB
mybatis-plus:
diff --git a/src/main/resources/mapper/TbShopInfoMapper.xml b/src/main/resources/mapper/TbShopInfoMapper.xml
index 47ed043..e9f9f2b 100644
--- a/src/main/resources/mapper/TbShopInfoMapper.xml
+++ b/src/main/resources/mapper/TbShopInfoMapper.xml
@@ -51,6 +51,11 @@
+
+
+
+
+
@@ -61,7 +66,8 @@
detail, lat, lng, mch_id, register_type, is_wx_ma_independent, address, city, type,
industry, industry_name, business_time, post_time, post_amount_line, on_sale, settle_type,
settle_time, enter_at, expire_at, status, average, order_wait_pay_minute, support_device_number,
- distribute_level, created_at, updated_at, proxy_id,is_custom,is_return,is_member_in,is_member_return
+ distribute_level, created_at, updated_at, proxy_id,is_custom,is_return,is_member_in,is_member_return,
+ is_table_fee,table_fee,eat_model,small_qrcode,payment_qrcode
view
diff --git a/src/main/resources/spy.properties b/src/main/resources/spy.properties
new file mode 100644
index 0000000..2d47097
--- /dev/null
+++ b/src/main/resources/spy.properties
@@ -0,0 +1,32 @@
+#??????????
+modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
+#??????????
+logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
+#?????? ????
+#appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
+#??????? SLF4J ????
+#appender=com.p6spy.engine.spy.appender.Slf4JLogger
+#??????? file??
+appender=com.p6spy.engine.spy.appender.FileLogger
+#??????????
+logfile=sql.log
+#???? JDBC ???????????
+#deregisterdrivers=true
+#??????????????
+useprefix=true
+#?????????????????????
+excludecategories=info,debug,result,commit,resultset
+#?????????????
+dateformat=yyyy-MM-dd HH:mm:ss
+#??????????????
+databaseDialectTimestampFormat=yyyy-MM-dd HH:mm:ss
+#?? JDBC ??????
+#driverlist=org.h2.Driver
+#??????
+outagedetection=true
+#??????????????????
+outagedetectioninterval=2
+#?? SQL ????
+filter=true
+#?????? "SELECT 1" ? SQL ??
+exclude=SELECT 1
diff --git a/src/test/java/com/chaozhanggui/system/cashierservice/StaffPermissionTest.java b/src/test/java/com/chaozhanggui/system/cashierservice/StaffPermissionTest.java
new file mode 100644
index 0000000..302aed4
--- /dev/null
+++ b/src/test/java/com/chaozhanggui/system/cashierservice/StaffPermissionTest.java
@@ -0,0 +1,22 @@
+package com.chaozhanggui.system.cashierservice;
+
+import com.chaozhanggui.system.cashierservice.service.TbShopPermissionService;
+import com.chaozhanggui.system.cashierservice.sign.Result;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+
+@ActiveProfiles("dev")
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class StaffPermissionTest {
+ @Autowired
+ private TbShopPermissionService tbShopPermissionService;
+ @Test
+ public void testStaffPermission() {
+
+ Result yunXuTuiKuan = tbShopPermissionService.getStaffPermission("128", "yun_xu_tui_kuan2");
+ System.out.println(yunXuTuiKuan);
+
+ }
+}
diff --git a/src/test/java/com/chaozhanggui/system/cashierservice/Tets.java b/src/test/java/com/chaozhanggui/system/cashierservice/Tets.java
new file mode 100644
index 0000000..002d451
--- /dev/null
+++ b/src/test/java/com/chaozhanggui/system/cashierservice/Tets.java
@@ -0,0 +1,43 @@
+package com.chaozhanggui.system.cashierservice;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.chaozhanggui.system.cashierservice.rabbit.PrintConsumer;
+import com.chaozhanggui.system.cashierservice.rabbit.PrintMechineConsumer;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+@ActiveProfiles("dev")
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class Tets {
+ @Autowired
+ private PrintMechineConsumer printMechineConsumer;
+ @Autowired
+ private PrintConsumer printConsumer;
+
+ @Test
+ public void test() {
+// printMechineConsumer.listener("4537");
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("orderId", 4557);
+ jsonObject.put("orderDetailIds", new Integer[]{10454, 10455});
+ jsonObject.put("isReturn", false);
+// printConsumer.printDishesListener(jsonObject);
+ }
+
+ public static void main(String[] args) {
+
+ }
+}