/**
订单中心，处理订单公共业务：支付、退款等
OrderCenterService 对应实现 OrderCenterServiceImpl 类
-- 项目地址：https://gogs.ywtinfo.com/ywt/rpc-ordercenter-service.git
*/
syntax = "proto3";

package com.ywt.gapi.ordercenter;

//option java_generic_services = true;
option java_multiple_files = true;
option java_package = "com.ywt.gapi.ordercenter";
option java_outer_classname = "OrderCenterProto";
option go_package = "/ordercenter";

enum PaymentChannelEnum {
    UNKNOW = 0;
    WeChat = 1; //微信
    AliPay = 2; //支付宝
    Cash = 3; //现金
    MedicalCard = 4; //诊疗卡
    POS = 5; //pos机
    FREE = 6; //无须支付
    MedicalInsurance = 7; //医保
}

//创建订单请求消息
message CreateOrderRequest{
    int32 userId = 1;
    string patientMobile = 2;
    int32 amount = 3;                           //单位：分
    string remark = 4;
    int32 orderType = 5;
    int32 bizId = 6;
    int32 doctorId = 7;
    string title = 8;
    string paymentCallbackMethod = 9;           //支付成功后回调grpc方法，结构：(/${package}.${service}/${method})，如：/com.ywt.gapi.mq.MQExecutorService/executeGRPC
    string statusChangedCallbackMethod = 10;
    string custom = 11;                         //自定义数据
    string payCode = 12;                        //支付代码--支付中心统一编码
    string payBody = 13;
    int32 terminal = 14;
    string refundNotifyRestUrl = 15;            //退款成功后回调rest服务方法，url格式: rest://com.ywt.MgDrugApiService/path1/path2
}
//创建订单响应消息
message CreateOrderResponse{
    int32 code = 1;
    string info = 2;
    int32 orderId = 3;
    string orderNo = 4;
}
//订单支付成功通知消息
message PaymentCallbackNotifyRequest{
    string orderNo = 1;
    int32 orderId = 2;
    int32 payType = 3; //1: 微信; 2: 管理员线下收费；3-支付宝支付
    string custom = 4; //回发创建单时设置的自定义数据
    int32 bizId = 5;
    string paymentNo = 6; //订单中心支付流水号
    int32 userId = 7;//用户id
    string prepayId = 8; //本次支付微信 prepay_id
    int32 terminal = 9;  //发起支付终端
    string openid = 10; //完成微信支付的微信用户 openid
    int32 paymentChannel = 11;
    string oneTimeCustom = 12;//本次操作自定义数据
    string wxTransactionId = 13; //本次微信支付交易流水号
    int64 payFinishDate = 14; //支付完成时间（秒）
    string alipayTradeNo = 15; // 支付宝支付单号
}
//管理员线下收费请求消息
message PayByAdminRequest{
    int32 amount = 1;           //单位：分
    string spbillCreateIp = 2;  //操作请求IP
    string byUserName = 3;      //操作用户名
    int32 paymentChannel = 4;   //3: 现金；5: pos机
    int32 orderId = 5;          //订单中心ID
    string custom = 6;          //本次操作自定义数据，【订单支付成功通知】会通过 oneTimeCustom 回发
}
//管理员线下收费响应消息
message PayByAdminResponse{
    int32 code = 1;
    string info = 2;
}
//微信支付方式支付订单请求消息
message WechatPaymentRequest{
    string payCode = 1;         //支付代码--支付中心统一编码
    string body = 2;            //商品描述
    string spbillCreateIp = 3;  //发起支付IP
    string openid = 4;          //用户openid
    int32 amount = 5;           //单位：分
    int32 terminal = 6;         //发起支付终端
    int32 orderId = 7;          //订单ID
    int32 userId = 8;           //发起支付用户ID
}
//微信支付方式支付订单响应消息
message WechatPaymentResponse{
    int32 code = 1;
    string info = 2;
    string timeStamp = 3;
	string nonceStr = 4;
	string package = 5;
	string signType = 6;
	string paySign = 7;
	string appId = 8;
}
//微信支付内部grpc通知消息结构
message WechatPaymentNotifyRequest {
    string internalPayNo = 1; //内部支付实例唯一编码
    string mchId = 2; //微信支付商户号/服务商的特约商户号
    string transactionId = 3; //微信支付订单号
    string attach = 4; //附加数据
    string outTradeNo = 5; //商户订单号
    int32 fee = 6; //支付金额(单位: 分)
    int64 payFinishDate = 7; //支付完成时间
    int64 payDate = 8; //支付时间
}
//支付中心微信支付成功后回调通知响应消息
message WechatPaymentNotifyResponse {
    int32 code = 1;
    string info = 2;
}
//获取订单信息请求消息
message GetOrderInfoRequest {
    int32 orderId = 1;
    string orderNo = 2;
}
//获取订单信息响应消息
message GetOrderInfeResponse {
    int32 code = 1;
    string info = 2;
    string orderNo = 3;
    int32 orderId = 4;
    int32 orderType = 5;
    int32 amount = 6;
}
//更新订单信息请求消息
message UpdateOrderInfoRequest {
    int32 orderId = 1;
    int32 amount = 2;
    string payCode = 3;
}
//更新订单信息响应消息
message UpdateOrderInfoResponse {
    int32 code = 1;
    string info = 2;
}
//退款请求消息
message RefundRequest {
    string orderNo = 1;          //订单编号
    int32 orderId = 2;          //订单号
    int32 amount = 3;           //退款金额(单位：分), 当为0时，默认该订单总金额
    string opBy = 4;            //操作人, 当人工退款方式时必填
    int32 refundType = 5;       //退款方式，1: 人工, 2: 系统
    string refundNotifyMethod = 6; //退款成功后回调grpc方法，结构：(/${package}.${service}/${method})，如：/com.ywt.gapi.mq.MQExecutorService/executeGRPC
    string refundNotifyRestUrl = 7; //退款成功后回调rest服务方法，url格式: rest://com.ywt.MgDrugApiService/path1/path2
    string remark = 8;
    string custom = 9;          //本次操作自定义数据，【订单退款成功通知】会通过 custom 回发
}
//退款响应消息
message RefundResponse {
    int32 code = 1;
    string info = 2;
    string refundNo = 3;    //退款流水号
}
//退款结果通知请求消息
message RefundNotifyRequest {
    int32 amount = 1;               //已退金额
    int32 bizId = 2;
    int32 orderId = 3;
    string orderNo = 4;
    string refundNo = 5;            //退款单号
    int32 refundStatus = 6;         //退款状态 1: 退款成功，2: 退款异常，3: 退款关闭
    string custom = 7;              //回发 custom 数据
    int64 refundSuccessTime = 8;    //退款成功时间, 时间戳: 秒
}
//微信退款结果通知请求消息
message WechatRefundNotifyRequest {
    string refundNo = 1;            //商户退款单号
    string outTradeNo = 2;          //商户订单号
    int64 refundDate = 3;           //申请退款时间, 时间戳: 秒
    int64 refundFinishDate = 4;     //退款处理完成时间, 时间戳: 秒
    int64 refundSuccessTime = 5;    //退款成功时间, 时间戳: 秒
    int32 refundFee = 6;            //微信退款金额，单位为分
    int32 refundStatus = 7;         //退款状态 1: 退款成功，2: 退款异常，3: 退款关闭
}
//微信退款结果通知响应消息
message WechatRefundNotifyResponse {
    int32 code = 1;
    string info = 2;
}
//获取订单中心账单请求消息
message GetOrderBillRequest {
    string billDate = 1;    //下载对账单的日期，格式：20180603
}
//获取订单中心账单响应消息
message GetOrderBillResponse {
    int32 code = 1;
    string info = 2;
    string data = 3;        //账单数据 csv数据格式
}
//POS机申请预支付信息请求消息
message PrePayByPOSRequest {
    int32 amount = 1;           //单位：分
    string spbillCreateIp = 2;  //操作请求IP
    string byUserName = 3;      //操作用户名
    int32 orderId = 4;          //订单中心ID
}
//POS机申请预支付信息响应消息
message PrePayByPOSResponse {
    int32 code = 1;
    string info = 2;
    string paymentNo = 3; //支付流水号
}
//POS机完成支付信息更新请求消息
message FinishPayByPOSRequest {
    string paymentNo = 1;       //支付流水号
    string referNo = 2;         //系统检索号
    string authNo = 3;          //授权号
    string rspCode = 4;         //返回码
    string cardNo = 5;          //交易卡号
    string transTime = 6;       //交易时间
    string transDate = 7;       //交易日期
    string terminalId = 8;      //POS机终端ID
    string terminalTraceNo = 9; //终端流水号
}
//POS机完成支付信息更新响应消息
message FinishPayByPOSResponse {
    int32 code = 1;
    string info = 2;
}

