Esempio n. 1
0
 public static function createPrize($params, $activityId)
 {
     $accountId = Token::getAccountId();
     if (empty($accountId)) {
         throw new ServerErrorHttpException("Fail to get account's id");
     }
     for ($i = 0; $i < count($params); $i++) {
         unset($params[$i]['_id']);
         //remove default _id, create MongoId
         $params[$i]['activityId'] = $activityId;
         $params[$i]['accountId'] = $accountId;
         $params[$i]['points'] = (int) $params[$i]['points'];
         $params[$i]['quantity'] = (int) $params[$i]['quantity'];
         $prize = new ActivityPrize();
         if (!empty($params[$i]['startDate'])) {
             $params[$i]['startDate'] = MongodbUtil::msTimetamp2MongoDate($params[$i]['startDate']);
             $params[$i]['endDate'] = MongodbUtil::msTimetamp2MongoDate($params[$i]['endDate']);
         }
         $prize->attributes = $params[$i];
         if (!$prize->save()) {
             LogUtil::error(['message' => 'save activity-prize failed', 'error' => $prize->errors], 'activityPrize');
             // throw new ServerErrorHttpException('save activityPrize failed');
             return false;
         }
         unset($prize);
     }
     return true;
 }
Esempio n. 2
0
 public static function createSmsJob($condition, $operator, $smsName)
 {
     $totalCount = 0;
     $accountId = Token::getAccountId();
     if (!array_key_exists('accountId', $condition)) {
         $condition = array_merge($condition, ['accountId' => $accountId]);
     }
     switch ($smsName) {
         case 'cny_winners':
             $smsTemplate = self::CNY_WINNERS_SMS_TEMPLATE;
             $totalCount = LuckyDrawWinner::find()->where($condition)->count();
             break;
         default:
             break;
     }
     $recordId = BulkSmsRecord::createSmsRecord($operator, $smsName, $smsTemplate, $totalCount);
     if (is_bool($recordId) && !$recordId) {
         throw new ServerErrorHttpException("發送失敗,請刷新頁面重試!");
     }
     $args = ['condition' => serialize($condition), 'smsName' => $smsName, 'smsRecord' => (string) $recordId];
     $jobId = Yii::$app->job->create('backend\\modules\\uhkklp\\job\\BulkSms', $args);
     if (!empty($jobId)) {
         return ['smsRecordId' => (string) $recordId, 'count' => $totalCount];
     } else {
         throw new ServerErrorHttpException("發送失敗,請刷新頁面重試!");
     }
 }
Esempio n. 3
0
 public static function getCountBySmsRecordId($smsRecordId)
 {
     $accountId = Token::getAccountId();
     $successful = BulkSmsLog::find()->where(['smsRecordId' => $smsRecordId, 'status' => true, 'accountId' => $accountId])->count();
     $failed = BulkSmsLog::find()->where(['smsRecordId' => $smsRecordId, 'status' => false, 'accountId' => $accountId])->count();
     unset($accountId);
     return ['successful' => $successful, 'failed' => $failed];
 }
Esempio n. 4
0
 public static function createSmsRecord($operator, $smsName, $smsTemplate, $total = 0, $process = 0)
 {
     $properties = ['smsName' => $smsName, 'total' => $total, 'successful' => 0, 'failed' => 0, 'process' => $process, 'smsTemplate' => $smsTemplate, 'accountId' => Token::getAccountId(), 'operator' => $operator];
     $smsRecord = new BulkSmsRecord();
     $smsRecord->attributes = $properties;
     if (!$smsRecord->save()) {
         return false;
     }
     return $smsRecord->_id;
 }
Esempio n. 5
0
 public static function createWinner($params)
 {
     $winner = new LuckyDrawWinner();
     if (!array_key_exists('accountId', $params)) {
         $winner->accountId = Token::getAccountId();
     }
     $winner->attributes = $params;
     $winner->createdAt = new \MongoDate();
     $winner->save();
     unset($winner);
 }
 public static function getLastSmsRecord()
 {
     $accountId = Token::getAccountId();
     $query = new Query();
     $query = $query->from('uhkklpEarlyBirdSmsRecord')->select(['_id', 'total', 'successful', 'failed', 'process']);
     $recordOne = $query->where(['smsName' => 'sms_one', 'accountId' => $accountId])->orderBy(['createdAt' => SORT_DESC])->one();
     $recordTwo = $query->where(['smsName' => 'sms_two', 'accountId' => $accountId])->orderBy(['createdAt' => SORT_DESC])->one();
     $recordThree = $query->where(['smsName' => 'sms_three', 'accountId' => $accountId])->orderBy(['createdAt' => SORT_DESC])->one();
     $recordFour = $query->where(['smsName' => 'sms_four', 'accountId' => $accountId])->orderBy(['createdAt' => SORT_DESC])->one();
     unset($accountId, $query);
     return ['sms_one' => $recordOne, 'sms_two' => $recordTwo, 'sms_three' => $recordThree, 'sms_four' => $recordFour];
 }
