@juzi/wechaty
Version:
Wechaty is a RPA SDK for Chatbot Makers.
161 lines • 5.24 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WxxdOrderImpl = void 0;
const PUPPET = __importStar(require("@juzi/wechaty-puppet"));
const config_js_1 = require("../config.js");
const poolify_js_1 = require("../user-mixins/poolify.js");
const validation_js_1 = require("../user-mixins/validation.js");
const wechatify_js_1 = require("../user-mixins/wechatify.js");
const MixinBase = (0, wechatify_js_1.wechatifyMixin)((0, poolify_js_1.poolifyMixin)(Object)());
class WxxdOrderMixin extends MixinBase {
id;
/**
* Instance properties
* @ignore
*/
payload;
/**
* @hideconstructor
*/
constructor(id) {
super();
this.id = id;
config_js_1.log.silly('WxxdOrder', 'constructor(%s)', id);
}
/**
* List all orders
*/
static async list(query) {
config_js_1.log.verbose('WxxdOrder', 'list(%s)', JSON.stringify(query));
return await this.wechaty.puppet.listWxxdOrders(query);
}
/**
* Find order by id or filter
*/
static async find(query) {
config_js_1.log.verbose('WxxdOrder', 'find(%s)', JSON.stringify(query));
const id = typeof query === 'string' ? query : query.id;
if (!id) {
return undefined;
}
const order = this.wechaty.WxxdOrder.load(id);
try {
await order.ready();
}
catch (e) {
this.wechaty.emitError(e);
return undefined;
}
return order;
}
/**
* Send delivery for an order
*/
static async deliverySend(orderId, deliveryId, waybillId) {
config_js_1.log.verbose('WxxdOrder', 'deliverySend(%s, %s, %s)', orderId, deliveryId, waybillId);
return this.wechaty.puppet.wxxdOrderDeliverySend({ orderId, deliveryId, waybillId });
}
/**
* Generate after sale order
*/
static async genAfterSaleOrder(orderId, reason) {
config_js_1.log.verbose('WxxdOrder', 'genAfterSaleOrder(%s, %s)', orderId, reason);
return this.wechaty.puppet.wxxdOrderGenAfterSaleOrder({ orderId, reason });
}
/**
* Update order merchant notes
*/
static async updateWxxdMerchantnotes(orderId, merchantNotes) {
config_js_1.log.verbose('WxxdOrder', 'updateWxxdMerchantnotes(%s, %s)', orderId, merchantNotes);
return this.wechaty.puppet.updateWxxdMerchantnotes(orderId, merchantNotes);
}
isReady() {
return !!(this.payload && this.payload.orderId);
}
async ready(forceSync = false) {
config_js_1.log.silly('WxxdOrder', 'ready() @ %s with id="%s"', this.wechaty.puppet, this.id);
if (!forceSync && this.isReady()) {
config_js_1.log.silly('WxxdOrder', 'ready() isReady() true');
return;
}
try {
this.payload = await this.wechaty.puppet.wxxdOrderPayload(this.id);
}
catch (e) {
this.wechaty.emitError(e);
config_js_1.log.verbose('WxxdOrder', 'ready() this.wechaty.puppet.wxxdOrderPayload(%s) exception: %s', this.id, e.message);
throw e;
}
}
/**
* Get order ID
*/
orderId() {
return this.payload?.orderId || this.id;
}
/**
* Get order open ID
*/
openId() {
return this.payload?.openId || '';
}
/**
* Get order status
*/
status() {
return this.payload?.status || PUPPET.types.WxxdOrderStatus.Unpaid;
}
/**
* Get order create time
*/
createTime() {
return this.payload?.createTime || 0;
}
/**
* Get order update time
*/
updateTime() {
return this.payload?.updateTime || 0;
}
/**
* Get order products
*/
products() {
return this.payload?.products || [];
}
/**
* Get order ext info
*/
extInfo() {
return this.payload?.extInfo;
}
}
class WxxdOrderImplBase extends (0, validation_js_1.validationMixin)(WxxdOrderMixin)() {
}
class WxxdOrderImpl extends (0, validation_js_1.validationMixin)(WxxdOrderImplBase)() {
}
exports.WxxdOrderImpl = WxxdOrderImpl;
//# sourceMappingURL=wxxd-order.js.map