123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- // +----------------------------------------------------------------------
- // | 海豚PHP框架 [ DolphinPHP ]
- // +----------------------------------------------------------------------
- // | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://dolphinphp.com
- // +----------------------------------------------------------------------
- // | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // 为方便系统核心升级,二次开发中需要用到的公共函数请写在这个文件,不要去修改common.php文件
- //取数组每个键值
- if(!function_exists('array_v')){
- function array_v($key,$arr=array())
- {
- return $arr?(array_key_exists($key,$arr)?$arr[$key]:$arr[0]):'';
- }
- }
- //静态文本选择器
- if(!function_exists('staticText')){
- function staticText($data='',$type='view',$pp='Y-m-d H:i'){
- if($type=='view'){
- return "<div>{$data}</div>";
- }elseif($type=='url'){
- if(!$data) return no_font('暂无');
- return "<a href='{$data}' target='_bank' title='点击打开'>{$data}</a>";
- }elseif($type=='pic'){
- if(!$data) return no_font('暂无');
- return "<style>img.dj_img{max-width:300px;max-height:300px;}</style><a href='".get_file_path($data)."' target='_bank' title='点击查看原图'><img src='".get_file_path($data)."' class='dj_img'></a>";
- }elseif ($type=='pics') {
- if(!$data) return no_font('暂无');
- $html="";
- if(!is_array($data)){
- $data=explode(',',$data);
- }
- foreach ($data as $k => $v) {
- if(!$data) return no_font('暂无');
- $html.="<style>img.dj_img{max-width:300px;max-height:300px;}</style><a href='".get_file_path($v)."' target='_bank' title='点击查看原图'><img src='".get_file_path($v)."' class='dj_img'></a>";
- }
- return $html;
- }elseif($type=='file'){
- if(!$data) return no_font('暂无');
- return "<a href='".get_file_path($data)."' title='".get_file_name($data)."'>".get_file_name($data)."</a>";
- }elseif ($type=='files') {
- if(!$data) return no_font('暂无');
- $html="";
- if(!is_array($data)){
- $data=explode(',',$data);
- }
- foreach ($data as $k => $v) {
- $html.="<li><a href='".get_file_path($v)."' title='".get_file_name($v)."'>".get_file_name($v)."</a></li>";
- }
- return $html;
- }elseif($type=='time'){
- if(!$data) return no_font('未知');
- return date($pp,$data);
- }elseif($type=='admin_username'){
- if(!$data) return no_font('未知');
- return admin_username($data);
- }elseif($type=='img'){
- if(!$data) return no_font('暂无');
- return "<style>img.dj_img{max-width:300px;max-height:300px;}</style><a href='".config('mall.public_url').$data."' target='_bank' title='点击查看原图'><img src='".config('mall.public_url').$data."' class='dj_img'></a>";
- }elseif ($type=='imgs') {
- if(!$data) return no_font('暂无');
- $html="";
- if(!is_array($data)){
- $data=explode(',',$data);
- }
- foreach ($data as $k => $v) {
- if(!$data) return no_font('暂无');
- $html.="<style>img.dj_img{max-width:300px;max-height:300px;}</style><a href='".config('mall.public_url').$v."' target='_bank' title='点击查看原图'><img src='".config('mall.public_url').$v."' class='dj_img'></a>";
- }
- return $html;
- }else{
- if(!$data) return no_font('暂无');
- return $data;
- }
- }
- }
- //判断是否有此菜单权限
- if(!function_exists('if_menu_auth')){
- function if_menu_auth($menu_id,$admin_id=UID){
- $role=db('admin_user')->where('id',$admin_id)->value('role');
- if($role=='1') return true;
- $menu_auth=db('admin_role')->where('id',$role)->value('menu_auth');
- if(strpos($menu_auth,'"'.$menu_id.'"')===false){
- return false;
- }else{
- return true;
- }
- }
- }
- //树形数组结构
- if(!function_exists('get_arr_tree')){
- function get_arr_tree($items,$pid ="parent_id") {
- $map = [];
- $tree = [];
- foreach ($items as &$it){ //数据的ID名生成新的引用索引树
- $map[$it['id']] = &$it;
- }
- foreach ($items as &$it){
- $parent = &$map[$it[$pid]];
- if($parent) {
- $parent['son'][] = &$it;
- }else{
- $tree[] = &$it;
- }
- }
- return $tree;
- }
- }
- //普通数组结构
- if(!function_exists('get_tree_ids')){
- function get_tree_ids($arr,$pid='0',$pix=0){
- global $tree_ids;
- foreach($arr as $key=>$value) {
- if($value['parent_id'] == $pid) {
- $tree_ids[$value['id']]= str_repeat(' ', $value['level']-$pix).$value['name'];
- get_tree_ids($arr , $value['id'] );
- }
- }
- return $tree_ids;
- }
- }
- //生成供应商编号
- if(!function_exists('get_supplier_serial_num')){
- function get_supplier_serial_num(){
- $serial_num=mt_rand(0,99999999999);
- $serial_num=str_pad($serial_num,11,"0",STR_PAD_LEFT);
- $supplier=db('suppliers')->field('id')->where('serial_num',$serial_num)->find();
- if($supplier){
- get_supplier_serial_num();
- }else{
- return $serial_num;
- }
- }
- }
- //平台流水号随机生成
- if(!function_exists('get_platform_water_sn')){
- function get_platform_water_sn(){
- $sn=mt_rand(0,9999999999);
- $sn=str_pad($sn,10,"0",STR_PAD_LEFT);
- $sn=date('YmdHis').$sn;
- $platform_warte=db('platform_waters')->field('id')->where('sn',$sn)->find();
- if($platform_warte){
- get_platform_water_sn();
- }else{
- return $sn;
- }
- }
- }
- /**
- * 清空/删除 文件夹
- * @param string $dirname 文件夹路径
- * @param bool $self 是否删除当前文件夹
- * @return bool
- */
- if(!function_exists('do_rmdir')){
- function do_rmdir($dirname, $self = true) {
- if (!file_exists($dirname)) {
- return false;
- }
- if (is_file($dirname) || is_link($dirname)) {
- return @unlink($dirname);
- }
- $dir = dir($dirname);
- if ($dir) {
- while (false !== $entry = $dir->read()) {
- if ($entry == '.' || $entry == '..') {
- continue;
- }
- do_rmdir($dirname . '/' . $entry);
- }
- }
- $dir->close();
- $self && @rmdir($dirname);
- }
- }
|