array(1 => '正常', -1 => '删除', 0 => '禁用', 2 => '未审核', 3 => '草稿'))) { if ($data === false || $data === null) { return $data; } $data = (array) $data; foreach ($data as $key => $row) { foreach ($map as $col => $pair) { if (isset($row[$col]) && isset($pair[$row[$col]])) { $data[$key][$col . '_text'] = $pair[$row[$col]]; } } } return $data; } /** * 获取对应状态的文字信息 * @param int $status * @return string 状态文字 ,false 未获取到 * @author huajie */ function get_status_title($status = null) { if (!isset($status)) { return false; } switch ($status) { case -1:return '已删除'; break; case 0:return '禁用'; break; case 1:return '正常'; break; case 2:return '待审核'; break; default:return false; break; } } // 获取数据的状态操作 function show_status_op($status) { switch ($status) { case 0:return '启用'; break; case 1:return '禁用'; break; case 2:return '审核'; break; default:return false; break; } } /** * 获取行为类型 * @param intger $type 类型 * @param bool $all 是否返回全部类型 * @author huajie */ function get_action_type($type, $all = false) { $list = array( 1 => '系统', 2 => '用户', ); if ($all) { return $list; } return $list[$type]; } /** * 获取行为数据 * @param string $id 行为id * @param string $field 需要获取的字段 */ function get_action($id = null, $field = null) { if (empty($id) && !is_numeric($id)) { return false; } $list = cache('action_list'); if (empty($list[$id])) { $map = array('status' => array('gt', -1), 'id' => $id); $list[$id] = db('Action')->where($map)->field(true)->find(); } return empty($field) ? $list[$id] : $list[$id][$field]; } function my_scandir($dir) { $files=array(); if(is_dir($dir)){ if($handle=opendir($dir)){ while(($file=readdir($handle))!==false){ if($file!='.' && $file!=".."){ $path = $dir."/".$file; // 设置目录,用于含有子目录的情况 if(is_dir($path)){ $files[$file]=my_scandir($path); }else{ $filename[] = $path;//获取文件名称 $files[]=$dir."/".$file; } } } } } closedir($handle); //array_multisort($filetime,SORT_DESC,SORT_STRING,$files);//按时间排序 //array_multisort($filename,SORT_ASC,SORT_STRING, $files);//按名字排序 return $files; } /****复制文件*****/ function copyfile($from_file, $to_file, $mode = 511, $move = false) { $from_file = trim($from_file); if (!is_file($from_file)) { return false; } $to_file = trim($to_file); $matches = array(); checkdir(dirname($to_file), true); if (is_file($to_file)) { @unlink($to_file); } if ($move) { $ret = rename($from_file, $to_file); } else { $ret = copy($from_file, $to_file); } if ($ret && $mode) { @chmod($to_file, $mode); } return $ret; } /** * zipfolder [解压文件] * * @param type $target_dir [当前解压目录] * @param type $upfilePath [上传ZIP的目录] * @param type $newfilePath [解压以后移动的目录] * @param type $file_dir [网站根目录] * @param type $ebook [文件路径] * * @return array **/ function zipfolder($target_dir,$upfilePath,$newfilePath,$file_dir,$ebook){ $zip = zip_open($file_dir.$ebook); if ($zip) { while ($zip_entry = zip_read($zip)) { if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry,zip_entry_filesize($zip_entry));// 读取zip文件, 并制定读取的长度 $fname = $target_dir.'/'.zip_entry_name($zip_entry); if(is_dir($fname)) // 如果是目录则创建目录(目录是未创建的) { checkdir($fname, 1 ); }else{ checkdir(dirname($fname), 1 ); if(strpos($fname,'.jpg') !==false || strpos($fname,'.png') !==false || strpos($fname,'.gif') !==false){ file_put_contents($fname,$buf); } } zip_entry_close($zip_entry); } } zip_close($zip); } $files = my_scandir($target_dir); asort($files);//降序 //对文件进行排序 $array_imgs = array(); if($files){ foreach($files as $key=>$val){ $new_array= array(); $sort_array = array(); foreach($val as $v){ $sort_array[$v] = $v; } asort($sort_array);//降序 foreach($sort_array as $k=>$v){ $filename =$newfilePath.date('Ymd')."/".getRandomName($v); copyfile($v,dirname(APP_PATH).$filename, 511, true); $new_array[] = $filename; } $array_imgs[$key] = $new_array; } } //删除解压目录 delfolder($target_dir); delfolder($upfilePath); return $array_imgs; } /** * get_agent [desc] * * @param type $id [获取推广的URL] * @param type $uid [desc] * @param type $short_url[强制关闭短连接] channel 渠道标识 **/ function get_agent($id,$uid,$wxmpid=0,$short_url=true,$channel=0){ //$result = db('member')->find($uid); $wxmpid=$wxmpid?$wxmpid:session('wxmpid'); $agent_tuiguangurl = config('agent_tuiguangurl'); $site_url = config('web_site_url'); $url = ''; $wxmp = array(); $wxid = db('tuiguang')->where('id',$id)->value('wxid'); //渠道用户 // if($result['is_top']==1){ // //渠道服务号是否存在 // $wxmp = db('wxmp')->where(['id'=>$wxmpid,'status'=>1])->field('id,open_appid')->find(); // if($wxmp){ // $url = get_agent_domain($uid,$wxmp['open_appid'],$wxmp['id'])."/referrals/index/".$id."/channel"."/".$channel; // }else{ // $url = $site_url."/referrals/index/".$id."/channel"."/".$channel; // } // }else{ // //代理商对应的渠道用户服务号是否存在 // $wxmp = db('wxmp')->where(['id'=>$wxmpid,'status'=>1])->field('id,open_appid')->find(); // if($wxmp&&$result['s_uid']!=1&&$result['s_uid']){ // $url = get_agent_domain($result['s_uid'],$wxmp['open_appid'],$wxmp['id'])."/referrals/index/".$id."/channel"."/".$channel; // }else{ // $url = $site_url."/referrals/index/".$id."/channel"."/".$channel; // } // } $url = $site_url."/referrals/index/".$id."/wxid"."/".$wxid; if(config('sina_short_url')&&$short_url){ $url = trim($url); return getSinaShortUrl($url); }else{ return trim($url); } } /** * get_appid [获取APPID] * * @param type $uid [用户ID] * * @return type **/ function get_appid($uid,$wxmpid=0){ $result = db('member')->find($uid); $appid = config('wx_apiid'); //渠道用户 if($result['is_top']==1){ //渠道服务号是否存在 $wxmp = db('wxmp')->where(['id'=>$wxmpid,'status'=>1])->find(); if($wxmp){ $appid = $wxmp['appid']; } }elseif($result['s_uid']>0){ //代理商对应的渠道用户服务号是否存在 $wxmp = db('wxmp')->where(['id'=>$wxmpid,'status'=>1])->find(); if($wxmp){ $appid = $wxmp['appid']; } } return $appid; } /** * get_payinfo [获取用户支付信息] * * @param type $uid [desc] * * @return type **/ function get_payinfo($uid){ $payinfo = db('MemberExtend')->where('uid',$uid)->find(); $info = ''; switch($payinfo['payment_type']){ case 'bank': $info .="

