This commit is contained in:
韩鹏辉
2024-03-21 10:22:29 +08:00
parent 1c47f567d8
commit b77eacdccb
270 changed files with 32916 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
//package com.chaozhanggui.system.cashierservice.controller;
//
//import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
//import com.chaozhanggui.system.cashierservice.entity.dto.ProductCartDto;
//import com.chaozhanggui.system.cashierservice.service.CashierCartService;
//import com.chaozhanggui.system.cashierservice.sign.Result;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import java.util.List;
//
///**
// * @author lyf
// */
//@CrossOrigin(origins = "*")
//@RestController
//@Slf4j
//@RequestMapping("/cart")
//public class CashierCartController {
//
// @Resource
// private CashierCartService cashierCartService;
// /**
// * 添加购物车
// * @param productCartDto
// * @return
// */
// @PostMapping("/add")
// public Result batchAdd(@RequestBody ProductCartDto productCartDto) {
// return cashierCartService.batchAdd(productCartDto);
// }
//
// /**
// * 购物车
// * @param tableId
// * @return
// */
// @GetMapping("/cartList")
// public Result cartList(@RequestParam Integer tableId){
// return cashierCartService.cartList(tableId);
// }
//
// /**
// *更改数量
// * @param
// * @return
// */
// @GetMapping("/updateNumber")
// public Result updateNumber(@RequestParam Integer id ,@RequestParam String type){
// return cashierCartService.updateNumber(id,type);
// }
//
//
// /**
// *清空购物车
// * @param
// * @return
// */
// @GetMapping("/clear")
// public Result clearCart(@RequestParam Integer tableId){
// return cashierCartService.clearCart(tableId);
// }
//}

View File

@@ -0,0 +1,35 @@
package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.service.CloudPrinterService;
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.*;
@CrossOrigin(origins = "*")
@RestController
@Slf4j
@RequestMapping("cloudPrinter")
public class CloudPrinterController {
@Autowired
CloudPrinterService cloudPrinterService;
/**
* 一单一旦
* @param type
* @param orderId
* @return
*/
@GetMapping("print")
public Result print(
@RequestParam("type") String type,
@RequestParam("orderId") String orderId,
@RequestParam("ispre") Boolean ispre
){
return cloudPrinterService.printReceipt(type,orderId,ispre);
}
}

View File

