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); } }