收款方式:银行卡

"; break; case 'alipay': $info .="

收款方式:支付宝

"; break; case 'weixin': $info .="

收款方式:微信

"; break; default: $info .="

收款方式:未配置

"; } if($payinfo['payment_type'] =='bank'){ $info .="

持卡人姓名:".$payinfo['card_holder_name']."

"; $info .="

卡号:".$payinfo['card_number']."

"; $info .="

开户行:".$payinfo['card_bank_name'].$payinfo['card_bank_province'].$payinfo['card_bank_city'].$payinfo['card_bank_branch']."

"; }elseif($payinfo['payment_type'] =='alipay'){ $info .="

帐号:".$payinfo['alipay_account_number']."

"; $info .="

姓名:".$payinfo['alipay_account_name']."

"; }elseif($payinfo['payment_type'] =='weixin'){ $info .="

微信号:".$payinfo['weixin_account']."

"; $info .="

昵称:".$payinfo['weixin_nickname']."

"; } return $info; } /** * 调用新浪接口将长链接转为短链接 * @param string $source 申请应用的AppKey * @param array|string $url_long 长链接,支持多个转换(需要先执行urlencode) * @return array */ function getSinaShortUrl($url_long){ //长链接转成短链接 $Extends = &load_wechat(1,'Extends'); $data = $Extends->getShortUrl($url_long); return $data; } function get_spread($bookid,$urltype){ $num = db('tuiguang')->where(['modelid'=>1,'articleid'=>$bookid,'urltype'=>$urltype])->count(); return $num?$num:0; } /** * 一维数据数组生成数据树 * @param array $list 数据列表 * @param string $id 父ID Key * @param string $pid ID Key * @param string $son 定义子数据Key * @return array */ function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub') { list($tree, $map) = [[], []]; foreach ($list as $item) { $map[$item[$id]] = $item; } foreach ($list as $item) { if (isset($item[$pid]) && isset($map[$item[$pid]])) { $map[$item[$pid]][$son][] = &$map[$item[$id]]; } else { $tree[] = &$map[$item[$id]]; } } unset($map); return $tree; } /** * paySum [活动充值金额] * @return type **/ function get_activity_amount($activityid) { $wxmpid = session('wxmpid'); $map['status'] = 1; $map['is_kouliang'] = 0; if($activityid){ $map['activityid'] = $activityid; } if(session('user_auth.group')!=999){ $map['agentid'] = array('in',get_agent_user(session('user_auth.uid'))); $map['wxmpid'] = $wxmpid; } $sum = db('order')->where($map)->cache(true,600)->sum('money'); return $sum; } /** * statistics [活动充值笔数] * * @return type **/ function get_activity_paynum($activityid) { $wxmpid = session('wxmpid'); $map['status'] = 1; $map['is_kouliang'] = 0; if($activityid){ $map['activityid'] = $activityid; } if(session('user_auth.group')!=999){ $map['agentid'] = array('in',get_agent_user(session('user_auth.uid'))); $map['wxmpid'] = $wxmpid; } $total = db('order')->where($map)->count(); return $total; } function get_agent_user($uid) { $member = db('member')->where('uid='.$uid)->find(); if($member['is_top']==1){ $map['s_uid'] = $uid; }/***elseif($member['is_top']==0 && empty($member['t_uid'])){ $map['t_uid'] = $uid; }***/else{ return $uid; } $map['status'] =1; $map['group'] =array('IN','3,4'); $daili = db('member')->where($map)->cache(true,600)->column('uid'); $daili[]=$uid; $agentid = implode(",",$daili); return $agentid; }