/** * 该方法的返回值为一下格式 * $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); }
/** * 定时任务,将redis中的点击次数更新到mysql中 */ public function redisToMysql() { //>>1.连接上redis $redis = getRedis(); //>>2.需要从redis中得到所有商品的浏览次数 $keys = $redis->keys('goods_view_times:*'); $values = $redis->mget($keys); //>>3.将浏览次数保存到数据库表goods_click中 foreach ($keys as $i => $key) { $goods_id = str2arr($key, ':')[1]; //从goods_view_times:10中取出商品的id $view_times = $values[$i]; //对应的浏览次数 $row = M('GoodsClick')->where('goods_id=' . $goods_id)->find(); if ($row) { //有则更新 M('GoodsClick')->where(array('goods_id' => $goods_id))->setInc('click_times', $view_times); } else { //无则生成 M('GoodsClick')->add(array('goods_id' => $goods_id, 'click_times' => $view_times)); } } //>>4.将redis中的键删除 $redis->del($keys); }
public function upload() { /* 返回标准数据 */ $return = array('status' => 1, 'info' => '上传成功', 'data' => ''); /* 获取当前分类附件配置信息 */ $default = C('ATTACHMENT_DEFAULT'); $category = get_category(I('get.category')); /* 分类正确性检测 */ if (empty($category)) { $return['status'] = 0; $return['info'] = '没有指定分类或分类不正确;'; } else { $config = $category['extend']['attachment']; $config = empty($config) ? $default : array_merge($default, $config); /* 检测并上传附件 */ if (in_array('2', str2arr($config['allow_type']))) { $setting = C('ATTACHMENT_UPLOAD'); /* 调用文件上传组件上传文件 */ $File = M('File'); $info = $File->upload($_FILES, $setting, $config['driver'], $config['driver_config']); /* 记录附件信息 */ if ($info) { $return['data'] = think_encrypt(json_encode($info['attachment'])); } else { $return['status'] = 0; $return['info'] = $File->getError(); } } else { $return['info'] = '该分类不允许上传文件附件!'; $return['status'] = 0; } } /* 返回JSON数据 */ $this->ajaxReturn($return); }
/** * 文档保存成功后执行行为 * @param array $data 文档数据 * @param array $catecory 分类数据 */ public function documentSaveComplete($param) { if (MODULE_NAME == 'Home') { list($data, $category) = $param; /* 附件默认配置项 */ $default = C('ATTACHMENT_DEFAULT'); /* 合并当前配置 */ $config = $category['extend']['attachment']; $config = empty($config) ? $default : array_merge($default, $config); $attach = I('post.attachment'); /* 该分类不允许上传附件 */ if (!$config['is_upload'] || !in_array($attach['type'], str2arr($config['allow_type']))) { return; } switch ($attach['type']) { case 1: //外链 # code... break; case 2: //文件 $info = json_decode(think_decrypt($attach['info']), true); if (!empty($info)) { $Attachment = D('Addons://Attachment/Attachment'); $Attachment->saveFile($info['name'], $info, $data['id']); } else { return; //TODO:非法附件上传,可记录日志 } break; } } }
private function hanlderRow(&$rows) { foreach ($rows as &$row) { if (!empty($row['option_values'])) { $row['option_values'] = str2arr($row['option_values'], "\r\n"); } } }
/** * 根据goods_type_id,查询属性信息 * @param $goods_type_id * @return mixed */ public function getListByGoodsTypeId($goods_type_id) { $rows = $this->where(array('goods_type_id' => $goods_type_id, 'status' => 1))->field('sort,intro,status', true)->select(); //将option_values变成数组 foreach ($rows as &$row) { $row['option_values'] = str2arr($row['option_values']); } unset($row); return $rows; }
public function clear() { if (IS_POST) { $PATHs = $_REQUEST['delids']; $arrPath = str2arr($PATHs, ','); foreach ($arrPath as $path) { //var_dump(delDirAndFile($path)); delDirAndFile($path); } $this->ajaxReturn(array("status" => 200, "message" => "缓存文件已清除")); } }
/** * 设置where查询条件 * @param number $category 分类ID * @param number $pos 推荐位 * @param integer $status 状态 * @return array 查询条件 */ private function listMap($category, $status = '', $pos = null) { /* 设置状态 */ if ($status) { $map = array('status' => $status); } /* 设置分类 */ if (!is_null($category)) { if (is_numeric($category)) { $map['category_id'] = $category; } else { $map['category_id'] = array('in', str2arr($category)); } } /* 设置推荐位 */ if (is_numeric($pos)) { $map[] = "position & {$pos} = {$pos}"; } return $map; }
function get_str2arr($str) { if ($str) { $emp = str2arr($str, ';'); for ($i = 0; $i < count($emp); $i++) { $emp_no[] = str2arr($emp[$i], '|')[1]; } if ($emp_no) { return $emp_no; } } }
private function delchildcat($cid) { // 找出所有子栏目及自身 $strchild = $this->category_model->getOne('catid,arrchildid', array('catid' => $cid)); $arrchild = str2arr($strchild['arrchildid']); // 判断子栏目或者自身下是否有文章 foreach ($arrchild as $c) { if ($this->article_model->getOne('artid,catid', array('catid' => $c))) { return $c; } else { continue; } } $this->category_model->deleteOne("catid in(" . $strchild['arrchildid'] . ")"); return true; }
/** * 检查$pos(推荐位的值)是否包含指定推荐位$contain * @param number $pos 推荐位的值 * @param number $contain 指定推荐位 * @return boolean true 包含 , false 不包含 * @author huajie <*****@*****.**> */ function check_document_position($pos = 0, $contain = 0) { if (empty($pos) || empty($contain)) { return false; } $arr = str2arr($pos); $count = count($arr); if ($count !== 1) { return in_array($contain, $arr); } else { //将两个参数进行按位与运算,不为0则表示$contain属于$pos $res = $pos & $contain; if ($res !== 0) { return true; } else { return false; } } }
$in = "{$in}{$in}"; echo "strbin_ulong(", $in, ") = ", strbin_ulong($in), "<BR>"; echo "<BR>"; /**********************************************************/ echo "*******************************<BR>"; echo "str2arr(\$string) : <BR>"; echo "*******************************<BR>"; /**********************************************************/ $in = "01000001"; echo "str2arr(", $in, ") = ", str2arr($in), "<BR>"; $in = "0100000v"; echo "str2arr(", $in, ") = ", str2arr($in), "<BR>"; $in = ""; echo "str2arr(", $in, ") = ", str2arr($in), "<BR>"; $in = "10000000000000000000000000000000"; echo "str2arr(", $in, ") = ", str2arr($in), "<BR>"; echo "<BR>"; /**********************************************************/ echo "*******************************<BR>"; echo "readbit_ulong(\$val,\$bit) : <BR>"; echo "*******************************<BR>"; /**********************************************************/ $in = "~U~U~"; $pos = "0"; echo "readbit_ulong(", $in, ",", $pos, ") = ", readbit_ulong($in, $pos), "<BR>"; $pos = "1"; echo "readbit_ulong(", $in, ",", $pos, ") = ", readbit_ulong($in, $pos), "<BR>"; $pos = "30"; echo "readbit_ulong(", $in, ",", $pos, ") = ", readbit_ulong($in, $pos), "<BR>"; $pos = "31"; echo "readbit_ulong(", $in, ",", $pos, ") = ", readbit_ulong($in, $pos), "<BR>";
/** * 邮箱列表 * @param [uid] [用户ID] * @param int $page 页数 * @param int $page_size 条数 * @param [folder=''] [error] * @param [folder=0] [未读邮件] * @param [folder=1] [收件箱] * @param [folder=2] [发件箱] * @param [folder=3] [草稿箱] * @param [folder=4] [已删除] * @param [folder=5] [垃圾邮件] * @param [folder=6] [永久删除] * @return [type] id [邮件ID] * @return [type] folder [类型] * @return [type] name [<标题>] * @return [type] content [内容] * @return [type] add_file [<附件>] * @return [type] from [发送者] * @return [type] reply_to [<接受者>] * @return [type] cc [<抄送>] * @return [type] read [<是否已读>] * @return [type] user_id [<发送者ID>] * @return [type] user_name [<发送者姓名>] * @return [type] create_time [<description>] * @return [type] update_time [<description>] * @return [type] is_del [<是否删除>] * @return [type] bcc [<密送>] * @return [type] is_bcc [<是否密送>] */ public function email_list() { $emp_id = UID; $folder = $_REQUEST['folder']; $page = $_REQUEST['page']; $page_size = $_REQUEST['page_size']; $where = $this->search_email(); switch ($folder) { case '1': //收件箱 $where['folder'] = array('eq', 1); $where['is_del'] = array('eq', 0); break; case '2': //发件箱 $where['folder'] = array('eq', 2); $where['is_del'] = array('eq', 0); break; case '3': //草稿箱 $where['folder'] = array('eq', 3); $where['is_del'] = array('eq', 0); break; case '4': //已删除 $where['folder'] = array('eq', 4); break; case '5': //垃圾邮件 $where['folder'] = array('eq', 5); $where['is_del'] = array('eq', 0); break; case '6': //永久删除 $where['is_del'] = array('eq', 1); break; case '0': //未读邮件 $where['folder'] = array('eq', 1); $where['read'] = array('eq', 0); $where['is_del'] = array('eq', 0); break; default: $where['is_del'] = array('eq', 0); break; } $where['user_id'] = $emp_id; $order = 'create_time desc'; $data = M("Mail")->where($where)->order($order)->select(); for ($i = 0; $i < count($data); $i++) { $from[$i] = str2arr($data[$i]['from'], '|'); $data[$i]['from'] = $from[$i][0] ? $from[$i][0] : ''; $data[$i]['folder'] = $data[$i]['folder'] ?: ''; $data[$i]['mid'] = $data[$i]['mid'] ?: ''; $data[$i]['name'] = $data[$i]['name'] ?: ''; $data[$i]['content'] = $data[$i]['content'] ?: ''; $data[$i]['add_file'] = $data[$i]['add_file'] ?: ''; $data[$i]['read'] = $data[$i]['read'] ?: ''; $data[$i]['user_name'] = $data[$i]['user_name'] ?: ''; $data[$i]['create_time'] = $data[$i]['create_time'] ?: ''; $data[$i]['update_time'] = $data[$i]['update_time'] ?: ''; $data[$i]['is_bcc'] = $data[$i]['is_bcc'] ?: ''; } $result = page($page, $page_size, $data); if ($result) { $this->result(1, '查询成功', $result); } else { $this->result(0, '没有数据', ''); } }
function hexString_2_booleanArray($hex) { $len = strlen($hex); $t = "0000000100100011010001010110011110001001101010111100110111101111"; $binString = ""; for ($i = 0; $i < $len; $i++) { $binString .= substr($t, hexdec(substr($hex, $i, 1)) * 4, 4); } return str2arr($binString); }
public function news($p = 1) { $pagesize = 15; $categoryURL = I('get.category', ''); $Document = D('Document'); $field = 'id,name,pid,title,link_id'; //获取新闻下的所有子分类 $category = D('Category')->getTree("news", $field); $category = $category["_"]; $map['pid'] = 0; $map['status'] = 1; if (cookie("think_language") == "en") { $prevPage = "Previous"; $nextPage = "Next"; $langall = "All "; $langpage = " Tatols"; $map['group_id'] = 1; } else { $prevPage = "上一页"; $nextPage = "下一页"; $langall = "共"; $langpage = "页"; $map['group_id'] = 0; } if (isset($_GET['category']) && $_GET['category'] != "") { $categoryinfo = R("Article/category", array('id' => I('get.category'))); $map['category_id'] = $categoryinfo['id']; $list = $Document->where($map)->order("create_time DESC")->select(); $num = sizeof($list); $end = ceil($num / $pagesize); echo $end; if ($p == 1) { $prev = "<li class='disabled'><a href='#'>" . $prevPage . "</a></li>"; } elseif ($p > 1) { $prevp = $p - 1; $prev = "<li><a href='" . U('Nav/news', 'category=' . $categoryURL . '&p=' . $prevp) . "'>" . $prevPage . "</a></li>"; } if ($p == $end) { $next = "<li class='disabled'><a href='#'>" . $nextPage . "</a></li>"; } elseif ($p < $end) { $nextp = $p + 1; $next = "<li><a href='" . U('Nav/news', 'category=' . $categoryURL . '&p=' . $nextp) . "'>" . $nextPage . "</a></li>"; } $list = $Document->page($p, $pagesize)->where($map)->order("create_time DESC")->select(); } else { $categoryIDs = D('Category')->getTree("news"); $count = 0; foreach ($categoryIDs["_"] as $k => $v) { if ($count == 0) { $ids = $v['id']; } else { $ids = $ids . "," . $v['id']; } $count = 1; } if (is_numeric($ids)) { $map['category_id'] = $ids; } else { $map['category_id'] = array('in', str2arr($ids)); } $list = $Document->where($map)->order("create_time DESC")->select(); $num = sizeof($list); $end = ceil($num / $pagesize); if ($p == 1) { $prev = "<li class='disabled'><a href='#'>" . $prevPage . "</a></li>"; } elseif ($p > 1) { $prevp = $p - 1; $prev = "<li><a href='" . U('Nav/news', 'category=' . $categoryURL . '&p=' . $prevp) . "'>" . $prevPage . "</a></li>"; } if ($p == $end) { $next = "<li class='disabled'><a href='#'>" . $nextPage . "</a></li>"; } elseif ($p < $end) { $nextp = $p + 1; $next = "<li><a href='" . U('Nav/news', 'category=' . $categoryURL . '&p=' . $nextp) . "'>" . $nextPage . "</a></li>"; } $list = $Document->page($p, $pagesize)->where($map)->order("create_time DESC")->select(); } $this->assign("pagearea", $prev . $next . "<li><a href='#'>" . $langall . $end . $langpage . "</a></li>"); $this->assign("list", $list); if (cookie("think_language") == "en") { foreach ($category as $k => $v) { $category[$k]['title'] = $category[$k]['name']; } } $this->assign("category", $category); $this->display(); }
/** * 获取HttpQueryString的Array形式 * 根据url类型进行处理 * @param $diff 排除的参数 * @author 温开元 <wenkaiyuan.6@163.com 594164084@qq.com> * @return [array] [QueryParams] */ function get_http_query_string_array($diff = array()) { // 默认要去除的参数 $diff = array_merge($diff, array('p', 'r')); // 去除伪静态补充的后缀 $HttpQueryString = rtrim($_SERVER['QUERY_STRING'], C('TMPL_TEMPLATE_SUFFIX')); $QueryParams = array(); if ((int) C('URL_MODEL') === 3) { $HttpQueryString = ltrim($HttpQueryString, 's=/'); $queryArray = str2arr($HttpQueryString, '/'); // 去掉c a array_shift($queryArray); array_shift($queryArray); /* 如果这里报错则是因为这里需要PHP5.5语法支持 */ $item = true; while ($item) { $item = array_shift($queryArray); if (!empty($item)) { $val = array_shift($queryArray); $QueryParams[$item] = empty($val) ? '' : $val; } } } foreach ($diff as &$item) { if (isset($QueryParams[$item])) { unset($QueryParams[$item]); } } return $QueryParams; }
/** * 去除单个钩子里对应的插件数据 */ 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; }
/** * 获取数据 * @param string $field * @param $isbn * @return string */ function getInfoField($isbn, $field = '') { $ret = $this->getBookInfo('bookinfo', $isbn); if (empty($field)) { return $ret; } $keys = array_flip(str2arr($field)); $values = json_decode($ret, true); $data = array_intersect_key($values, $keys); return json_encode($data); }
function insertspecialchars($str) { $strarr = str2arr($str); $str = implode("<!---->", $strarr); return $str; }
<th>操作</th> </tr> </thead> <tbody> <?php if ($delivery_region_list) { ?> <?php $region_conf = $region_tid = array(); ?> <?php foreach ($delivery_region_list as $k => $v) { ?> <?php $tr_id = random(6); list($weight, $price) = str2arr($v['weightprice']); $region_id = explode(',', $v['region_id']); $region_conf = array_merge($region_conf, $region_id); $region_tid[$tr_id] = $region_id; $region_name = array(); foreach ($region_id as $rid) { $region_name[] = $regions[$rid]; } $region_name = implode(',', $region_name); ?> <tr class="area_item" id="<?php echo $tr_id; ?> " data-id = "<?php echo $v['id']; ?>
/** * 设置where查询条件 * @param number $category 分类ID * @param number $pos 推荐位 * @param integer $status 状态 * @return array 查询条件 */ private function listMap($category, $status = 1, $pos = null) { /* 设置状态 */ $map = array('status' => $status, 'pid' => 0); /* 设置分类 */ if (!is_null($category)) { if (is_numeric($category)) { $map['category_id'] = $category; } else { $map['category_id'] = array('in', str2arr($category)); } } $map['create_time'] = array('lt', NOW_TIME); $map['_string'] = 'deadline = 0 OR deadline > ' . NOW_TIME; /* 设置推荐位 */ if (is_numeric($pos)) { $map[] = "position & {$pos} = {$pos}"; } return $map; }
/** * 更新单个钩子处的插件 * @param $hook_name * @param $plugs_name * @return mixed */ public function updatePlugs($hook_name, array $plugs_name) { $o_plugs = db()->table("hook")->getRow(array("name" => $hook_name))->fields('plugs')->done(); $o_plugs = $o_plugs['plugs']; if ($o_plugs) { $o_plugs = str2arr($o_plugs); } if ($o_plugs) { $plugs = array_merge($o_plugs, $plugs_name); $plugs = array_unique($plugs); } else { $plugs = $plugs_name; } $flag = db()->table("hook")->upDate(array('plugs' => strtolower(arr2str($plugs))), array('name' => $hook_name))->done(); if (false === $flag) { db()->table("hook")->upDate(array('plugs' => strtolower(arr2str($o_plugs))), array('name' => $hook_name))->done(); } return $flag; }
function ivcs_transform_from($six_word) { global $rev_ivcs; if (!is_array($six_word)) { error_log("*************** non - array argument ****************"); error_log("ivcs_transform_from : non-array argument"); return false; // conversion to an array // is responsibility of calling routines } /* translate all six words into unsigned long versions of their int values as defined by their offset into $ivcs (iso-646 2048-word dictionary) */ $binArray = array(); for ($i = 0; $i < 6; $i++) { $lutIndex = strtoupper($six_word[$i]); $packedIndex = pack("L", $rev_ivcs[$lutIndex]); $wordArray = str2arr(ulong2binstr($packedIndex)); $binArray = array_merge($binArray, array_slice($wordArray, 21, 11)); } $checksumCheckArray = rfc2289_checksum($binArray); if ($binArray[64] != $checksumCheckArray[0] || $binArray[65] != $checksumCheckArray[1]) { error_log("***************checksum error!****************"); error_log("ivcs_transform_from : Checksum error"); return false; } return booleanArray_2_hexString(array_slice($binArray, 0, 64)); }
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']) ! }