public function perform() { $args = $this->args; if (empty($args['accountId']) || empty($args['key']) || empty($args['header'])) { ResqueUtil::log(['status' => 'fail to export member', 'message' => 'missing params', 'args' => $args]); return false; } Yii::$app->language = empty($args['language']) ? LanguageUtil::DEFAULT_LANGUAGE : $args['language']; $accountId = new \MongoId($args['accountId']); $header = $args['header']; // get member's customized properties $memberProperties = MemberProperty::getByAccount($accountId); foreach ($memberProperties as $memberProperty) { if ($memberProperty->isDefault) { $header[$memberProperty->name] = Yii::t('member', $memberProperty->name); } else { $header[$memberProperty->name] = $memberProperty->name; } } $socialAccountsMap = []; $account = Account::findByPk($accountId); $channelIds = Channel::getEnableChannelIds($accountId); if (!empty($channelIds)) { $socialAccounts = \Yii::$app->weConnect->getAccounts($channelIds); foreach ($socialAccounts as $socialAccount) { $socialAccountsMap[$socialAccount['id']] = $socialAccount['name']; } } $cardMap = []; $cards = MemberShipCard::getByAccount($accountId); foreach ($cards as $card) { $cardMap[(string) $card->_id] = $card->name; } $condition = unserialize($args['condition']); //get properties $memberProperties = MemberProperty::findAll(['accountId' => $accountId]); $base = ['cardMap' => $cardMap, 'socialAccountsMap' => $socialAccountsMap, 'memberProperties' => $memberProperties]; $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $orderBy = Member::normalizeOrderBy($args['params']); $object = Member::find(); $classFunction = '\\backend\\modules\\member\\models\\Member::preProcessMemberData'; ExcelUtil::processMultiData($header, $filePath, $base, $condition, $object, $classFunction, [], $orderBy); $hashKey = ExcelUtil::setQiniuKey($filePath, $fileName); if ($hashKey) { //notice frontend the job is finished \Yii::$app->tuisongbao->triggerEvent(Message::EVENT_EXPORT_FINISH, ['key' => $fileName], [Message::CHANNEL_GLOBAL . $args['accountId']]); return true; } else { return false; } }
public function actionRemove() { $name = $this->getParams('name', ''); if ($name === '') { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } $accountId = $this->getAccountId(); $account = Account::findByPk($accountId); $channels = Channel::getEnableChannelIds($accountId); if (!defined('KLP') || !KLP) { if (!empty($channels)) { $followerTags = Yii::$app->weConnect->deleteTag($channels, $name); } } $this->attachBehavior('TagBehavior', new TagBehavior()); $this->deleteTag($accountId, $name); return ['message' => 'OK', 'data' => null]; }
/** * Synchroniz account channels, remove disable channels * @param Account $account * @throws ServerErrorHttpException * @return array */ public function syncAccountChannels($accountId) { $channelIds = Channel::getEnableChannelIds($accountId); $channelInfo = ['wechat' => [], 'weibo' => [], 'alipay' => []]; if (empty($channelIds)) { return $channelInfo; } $weChannels = \Yii::$app->weConnect->getAccounts($channelIds); $this->syncWebHookChannels($accountId, $weChannels); $enbaleChannel = []; foreach ($weChannels as $weChannel) { if ($weChannel['channel'] == Account::WECONNECT_CHANNEL_WEIXIN && !empty($weChannel['refreshToken'])) { $channelInfo['wechat'][] = $weChannel; $enbaleChannel[] = $weChannel['id']; } else { if ($weChannel['channel'] == Account::WECONNECT_CHANNEL_WEIXIN && !empty($weChannel['appSecret'])) { $channelInfo['wechat'][] = $weChannel; $enbaleChannel[] = $weChannel['id']; } else { if ($weChannel['channel'] == Account::WECONNECT_CHANNEL_WEIBO) { $weChannel['appkey'] = WEIBO_APP_KEY; $channelInfo['weibo'][] = $weChannel; $enbaleChannel[] = $weChannel['id']; } else { if ($weChannel['channel'] == Account::WECONNECT_CHANNEL_ALIPAY) { $channelInfo['alipay'][] = $weChannel; $enbaleChannel[] = $weChannel['id']; } } } } Channel::updateAll(['$set' => ['name' => $weChannel['name'], 'type' => empty($weChannel['accountType']) ? '' : $weChannel['accountType']]], ['channelId' => $weChannel['id'], 'accountId' => $accountId]); } $disableChannelIds = array_diff($channelIds, $enbaleChannel); if (!empty($disableChannelIds)) { $disableChannelIds = array_values($disableChannelIds); Channel::disableByChannelIds($accountId, $disableChannelIds); } return $channelInfo; }