//#import $owl_refundrec:services/modelService.jsx

//退款记录辅助程序
var RefundRecordHelper = (function () {
    var f = {
        getRefundRecord: function (jPayRecord, jRefundOrder, refundOrderItemId, refundAmount, operatorUserIsd) {
            var refundRecId = owl_refundrecService.getId({});
            var refundCode = f.getRefundRecordCode(refundRecId);

            var curTime = new Date().getTime();

            var jRefundRecord = {};
            jRefundRecord.id = refundRecId;
            jRefundRecord.refund_code = refundCode;
            jRefundRecord.payRecId = jPayRecord.id;
            jRefundRecord.payRecCode = jPayRecord.pay_code;
            jRefundRecord.refundOrderId = jRefundOrder.id;
            jRefundRecord.refundOrderItemId = refundOrderItemId;
            jRefundRecord.relatedObjType = jRefundOrder.relatedObjType;
            jRefundRecord.order_id = jRefundOrder.order_id;
            jRefundRecord.order_code = jRefundOrder.order_code;
            jRefundRecord.parent_order_id = jRefundOrder.parent_order_id;
            jRefundRecord.parent_order_code = jRefundOrder.parent_order_code;
            jRefundRecord.uid = jPayRecord.uid;
            jRefundRecord.refundState = "unrefund";
            jRefundRecord.createTime = curTime;
            jRefundRecord.refundAmount = refundAmount;
            jRefundRecord.factRefundAmount = 0;
            jRefundRecord.interfaceId = jPayRecord.interfaceId;
            jRefundRecord.interfaceName = jPayRecord.interfaceName;
            jRefundRecord._orgId = "0";
            jRefundRecord._orgIds = ["0"];
            jRefundRecord.owl_createUserId = operatorUserIsd;

            jRefundRecord = owl_refundrecService.add(jRefundRecord);

            return {
                code: "0",
                msg: "操作成功",
                data: jRefundRecord
            };
        },
        getRefundRecordCode: function (refundRecId) {
            var now = new Date();
            var year = "" + now.getFullYear();
            var month = now.getMonth() + 1;
            var date = now.getDate();
            // var hour = now.getHours();
            // var minute = "" + now.getMinutes();
            // var second = "" + now.getSeconds();

            year = year.substring(2);
            month = month < 10 ? "0" + month : "" + month;
            date = date < 10 ? "0" + date : "" + date;
            // hour = hour < 10 ? "0" + hour : "" + hour;
            // minute = minute < 10 ? "0" + minute : "" + minute;
            // second = second < 10 ? "0" + second : "" + second;

            var num = refundRecId.replace("owl_refundrec_", "");

            //81开头是退款记录单号
            var code = "81" + year + month + date + num;

            return code;
        }
    }
    return f;
})();