@@ -0,0 +1,229 @@
package com.chaozhanggui.system.cashierservice.controller;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.TbMerchantAccountMapper;
import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount;
import com.chaozhanggui.system.cashierservice.entity.dto.AuthUserDto;
import com.chaozhanggui.system.cashierservice.entity.dto.OnlineUserDto;
import com.chaozhanggui.system.cashierservice.service.LoginService;
import com.chaozhanggui.system.cashierservice.service.OnlineUserService;
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.MD5Utils;
import com.chaozhanggui.system.cashierservice.util.StringUtil;
import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
@CrossOrigin(origins = "*")
@RestController
@Slf4j
@RequestMapping("login")
public class LoginContoller {
@Value("${wx.login.business.appId}")
private String businessAppId;
@Value("${wx.login.business.secrete}")
private String businessSecrete;
@Value("${wx.login.custom.appId}")
private String customAppId;
@Value("${wx.login.custom.secrete}")
private String customSecrete;
@Autowired
LoginService loginService;
@Resource
TbMerchantAccountMapper merchantAccountMapper;
@RequestMapping("/wx/business/login")
public Result wxBusinessLogin(@RequestParam(value = "code", required = false) String code,
@RequestParam(value = "rawData", required = false) String rawData,
@RequestParam(value = "signature", required = false) String signature
) {
// 用户非敏感信息rawData
// 签名signature
JSONObject rawDataJson = JSON.parseObject(rawData);
// 1.接收小程序发送的code
// 2.开发者服务器 登录凭证校验接口 appi + appsecret + code
JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(code, businessAppId, businessSecrete);
// 3.接收微信接口服务 获取返回的参数
String openid = SessionKeyOpenId.getString("openid");
String sessionKey = SessionKeyOpenId.getString("session_key");
// 4.校验签名 小程序发送的签名signature与服务器端生成的签名signature2 = sha1(rawData + sessionKey)
String signature2 = DigestUtils.sha1Hex(rawData + sessionKey);
if (!signature.equals(signature2)) {
return Result.fail("签名校验失败");
}
return Result.success(CodeEnum.ENCRYPT);
}
@RequestMapping("/wx/custom/login")
public Result wxCustomLogin(HttpServletRequest request, @RequestBody Map<String, String> map
// ,
// @RequestParam(value = "rawData", required = false) String rawData,
// @RequestParam(value = "signature", required = false) String signature
) {
if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map)||!map.containsKey("code")||ObjectUtil.isEmpty(map.get("code"))) {
Result.fail("code不能为空");
}
String code=map.get("code").toString();
String qrCode=map.get("qrCode");
String rawData=map.get("rawData");
String signature=map.get("signature");
String encryptedData=map.get("encryptedData");
String ivStr=map.get("iv");
String phone=map.get("phone");
// 用户非敏感信息rawData
// 签名signature
JSONObject rawDataJson = JSON.parseObject(rawData);
// 1.接收小程序发送的code
// 2.开发者服务器 登录凭证校验接口 appi + appsecret + code
JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(code, customAppId, customSecrete);
// 3.接收微信接口服务 获取返回的参数
String openid = SessionKeyOpenId.getString("openid");
String sessionKey = SessionKeyOpenId.getString("session_key");
// 4.校验签名 小程序发送的签名signature与服务器端生成的签名signature2 = sha1(rawData + sessionKey)
String signature2 = DigestUtils.sha1Hex(rawData + sessionKey);
if (!signature.equals(signature2)) {
return Result.fail("签名校验失败");
}
String nickName = rawDataJson.getString( "nickName");
String avatarUrl = rawDataJson.getString( "avatarUrl");
try {
return loginService.wxCustomLogin(openid, avatarUrl, nickName, phone,qrCode, IpUtil.getIpAddr(request));
} catch (Exception e) {
e.printStackTrace();
}
return Result.fail("登录失败");
}
@RequestMapping("getPhoneNumber")
public Result getPhoneNumber(@RequestBody Map<String,String> map){
if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map)||!map.containsKey("code")||ObjectUtil.isEmpty(map.get("code"))) {
Result.fail("code不能为空");
}
String code=map.get("code").toString();
String encryptedData=map.get("encryptedData");
String ivStr=map.get("iv");
JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(code, customAppId, customSecrete);
// 3.接收微信接口服务 获取返回的参数
String openid = SessionKeyOpenId.getString("openid");
String sessionKey = SessionKeyOpenId.getString("session_key");
String data= WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr);
if(ObjectUtil.isNotEmpty(data)&&JSONObject.parseObject(data).containsKey("phoneNumber")){
return Result.success(CodeEnum.SUCCESS, JSONObject.parseObject(data).get("phoneNumber"));
}
return Result.fail("获取手机号失败");
}
@Resource
private OnlineUserService onlineUserService;
@PostMapping("/wx/merchant/login")
public Result wxCustomLogin(@RequestBody AuthUserDto authUserDto) {
//验证密码
String mdPasswordString = MD5Utils.MD5Encode(authUserDto.getPassword(), "utf-8");
//
TbMerchantAccount merchantAccount = merchantAccountMapper.selectByAccount(authUserDto.getUsername());
if (merchantAccount == null) {
return Result.fail("无此用户");
}
if (!mdPasswordString.equalsIgnoreCase(merchantAccount.getPassword())) {
return Result.fail("密码错误");
}
//生成token
String token = StringUtil.genRandomNum(6) + StringUtil.getBillno() + StringUtil.genRandomNum(6);
//存入redis
OnlineUserDto jwtUserDto = onlineUserService.save(merchantAccount.getName(), merchantAccount.getAccount(), Integer.valueOf(merchantAccount.getShopId()), token,merchantAccount.getStatus());
//组装登录数据
Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
put("token", token);
put("user", jwtUserDto);
}};
return Result.success(CodeEnum.ENCRYPT,authInfo);
}
/**
* 获取会员码
* @param openId
* @param token
* @param id
* @return
*/
@RequestMapping("createCardNo")
public Result createCardNo(@RequestHeader("openId") String openId,@RequestHeader("token") String token,@RequestHeader("id") String id){
return loginService.createCardNo(id,openId);
}
@GetMapping("/wx/userInfo")
public Result userInfo(@RequestParam("userId") Integer userId,@RequestParam("shopId") String shopId ){
return loginService.userInfo(userId,shopId);
}
}

