示例#1
0
 /**
  * 中奖列表
  * @return \Zend\Http\Response|ViewModel
  */
 public function winListAction()
 {
     $view = new ViewModel();
     $activityId = $this->getParam('activityId', 0);
     $page = $this->getEvent()->getRouteMatch()->getParam('page', 1);
     $size = $this->getEvent()->getRouteMatch()->getParam('size', 10);
     $paginator = $this->awardModel->getWinList($activityId, $page, $size);
     $activities = array();
     foreach ($paginator as $win) {
         $activities[$win->id] = $this->activityModel->getById($win->activityId);
     }
     $view->setVariables(array('paginator' => $paginator, 'activities' => $activities, 'activityId' => $activityId, 'page' => $page));
     return $view;
 }
示例#2
0
 /**
  * ajax获取随机的抽奖奖项
  * 从长度为100的数组中随机一个值
  */
 public function RandAwardAction()
 {
     $activityId = $this->getParam('activityId', null);
     $activity = $this->activityModel->getById($activityId);
     $now = time();
     if ($activity->endTime->getTimestamp() < $now || $now < $activity->startTime->getTimestamp()) {
         return new UnifyJsonModel(array(0));
     }
     $user = $this->userModel->getById($this->identity()->id);
     $is_lucky = 0;
     switch ($activityId) {
         case 2:
             $is_lucky = $user->is_luck_draw_1;
             break;
         case 3:
             $is_lucky = $user->is_luck_draw_2;
             break;
         case 4:
             $is_lucky = $user->is_luck_draw_3;
             break;
         case 6:
             $is_lucky = $user->is_luck_draw_4;
             break;
     }
     if ($is_lucky == 0) {
         return new ErrorJsonModel(1022, '抱歉!您不满足参与该活动的条件');
     }
     $existed = $this->awardModel->isWin($activityId, $this->identity()->id);
     if (!empty($existed)) {
         return new ErrorJsonModel(1021, '对不起!您已经参与过该活动');
     }
     //随机奖项
     $items = $this->awardModel->getList($activityId);
     $randArr = array();
     foreach ($items as $item) {
         if ($item->count != 0) {
             $randArr[] = $item->goods->id;
         }
     }
     if (count($randArr) == 0) {
         //没有中奖
         $randArr[] = -1;
         $randArr[] = -2;
         $randArr[] = -3;
     }
     $r = rand(0, count($randArr) - 1);
     $goodsId = $randArr[$r];
     if ($goodsId > 0) {
         //奖项数量-1
         $item = $this->awardModel->getByActivityIdAndGoodsId($activityId, $goodsId);
         $item->count -= 1;
         $this->awardModel->save($item);
         //添加到中奖列表
         $win = new WinEntity();
         $win->item = $item;
         $win->user = $this->identity()->id;
         $win->activityId = $activityId;
         $this->awardModel->saveWin($win);
         $data = array('first' => '恭喜您参与的活动中奖了!', 'keyword1' => '幸运转盘大抽奖', 'keyword2' => $item->goods->name, 'remark' => '感谢您的参与。');
         $tplId = WechatMessageEntity::TEMPLATE_LUCKY_DRAW;
         $this->wechat->sendTemplateMessage($user->open_id, $tplId, $data);
     } else {
         //添加到中奖列表
         $win = new WinEntity();
         $win->item = null;
         $win->activityId = $activityId;
         $win->user = $this->identity()->id;
         $this->awardModel->saveWin($win);
     }
     return new UnifyJsonModel(array($goodsId));
 }