where('site_id', SITE_ID); //id存在需要判断修改逻辑下排除id本身且不为空的情况下 有没有重复 $id = !empty($data['id']) ? $data['id'] : ''; if ($id) { $_db->where('id', '<>', $id); $_db->where($name, '<>', ' '); } $_data = $_db->where($name, $value)->find(); if (empty($_data)) { return true; } return $note . '已存在,请重新输入!!!'; } /** * json统一返回 * @param type $code 状态编码 0正常 * @param type $data 返回数据 * @param type $msg 错误的提示信息 * @return type */ function send_http_status($data = [], $code = 0, $httpStatus = 200, $msg = '') { $msg = !empty($msg) ? $msg : config('dictionary')[$code]; //排除成功的状态信息 if (in_array($code, [201, 203, 205, 207, 209])) { $code = 0; } $_data = [ 'code' => $code, 'msg' => $msg, 'count' => 0, 'data' => $data, ]; //更改data2级数据为一级 增加列表页count数据 if (isset($data['page_total'])) { $_data['count'] = $data['page_total']; $_data['data'] = empty($data['data']) ? [] : $data['data']; } if ($code != 0 && $code != 200) { throw new \app\exception\HttpException($httpStatus, $msg, $code); } return json($_data, $httpStatus); } /** * 把格式数组,拆分父栏目,与子栏目 * @param type $arr 一级数组 * @param type $pid 父id * @param type $child_name 生成子数组的名称 * @param type $primary 表的主键值,上一级id * @return type */ function get_tree(array $arr, $pid = 0, $child_name = 'children', $primary = 'id') { if (empty($arr)) { return $arr; } if (is_array($arr)) { $child = get_child($arr, $pid); if (empty($child)) { return null; } foreach ($child as $key => $value) { $current_child = get_tree($arr, $value[$primary]); if ($current_child != null) { $child[$key][$child_name] = $current_child; } } } return $child; } //根据pid获取子栏目 返回子栏目数组集合 function get_child($arr, $pid = 0) { if (is_array($arr)) { $child = array(); foreach ($arr as $key => $value) { if ($value['parent_id'] == $pid) { $child[$key] = $value; } } return array_values($child); } return $arr; } /** * 云掌图片服务器裁剪函数 * @param $src 源地址,不带?号 * @param $w 宽度 * @param $h 高度 * @param $g 裁剪位置 nw西北 north正北 ne东北 west正西 center中间 east正东 sw西南 south正南 se东南 * @param string $type 执行方式 crop:裁剪 resize:缩放 */ function crop_thumb($src, $w = '', $h = '') { //判断图片是不是全路径 $cdn_img_host = strpos($src, 'http') !== 0 ? config('cdn_img_host') : ''; if (empty($src) || !$w || !$h) { return $cdn_img_host . $src; } //限制宽、高大小 if ($w > 2000 || $w < 5 || $h > 2000 || $h < 5) { return $src; } //有逗号分割符取第一张图片 $first_pic = strstr($src, ',', true); $src = !empty($first_pic) ? $first_pic : $src; //拆分图片后缀 $last_pos = strripos($src, '.'); //图片格式中点的位置 $base_url = mb_substr($src, 0, $last_pos); //去图片后缀的url $exp_url = mb_substr($src, $last_pos); //图片后缀 return $cdn_img_host . $base_url . '_' . $w . 'x' . $h . $exp_url; } /** * 判断浏览器名称和版本 */ function get_client_browser() { $agent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : false; if (!$agent) { return false; } if ((strpos($agent, 'MSIE') == false) && (strpos($agent, 'Trident') !== FALSE)) { return 'Internet Explorer 11.0'; } if (strpos($agent, 'MSIE 10.0') != false) { return 'Internet Explorer 10.0'; } if (strpos($agent, 'MSIE 9.0') != false) { return 'Internet Explorer 9.0'; } if (strpos($agent, 'MSIE 8.0') != false) { return 'Internet Explorer 8.0'; } if (strpos($agent, 'MSIE 7.0') != false) { return 'Internet Explorer 7.0'; } if (strpos($agent, 'MSIE 6.0') != false) { return 'Internet Explorer 6.0'; } if (strpos($agent, 'Edge') != false) { return 'Edge'; } if (strpos($agent, '360SE') != false) { return '360SE'; } if (strpos($agent, 'QQBrowser') != false) { return 'QQBrowser'; } if (strpos($agent, 'Firefox') != false) { return 'Firefox'; } if (strpos($agent, 'Chrome') != false) { return 'Chrome'; } if (strpos($agent, 'Safari') != false) { return 'Safari'; } if (strpos($agent, 'Opera') != false) { return 'Opera'; } //微信浏览器 if (strpos($agent, 'MicroMessage') != false) { return '微信浏览器'; } } /** * 获取系统类型 */ function get_client_os() { $agent = strtolower($_SERVER['HTTP_USER_AGENT']); if (strpos($agent, 'windows nt')) { $platform = 'Windows'; } elseif (strpos($agent, 'macintosh')) { $platform = 'Mac'; } elseif (strpos($agent, 'ipod')) { $platform = 'iPod'; } elseif (strpos($agent, 'ipad')) { $platform = 'iPad'; } elseif (strpos($agent, 'iphone')) { $platform = 'iPhone'; } elseif (strpos($agent, 'android')) { $platform = 'Android'; } elseif (strpos($agent, 'unix')) { $platform = 'Unix'; } elseif (strpos($agent, 'linux')) { $platform = 'Linux'; } else { $platform = '其他'; } return $platform; } //过滤单双引号 function htmlspecialchars_custom($str) { return htmlspecialchars($str, ENT_QUOTES); }