//ICBC支付方式支付订单请求消息
message ICBCPaymentRequest{
    // 子订单
    message SubOrder{
        int32 amount = 1;           //单位：分
        int32 orderId = 2;          //订单ID
    }
    string payCode = 1;         //支付代码--支付中心统一编码
    string body = 2;            //商品描述
    string spbillCreateIp = 3;  //发起支付IP
    string openid = 4;          //用户openid
    int32 amount = 5;           //单位：分
    int32 terminal = 6;         //发起支付终端
    int32 orderId = 7;          //订单ID
    int32 userId = 8;           //发起支付用户ID
    int32 payType = 9;          //合并支付标识：1-单订单, 2-多订单合并支付
    repeated SubOrder subOrder = 10;     // 子订单(用于多订单合并支付)
}
//ICBC支付方式支付订单响应消息
message ICBCPaymentResponse{
    int32 code = 1;
    string info = 2;
    string timeStamp = 3;
	string nonceStr = 4;
	string package = 5;
	string signType = 6;
	string paySign = 7;
	string appId = 8;
}
//ICBC支付内部grpc通知消息结构
message ICBCPaymentNotifyRequest {
    string internalPayNo = 1;   //内部支付实例唯一编码
    string mchId = 2;           //微信支付商户号/服务商的特约商户号
    string transactionId = 3;   //微信支付订单号
    string attach = 4;          //附加数据
    string outTradeNo = 5;      //商户订单号
    int32 fee = 6;              //支付金额(单位: 分)
    int64 payFinishDate = 7;    //支付完成时间
    int64 payDate = 8;          //支付时间
}
//支付中心ICBC支付成功后回调通知响应消息
message ICBCPaymentNotifyResponse {
    int32 code = 1;
    string info = 2;
}
//ICBC退款结果通知请求消息
message ICBCRefundNotifyRequest {
     // 子订单
    message SubOrder{
        int32 refundFee = 1;        //单位：分
        int32 orderId = 2;          //订单ID
        string payCode = 3;         //支付代码--支付中心统一编码
        int32 orderRefundLogId = 4; //退款日志ID
    }
    string refundNo = 1;            //商户退款单号
    string outTradeNo = 2;          //商户订单号
    int64 refundDate = 3;           //申请退款时间, 时间戳: 秒
    int64 refundFinishDate = 4;     //退款处理完成时间, 时间戳: 秒
    int64 refundSuccessTime = 5;    //退款成功时间, 时间戳: 秒
    int32 refundFee = 6;            //工行退款金额，单位为分
    int32 refundStatus = 7;         //退款状态 1: 退款成功，2: 退款异常，3: 退款关闭
    repeated SubOrder subOrderList = 8;
}
//ICBC退款结果通知响应消息
message ICBCRefundNotifyResponse {
    int32 code = 1;
    string info = 2;
}
//清除支付锁Request
message CleanPayLockRequest {
    int32 orderId = 1;
}
//清除支付锁Response
message CleanPayLockResponse {
    int32 code = 1;
    string info = 2;
}
//判断是否在支付中
message CheckIsPayingRequest {
    int32 orderId = 1;
}
//判断是否在支付中
message CheckIsPayingResponse {
    int32 code = 1;
    string info = 2;
    bool paying = 3;    // 判断是否正在支付中，支付中：true，不在支付中：false
}

