public function createUserAction() { $user = new UserEntity(); $user->username = '******'; $user->mobile = '18989898989'; $this->userModel->createUser($user); }
/** * */ public function huanyingxinAction() { //自动登陆 $request = $this->getRequest(); if (parent::isWeixin() && !$request->isPost()) { $code = $this->getParam('code', false); if (!$code) { $redirectUrl = $this->wechat->getOauthRedirect('http://' . $_SERVER['SERVER_NAME'] . '/test_qoros/index/huanyingxin'); return $this->redirect()->toUrl($redirectUrl); } $tokenData = $this->wechat->getOauthData(); $user = $this->userModel->getByOpenId($tokenData['openid']); if ($user) { $result = $this->login($user->mobile, null, false); if ($result->getCode() == Result::SUCCESS && $user->username != $user->openid) { // return $this->redirect()->toUrl('/test_qoros'); } } } $view = new ViewModel(); // 注意 URL 一定要动态获取,不能 hardcode. $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://"; $href = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $jsSign = $this->wechat->getJsSign($href); $url = 'http://' . $_SERVER['HTTP_HOST'] . '/test_qoros/img/share_image.png'; $view->setVariables(array('jsSign' => $jsSign, 'url' => $url)); return $view; }
/** * 检查用户是否登陆过 */ public function checkUserLogin($openId) { try { // if(DW_ENV_DEBUG){ //测试环境没有unionid $userOauth = $this->userModel->getByOpenId($openId); // }else{ // $userInfo = $this->wechat->getUserInfo($openId); // $userOauth = $this->userModel->getUserOauthByUnionIdAndVender($userInfo['unionid'],UserOauthEntity::VENDER_WECHAT); // } if (!$userOauth) { //提示用户 去绑定帐号 $rst = $this->wechat->textReply('您好,继续其他操作请先绑定账号:' . 'http://' . $_SERVER['SERVER_NAME'] . '/user/bind'); return false; } else { //如果用户存在,则直接去登陆一下 } } catch (\Exception $e) { $this->wechat->log($e->getMessage()); } return true; }
/** * 导入用户 * @author bzhang */ public function importUserAction() { $request = $this->getRequest(); if ($request->isPost()) { $user = $this->authentication()->getIdentity(); if (empty($_FILES['userList'])) { throw new BusinessException('请选择用户列表文件', 1021); } $fileHandler = new ExcelFileHandler($user->id); $uploader = new Uploader($fileHandler); $data = $uploader->processUpload($_FILES['userList']); $attachment = new AttachmentEntity(); $attachment->exchangeArray($data); $attachment->filepath = str_replace("\\", "/", $attachment->filepath); if (!isset($attachment->filename) || !isset($attachment->filepath)) { throw new BusinessException('用户列表Excel导入失败', 1303); } $userArr = $this->userModel->getUserAndAddressFromExcel($attachment); $this->userModel->batchCreateUsers($userArr); return new UnifyJsonModel(); } $view = new ViewModel(); return $view; }
/** * 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)); }