import OrderappMerchantApi from './index' import { produce } from 'immer' import _ from 'lodash' import shortCode from '../../libs/shortCode' export default class MerchantApi { api: OrderappMerchantApi constructor (api: OrderappMerchantApi) { this.api = api } async getMerchant (): Promise { const response = await this.api.axiosGo.get('/m/merchant/') return response.data } // 更改餐廳的 name, desc, contact, address async updateInfo (info: IMerchantUpdateInfoRequest): Promise { const response = await this.api.axiosGo.post('/m/merchant/info', info) return response.data } // 更改服務費 async updateSurcharge (surcharge: IMerchantUpdateSurchargeRequest): Promise { const response = await this.api.axiosGo.post('/m/merchant/surcharge', surcharge) return response.data } // 更改小數處理 async updateRounding (rounding: IOrderRounding): Promise { const response = await this.api.axiosGo.post('/m/merchant/rounding', rounding) return response.data } // 更改用戶介面語言,例如 locales: ['zh', 'en'] async updateClientLocales (locales: string[]): Promise { const response = await this.api.axiosGo.post('/m/merchant/locales', { locales }) return response.data } // 更改用戶介面預設語言,例如 language: 'zh' async updateClientDefaultLanguage (language: string): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/defaultclientlanguage', { value: language }) return response.data } // 更改廚房單預設語言,例如 language: 'zh' async updateBatchPrintLanguage (language: string): Promise { const response = await this.api.axiosGo.post('/m/merchant/batchlocale', { locale: language }) return response.data } // 開關叫侍應功能 async updateWaiterEnable (enabled: boolean): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/waiter', { enabled }) return response.data } // 開關動態 QRCode 功能 async updateDynamicQRCodeEnable (dynamic: boolean): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/qrcode', { dynamic }) return response.data } // 更改動態 QRCode 自訂顯示文字 async updateDynamicQRCodeCustomText (value: string): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/qrcustomtext', { value }) return response.data } // 更改動態 QRCode 不須輸入人數 async updateDynamicQRCodeDisableCustomerCount (disableCustomerCount: string): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/qrdisablecustomercount', { value: disableCustomerCount }) return response.data } // 更改外賣最快取餐時間(分鐘) async updateTakeawayPickupAfterMinutes (minutes: number): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/takeawaypickupafter', { minutes }) return response.data } // 更改結帳後自動打印收據開關 async updateAutoPrintReceipt (autoPrintReceipt: number): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/autoprintreceipt', { value: autoPrintReceipt }) return response.data } // 更改自訂推薦文字 async updateRecommendCustomText (value: string): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/recommendcustomtext', { value }) return response.data } // 更改精簡模式(列印?) async updateLitePrinting (litePrinting: boolean): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/liteprinting', { value: litePrinting }) return response.data } // 更改啟用餐單編號 async updateEnableCode (enable: boolean): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/code', { value: enable }) return response.data } // 更改頁腳自訂文字 async updateFooterCustomText (value: string): Promise { const response = await this.api.axiosGo.post('/m/merchant/setting/footercustomtext', { value }) return response.data } // 更改營業時間設定 openings 為7天的 array,每天可以設定多個 IMerchantOpeningSetting async updateOpening (openings: { [ weekdayFrom0: number ]: IOpeningWithSurcharge[] }): Promise { const data = produce(openings, (draft) => { _.forEach(draft, dayConfigs => { dayConfigs.forEach(config => { if (typeof config.surcharge === 'object') { config.surcharge = _.get(config, 'surcharge.percent') } }) }) return draft }) const response = await this.api.axiosGo.post('/m/merchant/opening', data) return response.data } // 新增/修改/刪除一個 payment,根據 key 決定,如果不存在就會建立,如果有給 remove: true 就會刪除 async updatePayment (payment: IMerchantSetPaymentRequest): Promise { const data = { key: payment.key ?? shortCode.generate(7), name: payment.name, amount: payment.amount ?? 0, percent: payment.percent ?? 0, remove: payment.remove ?? false, extra: payment.extra ?? false, tips: payment.tips ?? false, } const response = await this.api.axiosGo.post('/m/merchant/payment', data) return response.data } // 新增 table group async createTablegroup (group: string): Promise { const response = await this.api.axiosGo.post('/m/merchant/tablegroup', { group }) return response.data } // 刪除 table group async deleteTablegroup (group: string): Promise { const response = await this.api.axiosGo.post('/m/merchant/tablegroup', { group, remove: true }) return response.data } // 新增 table 或修改 table 的 group async updateTable (table: string, group: string): Promise { const response = await this.api.axiosGo.post('/m/merchant/table', { table, group }) return response.data } // 刪除 table async deleteTable (table: string): Promise { const response = await this.api.axiosGo.post('/m/merchant/table', { table, remove: true }) return response.data } async getUiVersion (client: string): Promise { const response = await this.api.axiosGo.post('/s/health/version', { client: client }) return response.data } }