// 支付宝下单请求
message CreateAlipayOrderRequest {
    string payCode = 1; // 支付代码，1xxx 是微信支付，2xxx 是支付宝支付
    string body = 2; // 商品描述
    string alipayUid = 3; // 支付宝用户 id
    int32 orderId = 4; // 系统订单 id
    string orderNo = 5;  // 系统订单编号
    int32 amount = 6; // 金额，单位：分
    int32 userId = 7; // 用户 id
    int32 terminal = 8; // 发起支付终端
}

// 支付宝下单响应
message CreateAlipayOrderResponse {
    int32 code = 1;
    string info = 2;
    string tradeNo = 3; // 支付宝交易号
    int32 orderId = 4;
    string orderNo = 5;
}


// 支付宝支付回调
// 参考文档：https://opendocs.alipay.com/open/203/105286
// https://opendocs.alipay.com/support/01raw4#%E5%BC%82%E6%AD%A5%E9%80%9A%E7%9F%A5%E4%BA%A4%E6%98%93%E7%8A%B6%E6%80%81%E4%BB%8B%E7%BB%8D
message AlipayNotifyRequest {
    string callbackData = 1; // 全部回调数据
}

message AlipayNotifyResponse {
    int32 code = 1;
    string info = 2;
}

//订单中心服务  // 对应 rpc-ordercenter-service 项目的 OrderCenterServiceImpl 类
service OrderCenterService {
    //创建订单
    rpc createOrder(CreateOrderRequest) returns (CreateOrderResponse);
    //管理员线下收费
    rpc payByAdmin(PayByAdminRequest) returns (PayByAdminResponse);
    //微信支付方式支付订单
    rpc wechatPayment(WechatPaymentRequest) returns (WechatPaymentResponse);
    //支付中心微信支付成功后回调通知
    rpc WechatPaymentNotify(WechatPaymentNotifyRequest) returns (WechatPaymentNotifyResponse);
    //获取订单信息
    rpc getOrderInfo(GetOrderInfoRequest) returns (GetOrderInfeResponse);
    //更新订单信息
    rpc updateOrderInfo(UpdateOrderInfoRequest) returns (UpdateOrderInfoResponse);
    //退款
    rpc refund(RefundRequest) returns (RefundResponse);
    //支付中心微信退款成功通知
    rpc wechatRefundNotify(WechatRefundNotifyRequest) returns (WechatRefundNotifyResponse);
    //获取订单中心账单
    rpc getOrderBill(GetOrderBillRequest) returns (GetOrderBillResponse);
    //POS机申请预支付信息
    rpc prePayByPOS(PrePayByPOSRequest) returns (PrePayByPOSResponse);
    //POS机完成支付信息更新
    rpc finishPayByPOS(FinishPayByPOSRequest) returns (FinishPayByPOSResponse);
    //ICBC支付方式支付订单
    rpc icbcPayment(ICBCPaymentRequest) returns (ICBCPaymentResponse);
    //支付中心ICBC支付成功后回调通知
    rpc icbcPaymentNotify(ICBCPaymentNotifyRequest) returns (ICBCPaymentNotifyResponse);
     //支付中心工行退款成功通知
    rpc icbcRefundNotify(ICBCRefundNotifyRequest) returns (ICBCRefundNotifyResponse);
    //清除支付锁
    rpc cleanPayLock(CleanPayLockRequest) returns (CleanPayLockResponse);
    //判断是否在支付中
    rpc checkIsPaying(CheckIsPayingRequest) returns (CheckIsPayingResponse);
    // 创建支付宝订单
    rpc createAlipayOrder(CreateAlipayOrderRequest) returns (CreateAlipayOrderResponse);
    // 支付宝支付回调
    rpc alipayNotify(AlipayNotifyRequest) returns (AlipayNotifyResponse);
}