diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/controller/FyPayController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/controller/FyPayController.java index 359dbc4a9..f230e517d 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/controller/FyPayController.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/controller/FyPayController.java @@ -36,4 +36,16 @@ public class FyPayController { Map map = payService.queryOrder(map1); return map; } + + /** + * 退款 成功 result_msg 显示success + * result_code显示000000 + * @return + * @throws Exception + */ + @PostMapping("/refund") + public Map refund(Map map1) throws Exception { + Map map = payService.refund(map1); + return map; + } } \ No newline at end of file diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/entity/Builder.java b/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/entity/Builder.java index 8caf30c68..5bf01f022 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/entity/Builder.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/entity/Builder.java @@ -52,7 +52,7 @@ public class Builder { } /** - * 条码支付下单查询 + * 条码支付下单 查询订单是否支付成功 * * @return */ @@ -71,4 +71,34 @@ public class Builder { return map; } + /** + * 退款 + * + * @return + */ + public static Map buildFuiou24() { + Map map = new HashMap<>(); + + map.put("version", Const.version); + map.put("ins_cd", Const.ins_cd); + map.put("mchnt_cd", Const.mchnt_cd); + map.put("term_id", Const.term_id); + map.put("random_str", randomNumberGenerator.nextBytes().toHex()); + map.put("sign", ""); + map.put("order_type", Const.order_type); + map.put("mchnt_order_no", ""); +// 商户退款单号 + map.put("refund_order_no", ""); +// 总金额 + map.put("total_amt", ""); +// 退款金额 + map.put("refund_amt", ""); + map.put("operator_id", ""); + map.put("reserved_fy_term_id", ""); + map.put("reserved_origi_dt", ""); + map.put("reserved_addn_inf", ""); + + return map; + } + } \ No newline at end of file diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/FyPayService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/FyPayService.java index 0046a93e1..a06d749f6 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/FyPayService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/FyPayService.java @@ -16,4 +16,11 @@ public interface FyPayService { * @throws Exception */ public Map queryOrder(Map map) throws Exception; + + /** + * 退款 + * @return + * @throws Exception + */ + public Map refund(Map map) throws Exception; } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/impl/FyPayServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/impl/FyPayServiceImpl.java index 685854af7..a60b5199e 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/impl/FyPayServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/api/fuyou/service/impl/FyPayServiceImpl.java @@ -11,16 +11,12 @@ import com.fuint.api.fuyou.service.FyPayService; import com.fuint.api.fuyou.service.MerchantConfigService; import com.fuint.api.fuyou.util.Utils; import com.fuint.business.integral.service.IntegralOrdersService; +import com.fuint.business.marketingActivity.cardFavorable.entity.CardFavorableRecord; +import com.fuint.business.marketingActivity.cardFavorable.service.CardFavorableRecordService; import com.fuint.business.marketingActivity.cardFule.service.CardFuelRecordService; import com.fuint.business.marketingActivity.cardValue.service.CardValueRecordService; -import com.fuint.business.order.entity.CashierOrder; -import com.fuint.business.order.entity.HangBill; -import com.fuint.business.order.entity.LJOrder; -import com.fuint.business.order.entity.OilOrder; -import com.fuint.business.order.service.CashierOrderService; -import com.fuint.business.order.service.HangBillService; -import com.fuint.business.order.service.LJOrderService; -import com.fuint.business.order.service.OilOrderService; +import com.fuint.business.order.entity.*; +import com.fuint.business.order.service.*; import com.fuint.common.dto.AccountInfo; import com.fuint.common.util.TokenUtil; import io.swagger.models.auth.In; @@ -83,7 +79,6 @@ public class FyPayServiceImpl implements FyPayService { String str = resMap.get("sign"); if (Utils.verifySign(resMap, str)){ - String resultCode = resMap.get("result_code"); ThreadUtil.execAsync(() -> { Timer timer = new Timer(); timer.schedule(new TimerTask() { @@ -110,6 +105,10 @@ public class FyPayServiceImpl implements FyPayService { private MerchantConfigService merchantConfigService; @Autowired private HangBillService hangBillService; + @Autowired + private ReturnRecordService returnRecordService; + @Autowired + private CardFavorableRecordService cardFavorableRecordService; @Override public Map queryOrder(Map map1) throws Exception { @@ -148,24 +147,43 @@ public class FyPayServiceImpl implements FyPayService { LJOrder goodsOrder = goodsOrderService.selectGoodsOrder(orderNo); CashierOrder cashierOrder = cashierOrderService.selectCashierOrder(orderNo); MerchantConfig merchantConfig = merchantConfigService.selectMeChByIsUse("1"); - HangBill hangBill = hangBillService.selectHangBillByOrderNo(orderNo); + List returnRecords = returnRecordService.selectReturnRecordByOrderNo(orderNo); Date date = new Date(); if (reqMap.get("trans_stat").equals("SUCCESS")){ if (!ObjectUtil.isEmpty(oilOrder)){ +// 油品订单 oilOrder.setOrderStatus("paid"); oilOrder.setPayTime(date); +// 修改优惠券使用状态 + CardFavorableRecord byId = cardFavorableRecordService.getById(oilOrder.getCouponId()); + if (!ObjectUtil.isEmpty(byId)){ + byId.setStatus("1"); + cardFavorableRecordService.updateById(byId); + } } if (!ObjectUtil.isEmpty(goodsOrder)){ +// 商品订单 goodsOrder.setStatus("paid"); + goodsOrder.setPayTime(date); } if (!ObjectUtil.isEmpty(cashierOrder)){ +// 收银台订单 cashierOrder.setStatus("paid"); + cashierOrder.setPayTime(date); } - if (!ObjectUtil.isEmpty(hangBill)){ - hangBillService.updateHangBills(hangBill,allAmount,"paid"); + if (!ArrayUtil.isEmpty(returnRecords)){ + for (ReturnRecord returnRecord : returnRecords) { +// 挂账归还信息 + returnRecord.setReturnType("1"); + returnRecord.setPayStatus("paid"); + returnRecord.setPayTime(date); + hangBillService.updateHangBill(returnRecord.getHangBillId(), returnRecord.getAmount()); + returnRecordService.updateReturnRecord(returnRecord); + } } - if (ArrayUtil.isEmpty(list)){ + if (!ArrayUtil.isEmpty(list)){ for (OilOrder order : list) { +// 添加多个油品订单 order.setOrderStatus("paid"); order.setPayTime(date); oilOrderService.updateOilOrder(order); @@ -200,9 +218,12 @@ public class FyPayServiceImpl implements FyPayService { if (!ObjectUtil.isEmpty(cashierOrder)){ cashierOrder.setStatus("payFail"); } - if (!ObjectUtil.isEmpty(hangBill)){ - hangBill.setPayStatus("payFail"); - hangBillService.updateById(hangBill); + if (!ArrayUtil.isEmpty(returnRecords)){ + for (ReturnRecord returnRecord : returnRecords) { + returnRecord.setReturnType("0"); + returnRecord.setPayStatus("payFail"); + returnRecordService.updateReturnRecord(returnRecord); + } } if (!ArrayUtil.isEmpty(list)){ for (OilOrder order : list) { @@ -254,4 +275,37 @@ public class FyPayServiceImpl implements FyPayService { return resMap; } + @Override + public Map refund(Map map1) throws Exception { + String orderNo = map1.get("orderNo"); + String refundOrderNo = map1.get("refundOrderNo"); + String payType = map1.get("payType"); + String allAmount = map1.get("allAmount"); + String insCd = map1.get("insCd"); + String mchntCd = map1.get("mchntCd"); + Map map = Builder.buildFuiou24(); + map.put("mchnt_order_no",orderNo); + map.put("order_type",payType); + map.put("total_amt", allAmount); + map.put("refund_amt", allAmount); + map.put("ins_cd", insCd); + map.put("mchnt_cd", mchntCd); + map.put("refund_order_no", refundOrderNo); + + +// 请求报文 + String reqBody = Message.requestMsg(map); +// 响应报文 + String rspXml = Message.responseMsg(reqBody,Const.fuiou_24_url); + + //响应报文验签 + Map resMap = Utils.xmlStr2Map(rspXml); + + String str = resMap.get("sign"); + if (Utils.verifySign(resMap, str)){ + + } + return resMap; + } + } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/controller/HangBillController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/controller/HangBillController.java index 1cdbf7ae3..7094b36a1 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/controller/HangBillController.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/controller/HangBillController.java @@ -75,8 +75,7 @@ public class HangBillController extends BaseController { */ @PutMapping public ResponseObject edit(@Validated @RequestBody Map map){ - HangBill hangBill = hangBillService.updateHangBill(map); - return getSuccessResult(hangBill); + return getSuccessResult(hangBillService.collection(map)); } /** @@ -86,8 +85,7 @@ public class HangBillController extends BaseController { */ @PostMapping("/batch") public ResponseObject batchUpdate(@Validated @RequestBody Map map){ - int row = hangBillService.batchUpdate(map); - return getSuccessResult(row); + return getSuccessResult(hangBillService.batchUpdate(map)); } /** diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/controller/ReturnRecordController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/controller/ReturnRecordController.java new file mode 100644 index 000000000..6a8c54df3 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/controller/ReturnRecordController.java @@ -0,0 +1,60 @@ +package com.fuint.business.order.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuint.business.order.service.ReturnRecordService; +import com.fuint.business.order.vo.ReturnRecordVo; +import com.fuint.framework.web.BaseController; +import com.fuint.framework.web.ResponseObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * 归还记录信息 controller层 + */ +@RestController +@RequestMapping("/business/returnRecord") +public class ReturnRecordController extends BaseController { + @Autowired + private ReturnRecordService returnRecordService; + + /** + * 根据挂账记录id查询归还记录信息 + * @param returnRecordVo + * @param pageNo + * @param pageSize + * @return + */ + @GetMapping("/list") + public ResponseObject list(ReturnRecordVo returnRecordVo, + @RequestParam(value = "page",defaultValue = "1") Integer pageNo, + @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){ + Page page =new Page(pageNo,pageSize); + IPage returnRecordVoIPage = returnRecordService.selectReturnRecordList(page, returnRecordVo); + return getSuccessResult(returnRecordVoIPage); + } + + /** + * 根据id查询挂账归还信息 + * @param id + * @return + */ + @GetMapping("/{id}") + public ResponseObject info(@PathVariable Integer id){ + return getSuccessResult(returnRecordService.selectReturnRecordById(id)); + } + + /** + * 根据订单号查询挂账归还信息 + * @param map + * @return + */ + @PostMapping("/order") + public ResponseObject infoByOrderNo(@Validated @RequestBody Map map){ + String orderNo = map.get("orderNo"); + return getSuccessResult(returnRecordService.selectReturnRecordByOrderNo(orderNo)); + } +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/CashierOrder.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/CashierOrder.java index 3ddf4ca9b..ced4e1af2 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/CashierOrder.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/CashierOrder.java @@ -54,6 +54,10 @@ public class CashierOrder extends BaseEntity implements Serializable { * 订单号 */ private String orderNo; + /** + * 退款订单号 + */ + private String refundOrderNo; /** * 油品订单金额 */ diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/ReturnRecord.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/ReturnRecord.java new file mode 100644 index 000000000..5549ebaec --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/entity/ReturnRecord.java @@ -0,0 +1,82 @@ +package com.fuint.business.order.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fuint.framework.entity.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; +import java.io.Serializable; + +/** + * 归还记录表(ReturnRecord)实体类 + */ +@Data +@TableName("return_record") +@ApiModel(value = "ReturnRecord对象", description = "归还记录表") +public class ReturnRecord extends BaseEntity implements Serializable { + + private static final long serialVersionUID = 1L; + /** + * 主键 + */ + @ApiModelProperty("自增ID") + @TableId(value = "ID", type = IdType.AUTO) + private Integer id; + /** + * 挂账记录id + */ + private Integer hangBillId; + /** + * 店铺id + */ + private Integer storeId; + /** + * 订单号 + */ + private String orderNo; + /** + * 挂账单位id + */ + private Integer creditUnitId; + /** + * 订单状态:0未归还,1已归还 + */ + private String status; + /** + * 归还状态:0挂账,1归还 + */ + private String returnType; + /** + * 挂账金额 + */ + private Double amount; + /** + * 收款金额 + */ + private Double collectAmount; + /** + * 找零金额 + */ + private Double seekZero; + /** + * 操作员工id + */ + private Integer staffId; + /** + * 单据备注 + */ + private String remark; + /** + * 支付状态:已支付,未支付,支付失败 + */ + private String payStatus; + /** + * 支付时间 + */ + private Date payTime; +} + diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/mapper/ReturnRecordMapper.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/mapper/ReturnRecordMapper.java new file mode 100644 index 000000000..1855871da --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/mapper/ReturnRecordMapper.java @@ -0,0 +1,21 @@ +package com.fuint.business.order.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fuint.business.order.entity.ReturnRecord; +import com.fuint.business.order.vo.ReturnRecordVo; +import org.apache.ibatis.annotations.Param; + +/** + * 挂账归还记录表 mapper层 + */ +public interface ReturnRecordMapper extends BaseMapper { + /** + * 根据挂账记录id查询归还信息 + * @param page + * @param returnRecord + * @return + */ + public IPage selectReturnRecordList(Page page, @Param("returnRecord") ReturnRecordVo returnRecord); +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/mapper/xml/ReturnRecordMapper.xml b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/mapper/xml/ReturnRecordMapper.xml new file mode 100644 index 000000000..372d14fda --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/mapper/xml/ReturnRecordMapper.xml @@ -0,0 +1,29 @@ + + + + + select rd.*,ms.real_name,ms.mobile,cu.unit_name,cu.person_credit,cu.contact_mobile,cu.credit_limit + from return_record rd + left join credit_unit cu on cu.id = rd.credit_unit_id + left join mt_staff ms on rd.staff_id = ms.id + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/HangBillService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/HangBillService.java index 639224599..10d1745d9 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/HangBillService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/HangBillService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.fuint.business.order.entity.HangBill; +import com.fuint.business.order.entity.ReturnRecord; import com.fuint.business.order.vo.HangBillVo; import java.util.List; @@ -49,18 +50,26 @@ public interface HangBillService extends IService { public int insertHangBill(HangBillVo hangBill); /** - * 修改挂账记录 并收款 + * 修改挂账记录信息 + * @param id + * @param amount + * @return + */ + public int updateHangBill(int id,Double amount); + + /** + * 添加归还信息并收款 * @param map * @return */ - public HangBill updateHangBill(Map map); + public String collection(Map map); /** * 批量归还挂账金额 * @param map * @return */ - public int batchUpdate(Map map); + public String batchUpdate(Map map); /** * 修改挂账信息 diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/ReturnRecordService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/ReturnRecordService.java new file mode 100644 index 000000000..8efba9e41 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/ReturnRecordService.java @@ -0,0 +1,50 @@ +package com.fuint.business.order.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.fuint.business.order.entity.ReturnRecord; +import com.fuint.business.order.vo.ReturnRecordVo; + +import java.util.List; + +/** + * 挂账归还记录表 业务层 + */ +public interface ReturnRecordService extends IService { + /** + * 根据挂账记录id查询归还信息 + * @param page + * @param returnRecord + * @return + */ + public IPage selectReturnRecordList(Page page,ReturnRecordVo returnRecord); + + /** + * 根据id查询归还记录信息 + * @param id + * @return + */ + public ReturnRecord selectReturnRecordById(int id); + + /** + * 根据订单号查询归还记录信息 + * @param orderNo + * @return + */ + public List selectReturnRecordByOrderNo(String orderNo); + + /** + * 添加挂账归还信息 并返回订单号 + * @param returnRecord + * @return + */ + public String insertReturnRecord(ReturnRecord returnRecord); + + /** + * 修改挂账归还信息 + * @param returnRecord + * @return + */ + public int updateReturnRecord(ReturnRecord returnRecord); +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/HangBillServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/HangBillServiceImpl.java index 0248e0566..96c2bd115 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/HangBillServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/HangBillServiceImpl.java @@ -13,9 +13,11 @@ import com.fuint.api.fuyou.service.MerchantConfigService; import com.fuint.api.fuyou.service.OilConfigService; import com.fuint.business.order.entity.CreditUnit; import com.fuint.business.order.entity.HangBill; +import com.fuint.business.order.entity.ReturnRecord; import com.fuint.business.order.mapper.HangBillMapper; import com.fuint.business.order.service.CreditUnitService; import com.fuint.business.order.service.HangBillService; +import com.fuint.business.order.service.ReturnRecordService; import com.fuint.business.order.vo.HangBillVo; import com.fuint.common.dto.AccountInfo; import com.fuint.common.util.TokenUtil; @@ -114,72 +116,109 @@ public class HangBillServiceImpl extends ServiceImpl i private OilConfigService oilConfigService; @Override - public HangBill updateHangBill(Map map) { - HangBill hangBill1 = this.selectHangBillByOrderNo(map.get("orderNo")); - hangBill1.setPayStatus("unpaid"); - baseMapper.updateById(hangBill1); - String payType = map.get("payType"); -// 调用支付接口 - this.pay(map); - -// 根据id查询挂账信息 - HangBill hangBill = baseMapper.selectById(Integer.parseInt(map.get("id"))); - if (payType.equals("CASH")){ + public int updateHangBill(int id,Double amount) { + HangBill hangBill = baseMapper.selectById(id); + Double repaidAmount = hangBill.getRepaidAmount(); + Double outstandAmount = hangBill.getOutstandAmount(); +// 修改变化金额 + Double repaidAmountAfter = repaidAmount+amount; + Double outstandAmountAfter = outstandAmount-amount; + hangBill.setRepaidAmount(repaidAmountAfter); + hangBill.setOutstandAmount(outstandAmountAfter); +// 修改状态 + if (repaidAmountAfter.equals(hangBill.getAmount()) && outstandAmountAfter.equals(0.0)){ + hangBill.setStatus("1"); + hangBill.setReturnType("1"); hangBill.setPayStatus("paid"); + }else { + hangBill.setStatus("2"); } - // 根据挂账单位id查询挂账单位信息 +// 根据挂账单位id查询挂账单位信息 CreditUnit creditUnit = creditUnitService.selectCreditUnitListById(hangBill.getCreditUnitId()); - if (creditUnit.getCreditLimit()!=0){ - Double creditLimit = creditUnit.getCreditLimit(); - creditUnit.setCreditLimit(creditLimit+Double.valueOf(map.get("repaidAmount"))); - } - - int row = 0; - hangBill.setRemark(map.get("remark")); -// 支付成功后修改挂账信息 - if (hangBill.getPayStatus().equals("paid")){ - Double repaidAmount1 = Double.valueOf(map.get("repaidAmount")); - Double amount = hangBill.getAmount(); - Double repaidAmount = hangBill.getRepaidAmount(); - Double outstandAmount = hangBill.getOutstandAmount(); - Double repaidAmountAfter = repaidAmount+repaidAmount1; -// 修改挂账信息 - hangBill.setRepaidAmount(repaidAmountAfter); - hangBill.setOutstandAmount(amount-repaidAmountAfter); - if (amount.equals(repaidAmountAfter)){ - hangBill.setStatus("1"); - hangBill.setReturnType("1"); - }else { - hangBill.setStatus("2"); - } -// 修改挂账单位余额信息 +// 挂账单位限额的数据添加 + Double creditLimit = creditUnit.getCreditLimit(); + if (creditLimit!=0) { + creditUnit.setCreditLimit(creditLimit+amount); creditUnitService.updateCreditUnit(creditUnit); } - row = baseMapper.updateById(hangBill); - return baseMapper.selectById(Integer.parseInt(map.get("id"))); + int row = baseMapper.updateById(hangBill); + return row; + } + + @Autowired + private ReturnRecordService returnRecordService; + + @Override + public String collection(Map map) { +// 添加归还账单信息 + ReturnRecord returnRecord = new ReturnRecord(); + returnRecord.setHangBillId(Integer.valueOf(map.get("id"))); + returnRecord.setStoreId(Integer.valueOf(map.get("storeId"))); + returnRecord.setCreditUnitId(Integer.valueOf(map.get("creditUnitId"))); + returnRecord.setStaffId(Integer.valueOf(map.get("staffId"))); + returnRecord.setStatus(map.get("payType")); + returnRecord.setRemark(map.get("remark")); + returnRecord.setAmount(Double.valueOf(map.get("repaidAmount"))); + if (map.get("payType").equals("CASH")){ + returnRecord.setCollectAmount(Double.valueOf(map.get("authCode"))); + returnRecord.setSeekZero(Double.valueOf(map.get("seekZero"))); + returnRecord.setPayStatus("paid"); + returnRecord.setReturnType("1"); + returnRecord.setPayTime(new Date()); + Double amount = Double.valueOf(map.get("authCode")) - Double.valueOf(map.get("seekZero")); + this.updateHangBill(returnRecord.getHangBillId(), amount); + }else { + returnRecord.setCollectAmount(Double.valueOf(map.get("repaidAmount"))); + returnRecord.setReturnType("0"); + returnRecord.setPayStatus("unpaid"); + } + String orderNo = returnRecordService.insertReturnRecord(returnRecord); + +// 调用支付接口 + this.pay(map,orderNo); + + return orderNo; } @Override - public int batchUpdate(Map map) { - this.pay(map); + public String batchUpdate(Map map) { List jsonObjects = JSONArray.parseArray(map.get("list"), JSONObject.class); - int row = 0; + // 根据日期生成归还订单号 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String timestamp = dateFormat.format(new Date()); + String randomString = UUID.randomUUID().toString().replace("-","").substring(0,6); + String orderNo = "H"+timestamp+randomString; for (JSONObject jsonObject : jsonObjects) { -// 现将需要修改的支付状态改为未支付 - HangBill hangBill1 = baseMapper.selectById((Integer) jsonObject.get("id")); - - hangBill1.setPayStatus("unpaid"); - baseMapper.updateById(hangBill1); - HangBill hangBill = baseMapper.selectById((Integer) jsonObject.get("id")); +// 添加归还记录信息 + ReturnRecord returnRecord = new ReturnRecord(); + returnRecord.setOrderNo(orderNo); + returnRecord.setHangBillId((Integer) jsonObject.get("id")); + returnRecord.setStoreId((Integer) jsonObject.get("storeId")); + returnRecord.setCreditUnitId((Integer) jsonObject.get("creditUnitId")); + returnRecord.setStaffId((Integer) jsonObject.get("staffId")); + returnRecord.setStatus(map.get("payType")); + returnRecord.setRemark((String) jsonObject.get("remark")); + returnRecord.setAmount(Double.valueOf(jsonObject.get("repaidAmount").toString())); if (map.get("payType").equals("CASH")){ - HangBill hangBill2 = this.updateStatus(hangBill, Double.valueOf(jsonObject.get("repaidAmount").toString())); - hangBill2.setPayStatus("paid"); - hangBill2.setRemark(map.get("remark")); - row = baseMapper.updateById(hangBill2); + returnRecord.setCollectAmount(Double.valueOf(map.get("authCode"))); + returnRecord.setSeekZero(Double.valueOf(map.get("seekZero"))); + returnRecord.setPayStatus("paid"); + returnRecord.setReturnType("1"); + returnRecord.setPayTime(new Date()); + Double amount = Double.valueOf(jsonObject.get("repaidAmount").toString()); + this.updateHangBill(returnRecord.getHangBillId(), amount); + }else { + returnRecord.setCollectAmount(Double.valueOf(jsonObject.get("repaidAmount").toString())); + returnRecord.setReturnType("0"); + returnRecord.setPayStatus("unpaid"); } + returnRecordService.insertReturnRecord(returnRecord); } - return row; +// 调用支付接口 + this.pay(map,orderNo); + + return orderNo; } @Override @@ -194,7 +233,8 @@ public class HangBillServiceImpl extends ServiceImpl i * 调用支付接口 * @param map */ - private void pay(Map map){ + private void pay(Map map,String orderNo){ +// 先将支付状态改为未支付 String payType = map.get("payType"); if (!map.get("repaidAmount").equals("0") && !payType.equals("CASH")){ Integer allAmount = (int) (Double.valueOf(map.get("repaidAmount"))*100); @@ -209,7 +249,7 @@ public class HangBillServiceImpl extends ServiceImpl i Map map1 = new HashMap<>(); map1.put("authCode",map.get("authCode")); map1.put("allAmount",allAmount.toString()); - map1.put("orderNo",map.get("orderNo")); + map1.put("orderNo",orderNo); map1.put("payType",payType); map1.put("insCd",merchantConfig.getInsCd()); map1.put("mchntCd",merchantConfig.getMchntCd()); diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/ReturnRecordServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/ReturnRecordServiceImpl.java new file mode 100644 index 000000000..3e43cc32d --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/service/impl/ReturnRecordServiceImpl.java @@ -0,0 +1,60 @@ +package com.fuint.business.order.service.impl; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.fuint.business.order.entity.ReturnRecord; +import com.fuint.business.order.mapper.ReturnRecordMapper; +import com.fuint.business.order.service.ReturnRecordService; +import com.fuint.business.order.vo.ReturnRecordVo; +import org.springframework.stereotype.Service; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +/** + * 挂账归还记录表 业务层 + */ +@Service +public class ReturnRecordServiceImpl extends ServiceImpl implements ReturnRecordService { + @Override + public IPage selectReturnRecordList(Page page, ReturnRecordVo returnRecord) { + return baseMapper.selectReturnRecordList(page,returnRecord); + } + + @Override + public ReturnRecord selectReturnRecordById(int id) { + return baseMapper.selectById(id); + } + + @Override + public List selectReturnRecordByOrderNo(String orderNo) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("order_no",orderNo); + List list = baseMapper.selectList(queryWrapper); + return list; + } + + @Override + public String insertReturnRecord(ReturnRecord returnRecord) { + if (StrUtil.isEmpty(returnRecord.getOrderNo())){ +// 根据日期生成归还订单号 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String timestamp = dateFormat.format(new Date()); + String randomString = UUID.randomUUID().toString().replace("-","").substring(0,6); + String orderNo = "H"+timestamp+randomString; + returnRecord.setOrderNo(orderNo); + } + baseMapper.insert(returnRecord); + return returnRecord.getOrderNo(); + } + + @Override + public int updateReturnRecord(ReturnRecord returnRecord) { + return baseMapper.updateById(returnRecord); + } +} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/vo/ReturnRecordVo.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/vo/ReturnRecordVo.java new file mode 100644 index 000000000..1b6cbdcbe --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/order/vo/ReturnRecordVo.java @@ -0,0 +1,20 @@ +package com.fuint.business.order.vo; + +import com.fuint.business.order.entity.ReturnRecord; +import lombok.Data; + +@Data +public class ReturnRecordVo extends ReturnRecord { + // 操作人名称 + private String realName; + // 操作人手机号 + private String mobile; + // 单位名称 + private String unitName; + // 挂账人 + private String personCredit; + // 联系电话 + private String contactMobile; + // 挂账额度 + private String creditLimit; +} diff --git a/fuintCashierWeb/src/api/cashier/returnrecord.js b/fuintCashierWeb/src/api/cashier/returnrecord.js new file mode 100644 index 000000000..ab20be3ad --- /dev/null +++ b/fuintCashierWeb/src/api/cashier/returnrecord.js @@ -0,0 +1,27 @@ +import request from '@/utils/request' + +// 根据挂账记录id查询归还记录信息 +export function listReturnRecord(query) { + return request({ + url: '/business/returnRecord/list', + method: 'get', + params: query + }) +} + +// 根据id查询挂账归还信息 +export function returnRecordInfo(id) { + return request({ + url: '/business/returnRecord/' + id, + method: 'get', + }) +} + +// 根据订单号查询挂账归还信息 +export function returnRecordByOrderNo(data) { + return request({ + url: '/business/returnRecord/order', + method: 'post', + data: data + }) +} diff --git a/fuintCashierWeb/src/views/cashier/NewComponents/credit.vue b/fuintCashierWeb/src/views/cashier/NewComponents/credit.vue index d019a52c5..b4d3f6a69 100644 --- a/fuintCashierWeb/src/views/cashier/NewComponents/credit.vue +++ b/fuintCashierWeb/src/views/cashier/NewComponents/credit.vue @@ -139,69 +139,35 @@ - - + - - - - - - + + + - + - - - + + - - + - - - + + - - - - - @@ -238,6 +204,90 @@ + + +
+ +
+
+
+

单据号:{{record.orderNo}}

+
+
+
+
+ 操作员工: + {{ record.realName }} +
+
+
+
+ 挂账单位 + {{record.unitName}} +
+
+ 挂账人 + {{record.personCredit}} +
+
+ 联系电话 + {{record.contactMobile}} +
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+ @@ -620,6 +670,7 @@ import { } from "@/api/cashier/hangbill"; import {addCreditUnit, listCreditUnit} from "@/api/cashier/creditunit"; import {getDicts} from "@/api/dict/data"; +import {listReturnRecord, returnRecordByOrderNo, returnRecordInfo} from "@/api/cashier/returnrecord"; export default { name: "credit", @@ -643,6 +694,7 @@ import {getDicts} from "@/api/dict/data"; isPay:true, isPaySuccess:false, loading: false, + drawer: false, // 弹出框标题 title:'', // 支付方式列表 @@ -664,6 +716,8 @@ import {getDicts} from "@/api/dict/data"; form2:{payType:"WECHAT"}, form3:{}, form4:{payType:"WECHAT"}, + // 挂账信息 + record:{}, // 查询参数 queryParams: { page: 1, @@ -673,13 +727,21 @@ import {getDicts} from "@/api/dict/data"; page: 1, pageSize: 10, }, + queryParams1: { + page: 1, + pageSize: 10, + hangBillId:"", + }, // 日期范围 dateRange: [], // 挂账记录列表 hangBillList:[], + // 归还记录列表 + returnRecordList:[], // 总条数 total: 0, total1: 0, + total2: 0, // 是否开启提示框 open:false, open1:false, @@ -693,6 +755,7 @@ import {getDicts} from "@/api/dict/data"; isBatch:false, timer:"", unitName:"", + orderNo:"", // 表单校验 rules: { unitName: [ { required: true, message: "请选择挂账单位", trigger: "blur" }, ], @@ -769,6 +832,42 @@ import {getDicts} from "@/api/dict/data"; this.getLists(); }, methods:{ + getPayMeth(list,val){ + let name = ""; + if (list!=null && list!=""){ + list.forEach(item => { + if (item.dictValue == val){ + name = item.dictLabel + } + }) + } + return name; + }, + // 是否关闭弹框 + handleClose(done) { + done(); + }, + // 归还记录详情弹框 + returnRecord(id){ + this.record = {} + this.drawer = true + hangBillInfo(id).then(response => { + this.record = response.data + }) + this.getRecordList(id,1); + }, + getRecordList(id,val){ + if (val!=1){ + this.queryParams1.page = id + this.queryParams1.hangBillId = this.record.id + }else { + this.queryParams1.hangBillId = id + } + listReturnRecord(this.queryParams1).then(response => { + this.returnRecordList = response.data.records + this.total2 = response.data.total + }) + }, changePayType(val){ this.payType = val }, @@ -778,17 +877,19 @@ import {getDicts} from "@/api/dict/data"; }, // 计算找零金额 changeSeekZero(){ - this.seekZero = this.authCode - this.oilActualPay - this.goodsActualPay + this.seekZero = (this.authCode - this.payAmount).toFixed(2) }, batchSub(){ this.form4.list = JSON.stringify(this.tableList); this.form4.repaidAmount = this.repaidAmount; + this.form4.payType = "WECHAT" this.open4 = true; }, batchReturn(){ this.open3 = true this.repayList = []; this.unitName = "" + this.getLists(); }, getRepayList(){ let result = []; @@ -854,37 +955,48 @@ import {getDicts} from "@/api/dict/data"; this.getList(); }, // 收款 - collection(){ + collection(val){ + if (this.payType=="CASH"){ + if (this.authCode==undefined || this.authCode=="" || this.seekZero<0){ + this.$modal.msgError("请输入正确的金额变化"); + return; + } + } let _this = this; if (this.isBatch){ // 批量归还 _this.form4.repaidAmount = _this.payAmount; _this.form4.authCode = _this.authCode; - _this.form4.orderNo = _this.tableList[0].orderNo; + _this.form4.seekZero = _this.seekZero batchHangBill(_this.form4).then(response => { - if (response.data!=0){ - _this.isPaySuccess = true; - _this.isPay = false; - this.getList(); - } + // 返回订单号信息 + _this.orderNo = response.data }) _this.loading = true; + _this.queryPayStatus(); + let timer = setInterval(function () { + if (_this.isQuery == false) { + _this.loading = false; + _this.isPay = false; + clearInterval(_this.timer); + } + },1000) + setTimeout(function (){ + _this.loading = false; + clearInterval(timer); + },30000) this.open3 = false; this.open4 = false; + this.getLists(); + this.getList(); }else { // 单个归还 _this.form2.repaidAmount = _this.payAmount; _this.form2.authCode = _this.authCode; + _this.form2.seekZero = _this.seekZero editHangBill(this.form2).then(response => { - console.log(response) - if (response.data==null){ - - }else { - if (response.data.payStatus == 'paid'){ - _this.isPaySuccess = true; - _this.isPay = false; - } - } + // 返回订单号信息 + _this.orderNo = response.data }) _this.loading = true; _this.queryPayStatus(); @@ -907,20 +1019,22 @@ import {getDicts} from "@/api/dict/data"; queryPayStatus(){ let _this = this; _this.timer = setInterval(function (){ - queryHangBill({orderNo:_this.form2.orderNo}).then(response => { - if (response.data.payStatus == "unpaid"){ - _this.isQuery = true; - } - if (response.data.payStatus == "paid"){ - _this.isPaySuccess = true; - _this.isQuery = false; - } - if (response.data.payStatus == "payFail"){ - _this.isPaySuccess = false; - _this.isQuery = false; - } + returnRecordByOrderNo({orderNo:_this.orderNo}).then(response => { + response.data.forEach(item => { + if (item.payStatus == "unpaid"){ + _this.isQuery = true; + } + if (item.payStatus == "paid"){ + _this.isPaySuccess = true; + _this.isQuery = false; + } + if (item.payStatus == "payFail"){ + _this.isPaySuccess = false; + _this.isQuery = false; + } + }) }) - },1000) + },1001) }, submitReturn(){ this.isPay = true; @@ -937,8 +1051,10 @@ import {getDicts} from "@/api/dict/data"; submitReturn1(){ this.isPay = true; this.isBatch = true; + this.loading = false; this.payAmount = this.form4.repaidAmount; - this.authCode = this.form4.authCode; + this.authCode = ""; + // this.authCode = this.form4.authCode; if (this.form4.payType!="CASH"){ this.title = "扫码付款"; }else { @@ -954,6 +1070,7 @@ import {getDicts} from "@/api/dict/data"; }, // 归还 repay(id){ + this.payType = "WECHAT" hangBillInfo(id).then( response => { this.open2 = true; this.form2 = response.data @@ -1047,7 +1164,10 @@ import {getDicts} from "@/api/dict/data"; }) }, // 获取列表信息 - getList(){ + getList(val){ + if (val!=undefined){ + this.queryParams.page = val + } listHangBill(this.addDateRange(this.queryParams, this.dateRange)).then( response => { this.hangBillList = response.data.records this.total = response.data.total; diff --git a/fuintCashierWeb/src/views/cashier/NewComponents/homeindex.vue b/fuintCashierWeb/src/views/cashier/NewComponents/homeindex.vue index 5d6205b9b..27a1c890d 100644 --- a/fuintCashierWeb/src/views/cashier/NewComponents/homeindex.vue +++ b/fuintCashierWeb/src/views/cashier/NewComponents/homeindex.vue @@ -152,8 +152,20 @@ width="400" trigger="click">
- - + + + + + + + + + + + + +
{{item.name}}
@@ -161,8 +173,8 @@
满{{ item.full }}元,减{{ item.reduce }}元
-
-
+ +
{ - list.push(item.name) - }) if (val){ this.couponAmount = 0 - this.couponDiscount.forEach(item2 => { - this.couponAmount += item2.reduce + this.couponAmount = this.couponDiscount[0].reduce + this.useCouponIds = "" + this.couponIds.forEach(item => { + if (item.name = this.couponDiscount[0].name){ + this.useCouponIds = item.id + } }) + this.checkedCities5 = this.couponDiscount[0].name; }else { + this.useCouponIds = "" this.couponAmount = 0 + this.checkedCities5 = "" } - this.checkedCities5 = val ? list : []; - this.isIndeterminate5 = false; this.isExclusion(); }, handleCheckedCitiesChange5(value) { this.couponAmount = 0; this.couponDiscount.forEach(item => { - let reduces = 0 - for (let i = 0; i < value.length; i++){ - if (item.name == value[i]){ - reduces = item.reduce - } + if (item.name == value){ + this.couponAmount = item.reduce } - this.couponAmount += reduces }) - let checkedCount = value.length; - this.checkAll5 = checkedCount === this.couponDiscount.length; - this.isIndeterminate5 = checkedCount > 0 && checkedCount < this.couponDiscount.length; + this.useCouponIds = "" + this.couponIds.forEach(item => { + if (item.name == value){ + this.useCouponIds = item.id + } + }) + this.checkAll5 = true; this.isExclusion(); }, // 模糊查询商品信息 @@ -1646,10 +1667,13 @@ _this.preferentialData.oilPrice = item1.oilPrice; _this.preferentialData.oilLiters = item1.liters; _this.couponDiscount =[]; + _this.couponIds = [], selectCoupon(_this.preferentialData).then(response => { _this.couponAmount = 0; + _this.couponIds = response.data if (response.data.length>0){ response.data.forEach(item => { + _this.useCouponIds.push(item.id) let discount = {type:item.type,discountType:item.discountType,name:item.name,oilName:item1.oilName,full:0,reduce:0,discount:0} discount.full = item.satisfiedAmount if (item.type==0){ @@ -1688,12 +1712,19 @@ _this.couponDiscount.forEach(item2 => { if (item2.oilName!=discount.oilName) { _this.couponDiscount.push(discount) - _this.checkedCities5.push(item.name) + _this.checkedCities5 = item.name + _this.couponAmount = discount.reduce + } + if (item2.name!=discount.name && item2.oilName==discount.oilName) { + _this.couponDiscount.push(discount) + _this.checkedCities5 = item.name + _this.couponAmount = discount.reduce } }) }else { _this.couponDiscount.push(discount) - _this.checkedCities5.push(item.name) + _this.checkedCities5 = item.name + _this.couponAmount = discount.reduce } } if (item.exclusiveFunction == 0){ @@ -1712,12 +1743,7 @@ _this.exclusion = item.exclusiveFunction }) } - let couponAmount = 0; - _this.couponDiscount.forEach(item2 => { - couponAmount += item2.reduce - _this.checkAll5 = true; - }) - _this.couponAmount = couponAmount + _this.checkAll5 = true; _this.isExclusion(); }) }) @@ -1763,6 +1789,11 @@ // 判断互斥限制 isExclusion(){ if (this.exclusion == 1){ + // 不使用满减 + if (this.isUseBalance){ + this.countAmountFull() + return; + } // 储值卡互斥 if (this.isUseBalance){ this.countAmountUnBalance() @@ -1773,6 +1804,11 @@ } }else if (this.exclusion == 0){ // 满减互斥 + // 不使用储值卡 + if (this.isUseBalance){ + this.countAmountUnBalance() + return; + } if (this.isUseFull){ this.countAmountFull() return; @@ -1848,17 +1884,6 @@ _this.fullReduction = 0 } _this.isExclusion(); - // if (_this.isUseFull){ - // _this.checkAll1 = false; - // _this.fullReduction = 0; - // _this.checkedCities1 = [] - // _this.countAmountFull() - // return; - // }else { - // _this.countAmountBalance() - // return; - // } - // _this.oilActualPay = oilActualPay - _this.oilDiscount - _this.fullReduction - _this.balance }) }) }, @@ -1994,11 +2019,6 @@ this.oilAmount += +item.amount }) - // if (this.select == "元"){ - // this.oilAmount = +this.form.amount + this.oilAmount; - // }else { - // this.oilAmount = this.form.amount + this.oilAmount; - // } this.oilActualPay = this.oilAmount - this.oilDiscount; this.oilTotal = this.oilOrder.length; this.select = "元"; @@ -2174,6 +2194,7 @@ this.map.consumeAmount = this.consumeAmount; this.updateRefuelMoney(); this.map.refuelMoney = JSON.stringify(this.refuelMoney) + this.map.couponId = this.useCouponIds let _this = this; addLJGoods(_this.map).then( response => {