Esempio n. 7
0
 public static function creatWinner($winnerArr, $recordId, $prizeName)
 {
     $winner = new EarlyBirdWinner();
     $winner->memberId = new \MongoId($winnerArr['id']);
     $winner->prizeLevel = $winnerArr['prizeLevel'];
     $winner->mobile = $winnerArr['mobile'];
     $winner->name = $winnerArr['name'];
     $winner->exchangeGoodsScore = $winnerArr['exchangeGoodsScore'];
     $winner->accountId = Token::getAccountId();
     $winner->createdAt = new \MongoDate();
     $winner->drawRecordId = $recordId;
     $winner->prizeName = $prizeName;
     $winner->save();
     unset($winner);
 }
Esempio n. 8
0
 public static function createBar($params)
 {
     $params['accountId'] = Token::getAccountId();
     if (empty($params['accountId'])) {
         throw new ServerErrorHttpException("Fail to get account's id");
     }
     unset($params['_id']);
     $bar = new ActivityBar();
     $params['startDate'] = MongodbUtil::msTimetamp2MongoDate($params['startDate']);
     $params['endDate'] = MongodbUtil::msTimetamp2MongoDate($params['endDate']);
     $params['probability'] = (int) $params['probability'];
     $bar->attributes = $params;
     if (!$bar->save()) {
         LogUtil::error(['message' => 'save activity-bar failed', 'error' => $bar->errors], 'activityBar');
         throw new ServerErrorHttpException('save activityBar failed');
     }
     return $bar['_id'];
 }
Esempio n. 9
0
 public static function getList($currentPage = 1, $pageSize = 10, $sort = [], $condition = [])
 {
     if (empty($sort)) {
         $sort = ['_id' => SORT_DESC];
     } else {
         foreach ($sort as $key => $value) {
             if ($value) {
                 $sort = [$key => SORT_DESC];
             } else {
                 $sort = [$key => SORT_ASC];
             }
         }
     }
     $offset = ($currentPage - 1) * $pageSize;
     $query = new Query();
     $datas = $query->from(self::collectionName())->select(self::attributes())->where(['accountId' => Token::getAccountId()])->andWhere($condition)->orderBy($sort)->offset($offset)->limit($pageSize)->all();
     return $datas;
 }
Esempio n. 10
0
 public static function createUser($params)
 {
     try {
         $result = true;
         $accountId = Token::getAccountId();
         if (empty($accountId)) {
             throw new ServerErrorHttpException("Fail to get account's id");
         }
         $params['accountId'] = $accountId;
         $user = new ActivityUser();
         $user->attributes = $params;
         if (!$user->save()) {
             LogUtil::error(['message' => 'save activity-user failed', 'error' => $user->errors], 'activityUser');
             $result = false;
         }
         return $result;
     } catch (\Exception $ex) {
         LogUtil::error(['message' => 'save activity-user failed', 'error' => $ex->getMessage()], 'activityUser');
         return false;
     }
 }
Esempio n. 11
0
 /**
  * Sync the stores data from wechat
  */
 public function actionSync()
 {
     $accountId = Token::getAccountId();
     $result = ['finished' => true];
     $account = Account::find()->select(['syncWechat'])->where(['_id' => $accountId, 'isDeleted' => Account::NOT_DELETED])->one();
     $wechat = Channel::getWechatByAccount($accountId, false);
     if (!empty($wechat)) {
         $unsyncWechat = array_diff($wechat, (array) $account->syncWechat);
         if (!empty($unsyncWechat)) {
             $args = ['accountId' => $accountId . '', 'channels' => $unsyncWechat, 'description' => 'Direct: Sync the stores data from wechat'];
             $token = Yii::$app->job->create('backend\\modules\\channel\\job\\StoreSync', $args);
             $result = ['finished' => false, 'token' => $token];
         }
     }
     return $result;
 }
