public function perform()
 {
     $args = $this->args;
     if (empty($args['language']) || empty($args['header']) || empty($args['key']) || empty($args['accountId']) || empty($args['condition'])) {
         ResqueUtil::log(['status' => 'fail to export code', 'message' => 'missing params', 'args' => $args]);
         return false;
     }
     //set the language
     Yii::$app->language = empty($args['language']) ? LanguageUtil::DEFAULT_LANGUAGE : $args['language'];
     $header = $args['header'];
     $fileName = $args['key'];
     $filePath = ExcelUtil::getFile($fileName, 'csv');
     $condition = unserialize($args['condition']);
     $object = GoodsExchangeLog::find();
     $classFunction = '\\backend\\modules\\product\\models\\GoodsExchangeLog::preProcessExportData';
     $backendUser = Account::findByPk(new \MongoId($args['accountId']));
     ExcelUtil::processMultiData($header, $filePath, $backendUser, $condition, $object, $classFunction, ['changeTostring' => ['goods']]);
     $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;
     }
 }
Exemplo n.º 2
0
 /**
  * Update company info
  *
  * <b>Request Type</b>: PUT<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/management/company/{id}<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used to update company info
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     captcha: string<br/>
  *     company: string<br/>
  *     name: string<br/>
  *     phone: string<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  *  {
  *      'message' => 'OK';
  *  }
  * </pre>
  */
 public function actionUpdate($id)
 {
     $account = Account::findByPk(new \MongoId($id));
     $company = $this->getParams('company');
     $name = $this->getParams('name');
     $phone = $this->getParams('phone');
     $code = $this->getParams('captcha');
     if (empty($company) && empty($name) && empty($phone)) {
         throw new BadRequestHttpException('Missing require params');
     }
     !empty($company) ? $account->company = $company : '';
     !empty($name) ? $account->name = $name : '';
     if (!empty($phone)) {
         if (empty($code)) {
             throw new InvalidParameterException(['captcha' => \Yii::t('management', 'empty_captcha_error')]);
         }
         $this->attachBehavior('CaptchaBehavior', new CaptchaBehavior());
         $this->checkCaptcha($phone, $code);
         $account->phone = $phone;
     }
     if ($account->save()) {
         return ['message' => 'ok'];
     } else {
         throw new ServerErrorHttpException('Comapny save fail');
     }
 }
Exemplo n.º 3
0
 /**
  * Login
  *
  * <b>Request Type</b>: POST<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/site/login<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for the users to login.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     email: string, the user email, required<br/>
  *     password: string, the user password, required<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     ack: integer, mark the create result, 0 means create successfully, 1 means create fail<br/>
  *     msg: string, if create fail, it contains the error message<br/>
  *     data: array, json array to describe the users detail information<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <pre>
  * {
  *     "email" : "*****@*****.**",
  *     "password" : "aaaaaaaaaaaaaaaaaaaaaaaaa"
  * }
  * </pre>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *    'ack' : 1,
  *    'data': {"userInfo": {name:"Devin Jin", avatar:"path/to/avatar", enabledModules:['a', 'b', 'c']}}
  * }
  * </pre>
  */
 public function actionLogin()
 {
     $params = $this->getParams();
     if (empty($params['email']) || empty($params['password'])) {
         throw new BadRequestHttpException(Yii::t('common', 'parameters_missing'));
     }
     $user = User::getByEmail(mb_strtolower($params['email']));
     if (empty($user)) {
         throw new InvalidParameterException(['email' => Yii::t('common', 'incorrect_userid')]);
     }
     $account = Account::findByPk($user->accountId);
     if (empty($account) || $account->status !== Account::STATUS_ACTIVATED) {
         throw new BadRequestHttpException(Yii::t('common', 'account_is_unactivated'));
     }
     if (!$user->isActivated) {
         throw new InvalidParameterException(['email' => Yii::t('common', 'user_not_activate')]);
     }
     if ($user->validatePassword($params['password'])) {
         $accessToken = Token::create($user);
         $userInfo = ['name' => $user->name, 'email' => $user->email, 'language' => $user->language, 'avatar' => empty($user->avatar) ? '' : $user->avatar, 'enabledModules' => $accessToken['enabledMods'], 'role' => $user->role, 'id' => $user->_id . '', 'accountId' => (string) $user->accountId, 'company' => $account->company];
         $this->setAccessToken($accessToken['accessToken']);
         return ['userInfo' => $userInfo];
     } else {
         throw new InvalidParameterException(['password' => Yii::t('common', 'password_error')]);
     }
 }
Exemplo n.º 4
0
 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;
     }
 }
Exemplo n.º 5
0
 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];
 }
