/** * 判断活动是否有效 * * @param int $activity_id * @return array */ public static function check_activity_is_active($activity_id) { $activity_info = Bll_Cms_BrokerActivity::get_broker_activity_info_by_id($activity_id); if (false === $activity_info || empty($activity_info)) { return array('status' => -__LINE__, 'message' => '活动不存在', 'debug' => __CLASS__); } $iCurrentTimestamp = time(); if ($activity_info['start_time'] > $iCurrentTimestamp || $activity_info['end_time'] < $iCurrentTimestamp) { return array('status' => -__LINE__, 'message' => '活动未开始或者已经结束', 'debug' => __CLASS__); } return array('status' => 0); }
/** * 积分兑换 * * @param array $params * @return array */ private function ajax_exchange($params) { $request = APF::get_instance()->get_request(); $broker_id = $request->getBrokerId(); if (!isset($params['aid']) || empty($params['aid']) || !isset($params['prize_id']) || empty($params['prize_id']) || !isset($params['pro_id']) || empty($params['pro_id'])) { return array('status' => -99, 'message' => '参数错误', 'debug' => __CLASS__); } /** 判断活动是否有效 */ $activity_id = $params['aid']; $activity_check = Bll_Cms_BrokerActivity::check_activity_is_active($activity_id); if ($activity_check['status'] != 0) { return $activity_check; } /** 判断奖品是否可以兑换 */ $prize_id = $params['prize_id']; $periods_no = $params['pro_id']; $exchange_check = Bll_Cms_ExchangeProperty::check_exchange_is_valid($broker_id, $activity_id, $prize_id, $periods_no); if ($exchange_check['status'] != 0) { return $exchange_check; } $consume = $exchange_check['exchangeConfig']['consume']; $times_limit = $exchange_check['exchangeConfig']['times_limit']; /** 判断经纪人可兑换资源是否可以兑换奖品 */ $userPropertyCheck = Bll_Cms_ActivityUserProperty::check_exchange_is_valid($broker_id, $activity_id, $consume); if ($userPropertyCheck['status'] != 0) { return $userPropertyCheck; } /** 判断经纪人每期可以兑换的次数是否达到上限 */ $exchangeTimesCheck = Bll_Cms_LuckyDrawTimes::check_exchange_times_is_valid($activity_id, $broker_id, $periods_no, $times_limit); if ($exchangeTimesCheck['status'] != 0) { return $exchangeTimesCheck; } /** 开始兑换奖品 */ $exchange = Bll_Cms_ExchangeProperty::exchange_property($broker_id, $activity_id, $prize_id, $periods_no, $consume, $times_limit); if ($exchange['status'] != 0) { return $exchange; } /** $aid, $broker_id, $prize_id, $user_name, $phone, $title, $consume, $property_old, $ip */ Bll_Cms_ActivityComsumePropertyLog::add_exchange_log(1, $broker_id, $prize_id, $userPropertyCheck['userProperty']['user_name'], $userPropertyCheck['userProperty']['phone'], $exchange_check['exchangeConfig']['prize_title'], $consume, $userPropertyCheck['userProperty']['propertys'], $request->get_client_ip()); $exchange_property = Bll_Cms_ExchangeProperty::get_exchange_property_config($activity_id, $prize_id, $periods_no); $exchange['prize_title'] = $exchange_property['prize_title']; $exchange['leavings'] = $exchange_property['leavings']; $exchange['consume'] = $exchange_property['consume']; $exchange['property'] = $userPropertyCheck['userProperty']['propertys'] - $exchange_property['consume']; return $exchange; }