Esempio n. 12
0
 public static function saveByCookbook($cookbook, $accountId = null, $admin = null)
 {
     if ($accountId == null) {
         $accountId = Token::getAccountId();
     }
     if ($admin == null) {
         $accessToken = Token::getToken();
         $userId = $accessToken->userId;
         $admin = User::findOne(['_id' => $userId]);
     }
     $queryCookingtype = new Query();
     $queryCookingtype->from('uhkklpCookingtype')->where(['accountId' => $accountId]);
     $cookingTypes = $queryCookingtype->all();
     if (isset($cookbook['category'])) {
         for ($j = 0; $j < count($cookbook['category']); $j++) {
             if (self::checkExist($accountId, $cookbook['category'][$j])) {
                 $cookingType = new CookingType();
                 $cookingType->name = $cookbook['category'][$j];
                 $cookingType->category = '標簽';
                 $cookingType->operator = $admin['name'];
                 $cookingType->accountId = $accountId;
                 $cookingType->save();
             }
         }
     }
     /*if (isset($cookbook['restaurantName']) && $cookbook['restaurantName'] != '' && self::checkExist($accountId, $cookbook['restaurantName'])) {
           $cookingType = new CookingType();
           $cookingType->name = $cookbook['restaurantName'];
           $cookingType->category = '餐廳';
           $cookingType->operator = $admin['name'];
           $cookingType->accountId = $accountId;
           $cookingType->save();
       }*/
     if (isset($cookbook['subCategory'])) {
         for ($j = 0; $j < count($cookbook['subCategory']); $j++) {
             if (self::checkExist($accountId, $cookbook['subCategory'][$j])) {
                 $cookingType = new CookingType();
                 $cookingType->name = $cookbook['subCategory'][$j];
                 $cookingType->category = '標簽';
                 $cookingType->operator = $admin['name'];
                 $cookingType->accountId = $accountId;
                 $cookingType->save();
             }
         }
     }
     if (isset($cookbook['tag'])) {
         for ($j = 0; $j < count($cookbook['tag']); $j++) {
             if (self::checkExist($accountId, $cookbook['tag'][$j])) {
                 $cookingType = new CookingType();
                 $cookingType->name = $cookbook['tag'][$j];
                 $cookingType->category = '標簽';
                 $cookingType->operator = $admin['name'];
                 $cookingType->accountId = $accountId;
                 $cookingType->save();
             }
         }
     }
     if (isset($cookbook['cuisineType'])) {
         for ($j = 0; $j < count($cookbook['cuisineType']); $j++) {
             if (self::checkExist($accountId, $cookbook['cuisineType'][$j])) {
                 $cookingType = new CookingType();
                 $cookingType->name = $cookbook['cuisineType'][$j];
                 $cookingType->category = '標簽';
                 $cookingType->operator = $admin['name'];
                 $cookingType->accountId = $accountId;
                 $cookingType->save();
             }
         }
     }
     return ['code' => 200, 'msg' => 'Update types success!'];
 }
Esempio n. 13
0
 public static function getDrawCount()
 {
     return self::find(['accountId' => Token::getAccountId()])->count();
 }
Esempio n. 14
0
 /**
  * Query all menu actions
  *
  * <b>Request Type</b>: GET<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/api/common/channel/menu-action<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for querying all menu actions.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *     "member": {
  *         "title": "channel_menu_member",
  *         "keycode": "USER_CENTER",
  *         "actionKey": "channel_menu_member_title",
  *         "msgType": "URL",
  *         "content": "http://wm.com/api/mobile/member?appId=wx2df5d7e4ce8a04ca&channelId=54d9c155e4b0abe717853ee1"
  *     },
  *     "helpdesk": {
  *         "title": "helpdesk",
  *         "keycode": "CUSTOMER_SERVICE",
  *         "actionKey": "channel_menu_helpdesk_title",
  *         "msgType": "",
  *         "content": false
  *     }
  * }
  * </pre>
  */
 public function actionMenuAction()
 {
     $channelId = $this->getQuery('channelId');
     $accountId = Token::getAccountId();
     return Yii::$app->channelMenu->getMenuActions($channelId, $accountId);
 }
Esempio n. 15
0
 public static function getActivityByName($name)
 {
     $accountId = Token::getAccountId();
     $activity = Activity::findOne(['name' => $name, 'accountId' => $accountId]);
     return $activity;
 }
