/** * get the template list only with the information for webhook usage */ public function actionWebhooks() { $accountId = $this->getAccountId(); $result = []; $templates = MessageTemplate::findAll(['accountId' => $accountId]); foreach ($templates as $template) { $result[] = ['name' => $template->name, 'useWebhook' => $template->useWebhook]; } return $result; }
/** * get the name of template */ public function actionIndex() { $accountId = $this->getAccountId(); return MessageTemplate::findAll(['accountId' => $accountId]); }
/** * delete muti redemption template and promotion template(delete-product-template) */ public function actionDeleteProductTemplate() { $accountInfos = Account::findAll(['enabledMods' => ['$all' => ['product']]]); if ($accountInfos) { $redemptionTemplate = $promotionTemplate = []; foreach ($accountInfos as $accountInfo) { if (empty($redemptionTemplate) || empty($promotionTemplate)) { $datas = MessageTemplate::getDefaultTemplateData($accountInfo['_id']); foreach ($datas as $data) { if ($data['name'] == MessageTemplate::REDEMPTION_TITLE) { $redemptionTemplate = ['name' => $data['name'], 'weChat' => $data['weChat'], 'email' => $data['email'], 'mobile' => $data['mobile']]; } if ($data['name'] == MessageTemplate::PROMOTIONCODE_TITLE) { $promotionTemplate = ['name' => $data['name'], 'weChat' => $data['weChat'], 'email' => $data['email'], 'mobile' => $data['mobile']]; } } } $redemptionTemplate['accountId'] = $accountInfo['_id']; $promotionTemplate['accountId'] = $accountInfo['_id']; $redemptionDatas = MessageTemplate::findAll($redemptionTemplate); if (count($redemptionDatas) >= 2) { MessageTemplate::deleteAll(['_id' => $redemptionDatas[0]->_id]); echo 'delete redemptionTemplate id:' . $redemptionDatas[0]->_id . PHP_EOL; } $promotionDatas = MessageTemplate::findAll($promotionTemplate); if (count($promotionDatas) >= 2) { MessageTemplate::deleteAll(['_id' => $promotionDatas[0]->_id]); echo 'delete promotionTemplate id:' . $promotionDatas[0]->_id . PHP_EOL; } } } echo 'over' . PHP_EOL; }