Exemplo n.º 6
0
 /**
  * Init the channel menus config
  * @param  string $channelId
  * @param  MongoId $accountId
  */
 protected function initConfig($channelId, $accountId)
 {
     $account = Account::findByPk($accountId);
     $modules = $account->enabledMods;
     $basePath = Yii::getAlias('@backend');
     if (!empty($modules)) {
         foreach ($modules as $module) {
             if (!empty($module)) {
                 $file = $basePath . '/modules/' . $module . '/config/channelMenu.php';
                 if (is_file($file)) {
                     $config = (require $file);
                     if (is_array($config)) {
                         if ($this->_isNotAssoc($config)) {
                             $this->config = array_merge((array) $this->config, (array) $config);
                         } else {
                             $this->config[$module] = $config;
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Generate app private key
  */
 public function generateKey()
 {
     $account = Account::findByPk($this->accountId);
     $token = ['uid' => (string) $this->accountId, 'scopes' => [], 'app' => (string) $this->_id];
     $this->privateKey = \JWT::encode($token, $account->secretKey, self::DEFAULT_ALG, $account->accessKey);
 }
Exemplo n.º 8
0
 public function actionCheckRefund()
 {
     $params = $this->getParams();
     $accountId = $this->getAccountId();
     $account = Account::findByPk($accountId);
     if (empty($params['outTradeNo']) || empty($params['refundFee'])) {
         throw new BadRequestHttpException(Yii::t('common', 'parameters_missing'));
     }
     $condition = ['quncrmAccountId' => (string) $accountId, 'outTradeNo' => $params['outTradeNo'], 'outRefundNo' => $params['outTradeNo'], 'totalFee' => (int) $params['refundFee'], 'refundFee' => (int) $params['refundFee'], 'opUserId' => $account['name']];
     $result = Yii::$app->weConnect->checkRefund($condition);
     return $result;
 }
Exemplo n.º 9
0
 public static function createForWechat($accountId)
 {
     $account = Account::findByPk($accountId);
     if (empty($account)) {
         throw new Exception("Illegal accountId");
     }
     $expire = 3600 * 24 * 10000;
     //never expired
     $token = new Token();
     $token->accessToken = StringUtil::uuid();
     $token->expireTime = new \MongoDate(time() + $expire);
     $token->userId = '';
     $token->accountId = $account['_id'];
     $token->language = self::DEFAULT_LANGUAGE;
     $token->enabledMods = ['chat'];
     $token->role = User::ROLE_WECONNECT;
     if ($token->save()) {
         return $token;
     }
     throw new Exception("Faile to create token for database problems");
 }
Exemplo n.º 10
0
 /**
  * Get accountId and company when exchange
  * @param array $params
  * @return array
  */
 public function exchange($params)
 {
     $token = Token::getToken();
     \Yii::$app->language = empty($token->language) ? LanguageUtil::DEFAULT_LANGUAGE : $token->language;
     $this->checkCode($params);
     $accountId = $params['accountId'];
     $account = Account::findByPk($accountId);
     return ['accountId' => $accountId, 'company' => empty($account->company) ? null : $account->company];
 }
Exemplo n.º 11
0
 public function perform()
 {
     $args = $this->args;
     $accountId = new \MongoId($args['accountId']);
     $channels = $args['channels'];
     if (!empty($args['storeIds'])) {
         // Sync store data to wechat
         $userId = $args['userId'];
         $storeIds = $args['storeIds'];
         $storeData = [];
         foreach ($storeIds as $key => $storeId) {
             $storeId = new \MongoId($storeId);
             $store = Store::findByPk($storeId);
             $storeData[] = $store->toData();
         }
         $failResult = [];
         foreach ($channels as $channelId) {
             try {
                 $result = \Yii::$app->weConnect->addStore($channelId, $storeData);
                 if (!empty($result['location_id_list']) && in_array(-1, $result['location_id_list'])) {
                     foreach ($result['location_id_list'] as $index => $locationId) {
                         if ($locationId === -1) {
                             $failResult[] = ['channelId' => $channelId, 'storeId' => $storeIds[$index], 'storeName' => $storeData[$index]['business_name']];
                         }
                     }
                 }
             } catch (\Exception $e) {
                 ResqueUtil::log($e);
                 foreach ($storeData as $index => $store) {
                     $failResult[] = ['channelId' => $channelId, 'storeId' => $storeIds[$index], 'storeName' => $store['business_name']];
                 }
             }
         }
         if (!empty($failResult)) {
             \Yii::$app->cache->set(Store::CACHE_PREFIX . $userId . Store::SYNC_TO_WECHAT, $failResult, Store::CACHE_EXPIRE_TIME);
             throw new \Exception('Sync store data to wechat failed.');
         }
     } else {
         // Sync store data from wechat
         $account = Account::findByPk($accountId);
         $syncWechat = [];
         if (!empty($account->syncWechat)) {
             $syncWechat = $account->syncWechat;
         }
         $sizeCondition = ['offset' => static::STORE_START_NUM, 'count' => static::STORE_END_NUM];
         foreach ($channels as $channelId) {
             $stores = \Yii::$app->weConnect->getStores($channelId, $sizeCondition);
             ResqueUtil::log($stores);
             if (!empty($stores['location_list'])) {
                 foreach ($stores['location_list'] as $storeData) {
                     $store = new Store();
                     $store->loadData($storeData);
                     $store->accountId = $accountId;
                     $store->save();
                 }
             }
             array_push($syncWechat, $channelId);
         }
         $account->syncWechat = $syncWechat;
         $account->save();
     }
 }
Exemplo n.º 12
0
 /**
  * Get account modules config
  *
  * <b>Request Type </b>:GET
  * <b>Request Endpoints </b>: http://{server-domain}/api/common/module/config
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used to get the account modules config.
  *
  * <b>Response Example</b>
  * {
  *     "menus": {
  *         "content": [
  *             {
  *                 "order": 1,
  *                 "title": "graphics_content",
  *                 "name": "graphics",
  *                 "state": "content-graphics"
  *             },
  *             {
  *                 "order": 2,
  *                 "title": "webpage_content",
  *                 "name": "webpage",
  *                 "state": "content-webpage"
  *             }
  *         ],
  *         "analytic": [
  *             {
  *                 "order": 1,
  *                 "title": "analytic_followers_growth",
  *                 "name": "growth",
  *                 "state": "analytic-growth"
  *             },
  *             {
  *                 "order": 2,
  *                 "title": "analytic_followers_property",
  *                 "name": "property",
  *                 "state": "analytic-property"
  *             },
  *             {
  *                 "order": 3,
  *                 "title": "analytic_content_spread",
  *                 "name": "content",
  *                 "state": "analytic-content"
  *             },
  *             {
  *                 "order": 4,
  *                 "title": "analytic_store",
  *                 "name": "store",
  *                 "state": "analytic-score"
  *             }
  *         ]
  *     },
  *     "mods": [
  *         {
  *             "name": "channel",
  *             "order": 1,
  *             "stateUrl": ""
  *         },
  *         {
  *             "name": "customer",
  *             "order": 2,
  *             "stateUrl": "/customer/follower"
  *         },
  *         {
  *             "name": "helpdesk",
  *             "order": 1,
  *             "stateUrl": "/helpdesk/helpdesk"
  *         }
  *     ],
  *     "forbiddenStates": [
  *         "member-score",
  *         "product-edit-product",
  *         "product-edit-product-{id}"
  *     ]
  * }
  **/
 public function actionConfig()
 {
     $accountId = $this->getAccountId();
     $account = Account::findByPk($accountId);
     $result = ['menus' => $account->menus, 'mods' => $account->mods];
     $token = Token::getToken();
     $forbiddenStates = [];
     if (empty($token->role) || $token->role !== User::ROLE_ADMIN) {
         $userId = empty($token->userId) ? '' : $token->userId;
         $forbiddenStates = SensitiveOperation::getForbiddenStates($userId, $accountId);
     }
     $menus =& $result['menus'];
     // Remove the forbidden menu
     foreach ($menus as &$menu) {
         foreach ($menu as $index => $subMenu) {
             if (!empty($subMenu['state']) && in_array($subMenu['state'], $forbiddenStates)) {
                 array_splice($menu, $index, 1);
             }
         }
     }
     $mods =& $result['mods'];
     foreach ($mods as $index => &$mod) {
         // Get the first menu's state in this mod
         if (!empty($menus[$mod['name']][0]['state'])) {
             // Use first menu's state to generate the mod's stateUrl
             $mod['stateUrl'] = $this->_state2Url($menus[$mod['name']][0]['state']);
         } else {
             // Remove the mod
             array_splice($mods, $index, 1);
         }
     }
     $result['forbiddenStates'] = $forbiddenStates;
     // Sort the menus and mods
     foreach ($result['menus'] as &$moduleItems) {
         ArrayHelper::multisort($moduleItems, 'order', SORT_ASC);
     }
     ArrayHelper::multisort($result['mods'], 'order', SORT_ASC);
     return $result;
 }
Exemplo n.º 13
0
 /**
  * Get extension modules
  *
  * <b>Request Type </b>:GET
  * <b>Request Endpoints </b>: http://{server-domain}/api/management/module/extension-module
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for the user to get extension modules.
  *
  * <b>Request Example </b>:
  * <pre>
  *  http://{server-domain}/api/management/module/extension-module
  * </pre>
  *
  **/
 public function actionExtensionModule()
 {
     $accountId = $this->getAccountId();
     $account = Account::findByPk($accountId);
     $availableExtMods = $account->availableExtMods;
     return $availableExtMods;
 }
Exemplo n.º 14
0
 /**
  * Get account app key
  *
  * <b>Request Type</b>: GET<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/management/app-key/key<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for billing account to get account app key
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *     "accessKey": "j57yguwea3",
  *     "secretKey": "hddbb36a5agy1u4vwov1612svlp537c2bcvg8cnc",
  *     "keyCreatedAt": 1428479366
  * }
  * </pre>
  */
 public function actionKey()
 {
     $token = Token::getToken();
     $account = Account::findByPk($token->accountId);
     return $account->getKey();
 }