/** * check member whether to fit with the condition of campaign, * if the member fit with the condition,then this function will return the campaign * otherwise it will return a empty array * @param $campaign, array, campaign info * @param $member , array, member info * @param $createReMemberCampaign, boolean, if the value is true, this function will create a record * in the table called ReMemberCampaign.when you check the condition for the campaign and you do not want to * exchange code,this value you can pass false */ public static function selectCampaign($campaign, $member, $params, $createReMemberCampaign = true) { //record fail message $msg = ''; $accountId = $member->accountId; //check the total member to take part in campaign $memberIds = CampaignLog::getCollection()->distinct("member.id", ['campaignId' => $campaign->_id]); if ($createReMemberCampaign) { self::createReMemberCampaign($campaign, $member, $accountId); } else { //check the limiter and participantCount $num = CampaignLog::count(['campaignId' => $campaign->_id, 'member.id' => $member->_id]); //check campaign limit times $result = self::checkCampaignLimitTimes($campaign, $member, $num); if (empty($result['campaign'])) { return $result; } //check the limit time in advance whnen check the limit in offline $result = self::preCheckCampaignLimitTimes($campaign, $member, $num); if (empty($result['campaign'])) { return $result; } //check the campaign participant count $result = self::checkCampaignParticipantCount($campaign, $member, $memberIds); if (empty($result['campaign'])) { return $result; } } // check the tags of member $result = self::checkCampaignMemberTag($campaign, $member); if (empty($result['campaign'])) { return $result; } // check the channels of member $result = self::checkCampaignChannel($campaign, $member, $params); if (empty($result['campaign'])) { return $result; } // check the experice $result = self::checkMemberExperice2Campaign($campaign, $member); if (empty($result['campaign'])) { return $result; } //when user redeem the code.we need operate the participate and limit for per-person if ($createReMemberCampaign) { $result = self::recordCampaignLimit($campaign, $member, $accountId, $memberIds); if (!empty($result['campaign'])) { return $result; } } return ['campaign' => $campaign, 'status' => self::CODE_STATUS_VALID, 'message' => 'code is vaild']; }