Esempio n. 1
0
 /**
  * 记录分享的用户
  */
 public function logShareAction()
 {
     $user = $this->authentication()->getIdentity();
     if (!$user) {
         //如果用户不存在,则说明是普通人转发,不记录任消息
         return new UnifyJsonModel();
     }
     $activityId = $this->getParam('activityId', false);
     if (!$activityId) {
         return new UnifyJsonModel();
     }
     $share = new ShareEntity();
     $share->openid = $user->open_id;
     $share->user = $user->id;
     $share->activityId = $activityId;
     if (!$this->share->getByActivityIdAndUserId($activityId, $user->id)) {
         $this->share->save($share);
         //send share message
         $time_str = date('Y-m-d H:i');
         $data = array('first' => '活动分享通知', 'keyword1' => '暖心活动分享', 'keyword2' => "{$time_str}", 'keyword3' => '完成', 'remark' => '敬爱的车主,恭喜您成功完成“暖心计划”首个神秘任务!我们将会为您寄出观致汽车暖心礼包。为便于礼物顺利到达您的手中,请务必核对手机首次注册时所填写的地址是否正确。如有变动,可联系观致小Q进行更改。再次感谢您对观致汽车“暖心计划”的支持,祝您生活愉快。');
         $tplId = WechatMessageEntity::TEMPLATE_FINISH_SHARE;
         $this->wechat->sendTemplateMessage($user->open_id, $tplId, $data);
     }
     return new UnifyJsonModel();
 }
Esempio n. 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));
 }