﻿-- 收款码流水退款 payBack 分支
ALTER TABLE xhScanPay
  ADD COLUMN tkPrice decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '累计退款金额' AFTER actPrice,
  ADD COLUMN refundLog tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否有退款记录' AFTER tkPrice;

CREATE TABLE IF NOT EXISTS xhScanPayRefund (
  id int(11) NOT NULL AUTO_INCREMENT,
  orderSn varchar(32) NOT NULL COMMENT '退款单号 SR*',
  relateOrderSn varchar(32) NOT NULL COMMENT '原收款单号 SC*',
  scanPayId int(11) NOT NULL DEFAULT 0,
  mainId int(11) NOT NULL DEFAULT 0,
  shopId int(11) NOT NULL DEFAULT 0,
  hdId int(11) NOT NULL DEFAULT 0,
  customId int(11) NOT NULL DEFAULT 0,
  customName varchar(64) NOT NULL DEFAULT '',
  refundPrice decimal(10,2) NOT NULL DEFAULT 0.00,
  payWay tinyint(1) NOT NULL DEFAULT 0 COMMENT '0微信 1支付宝',
  status tinyint(1) NOT NULL DEFAULT 1 COMMENT '1已通过',
  thirdRefundNo varchar(64) NOT NULL DEFAULT '' COMMENT '拉卡拉退款流水号',
  shopAdminId int(11) NOT NULL DEFAULT 0,
  shopAdminName varchar(32) NOT NULL DEFAULT '',
  remark varchar(255) NOT NULL DEFAULT '',
  addTime datetime NOT NULL,
  PRIMARY KEY (id),
  KEY idx_relateOrderSn (relateOrderSn),
  KEY idx_mainId (mainId),
  KEY idx_scanPayId (scanPayId)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='收款码退款流水';

CREATE TABLE IF NOT EXISTS xhScanPayRefundSn (
  id int(11) NOT NULL AUTO_INCREMENT,
  mainId int(11) NOT NULL DEFAULT 0,
  shopId int(11) NOT NULL DEFAULT 0,
  hdId int(11) NOT NULL DEFAULT 0,
  customId int(11) NOT NULL DEFAULT 0,
  addTime datetime NOT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
