@juzi/wechaty
Version:
Wechaty is a RPA SDK for Chatbot Makers.
135 lines • 3.88 kB
JavaScript
import * as PUPPET from '@juzi/wechaty-puppet';
import { log } from '../config.js';
import { poolifyMixin } from '../user-mixins/poolify.js';
import { validationMixin } from '../user-mixins/validation.js';
import { wechatifyMixin } from '../user-mixins/wechatify.js';
const MixinBase = wechatifyMixin(poolifyMixin(Object)());
class WxxdOrderMixin extends MixinBase {
id;
/**
* Instance properties
* @ignore
*/
payload;
/**
* @hideconstructor
*/
constructor(id) {
super();
this.id = id;
log.silly('WxxdOrder', 'constructor(%s)', id);
}
/**
* List all orders
*/
static async list(query) {
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) {
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) {
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) {
log.verbose('WxxdOrder', 'genAfterSaleOrder(%s, %s)', orderId, reason);
return this.wechaty.puppet.wxxdOrderGenAfterSaleOrder({ orderId, reason });
}
/**
* Update order merchant notes
*/
static async updateWxxdMerchantnotes(orderId, merchantNotes) {
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) {
log.silly('WxxdOrder', 'ready() @ %s with id="%s"', this.wechaty.puppet, this.id);
if (!forceSync && this.isReady()) {
log.silly('WxxdOrder', 'ready() isReady() true');
return;
}
try {
this.payload = await this.wechaty.puppet.wxxdOrderPayload(this.id);
}
catch (e) {
this.wechaty.emitError(e);
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 validationMixin(WxxdOrderMixin)() {
}
class WxxdOrderImpl extends validationMixin(WxxdOrderImplBase)() {
}
export { WxxdOrderImpl, };
//# sourceMappingURL=wxxd-order.js.map