View File

@@ -0,0 +1,74 @@
package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.chaozhanggui.system.cashierservice.interceptor.RequestWrapper;
import com.chaozhanggui.system.cashierservice.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@CrossOrigin(origins = "*")
@RestController
@Slf4j
@RequestMapping("notify")
public class NotifyController {
@Autowired
PayService payService;
@RequestMapping("memberInCallBack")
public String memberInCallBack(HttpServletRequest request){
Map<String, Object> map= getParameterMap(request);
log.info("回调返回信息:{}",JSONUtil.toJsonStr(map));
if(ObjectUtil.isNotEmpty(map)&&map.containsKey("code")&&"200".equals(map.get("code")+"")){
JSONObject object=JSONUtil.parseObj(map.get("data"));
if(ObjectUtil.isNotEmpty(object)&&object.containsKey("status")&&"1".equals(object.getStr("status"))){
String orderNo=object.getStr("orderNumber");
String channelTradeNo=object.getStr("channelTradeNo");
return payService.minsuccess(orderNo,channelTradeNo);
}
}
return null;
}
@RequestMapping("notifyCallBack")
public String notifyCallBack(HttpServletRequest request){
Map<String, Object> map= getParameterMap(request);
log.info("回调返回信息:{}",JSONUtil.toJsonStr(map));
if(ObjectUtil.isNotEmpty(map)&&map.containsKey("code")&&"200".equals(map.get("code")+"")){
JSONObject object=JSONUtil.parseObj(map.get("data"));
if(ObjectUtil.isNotEmpty(object)&&object.containsKey("status")&&"1".equals(object.getStr("status"))){
String orderNo=object.getStr("orderNumber");
return payService.callBackPay(orderNo);
}
}
return null;
}
private Map<String, Object> getParameterMap(HttpServletRequest request) {
RequestWrapper requestWrapper = new RequestWrapper(request);
String body = requestWrapper.getBody();
if (ObjectUtil.isNotEmpty(body)) {
return JSONUtil.toBean(body, Map.class);
}
return null;
}
}

View File

@@ -0,0 +1,53 @@
package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
import com.chaozhanggui.system.cashierservice.entity.dto.OrderDto;
import com.chaozhanggui.system.cashierservice.service.OrderService;
import com.chaozhanggui.system.cashierservice.sign.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;
@CrossOrigin(origins = "*")
@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController {
@Resource
private OrderService orderService;
/**
* 添加订单
* @return
*/
@PostMapping("/creatOrder")
public Result createOrder(@RequestBody OrderDto shopTable){
if (shopTable.getTableId() == null){
return Result.fail("台桌号有误");
}
return orderService.createOrder(shopTable.getTableId(),shopTable.getShopId(),shopTable.getUserId());
}
/**
* 订单回显
* @param orderId
* @return
*/
@GetMapping ("/orderInfo")
private Result orderInfo(@RequestParam Integer orderId){
return orderService.orderInfo(orderId);
}
@GetMapping("/orderList")
private Result orderList(@RequestParam Integer userId,@RequestParam Integer page,
@RequestParam Integer size, @RequestParam String status){
return orderService.orderList(userId,page,size,status);
}
@GetMapping("/testMessage")
private void testMessage(@RequestParam("tableId") String tableId, @RequestParam("message") String message) throws IOException {
orderService.testMessage(tableId,message);
}
}

View File

