| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 | <?phpnamespace Cas\Module;use KIF\Verify;use Cas\Dao\LotteryEvents;use KIF\Core\Config;use Cas\Dao\LotteryPrize;use KIF\Cache\Memcached;use KIF\Dao\SqlHelper;use Cas\Dao\LotteryPrizeVirtualData;use Cas\Dao\LotteryData;use Cas\Module\LotteryLog;use Cas\Dao\LotteryEventsLog as DLog;use Cas\Module\Lottery;use Cas\Dao\LotteryEventsLetters;use Cas\Dao\LotteryEventsUserLetters;use Cas\Dao\LotteryEventsUserPrizeData;use KIF\Data\ResultWrapper;use KIF\Core\Request;use Cas\Dao\LotteryEventsVote;use Cas\Dao\LotteryEventsVoteUserLog;use Cas\Dao\LotteryEventsTry;use Cas\Dao\LotteryUserExpress;use KIF\Dao\AbstractDao;/** *	 *  刮刮卡 [模型] * * @author lihuanchun */class LotteryEventsTypeScratch  {		private $uid;	private $events_id;	private $objMlottery;	private $objMLotteryLog;	private $thisTime;	private $objMLotteryEventsLimitations;			public function __construct($uid=null , $events_id=null ) {		$this->uid = $uid;		$this->events_id = $events_id;		$this->objMlottery = new Lottery();		$this->objMLotteryLog = new LotteryLog($uid,$events_id);		$this->thisTime = time();		$this->objMLotteryEventsLimitations = new LotteryEventsLimitations();		$this->objDLotteryUserExpress = new LotteryUserExpress();			}			/**	 * 获取当前“刮刮卡”信息	 */	public function getEventsData(){		return $this->objMlottery->getOneLotteryEventsAndPrize($this->events_id);	}			/**	 * 刮奖 操作	 */	public function userScratch(){				$eventsData = $this->objMlottery->getOneLotteryEvents($this->events_id);		# 活动是否开始				if($this->thisTime < $eventsData['begin_time'] || $this->thisTime > $eventsData['end_time']){			return ResultWrapper::fail('当前活动未开始');		}				# 活动限制		if(!$this->objMLotteryEventsLimitations->ckEventRestrictions($this->uid,Request::ip(), $this->events_id)){			return ResultWrapper::fail('您不可以重复参与哦!');		}								# 抽奖		$objMLotteryDraw = new LotteryDraw($this->uid,$this->events_id);		$lotteryDataId = $objMLotteryDraw -> verifyPrize();				// 测试		//$lotteryDataId = 191;				if(!$lotteryDataId){			#######用户行为记录########			#用户未中奖			$other = array(				'奖品:' => '未抽中'			);			$this->objMLotteryLog ->addUserParticipateLog($other);			#########################			return ResultWrapper::fail('没有中奖');		}				# 如果是默认此礼品用户未收取		$info = array(			'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_FALSE,		);		$this->objMlottery->upOneLetteryData($info,array('id' => $lotteryDataId));				# 获奖数据		$data = $this->objMlottery-> getOneLotteryData($lotteryDataId);				#######用户行为记录########		#用户抽中奖品		$other = array(		'奖品:' => $data['run_time_data']['prize'][$data['prize_id']]['prize_name']		);		$this->objMLotteryLog ->addUserParticipateLog($other);		#########################				return ResultWrapper::success($data);	}			/**	 * 用户领取此中奖数据操作 	 */	public function userReceive($lotteryDataId){				# 记录参与日志		$other = array();		$this->objMLotteryLog ->addLog(DLog::LOG_TYPE_PARTICIPATION, $other);				# 记录用户		$this->objMLotteryEventsLimitations->setUserEventNum($this->uid, $this->events_id); // 记录用户参与UID(天)		$this->objMLotteryEventsLimitations->setIpEventNum(Request::ip(), $this->events_id);// 记录用户参与IP(天)		$this->objMLotteryEventsLimitations->setUserParticipationNum($this->uid, $this->events_id); // 记录用户参与次数						$info = array(			'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_TRUE,		);		$this->objMlottery->upOneLetteryData($info,array('id' => $lotteryDataId));		return ResultWrapper::success('领取成功');	}							/**	 * 判断奖品是否需要快递	 * 需要用户 填写收货信息	 */	public function userExpress($lotteryDataId,$user_name,$phone,$address){				$objDLotteryData = new LotteryData();		$tableInfo = array(			'user_name' => $user_name,			'phone' => $phone,			'address' => $address		);				$objDLotteryData -> update($tableInfo, array('id' => $lotteryDataId));				$info = array(			'uid' => $this->uid,			'user_name' => $user_name,			'phone' => $phone,			'address' => $address		);		$this->objDLotteryUserExpress -> add($info,AbstractDao::PARAM_CREATE_ACTION_REPLACE);	}			}
 |