public function actionDelete($id)
 {
     if (empty($id)) {
         throw new BadRequestHttpException('activityId params missing');
     }
     $bar = ActivityBar::findOne(new \mongoId($id));
     $bar->isDeleted = true;
     if (!$bar->save()) {
         throw new ServerErrorHttpException('Fail to delete activity');
     }
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200];
 }
 private function _prizeDraw($activityId, $mobile, $deviceId)
 {
     $bar = ActivityBar::findOne($activityId);
     $probalility = $bar->probability;
     //未中奖几率
     $drawArr = array();
     //抽奖阵列
     // 加入中奖的比率
     $i = 100 - (int) $probalility;
     while ($i > 0) {
         $drawArr[] = 'Y';
         $i--;
     }
     // 加入沒中奖的比率
     $i = (int) $probalility;
     while ($i > 0) {
         $drawArr[] = 'N';
         $i--;
     }
     shuffle($drawArr);
     // 抽奖 (随机打乱阵列)
     $hasPrize = $drawArr[0];
     // 抽出其中一个看是否中奖
     $resultPrize = null;
     $thankPrize = array('name' => "銘謝惠顧", 'prizeImgUrl' => "", '_id' => 'thanks');
     //给中奖用户抽奖品
     if ($hasPrize == 'Y') {
         $prizeList = ActivityPrize::getValidPrizesByActivityId($activityId);
         if (!empty($prizeList)) {
             $prizeArr = array();
             //奖品阵列
             $today = strtotime(date('Y-m-d H:i:s'));
             $todayMstime = MongodbUtil::MongoDate2msTimeStamp(new \MongoDate($today));
             foreach ($prizeList as $prize) {
                 if ($prize['type'] == 'topPrize') {
                     if ($prize['startDate'] <= $todayMstime and $todayMstime < $prize['endDate']) {
                         $prizeArr[] = $prize;
                     }
                 } else {
                     $prizeArr[] = $prize;
                 }
             }
             unset($prizeList);
             shuffle($prizeArr);
             $resultPrize = $prizeArr[0];
         } else {
             //奖项列表为空,改发鸣谢惠顾
             $hasPrize = 'N';
             $resultPrize = $thankPrize;
         }
     } else {
         $resultPrize = $thankPrize;
     }
     //判断奖品数量是否足够
     $activityPrize = ActivityPrize::findOne($resultPrize['_id']);
     if (!empty($activityPrize)) {
         $quantity = $activityPrize->quantity - 1;
         $activityPrize->quantity = $quantity;
         if ($quantity >= 0) {
             if (!$activityPrize->save()) {
                 //更新奖品数量(减1), 失敗,改发鸣谢惠顾
                 $hasPrize = 'N';
                 $resultPrize = $thankPrize;
             }
         } else {
             //奖品不够,改发鸣谢惠顾
             $hasPrize = 'N';
             $resultPrize = $thankPrize;
         }
     }
     if ($resultPrize['_id'] != 'thanks' and $resultPrize['isPoint'] == 'Y') {
         //add points
         try {
             $service = Yii::$app->service;
             $service->accountId = $this->getAccountId();
             $member = Member::getByMobile($mobile, $this->getAccountId());
             $rewardResult = $service->member->rewardScore([$member['_id']], $resultPrize['points'], '拉霸活動中獎');
             if (is_bool($rewardResult) && $rewardResult) {
                 $resultPrize['name'] = $resultPrize['name'] . '(已發獎' . $resultPrize['points'] . '積分)';
             } else {
                 $hasPrize = 'N';
                 $resultPrize = $thankPrize;
                 //Failed,改发鸣谢惠顾
             }
             unset($service, $member, $rewardResult);
         } catch (Exception $e) {
             $hasPrize = 'N';
             $resultPrize = $thankPrize;
             LogUtil::error(['message' => '获奖者加积分捕获未知错误', 'result' => '改发鸣谢惠顾', 'mobile' => $mobile, 'exception' => $e], 'activitybar');
         }
     }
     //save in DB
     $params = array('activityId' => $activityId, 'prizeId' => $resultPrize['_id'], 'deviceId' => $deviceId, 'mobile' => $mobile, 'prizeContent' => $resultPrize['name']);
     $isOK = ActivityUser::createUser($params);
     if (!$isOK) {
         $hasPrize = 'N';
         $resultPrize = $thankPrize;
     }
     $result = ['hasPrize' => $hasPrize, 'prizeName' => $resultPrize['name'], 'prizeImage' => $resultPrize['prizeImgUrl']];
     unset($thankPrize, $resultPrize, $params);
     return ['code' => 200, 'msg' => 'ok', 'result' => $result];
 }
 public static function getCountByCondition($condition = [])
 {
     return ActivityBar::find()->where($condition)->count();
 }