public function index() { $userid = sp_get_current_userid(); $user = $this->users_model->where(array("id" => $userid))->find(); $this->assign($user); $this->display(':center'); }
function _initialize() { parent::_initialize(); $this->order_model = D("Server/Order"); $this->uid = sp_get_current_userid(); $this->serversell_model = D("Server/ServersSell"); }
private function _bang_handle($user_info, $type, $token) { $current_uid = sp_get_current_userid(); $oauth_user_model = M('OauthUser'); $type = strtolower($type); $find_oauth_user = $oauth_user_model->where(array("from" => $type, "openid" => $token['openid']))->find(); $need_bang = true; if ($find_oauth_user) { if ($find_oauth_user['uid'] == $current_uid) { $this->error("您之前已经绑定过此账号!", U('user/profile/bang')); exit; } else { $this->error("该帐号已被本站其他账号绑定!", U('user/profile/bang')); exit; } } if ($need_bang) { if ($current_uid) { //第三方用户表中创建数据 $new_oauth_user_data = array('from' => $type, 'name' => $user_info['name'], 'head_img' => $user_info['head'], 'create_time' => date("Y-m-d H:i:s"), 'uid' => $current_uid, 'last_login_time' => date("Y-m-d H:i:s"), 'last_login_ip' => get_client_ip(), 'login_times' => 1, 'status' => 1, 'access_token' => $token['access_token'], 'expires_date' => (int) (time() + $token['expires_in']), 'openid' => $token['openid']); $new_oauth_user_id = $oauth_user_model->add($new_oauth_user_data); if ($new_oauth_user_id) { $this->success("绑定成功!", U('user/profile/bang')); } else { $users_model->where(array("id" => $new_user_id))->delete(); $this->error("绑定失败!", U('user/profile/bang')); } } else { $this->error("绑定失败!", U('user/profile/bang')); } } }
function _initialize() { $adminid = sp_get_current_admin_id(); $userid = sp_get_current_userid(); if (empty($adminid) && empty($userid)) { exit("非法上传!"); } }
/** * 检查用户状态 */ protected function check_user() { $user_status = M('Users')->where(array("id" => sp_get_current_userid()))->getField("user_status"); if ($user_status == 2) { $this->error('您还没有激活账号,请激活后再使用!', U("user/login/active")); } if ($user_status == 0) { $this->error('此账号已经被禁止使用,请联系管理员!', __ROOT__ . "/"); } }
public function index() { $id = sp_get_current_userid(); $users_model = D("Common/Users"); $user = $users_model->where(array("id" => $id))->find(); if (empty($user)) { $this->error("查无此人!"); } $this->assign($user); $this->display(':user_account'); }
function index() { $uid = sp_get_current_userid(); $where = array("uid" => $uid); $count = $this->comments_model->where($where)->count(); $page = $this->page($count, 20); $page->setLinkWraper("li"); $comments = $this->comments_model->where($where)->order("createtime desc")->limit($page->firstRow . ',' . $page->listRows)->select(); $this->assign("pager", $page->show("default")); $this->assign("comments", $comments); $this->display(":index"); }
function delete_favorite() { $id = I("get.id", 0, "intval"); $uid = sp_get_current_userid(); $post['uid'] = $uid; $user_favorites_model = M("UserFavorites"); $result = $user_favorites_model->where(array('id' => $id, 'uid' => $uid))->delete(); if ($result) { $this->success("取消收藏成功!"); } else { $this->error("取消收藏失败!"); } }
function __construct() { parent::__construct(); $this->userid = sp_get_current_userid(); $this->user = $this->users_model->where(array("id" => $this->userid))->find(); $this->sign_num = $this->exchange->where(array("uid" => $this->userid, "memo" => "网站签到"))->count(); $this->assign('signNum', $this->sign_num); $this->sign_point = D('Config')->val("pc_sign"); $this->share_point = D('Config')->val('pc_share'); $this->assign('user', $this->user); $this->assign("servePromise", $this->_getAd("servePromise")); $this->assign("home_head", $this->_getAd("banner_user")); }
public function do_like() { $this->check_login(); $object_id = $_GET['id']; //content表中id $can_like = sp_check_user_action($object_id, 1); //这个函数是会有副作用的,不只是简单的check。如果没有结果会写数据库,坑。 if ($can_like) { D('content')->saveByUUID($object_id, array("post_like" => array("exp", "post_like+1"))); D('like')->data(['user_id' => sp_get_current_userid(), 'object_id' => $object_id])->add(); $this->success("赞好啦!"); } else { $this->error("您已赞过啦!"); } }
function order() { /*** * 1.判断服务器,是否存在。 * 2.判断用户是否登录。 * 3.判断购买的服务与价格是否存在 * 4.下单,再去支付页面 */ $serverid = intval(I("post.server_id")); if ($serverid) { $rst = $this->servers_model->where(array("id" => $serverid, "status" => 1, "isdel" => 0))->find(); if (!$rst) { $this->error("暂未发现该服务器", U("/")); } } else { $this->error('数据传入失败!', U("/")); } if (!sp_is_user_login()) { $_SESSION['login_http_referer'] = U("Server/Index/index", array("id" => $serverid)); $this->error('请先登录!', U("user/login/index")); } if (isset($_POST["timechange"])) { $timeMode = $_POST["timechange"]; $sell_re = $this->serversell_model->where(array("id" => $timeMode))->find(); if (!$sell_re || $sell_re['server_id'] != $serverid) { $this->error("暂未发现该服务器的价格", U("Server/index/index", 'id=' . $serverid)); } ////处理下单业务 $OrderModel = array("order_id" => $this->order_model->CreateOrderId(), "server_id" => $serverid, "user_id" => sp_get_current_userid(), "month" => $timeMode, "price" => $sell_re['price'], "status" => 1, "create_time" => date("Y-m-d H:i:s")); $result = $this->order_model->add($OrderModel); if ($result !== false) { $this->success("下单成功,即将跳转到支付页面!", U("Server/Index/pay", array("id" => $result))); } else { $this->error('数据传入失败!', U("/")); } } else { $this->error('数据传入失败!', U("/")); } }
public function savePortrait() { if (!($userid = sp_get_current_userid())) { $this->error("非法操作,封你IP"); } header('Content-Type: text/html; charset=utf-8'); $result = array(); $result['success'] = false; $success_num = 0; $msg = ''; //上传目录 $dir = $_SERVER['DOCUMENT_ROOT'] . "/data/upload/avatar"; //删除之前上传的图片 $member = M('Member')->where(array('id' => $userid))->find(); if ($member['avatar_origin']) { $old_avatar_origin = explode('?', $member['avatar_origin']); unlink($_SERVER['DOCUMENT_ROOT'] . $old_avatar_origin[0]); unlink($_SERVER['DOCUMENT_ROOT'] . $member['avatar']); unlink($_SERVER['DOCUMENT_ROOT'] . $member['avatar_small']); unlink($_SERVER['DOCUMENT_ROOT'] . $member['avatar_large']); } // 取服务器时间+8位随机码作为部分文件名,确保文件名无重复。 $filename = date("YmdHis") . '_' . floor(microtime() * 1000) . '_' . $this->createRandomCode(8); // 处理原始图片开始------------------------------------------------------------------------> //默认的 file 域名称是__source,可在插件配置参数中自定义。参数名:src_field_name $source_pic = $_FILES["__source"]; //如果在插件中定义可以上传原始图片的话,可在此处理,否则可以忽略。 if ($source_pic) { if ($source_pic['error'] > 0) { $msg .= $source_pic['error']; } else { //原始图片的文件名,如果是本地或网络图片为原始文件名、如果是摄像头拍照则为 *FromWebcam.jpg $sourceFileName = $source_pic["name"]; //原始文件的扩展名(不包含“.”) $sourceExtendName = substr($sourceFileName, strripos($sourceFileName, ".")); //保存路径 $savePath = "{$dir}" . "/" . $userid . "_origin" . $sourceExtendName; //当前头像基于原图的初始化参数(只有上传原图时才会发送该数据,且发送的方式为POST),用于修改头像时保证界面的视图跟保存头像时一致,提升用户体验度。 //修改头像时设置默认加载的原图url为当前原图url+该参数即可,可直接附加到原图url中储存,不影响图片呈现。 $init_params = $_POST["__initParams"]; move_uploaded_file($source_pic["tmp_name"], $savePath); $result['sourceUrl'] = $this->toVirtualPath($savePath) . $init_params; $success_num++; } } //<------------------------------------------------------------------------处理原始图片结束 // 处理头像图片开始------------------------------------------------------------------------> //头像图片(file 域的名称:__avatar1,2,3...)。 $avatars = array("__avatar1", "__avatar2", "__avatar3"); $avatars_length = count($avatars); for ($i = 0; $i < $avatars_length; $i++) { $avatar = $_FILES[$avatars[$i]]; $avatar_number = $i + 1; if ($avatar['error'] > 0) { $msg .= $avatar['error']; } else { $savePath = "{$dir}" . "/" . $userid . '_' . $avatar_number . "_{$filename}.jpg"; $result['avatarUrls'][$i] = $this->toVirtualPath($savePath); move_uploaded_file($avatar["tmp_name"], $savePath); $success_num++; } } $result['msg'] = $msg; if ($success_num > 0) { $result['success'] = true; } $data = array('id' => $userid, 'avatar' => $result['avatarUrls'][1], 'avatar_small' => $result['avatarUrls'][0], 'avatar_large' => $result['avatarUrls'][2], 'avatar_origin' => $result['sourceUrl']); M('Member')->save($data); //返回图片的保存结果(返回内容为json字符串) print json_encode($result); }
/** * 用户消费记录列表 * WJAZZ 2016-01-22 17:13:07 * @param * @return */ public function record_list() { if ($_GET['p'] == '') { $_GET['p'] = 1; } $userid = sp_get_current_userid(); $posts = $this->payrecord_model->field(array('cmf_payrecord.*', 'cmf_charge.project_name'))->join('LEFT JOIN __CHARGE__ ON __PAYRECORD__.typeid = __CHARGE__.id')->where('userid=' . $userid)->page($_GET['p'] . ',10')->order('created_at desc')->select(); $count = $this->payrecord_model->where('userid=' . $userid)->count(); //分页页数20 $Page = new \Think\Page($count, 10); $Page->setConfig('prev', '上一页'); $Page->setConfig('next', '下一页'); $Page->setConfig('first', '首页'); $Page->setConfig('end', '末页'); $show = $Page->show(); $this->assign('page', $show); $this->assign('posts', $posts); $this->display(':recordlist'); }
function avatar_update() { if (!empty($_SESSION['avatar'])) { $targ_w = intval($_POST['w']); $targ_h = intval($_POST['h']); $x = $_POST['x']; $y = $_POST['y']; $jpeg_quality = 90; $avatar = $_SESSION['avatar']; $avatar_dir = C("UPLOADPATH") . "avatar/"; if (sp_is_sae()) { //TODO 其它存储类型暂不考虑 $src = C("TMPL_PARSE_STRING.__UPLOAD__") . "avatar/{$avatar}"; } else { $src = $avatar_dir . $avatar; } $avatar_path = $avatar_dir . $avatar; if (sp_is_sae()) { //TODO 其它存储类型暂不考虑 $img_data = sp_file_read($avatar_path); $img = new \SaeImage(); $size = $img->getImageAttr(); $lx = $x / $size[0]; $rx = $x / $size[0] + $targ_w / $size[0]; $ty = $y / $size[1]; $by = $y / $size[1] + $targ_h / $size[1]; $img->crop($lx, $rx, $ty, $by); $img_content = $img->exec('png'); sp_file_write($avatar_dir . $avatar, $img_content); } else { $image = new \Think\Image(); $image->open($src); $image->crop($targ_w, $targ_h, $x, $y); $image->save($src); } $userid = sp_get_current_userid(); $result = $this->users_model->where(array("id" => $userid))->save(array("avatar" => $avatar)); $_SESSION['user']['avatar'] = $avatar; if ($result) { $this->success("头像更新成功!"); } else { $this->error("头像更新失败!"); } } }
function usercontact_post() { if (IS_POST) { $userid = sp_get_current_userid(); $_POST['id'] = $userid; if ($this->users_model->create($_POST)) { if ($this->users_model->save()) { $this->success("保存成功!", U("user/profile/usercontact")); } else { $this->error("保存失败!"); } } } }
function avatar_update() { if (!empty($_SESSION['avatar'])) { $targ_w = $_POST['w']; $targ_h = $_POST['h']; $jpeg_quality = 90; $avatar_dir = C("UPLOADPATH") . "avatar/"; $avatar = $_SESSION['avatar']; $src = $avatar_dir . $avatar; $imginfo = getimagesize($src); $ext = array("2" => ".jpg", "3" => ".png"); if (empty($imginfo)) { $this->error("图像非法!"); } if (!array_key_exists($imginfo[2], $ext)) { $this->error("文件类型不支持!"); } $createmethods = array("2" => "imagecreatefromjpeg", "3" => "imagecreatefrompng"); $createmethod = $createmethods[$imginfo[2]]; $img_r = $createmethod($src); imagesavealpha($img_r, true); $dst_r = ImageCreateTrueColor($targ_w, $targ_h); $color = imagecolorallocate($dst_r, 255, 255, 255); imagecolortransparent($dst_r, $color); imagefill($dst_r, 0, 0, $color); imagecopyresampled($dst_r, $img_r, 0, 0, $_POST['x'], $_POST['y'], $targ_w, $targ_h, $targ_w, $targ_h); $result = imagepng($dst_r, $src, 0); if ($result) { $userid = sp_get_current_userid(); $result = $this->users_model->where(array("id" => $userid))->save(array("avatar" => $avatar)); $_SESSION['user']['avatar'] = $avatar; if ($result) { $this->success("头像更新成功!"); } else { $this->error("头像更新失败!"); } } else { $this->success("头像文件保存失败!"); } } }