public function perform()
 {
     $args = $this->args;
     if (empty($args['condition'])) {
         ResqueUtil::log(['status' => 'fail to send early bird sms', 'message' => 'missing params', 'args' => $args]);
         LogUtil::error(['message' => 'EarlyBirdSms發送失敗', 'message' => 'missing params in job', 'args' => $args], 'earlybird');
     }
     $condition = unserialize($args['condition']);
     $smsRecord = new \MongoId($args['smsRecord']);
     if ($args['smsTag'] == 'sms_four') {
         EarlybirdSmsUtil::sendSmsByExchangeGoodsScore($condition, $args['smsTag'], $smsRecord);
     } else {
         EarlybirdSmsUtil::sendSmsBycondition($condition, $args['smsTag'], $smsRecord);
     }
 }
 public function actionGetTestSms()
 {
     $smsTag = $this->getQuery('smsTag');
     $accountId = $this->getAccountId();
     if (empty($smsTag)) {
         throw new BadRequestHttpException('param is missing.(smsTag)');
     }
     $member = Member::getByMobile(EarlybirdSmsUtil::MOBILE_FOR_TEST);
     $sms = EarlybirdSmsUtil::getSms($member, $smsTag, $accountId);
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if (empty($member)) {
         return ['code' => 1000];
     }
     return ['code' => 200, 'sms' => $sms];
 }
 private function preProcessDrawMembers($condition, $accountId)
 {
     $rows = array();
     $scores = EarlybirdSmsUtil::getExchangeGoodsScore($condition['startDate'], $condition['endDate'], $accountId);
     asort($scores);
     foreach ($scores as $key => $value) {
         $row = array();
         if (abs($value) >= $condition['pointsThree']) {
             $member = Member::findByPk(new \MongoId($key));
             if (!$member->isDeleted) {
                 $row['id'] = $key;
                 $row['exchangeGoodsScore'] = abs($value);
                 $row['cardNumber'] = $member->cardNumber;
                 //拿到符合一等奖条件的人
                 if (abs($value) >= $condition['pointsOne']) {
                     //eg: points>=2000
                     $row['prizeName'] = $condition['prizeNameOne'];
                     $row['prizeLevel'] = '一等獎資格';
                 }
                 //拿到符合二等奖条件的人
                 if (abs($value) < $condition['pointsOne'] && abs($value) >= $condition['pointsTwo']) {
                     //eg: 1000<=points<2000
                     $row['prizeName'] = $condition['prizeNameTwo'];
                     $row['prizeLevel'] = '二等獎資格';
                 }
                 //拿到符合三等奖条件的人
                 if (abs($value) < $condition['pointsTwo'] && abs($value) >= $condition['pointsThree']) {
                     //eg: 200<=points<1000
                     $row['prizeName'] = $condition['prizeNameThree'];
                     $row['prizeLevel'] = '三等獎資格';
                 }
                 if (!empty($member->properties)) {
                     foreach ($member->properties as $property) {
                         if ($property['name'] == 'tel') {
                             $row['mobile'] = "'" . $property['value'];
                         }
                         if ($property['name'] == 'name') {
                             $row['name'] = $property['value'];
                         }
                     }
                 }
             }
         }
         $rows[] = $row;
         unset($row, $member);
     }
     return $rows;
 }
 public function actionGetDrawTestSms()
 {
     $params = $this->getQuery();
     if (empty($params) || count($params) < 8) {
         throw new BadRequestHttpException('params are missing');
     }
     $member = Member::getByMobile(EarlybirdSmsUtil::MOBILE_FOR_TEST);
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if (empty($member)) {
         return ['code' => 1000];
     }
     $condition = array_merge($params, ['accountId' => $this->getAccountId()]);
     $smsArr = EarlybirdSmsUtil::getSmsForMemberCanDraw($condition);
     $testSms = array();
     foreach ($smsArr as $sms) {
         if (!empty($sms) && $sms['mobile'] == EarlybirdSmsUtil::MOBILE_FOR_TEST) {
             $testSms['mobile'] = $sms['mobile'];
             $testSms['smsContent'] = $sms['content'];
         }
     }
     if (empty($testSms)) {
         return ['code' => 2000];
         //测试号码不满足抽奖条件
     }
     return ['code' => 200, 'sms' => $testSms];
 }