/** * 该方法的返回值为一下格式 * $result => { * ' headers'=> //提供列表的头 * ' rows'=> //列表的内容(当前商品的属性的自由组合) * } * * *当前商品的属性值的值自由组合的sql * select concat(t0.id,'#',t1.id) as goods_attribute_ids,t0.value as value0,t1.value as value1 from (select id,value from goods_attribute where goods_id = 16 and attribute_id =2) as t0, (select id,value from goods_attribute where goods_id = 16 and attribute_id = 6) as t1 order by t0.id,t1.id * */ public function getProducts($goods_id) { //>>1.准备headers的数据(当前商品的多值属性) $headers = $this->getMultValueAttribute($goods_id); //>>2.准备rows的数据 //>>2.1 拼装自由组合的sql $sql = "select concat("; $goods_attribute_ids = array(); //存放id $values = array(); //存放值 $selects = array(); foreach ($headers as $k => $header) { $goods_attribute_ids[] = "t{$k}.id"; $values[] = "t{$k}.value as value{$k}"; $selects[] = "(select id,value from goods_attribute where goods_id = {$goods_id} and attribute_id ={$header['id']}) as t{$k}"; } $sql .= arr2str($goods_attribute_ids, ",'#',") . ' ) as goods_attribute_ids,'; $sql .= arr2str($values, ',') . ' from '; $sql .= arr2str($selects, ',') . ' order by '; $sql .= arr2str($goods_attribute_ids, ','); //>>2.2 再执行查询 $rows = $this->query($sql); foreach ($rows as &$row) { //>>这两步保证下的在前面 $goods_attribute_ids = str2arr($row['goods_attribute_ids'], '#'); sort($goods_attribute_ids); $row['goods_attribute_ids'] = arr2str($goods_attribute_ids, '#'); } //>>2.3.准备当前商品对应的产品 $products = $this->where(array('goods_id' => $goods_id))->select(); $goods_attribute_ids = array_column($products, 'goods_attribute_ids'); $products = array_combine($goods_attribute_ids, $products); return array('headers' => $headers, 'rows' => $rows, 'products' => $products); }
/** * 得到商品的多值属性,产品列表数据 * @param $goods_id * @return array */ public function getMultAttribute($goods_id) { //查询当前商品的多值的name $sql = "select DISTINCT a.name,ga.attribute_id from goods_attribute as ga join attribute as a on ga.attribute_id=a.id where ga.goods_id={$goods_id} and a.input_type=2 and a.attribute_type=2"; $head = $this->query($sql); //查询当前商品的多值笛卡尔积组合 $rows = ''; if ($head) { //拼凑sql $table = ''; $field1 = ''; $field2 = ''; foreach ($head as $k => $v) { $field1 .= "t{$k}.value as value{$k},"; $field2 .= "t{$k}.id,'#',"; $table .= "(select * from goods_attribute where goods_id={$goods_id} and attribute_id={$v['attribute_id']}) as t{$k},"; } $sql = 'select concat(' . trim($field2, ',\'#\',') . ') as attribute_ids,' . trim($field1, ',') . ' from ' . trim($table, ','); $rows = $this->query($sql); //将结果中attribute_ids排序 foreach ($rows as &$row) { $temp = str2arr($row['attribute_ids'], '#'); sort($temp); //排序 $row['attribute_ids'] = arr2str($temp, '#'); } unset($row); } return array('head' => $head, 'rows' => $rows); }
public function sortAction() { $data = post("data", "txt"); $id = post("id", "int"); $plugs = arr2str($data, ","); $res = db()->table('hook')->upDate(array('plugs' => $plugs), array('id' => $id))->done(); if ($res) { return JsonObject(array("msg" => "保存成功")); } }
/** * 重构请求参数 * 将xxx数据重构为yyy数据 * * array(4) { ["goods_attribute_ids"] => array(2) { ["颜色"] => string(1) "8" ["尺码"] => string(2) "10" } ["goods_attribute_strs"] => array(2) { ["颜色"] => string(6) "红色" ["尺码"] => string(1) "M" } ["amount"] => string(1) "1" ["goods_id"] => string(2) "16" } * * * array(4) { ["goods_attribute_ids"] => string(4) "8#10" ["goods_attribute_strs"] => string(26) "颜色:红色<br/>尺码:M" ["amount"] => string(1) "1" ["goods_id"] => string(2) "16" } * @param $requestData */ private function rebuildRequestData(&$requestData) { if (!empty($requestData['goods_attribute_ids'])) { //说明当前购买的商品是 多库存多价格 //组合商品属性的id $goods_attribute_ids = array_values($requestData['goods_attribute_ids']); sort($goods_attribute_ids); $requestData['goods_attribute_ids'] = arr2str($goods_attribute_ids, '#'); //组合商品属性的值 $goods_attribute_strs = array(); foreach ($requestData['goods_attribute_strs'] as $k => $v) { $goods_attribute_strs[] = $k . ':' . $v; } $goods_attribute_strs = arr2str($goods_attribute_strs, '<br/>'); $requestData['goods_attribute_strs'] = $goods_attribute_strs; } }
/** * 新增或更新一个文档 * @param array $data 手动传入的数据 * @return boolean fasle 失败 , int 成功 返回完整的数据 * @author huajie <*****@*****.**> */ public function update($data = null) { /* 获取数据对象 */ $data = $this->token(false)->create($data); $data['file_id'] = think_decrypt($data['file_id']); //推荐位 if (is_array($data['position'])) { $data['position'] = arr2str($data['position']); } //组图 if (is_array($data['pics_id'])) { $data['pics_id'] = arr2str($data['pics_id']); } //附件 $data['file_id'] = think_decrypt($data['file_id']); if (empty($data)) { return false; } /* 添加或新增基础内容 */ if (empty($data['id'])) { //新增数据 $id = $this->data($data)->add(); //添加基础内容 if (!$id) { $this->error = '新增基础内容出错!'; return false; } } else { //更新数据 $status = $this->data($data)->save(); //更新基础内容 if (false === $status) { $this->error = '更新基础内容出错!'; return false; } } //内容添加或更新完成 return $data; }
function OAuthWeixin($callback) { $isWeixinBrowser = isWeixinBrowser(); $info = get_mpid_appinfo(); trace('wechat:OAuthWeixin' . $info['id'], '微信', 'DEBUG', true); if (!$isWeixinBrowser || $info['type'] != 2 || empty($info['appid'])) { redirect($callback . '&openid=-1'); } $param['appid'] = $info['appid']; if (!isset($_GET['getOpenId'])) { $param['redirect_uri'] = $callback . '&getOpenId=1'; $param['response_type'] = 'code'; $param['scope'] = 'snsapi_base'; $param['state'] = 123; $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?' . http_build_query($param) . '#wechat_redirect'; trace('OAuthWeixin111' . $url, '微信', 'DEBUG', true); redirect($url); } elseif ($_GET['state']) { $param['secret'] = $info['secret']; $param['code'] = I('code'); $param['grant_type'] = 'authorization_code'; $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?' . http_build_query($param); $content = file_get_contents($url); $content = json_decode($content, true); trace('wechat:OAuthWeixin222' . arr2str($param), '微信', 'DEBUG', true); trace('wechat:OAuthWeixin333' . $content['openid'], '微信', 'DEBUG', true); redirect($callback . '&openid=' . $content['openid']); } }
public function AjaxExistMeeingRoom() { $MeetingreservID = $_REQUEST["id"]; $MeetingID = $_REQUEST["meetingid"]; $StartDate = $_REQUEST["startdate"]; $StartTime = $_REQUEST["starttime"]; $EndTime = $_REQUEST["endtime"]; $Devs = $_REQUEST["devs"]; //选择的设备ID /* P_MeetingID integer, P_StartDate date, P_StartTime time, P_EndTime time */ if (empty($MeetingreservID)) { $MeetingreservID = 0; } //$strSql=format("Call UP_GetMeetingDevicesByAdd ('{0}','{1}','{2}','{3}')",$StartDate,$StartTime,$EndTime,'12'); $strSql = format("Call UP_ExistMeeingRoom('{0}','{1}','{2}','{3}','{4}')", $MeetingreservID, $MeetingID, $StartDate, $StartTime, $EndTime); //echo $strSql; $Meetslist = M('')->query($strSql); $result = array(); if (count($Meetslist) > 0) { $result['error'] = "会议室已被占用"; //$result['message'] = "会议室已被占用"; exit(json_encode($result)); } else { $pDevs = arr2str($Devs, ','); $strSql = format("Call UP_ExistMeeingDevices('{0}','{1}','{2}','{3}','{4}')", $MeetingreservID, $pDevs, $StartDate, $StartTime, $EndTime); $DevsList = M('')->query($strSql); //var_dump($DevsList) ; if (count($DevsList) > 0) { $arrDeviceNames = array(); foreach ($DevsList as $key => $value) { array_push($arrDeviceNames, $value["DeviceName"]); // var_dump($value["DeviceName"]); } // var_dump($arrDeviceNames ); $result['error'] = format("设备已被占用[{0}]", arr2str($arrDeviceNames, ',')); //$result['message'] = "设备已被占用"; exit(json_encode($result)); } $result['ok'] = ''; //$result['message'] = ""; exit(json_encode($result)); } }
//wxb03abb1444f7308f //4ee5b123dc62e93e3778f7900062c823 //https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8888888888888888&redirect_uri=http://mascot.duapp.com/oauth2.php&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect public function responseMsg() { //get post data, May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post data if (!empty($postStr)) { /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection, the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $keyword = trim($postObj->Content); $kres = M('wxregular')->where("`wxkeyword`='" . $keyword . "'")->find(); if ($kres) { // if($kres['type'] == 'text') { $content = $kres['wxcontent']; $result = $this->transmitText($postObj, $content); echo $result; // } else if($kres['type'] == 'news') { // // $content = array(); // // $content[] = array("Title"=>$kres['title'], "Description"=>$kres['description'], "PicUrl"=>"http://laonian.hzasion.com".get_cover($kres['image'], 'path'), "Url" =>$kres['url']); // // $result = $this->transmitNews($postObj, $content); // // echo $result; // // // // } } else { if ($keyword == '') { $content = '请回复 “爱的老人节” 参与投票活动!' . arr2str($kres); $result = $this->transmitText($postObj, $content); echo $result; } else { $content = '无效关键字' . arr2str($kres); $result = $this->transmitText($postObj, $content); echo $result; } } } else {
$groupUser = $new['group']->findAll('group_user', array('groupid' => $groupid), 'addtime desc', null, 8); if (is_array($groupUser)) { foreach ($groupUser as $item) { $strUser = aac('user')->getOneUser($item['userid']); if ($strUser) { $arrGroupUser[] = $strUser; } else { $new['group']->delete('group_user', array('userid' => $item['userid'], 'groupid' => $groupid)); } } } //标签 $strGroup['tags'] = aac('tag')->getObjTagByObjid('group', 'groupid', $strGroup['groupid']); if ($page > 1) { $title = $strGroup['groupname'] . ' - 第' . $page . '页'; } //把标签作为关键词 if ($strGroup['tags']) { foreach ($strGroup['tags'] as $key => $item) { $arrTag[] = $item['tagname']; } $sitekey = $strGroup['groupname'] . ',' . arr2str($arrTag); } else { $sitekey = $strGroup['groupname']; } $sitedesc = tsCutContent($strGroup['groupdesc'], 50); if ($TS_CF['mobile']) { $sitemb = tsUrl('moblie', 'group', array('ts' => 'show', 'groupid' => $strGroup['groupid'])); } include template("show"); }
<?php defined('IN_TS') or die('Access Denied.'); $arrGroupUser = $new['my']->findAll('group_user', array('userid' => $strUser['userid'])); foreach ($arrGroupUser as $key => $item) { $arrGroupId[] = $item['groupid']; } $strGroupId = arr2str($arrGroupId); if ($strGroupId) { $arrTopic = $new['my']->findAll('group_topic', "`groupid` in ({$strGroupId})", 'addtime desc', null, 30); foreach ($arrTopic as $key => $item) { $arrTopic[$key]['user'] = aac('user')->getOneUser($item['userid']); $arrTopic[$key]['group'] = aac('group')->getOneGroup($item['groupid']); } } include template("index");
public function applylead() { $id = is_login(); if (!$id) { $this->error('您还没有登录,请先登录。', U('User/login')); return; } if (IS_POST) { $focus = $_POST['focus']; if (empty($focus)) { $this->error('请选择您感兴趣的领投领域。'); } if (empty($_POST['resume'])) { $this->error('请完善您的个人简介。'); } //领投资格 $ret = M('user_auth')->where(array('uid' => $id, 'auth_id' => 1, 'status' => 9))->find(); if (!$ret) { $this->error('您还没有进行实名认证,不能申请领投人。请先进行实名认证。', U('User/savecenter')); } $data = array('resume' => $_POST['resume'], 'focus' => arr2str($focus), 'id' => $id); M('UsersDetail')->save($data); //保存用户类别 $auth_id = 3; $ret = M('user_auth')->where(array('uid' => $id, 'auth_id' => $auth_id))->find(); if (!$ret) { $data = array('uid' => $id, 'auth_id' => $auth_id); M('user_auth')->add($data); } else { if ($ret['status'] != 9) { $ret['status'] = 0; M('user_auth')->save($ret); } } $this->success('领投信息提交成功!'); } else { $userdetail = M('UsersDetail')->find($id); $userauth = M('user_auth')->where(array('uid' => $id, 'auth_id' => 3))->find(); if ($userauth['status'] == '1') { $describe = M('Users')->field('investor_content')->find($id); $this->describe = $describe['investor_content']; } $this->industry = get_code('industry'); $this->userdetail = $userdetail; $this->userauth = $userauth; $this->display('applylead'); } }
public function delcate($cid = null) { $this->data['title'] = "删除栏目"; $this->load->view('mzsj/com_header', $this->data); if (isset($_POST['dosubmit'])) { $cids = $this->input->post('cids[]'); foreach ($cids as $c) { $res = $this->delchildcat($c); if ($res !== true) { $this->msg('栏目' . $res . '下有文章,请先删除文章!', 'mzsj/content/cate'); return; } else { continue; } } // 记录用户行为 $cids = arr2str($cids); $this->addlog("catid={$cids}"); } else { if ($cid == NULL || (int) $cid <= 0) { $this->msg('Parameter Error!', 'mzsj/content/cate'); } else { $res = $this->delchildcat((int) $cid); if ($res === true) { // 记录用户行为 $this->addlog("catid={$cid}"); } else { $this->msg('栏目' . $res . '下有文章,请先删除文章!', 'mzsj/content/cate'); return; } } } $this->updatecache->catecache(); $this->msg('Delete Success!', 'mzsj/content/cate'); $this->load->view('mzsj/com_footer'); }
function get_room_name($room_id) { if ($room_id) { $room_name = arr2str(M('Room')->where('id=' . $room_id)->field('name')->find()); if ($room_name) { return $room_name; } } }
$strTopic['content'] = @preg_replace("/\\[@(.*)\\:(.*)]/U", "<a href='" . tsUrl('user', 'space', array('id' => '$2')) . " ' rel=\"face\" uid=\"\$2\"'>@\$1</a>", $strTopic['content']); // 最新帖子 $newTopic = $new['group']->findAll('group_topic', array('isaudit' => '0'), 'addtime desc', null, 10); foreach ($newTopic as $key => $item) { $newTopic[$key]['title'] = tsTitle($item['title']); $newTopic[$key]['content'] = tsDecode($item['content']); } // 帖子标签 $strTopic['tags'] = aac('tag')->getObjTagByObjid('topic', 'topicid', $topicid); $strTopic['user'] = aac('user')->getOneUser($strTopic['userid']); //把标签作为关键词 if ($strTopic['tags']) { foreach ($strTopic['tags'] as $key => $item) { $arrTag[] = $item['tagname']; } $sitekey = arr2str($arrTag); } else { $sitekey = $strTopic['title']; } //标题 $title = $strTopic['title']; // 评论列表开始 $page = isset($_GET['page']) ? intval($_GET['page']) : 1; $url = tsUrl('group', 'topic', array('id' => $topicid, 'page' => '')); $lstart = $page * 15 - 15; $arrComment = $new['group']->findAll('group_topic_comment', array('topicid' => $topicid), 'addtime asc', null, $lstart . ',15'); foreach ($arrComment as $key => $item) { $arrTopicComment[] = $item; $arrTopicComment[$key]['l'] = ($page - 1) * 15 + $key + 1; $arrTopicComment[$key]['user'] = aac('user')->getOneUser($item['userid']); $arrTopicComment[$key]['content'] = @preg_replace("/\\[@(.*)\\:(.*)]/U", "<a href='" . tsUrl('user', 'space', array('id' => '$2')) . " ' rel=\"face\" uid=\"\$2\"'>@\$1</a>", tsDecode($item['content']));
/** * 添加单个钩子里对应的插件数据 * @param $hook_name * @param $plug_name * @return bool|mixed */ public function addPlugs($hook_name, $plug_name) { $o_plugs = db()->table("hook")->getRow(array("name" => $hook_name))->fields('plugs')->done(); if ($o_plugs) { $plugs = array_unique(array_merge($o_plugs, $plug_name)); } else { return true; } $flag = db()->table("hook")->upDate(array('plugs' => arr2str($plugs)), array('name' => $hook_name))->done(); if (false === $flag) { db()->table("hook")->upDate(array('plugs' => arr2str($o_plugs)), array('name' => $hook_name))->done(); } return $flag; }
/** * 导出用户数据 */ public function memberExcel() { // $Member = D('Member'); $map['status'] = ['in', '2,3,4']; $month_start = I('get.month_start'); $month_end = I('get.month_end'); $mouth_solt = get_month_solt($month_start, $month_end); if (I('get.type') == 'export') { foreach ($mouth_solt as $k => $v) { $time_start = $mouth_solt[1]['start']['ts']; $time_end = $mouth_solt[$k]['end']['ts']; $map['regtime'] = [between, [$time_start, $time_end]]; $mouth_solt_data[$k]['mouth_solt'] = $v; $x = $Member->field('userid')->where($map)->select(); $mouth_solt_data[$k]['count'] = count($x); } $time_start = $mouth_solt[1]['start']['ts']; $time_end = $mouth_solt_data[$k]['mouth_solt']['end']['ts']; $sql = "SELECT a.username,a.truename,a.mobile,a.areaid,b.areaname FROM destoon_member AS a LEFT JOIN destoon_area AS b ON (a.areaid = b.areaid) where a.regtime between {$time_start} and {$time_end} "; $data = queryMysql($sql); if (!empty($data)) { foreach ($data as $k => $v) { $member_info[$k]['username'] = $v['username']; $member_info[$k]['truename'] = $v['truename']; $member_info[$k]['mobile'] = $v['mobile']; $arealist = getAreaFullNameFromAreaID($v['areaid']); $member_info[$k]['areaname'] = arr2str($arealist, ''); } $fileName = "会员信息"; $headArr = array('用户名', '姓名', '联系方式', '所在地区'); exportExcel($fileName, $headArr, $member_info); //数据导出 } else { $this->error('错误'); } } }
array_push($arr, 'id:' . $row[0]); array_push($arr, 'name:"' . $row[1] . '"'); array_push($arr, 'href:"' . $row[2] . '"'); array_push($arr, 'parent_id:' . $row[3]); array_push($aResult, implode(',', $arr)); } if (count($aResult) > 0) { return '[{' . implode('},{', $aResult) . '}]'; } else { return '[]'; } } switch ($act) { case 'add': $name = $_GET['name']; $href = $_GET['href']; $parent_id = $_GET['parent_id']; $sql = "INSERT INTO tree (name,href,parent_id) VALUES('{$name}','{$href}','{$parent_id}')"; mysql_query($sql); echo '{error: 0}'; break; case 'get_tree': $id = (int) $_GET['id']; $sql = "SELECT * FROM tree WHERE parent_id={$id}"; echo '{error: 0, child: ' . arr2str(mysql_query($sql)) . '}'; break; case 'get_trees': $sql = "SELECT * FROM tree WHERE parent_id=0"; echo '{error: 0, child: ' . arr2str(mysql_query($sql)) . '}'; break; }
$menub = $View->Print_channel_view(5, 'channel_id', '99,105,122,127,114,143,146'); break; case 6: //普通用户 $menua = "99"; $menub = $View->Print_channel_view(6, 'channel_id', '302,162,163,101,102,165,100,166,167,168'); break; case 7: //临时用户 $menua = "99"; $menub = $View->Print_channel_view(7, 'channel_id', '302,162,163,101,102,165,100,166,167,168'); break; } //处理系统自带的和以前自定义的权限ID; $menua = arr2str(array_unique(explode(",", $View->Print_user($id, 'user_cview') . "," . $menua))); $menub = arr2str(array_unique(explode(",", $View->Print_user($id, 'user_view') . "," . $menub))); //print_r($menub);die; $user_sex = $Base->CheckUsr(htmlspecialchars(trim($_POST['user_sex']))); $user_phone = $Base->CheckUsr(htmlspecialchars(trim($_POST['user_phone']))); $user_qq = $Base->CheckUsr(htmlspecialchars(trim($_POST['user_qq']))); $user_email = trim($_POST['user_email']); //echo $user_entrydate;die; $old_user_name = $Db->Fetch($Db->ThisQuery("select `user_name` from `" . $db_prefix . "users` where `user_id`=" . $id . "")); if ($user_name != $old_user_name['user_name']) { if ($Db->RowsAll("select `user_id` from `" . $db_prefix . "users` where `user_name`='" . $user_name . "'") !== 0) { $Base->WarnBack('用户名已经存在!'); exit; } } $Db->ThisQuery("update `" . $db_prefix . "users` set `user_name`='" . $user_name . "',`user_ture_name`='" . $user_ture_name . "',`user_right`=" . $user_right . ",`user_quanxian`=" . $user_quanxian . ",`user_sex`='" . $user_sex . "',`user_phone`='" . $user_phone . "',`user_qq`='" . $user_qq . "',`user_email`='" . $user_email . "',`user_cview`='" . $menua . "',`user_view`='" . $menub . "' where `user_id`=" . $id . ""); if (!empty($user_password1)) {
function arr2str($a) { if (is_array($a)) { $ret = " [ "; foreach ($a as $k => $v) { $ret .= $k . "=>" . arr2str($v) . " , "; } $ret = substr($ret, 0, strlen($ret) - 2); $ret .= " ] "; return $ret; } else { return $a; } }
public function get_node_name($node_id) { if ($node_id) { $node_name = arr2str(M('Node')->where('id=' . $node_id)->field('name')->find()); return $node_name ? $node_name : false; } }
tsNotice('系统不允许用户编辑内容,请联系管理员编辑!'); } switch ($ts) { case "": $articleid = intval($_GET['articleid']); $cateid = intval($_GET['cateid']); $strArticle = $new['article']->find('article', array('articleid' => $articleid)); if ($strArticle['userid'] == $userid || $TS_USER['isadmin'] == 1) { $strArticle['title'] = stripslashes($strArticle['title']); $strArticle['content'] = tsDecode($strArticle['content']); // 找出TAG $arrTags = aac('tag')->getObjTagByObjid('article', 'articleid', $articleid); foreach ($arrTags as $key => $item) { $arrTag[] = $item['tagname']; } $strArticle['tag'] = arr2str($arrTag); $title = '修改文章'; include template('edit'); } else { tsNotice('非法操作!'); } break; case "do": if ($_POST['token'] != $_SESSION['token']) { tsNotice('非法操作!'); } $articleid = intval($_POST['articleid']); $strArticle = $new['article']->find('article', array('articleid' => $articleid)); if ($strArticle['userid'] != $userid && $TS_USER['isadmin'] == 0) { tsNotice('非法操作!'); }
/** * 实现的init_ucuser钩子方法,对公众号粉丝进行初始化,在需要初始化粉丝信息的地方通过 hook('init_ucuser',$params); 调用 * @params string $mp_id 公众号在系统中的唯一标识,member_public表的id,必填 * @params string $weObj 公众号实例 * @return void hook函数木有返回值 * 注意: */ public function init_ucuser($params) { if ($params['mp_id'] && $params['weObj'] instanceof TPWechat) { //带有公众号在系统中唯一ID,存在公众号实例,例如weixincontroller中的被动响应 $map['openid'] = get_openid(); $map['mp_id'] = $params['mp_id']; $ucuser = D('Ucuser'); $data = $ucuser->where($map)->find(); if (!$data) { //公众号没有这个粉丝信息,就注册一个 //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站 $aUsername = $aNickname = $map['openid']; //substr(,20); //以openid作为默认UcenterMember用户名和Member昵称 $aPassword = UCenterMember()->create_rand(); //随机密码,用户未通过公众号注册,就不可登录网站 $email = $aUsername . '@mp_id' . $map['mp_id'] . '.com'; //以openid@mpid123.com作为默认邮箱 $mobile = arr2str(UCenterMember()->rand_mobile()); //生成随机手机号已通过model校验,不实际使用,准确手机以微信绑定的为准 $aUnType = 5; //微信公众号粉丝注册 $aRole = 3; //默认公众号粉丝用户角色 /* 注册用户 */ $uid = UCenterMember()->register($aUsername, $aNickname, $aPassword, $email, $mobile, $aUnType); if (0 < $uid) { //注册成功 initRoleUser($aRole, $uid); //初始化角色用户 set_user_status($uid, 1); //微信注册的用户状态直接设置为1 } else { //注册失败,显示错误信息 } $uid = $ucuser->registerUser($uid, $map['mp_id'], $map['openid']); //用注册member获取的统一uid注册微信粉丝 get_ucuser_uid($uid); //设置session中uid } else { get_ucuser_uid($data['uid']); //设置session中uid } } else { //不存在公众号实例或没显式传mp_id参数,例如分享到朋友圈的内容,访问参数中必须带有公众号在系统中唯一标识mp_id $umap['openid'] = get_openid(); //只存在公众号信息的,在get_openid中通过oauth获取用户openid $umap['mp_id'] = I('mp_id'); //从controller的访问请求中获取mp_id if (!empty($umap['mp_id'])) { $ucuser = D('Ucuser'); $data = $ucuser->where($umap)->find(); if (!$data) { //公众号没有这个粉丝信息,就注册一个 //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站 $aUsername = $aNickname = $umap['openid']; //以openid作为默认UcenterMember用户名和Member昵称 $aPassword = UCenterMember()->create_rand(); //随机密码,用户未通过公众号注册,就不可登录网站 $email = $aUsername . '@mp_id' . $umap['mp_id'] . 'com'; //以openid@mpid123.com作为默认邮箱 $mobile = arr2str(UCenterMember()->rand_mobile()); //生成随机手机号已通过model校验,不实际使用,准确手机以微信绑定的为准 $aUnType = 5; //微信公众号粉丝注册 $aRole = 3; //默认公众号粉丝用户角色 /* 注册用户 */ $uid = UCenterMember()->register($aUsername, $aNickname, $aPassword, $email, $mobile, $aUnType); if (0 < $uid) { //注册成功 initRoleUser($aRole, $uid); //初始化角色用户 set_user_status($uid, 1); //微信注册的用户状态直接设置为1 } else { //注册失败,显示错误信息 } $uid = $ucuser->registerUser($uid, $umap['mp_id'], $umap['openid']); //用注册member获取的统一uid注册微信粉丝 get_ucuser_uid($uid); //设置session中uid } else { get_ucuser_uid($data['uid']); //设置session中uid } } else { //没有公众号信息,未能初始化粉丝 } } }
exit; } $strTopic = $new['group']->find('group_topic', array('topicid' => $topicid)); $strTopic['title'] = stripslashes($strTopic['title']); //$strTopic['content'] = tsDecode($strTopic['content']); $strGroup = $new['group']->find('group', array('groupid' => $strTopic['groupid'])); $strGroupUser = $new['group']->find('group_user', array('userid' => $userid, 'groupid' => $strTopic['groupid'])); //print_r($strGroupUser);exit; if ($strTopic['userid'] == $userid || $strGroup['userid'] == $userid || $TS_USER['isadmin'] == 1 || $strGroupUser['isadmin'] == 1) { $arrGroupType = $new['group']->findAll('group_topic_type', array('groupid' => $strGroup['groupid'])); //找出TAG $arrTags = aac('tag')->getObjTagByObjid('topic', 'topicid', $topicid); foreach ($arrTags as $key => $item) { $arrTag[] = $item['tagname']; } $strTopic['tag'] = arr2str($arrTag); $title = '编辑帖子'; include template("topic_edit"); } else { header("Location: " . SITE_URL); exit; } break; //编辑帖子执行 //编辑帖子执行 case "do": if ($_POST['token'] != $_SESSION['token']) { tsNotice('非法操作!'); } $topicid = intval($_POST['topicid']); $typeid = intval($_POST['typeid']);
public function wxoauth() { $scope = 'snsapi_base'; $code = isset($_GET['code']) ? $_GET['code'] : ''; trace('wechat:re5' . $code, '微信', 'DEBUG', true); $token_time = isset($_SESSION['token_time']) ? $_SESSION['token_time'] : 0; if (!$code && isset($_SESSION['open_id']) && isset($_SESSION['user_token']) && $token_time > time() - 3600) { trace($_SESSION['user_token'] . 'wechat:re6' . $_SESSION['open_id'], '微信', 'DEBUG', true); if (!$this->wxuser) { $this->wxuser = $_SESSION['wxuser']; } $this->open_id = $_SESSION['open_id']; return $this->open_id; } else { $options = array('token' => $this->options["token"], 'encodingaeskey' => $this->options["encodingaeskey"], 'appid' => $this->options["appid"], 'appsecret' => $this->options["appsecret"]); trace('wechat:re7' . arr2str($options), '微信', 'DEBUG', true); $we_obj = new TPWechat($options); if ($code) { $json = $we_obj->getOauthAccessToken(); if (!$json) { unset($_SESSION['wx_redirect']); die('获取用户授权失败,请重新确认'); } $_SESSION['open_id'] = $this->open_id = $json["openid"]; $access_token = $json['access_token']; $_SESSION['user_token'] = $access_token; $_SESSION['token_time'] = time(); $userinfo = $we_obj->getUserInfo($this->open_id); if ($userinfo && !empty($userinfo['nickname'])) { $this->wxuser = array('open_id' => $this->open_id, 'nickname' => $userinfo['nickname'], 'sex' => intval($userinfo['sex']), 'location' => $userinfo['province'] . '-' . $userinfo['city'], 'avatar' => $userinfo['headimgurl']); } elseif (strstr($json['scope'], 'snsapi_userinfo') !== false) { $userinfo = $we_obj->getOauthUserinfo($access_token, $this->open_id); if ($userinfo && !empty($userinfo['nickname'])) { $this->wxuser = array('open_id' => $this->open_id, 'nickname' => $userinfo['nickname'], 'sex' => intval($userinfo['sex']), 'location' => $userinfo['province'] . '-' . $userinfo['city'], 'avatar' => $userinfo['headimgurl']); } else { return $this->open_id; } } if ($this->wxuser) { $_SESSION['wxuser'] = $this->wxuser; $_SESSION['open_id'] = $json["openid"]; unset($_SESSION['wx_redirect']); return $this->open_id; } $scope = 'snsapi_userinfo'; } if ($scope == 'snsapi_base') { trace('wechat:re7' . $code, '微信', 'DEBUG', true); $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $_SESSION['wx_redirect'] = $url; } else { $url = $_SESSION['wx_redirect']; } if (!$url) { unset($_SESSION['wx_redirect']); die('获取用户授权失败'); } trace('wechat:re8' . $url, '微信', 'DEBUG', true); $oauth_url = $we_obj->getOauthRedirect($url, "wxbase", $scope); trace('wechat:re9' . $oauth_url, '微信', 'DEBUG', true); redirect($oauth_url); } }
public function getMenu() { //得到当前用户可以访问的菜单 $permission_ids = permissionId(); $permission_ids = arr2str($permission_ids); $sql = "select DISTINCT m.id,m.name,m.parent_id,m.level,m.url from menu as m join menu_permission as mp on m.id=mp.menu_id where mp.menu_id in ({$permission_ids}) and m.status>0 order BY m.lft"; return M()->query($sql); }
//用户是否登录 $userid = aac('user')->isLogin(); $groupid = intval($_GET['groupid']); $strGroup = $new['group']->find('group', array('groupid' => $groupid)); $strGroup['groupname'] = tsDecode($strGroup['groupname']); $strGroup['groupdesc'] = tsDecode($strGroup['groupdesc']); if ($strGroup['userid'] == $userid || $TS_USER['isadmin'] == 1) { switch ($ts) { //编辑小组基本信息 case "base": //小组标签 $arrTags = aac('tag')->getObjTagByObjid('group', 'groupid', $groupid); foreach ($arrTags as $key => $item) { $arrTag[] = $item['tagname']; } $strGroup['tag'] = arr2str($arrTag); $title = '编辑小组基本信息'; include template("edit_base"); break; //编辑小组头像 //编辑小组头像 case "icon": $title = '修改小组头像'; include template("edit_icon"); break; //修改访问权限 //修改访问权限 case "privacy": $title = '编辑小组权限'; include template("edit_privacy"); break;
function get_ucuser_uid($uid = 0) { $mp_id = get_mpid(); if ($uid !== NULL) { session('uid_' . $mp_id, $uid); } elseif (!empty($_REQUEST['uid'])) { session('uid_' . $mp_id, $_REQUEST['uid']); } //以上是带uid参数调用函数时设置session中的uid $uid = session('uid_' . $mp_id); $isWeixinBrowser = isWeixinBrowser(); if (!$isWeixinBrowser) { //非微信浏览器返回false,调用此函数必须对false结果进行判断,非微信浏览器不可访问调用的controller return false; } //下面这段应该逻辑没问题,如果公众号配置信息错误或者没有snsapi_base作用域的获取信息权限可能会出现死循环,注释掉以下if可治愈 if ($uid <= 0 && $isWeixinBrowser) { $map['openid'] = get_openid(); $map['mp_id'] = $mp_id; $ucuser = D('Ucuser'); $data = $ucuser->where($map)->find(); if (!$data) { //公众号没有这个粉丝信息,就注册一个 //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站 //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站 $aUsername = $aNickname = $map['openid']; //以openid作为默认UcenterMember用户名和Member昵称 $aPassword = UCenterMember()->create_rand(); //随机密码,用户未通过公众号注册,就不可登录网站 $email = $aUsername . '@mp_id' . $map['mp_id'] . '.com'; //以openid@mpid123.com作为默认邮箱 $mobile = arr2str(UCenterMember()->rand_mobile()); //生成随机手机号以通过model校验,不实际使用,准确手机以微信绑定的为准 $aUnType = 5; //微信公众号粉丝注册 $aRole = 3; //默认公众号粉丝用户角色 /* 注册用户 */ $uid = UCenterMember()->register($aUsername, $aNickname, $aPassword, $email, $mobile, $aUnType); if (0 < $uid) { //注册成功 initRoleUser($aRole, $uid); //初始化角色用户 set_user_status($uid, 1); //微信注册的用户状态直接设置为1 } else { //注册失败,显示错误信息 } $uid = $ucuser->registerUser($uid, $map['mp_id'], $map['openid']); //用注册member获取的统一uid注册微信粉丝 session('uid_' . $mp_id, $uid); } else { $uid = $data['uid']; session('uid_' . $mp_id, $uid); } } if (empty($uid)) { return -1; } return $uid; }
/** * 去除单个钩子里对应的插件数据 */ public function removeAddons($hook_name, $addons_name) { $o_addons = $this->where("name='{$hook_name}'")->getField('addons'); $o_addons = str2arr($o_addons); if ($o_addons) { $addons = array_diff($o_addons, $addons_name); } else { return true; } $flag = D('Hooks')->where("name='{$hook_name}'")->setField('addons', arr2str($addons)); if (false === $flag) { D('Hooks')->where("name='{$hook_name}'")->setField('addons', arr2str($o_addons)); } return $flag; }
public function vote() { $this->isauth(); if (time() < strtotime('2015-09-26 00:00:00')) { $this->ajaxReturn(array('status' => 0, 'info' => '投票将于9月26日开启!')); exit; } if (time() > strtotime(C('VOTE_STOP_TIME'))) { $this->ajaxReturn(array('status' => 0, 'info' => '活动已结束,无法投票!')); exit; } if (session('subscribe') == 0) { $this->ajaxReturn(array('status' => 0, 'info' => '必须关注公众号才可参与投票!')); exit; } $Apply = M('Apply'); $Weiauth = M('weiauth'); $id = I('id'); $openid = session('openid'); $map['openid'] = $openid; $data = $Weiauth->where($map)->find(); $voteto = str2arr($data['vote_to']); $votenum = $data['vote_day']; if (date('Ymd', $data['vote_time']) == date('Ymd', time()) && in_array($id, $voteto)) { $this->ajaxReturn(array('status' => 0, 'info' => '今日您已支持过该老人!')); } if (date('Ymd', $data['vote_time']) == date('Ymd', time())) { if ($votenum == 5) { $this->ajaxReturn(array('status' => 0, 'info' => '您今天的投票次数已用完')); } } if (date('Ymd', $data['vote_time']) != date('Ymd', time())) { $voteto = array(); $voteto[] = $id; $data = array(); $data['vote_to'] = arr2str($voteto); $data['vote_time'] = time(); $data['vote_day'] = 1; } else { $data = array(); $voteto[] = $id; $data['vote_to'] = arr2str($voteto); $data['vote_day'] = $votenum + 1; } $wres = $Weiauth->where($map)->save($data); $ares = $Apply->where('id=' . $id)->setInc('votes', 1); if ($wres && $ares) { M('statistics')->where('id=1')->setInc('vote_num', 1); $this->ajaxReturn(array('status' => 1, 'info' => '投票成功!')); } else { $this->ajaxReturn(array('status' => 0, 'info' => '投票失败!')); } //$votenum < 5 && !in_array($id, $voteto) //date('Ymd', $data['vote_time']) ! }