Esempio n. 16
0
 private function renderPage($page, $useRiot = false, $injectWechatJS = true, $socialWebviewOnly = true)
 {
     $actionName = $this->action->id;
     $params = Yii::$app->request->get();
     $this->registerCommonResource($page, $useRiot);
     if ($injectWechatJS) {
         $sdk = Yii::$app->wechatSdk;
         $sdk->refererUrl = $sdk->refererDomain . substr(Yii::$app->request->getUrl(), 1);
         $signPackage = json_encode($sdk->getSignPackage());
         $logObj = json_encode(['url' => Yii::$app->params['frontendTrackUrl'], 'env' => Yii::$app->params['currentEnv']]);
         $js = "var options={$signPackage}, page='{$page}';window.trackerLog={$logObj};";
         $this->view->registerJs($js, View::POS_HEAD);
         if (empty($params['debug'])) {
             $this->registerBodyJsFile(self::BUILD_PATH . 'handlewechat.js?v=' . Yii::$app->params['buildVersion']);
         }
     }
     $socialWebviewOnly = $socialWebviewOnly && empty($params['debug']);
     if ($socialWebviewOnly && !BrowserUtil::isWeixinBrowser() && !BrowserUtil::isWeiboBrower() && !BrowserUtil::isAliBrower()) {
         $this->view->js = null;
         $this->view->jsFiles = null;
         $this->view->cssFiles = null;
         $this->view->registerCssFile(self::BUILD_PATH . 'common/app.css');
         return $this->render('common/error');
     } else {
         //Member active record
         $accessToken = $this->getAccessToken();
         if (!empty($params['memberId']) && !empty($accessToken)) {
             $memberId = new \MongoId($params['memberId']);
             $accountId = Token::getAccountId($accessToken);
             MemberLogs::record($memberId, $accountId, MemberLogs::OPERATION_VIEWED);
         }
         return $this->render($actionName . '/' . $page);
     }
 }
Esempio n. 17
0
 public static function createSmsJob($condition, $operator, $smsTag)
 {
     $accountId = Token::getAccountId();
     switch ($smsTag) {
         case 'sms_one':
             $smsTemplate = self::EARLY_BIRD_ONE_TEMPLATE;
             break;
         case 'sms_two':
             $smsTemplate = self::EARLY_BIRD_TWO_TEMPLATE;
             break;
         case 'sms_three':
             $smsTemplate = self::EARLY_BIRD_THREE_TEMPLATE;
             break;
         case 'sms_four':
             $smsTemplate = self::EARLY_BIRD_FOUR_TEMPLATE;
             break;
         default:
             break;
     }
     $recordId = EarlyBirdSmsRecord::createSmsRecord($operator, $smsTag, $smsTemplate);
     $count = 0;
     if (is_bool($recordId) && !$recordId) {
         throw new ServerErrorHttpException("發送失敗,請刷新頁面重試!");
     }
     if (!array_key_exists('accountId', $condition)) {
         $condition = array_merge($condition, ['accountId' => $accountId]);
     }
     if ($smsTag == 'sms_four') {
         $count = count(self::getMemberCanDraw($condition));
         // get發送總量
     } else {
         $count = Member::find()->where($condition)->count();
     }
     $smsRecord = EarlyBirdSmsRecord::findOne($recordId);
     // set發送總量
     $smsRecord->total = $count;
     $smsRecord->save();
     unset($smsRecord);
     $args = ['condition' => serialize($condition), 'smsTag' => $smsTag, 'smsRecord' => (string) $recordId];
     $jobId = Yii::$app->job->create('backend\\modules\\uhkklp\\job\\EarlyBirdSendSms', $args);
     if (!empty($jobId)) {
         return ['smsRecordId' => (string) $recordId, 'count' => $count];
     } else {
         throw new ServerErrorHttpException("發送失敗,請刷新頁面重試!");
     }
 }
Esempio n. 18
0
 public function actionStatsMenuHits()
 {
     $query = $this->getQuery();
     $openId = $query['openId'];
     $channelId = $query['channelId'];
     $page = $query['page'];
     $perPage = $query['per-page'];
     $orderBy = $this->getQuery('orderby');
     $orderKey = $orderValue = '';
     $accountId = Token::getAccountId();
     if (empty($openId) || empty($channelId)) {
         throw new BadRequestHttpException(Yii::t('common', 'parameters_missing'));
     }
     if (!empty($orderBy)) {
         $orderBy = Json::decode($orderBy, true);
         foreach ($orderBy as $key => $value) {
             $orderKey = $key;
             if ('asc' === strtolower($value)) {
                 $orderValue = SORT_ASC;
             } else {
                 $orderValue = SORT_DESC;
             }
         }
     }
     // Get all menus.
     $menus = Yii::$app->weConnect->getMenus($channelId);
     $menuItems = $this->_transformMenus($menus);
     // Get every menus count.
     $result = Yii::$app->weConnect->statsMenusHits($openId, $channelId);
     $items = $this->_transformStatsMenuHits($channelId, $result, $menuItems);
     // Paging
     if (!empty($orderKey) && !empty($orderValue)) {
         ArrayHelper::multisort($items, $orderKey, $orderValue);
     }
     $offset = ($page - 1) * $perPage;
     $message = array_slice($items, $offset, $perPage);
     return ['items' => empty($message) ? [] : $message, '_meta' => ['totalCount' => count($items), 'pageCount' => ceil(count($items) / $perPage), 'currentPage' => $page, 'perPage' => $perPage]];
 }