@@ -0,0 +1,90 @@
package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.ObjectUtil;
import com.chaozhanggui.system.cashierservice.service.PayService;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.IpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;
@CrossOrigin(origins = "*")
@RestController
@Slf4j
@RequestMapping("pay")
public class PayController {
@Autowired
PayService payService;
/**
* 支付
* @param request
* @param openId
* @param map
* @return
*/
@RequestMapping("orderPay")
public Result pay(HttpServletRequest request, @RequestHeader("openId") String openId, @RequestBody Map<String,String> map) {
if(ObjectUtil.isEmpty(map)||map.size()<=0||!map.containsKey("orderId")||ObjectUtil.isEmpty(map.get("orderId"))){
return Result.fail("订单号不允许为空");
}
try {
return payService.payOrder(openId,map.get("orderId").toString(), IpUtil.getIpAddr(request));
} catch (Exception e) {
e.printStackTrace();
}
return Result.fail("支付失败");
}
/**
* 修改订单状态
* @param map
* @return
*/
@RequestMapping("modfiyOrderInfo")
public Result modfiyOrderInfo( @RequestBody Map<String,String> map){
if(ObjectUtil.isEmpty(map)||map.size()<=0||!map.containsKey("orderId")||ObjectUtil.isEmpty(map.get("orderId"))){
return Result.fail("订单号不允许为空");
}
try {
return payService.modifyOrderStatus(Integer.valueOf(map.get("orderId")));
} catch (IOException e) {
e.printStackTrace();
}
return Result.fail("操作失败");
}
/**
* 充值
* @param request
* @param openId
* @param map
* @return
*/
@RequestMapping("memeberIn")
public Result memeberIn(HttpServletRequest request,@RequestHeader("openId") String openId,@RequestHeader("id") String id,
@RequestBody Map<String,Object> map
){
return payService.memberIn(openId,id,map.get("amount").toString(),map.get("shopId").toString(),IpUtil.getIpAddr(request));
}
}

View File

@@ -0,0 +1,44 @@
package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.ObjectUtil;
import com.chaozhanggui.system.cashierservice.service.ProductService;
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.*;
import java.util.Map;
@CrossOrigin(origins = "*")
@RestController
@Slf4j
@RequestMapping("product")
public class ProductController {
@Autowired
private ProductService productService;
@RequestMapping("queryProduct")
public Result queryProduct(@RequestBody Map<String,String> map){
if(ObjectUtil.isEmpty(map)||map.size()<=0||!map.containsKey("code")){
return Result.fail("参数错误");
}
return productService.queryProduct(map.get("code").toString(),(map.containsKey("productGroupId")&&ObjectUtil.isNotEmpty(map.get("productGroupId")))?map.get("productGroupId").toString():"");
}
@GetMapping("queryProductSku")
public Result queryProductSku(
@RequestParam("shopId") String shopId,
@RequestParam("productId") String productId,
@RequestParam("spec_tag") String spec_tag
){
return productService.queryProductSku(shopId,productId,spec_tag);
}
}

View File

@@ -0,0 +1,49 @@
package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.service.ShopTableService;
import com.chaozhanggui.system.cashierservice.sign.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* @author lyf
*/
@CrossOrigin(origins = "*")
@RestController
@Slf4j
@RequestMapping("/table")
public class TableController {
@Resource
private ShopTableService shopTableService;
/**
* 桌台列表
* @return
*/
@PostMapping ("/list")
public Result tableList(@RequestBody TbShopTable shopTable){
return shopTableService.tableList(shopTable.getShopId(),shopTable.getAreaId());
}
/**
* 绑定桌码
* @param shopTable
* @return
*/
@PostMapping ("/binding")
public Result bindingQrcode(@RequestBody TbShopTable shopTable){
if (shopTable.getQrcode() == null || shopTable.getId() == null){
return Result.fail("参数有误");
}
return shopTableService.bindingQrcode(shopTable);
}
@GetMapping ("/area")
public Result areaList(@RequestParam Integer shopId){
return shopTableService.areaList(shopId);
}
}