コード例 #1
0
ファイル: Member.php プロジェクト: timelessmemory/uhkklp
 public static function getCondition($params, $accountId)
 {
     $comma = ',';
     $condition = ['accountId' => $accountId, 'isDeleted' => self::NOT_DELETED];
     if (!empty($params['accounts'])) {
         $accounts = explode($comma, $params['accounts']);
         $ids = [];
         $origins = [];
         foreach ($accounts as $account) {
             if (self::MONGO_ID_LENGTH == strlen($account)) {
                 $ids[] = $account;
             } else {
                 $origins[] = $account;
             }
         }
         $channelCondition = ['socialAccountId' => ['$in' => $ids], 'origin' => ['$in' => [self::WECHAT, self::WEIBO, self::ALIPAY]]];
         if (count($origins) > 0) {
             $newCondition = ['$or' => [$channelCondition, ['origin' => ['$in' => $origins]]]];
             $channelCondition = $newCondition;
         }
         $condition = array_merge($condition, $channelCondition);
     }
     $cardStatusCondition = [];
     if (!empty($params['cardExpiredAt'])) {
         $cardStatusCondition = $params['cardExpiredAt'];
     }
     if (!empty($params['cards'])) {
         $cards = explode($comma, $params['cards']);
         $cardIds = [];
         foreach ($cards as $card) {
             $cardIds[] = new \MongoId($card);
         }
         $cards = ['$in' => $cardIds];
         $condition = array_merge($condition, ['cardId' => $cards]);
     }
     if (!empty($params['tags'])) {
         $tags = explode($comma, $params['tags']);
         $tags = ['$all' => $tags];
         $condition = array_merge($condition, ['tags' => $tags]);
     }
     $searchCondition = [];
     if (isset($params['searchKey']) && $params['searchKey'] != '') {
         $key = $params['searchKey'];
         //get the type of condition from search key
         $searchCondition = self::createCondition($key, $accountId);
     }
     // After run new MongoDate, The time can lost accuracy, so it will plus 1 or subtract 1.
     if (!empty($params['startTime'])) {
         $startTime = TimeUtil::ms2sTime($params['startTime']) - 1;
         $condition['createdAt']['$gt'] = new \MongoDate($startTime);
     }
     if (!empty($params['endTime'])) {
         $endTime = TimeUtil::ms2sTime($params['endTime']) + 1;
         $condition['createdAt']['$lt'] = new \MongoDate($endTime);
     }
     if (!empty($params['gender'])) {
         $gender = ['properties' => ['$elemMatch' => ['name' => self::DEFAULT_PROPERTIES_GENDER, 'value' => strtolower($params['gender'])]]];
         $condition = array_merge($condition, $gender);
     }
     foreach ($params as $key => $value) {
         if (!empty($value)) {
             if ($key == 'country' || $key == 'province' || $key == 'city') {
                 $key = 'location.' . $key;
                 $condition = array_merge($condition, [$key => $value]);
             }
         }
     }
     //memberId
     if (!empty($params['memberId'])) {
         $memberIds = explode(',', $params['memberId']);
         $memberIds = MongodbUtil::toMongoIdList($memberIds);
         $condition = array_merge($condition, ['_id' => ['$in' => $memberIds]]);
     }
     return ['condition' => $condition, 'cardStatusCondition' => $cardStatusCondition, 'searchCondition' => $searchCondition];
 }
コード例 #2
0
ファイル: Campaign.php プロジェクト: timelessmemory/uhkklp
 public function validatePromotion($attribute)
 {
     if ($attribute !== 'promotion') {
         return true;
     }
     $promotion = $this->{$attribute};
     if (empty($promotion['type'])) {
         throw new BadRequestHttpException('missing promotion type');
     }
     if (empty($promotion['data']) || !is_array($promotion['data'])) {
         throw new InvalidParameterException(['campaignProducts' => \Yii::t('product', 'product_required')]);
     }
     $promotion['data'] = MongodbUtil::toMongoIdList($promotion['data']);
     $productCount = Product::count(['_id' => ['$in' => $promotion['data']], 'isBindCode' => true]);
     if ($productCount != count($promotion['data'])) {
         throw new InvalidParameterException(['promotionProduct' => \Yii::t('product', 'error_promotion_product')]);
     } else {
         $this->{$attribute} = $promotion;
     }
     if (!in_array($promotion['products'], [self::TYPE_GIFT_PRODUCT_FIRST, self::TYPE_GIFT_PRODUCT_UNLIMITED]) && !is_array($promotion['products'])) {
         throw new InvalidParameterException(['promotionCampaigns' => \Yii::t('product', 'invalid_gift_campaigns')]);
     }
     if (is_array($promotion['products'])) {
         $promotion['products'] = MongodbUtil::toMongoIdList($promotion['products']);
         if (count($promotion['products']) == Product::count(['_id' => ['$in' => $promotion['products']]])) {
             $this->{$attribute} = $promotion;
         } else {
             throw new BadRequestHttpException('error products');
         }
     }
     if (!is_array($promotion['tags'])) {
         throw new BadRequestHttpException('tags must be array');
     }
     if (!is_array($promotion['channels'])) {
         throw new BadRequestHttpException('channels must be array');
     }
     if (empty($promotion['gift']) || !is_array($promotion['gift'])) {
         return new BadRequestHttpException('gift must be array');
     }
     $gift = GiftValidator::validateGift($promotion['gift']);
     $promotion['gift'] = $gift;
     $this->{$attribute} = $promotion;
 }
コード例 #3
0
 public function actionNames()
 {
     $ids = $this->getQuery('campaignIds');
     if (empty($ids)) {
         return [];
     }
     $ids = explode(',', $ids);
     $campaignIds = MongodbUtil::toMongoIdList($ids);
     $campaigns = Campaign::getByIds($campaignIds);
     $names = [];
     foreach ($campaigns as $campaign) {
         $names[] = $campaign->name;
     }
     return $names;
 }