find($pk); if($column) { return $info[$column]; }else{ return $info; } } } if (!function_exists('array_sort')) { function array_sort($array,$row,$type){ $array_temp = array(); foreach($array as $v){ $array_temp[$v[$row]] = $v; } if($type == 'asc'){ ksort($array_temp); }elseif($type == 'desc'){ krsort($array_temp); }else{ } return $array_temp; } } if (!function_exists('goeasy_sms')) { function goeasy_sms($content) { $url = 'http://rest-hangzhou.goeasy.io/publish'; $channel="1"; $post_data = array("appkey"=>"BC-d2dd64b1ad024d67aa7a795798961668","channel"=>$channel,"content"=>$content); php_ajax($url,$post_data); } function php_ajax($url, $post_data) { $postdata = http_build_query($post_data); $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postdata, 'timeout' => 15 * 60 ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; } } if (!function_exists('curl_api')) { /** * curl请求(POST) * @param $url 请求地址 * @param array $data 请求参数 * @return bool|string 返回结果 * @author laravel开发员 * @date 2019/6/5 */ function curl_api_get($url, $header=[], $timeout=20) { // 初始化 $ch = curl_init(); // 设置post方式提交 // curl_setopt($ch, CURLOPT_POST, 1); // 设置头文件的信息作为数据流输出 curl_setopt($ch, CURLOPT_HEADER, 0); // 超时 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // 是否要求返回数据 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 请求头 if($header){ curl_setopt($ch, CURLOPT_HTTPHEADER, $header); } // 设置抓取的url curl_setopt($ch, CURLOPT_URL, $url); // 是否检测服务器的证书是否由正规浏览器认证过的授权CA颁发的 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 执行命令 $result = curl_exec($ch); // 关闭URL请求(释放句柄) curl_close($ch); return $result; } } // 公共助手函数 if (!function_exists('__')) { /** * 获取语言变量值 * @param string $name 语言变量名 * @param array $vars 动态变量值 * @param string $lang 语言 * @return mixed */ function __($name, $vars = [], $lang = '') { if (is_numeric($name) || !$name) { return $name; } if (!is_array($vars)) { $vars = func_get_args(); array_shift($vars); $lang = ''; } return \think\Lang::get($name, $vars, $lang); } } if (!function_exists('time_format')) { function time_format($time = NULL, $format='Y-m-d H:i'){ $time = $time === NULL ? NOW_TIME : intval($time); return date($format, $time); } } if (!function_exists('get_money_name_byident')) { /** * 获取币种名称 * @param unknown $k * @return Ambigous <> */ function get_money_name_byident($k){ $money_type_info=Db::name('money_type')->where('identification',"$k")->find(); return $money_type_info['name']; } } if (!function_exists('get_recharge_status')) { function get_recharge_status($k){ $arr=array('1'=>'审核中','2'=>'已完成','-1'=>'已拒绝'); return $arr[$k]; } } function randnumber($k) { $str='0123456789'; $code=str_shuffle($str); return substr($code, 0,$k); } if (!function_exists('get_paytype')) { function get_paytype($k){ $arr=array('1'=>'支付宝','2'=>'微信','3'=>'银行卡'); return $arr[$k]; } } if (!function_exists('format_bytes')) { /** * 将字节转换为可读文本 * @param int $size 大小 * @param string $delimiter 分隔符 * @return string */ function format_bytes($size, $delimiter = '') { $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); for ($i = 0; $size >= 1024 && $i < 6; $i++) { $size /= 1024; } return round($size, 2) . $delimiter . $units[$i]; } } if (!function_exists('datetime')) { /** * 将时间戳转换为日期时间 * @param int $time 时间戳 * @param string $format 日期时间格式 * @return string */ function datetime($time, $format = 'Y-m-d H:i:s') { $time = is_numeric($time) ? $time : strtotime($time); return date($format, $time); } } if (!function_exists('human_date')) { /** * 获取语义化时间 * @param int $time 时间 * @param int $local 本地时间 * @return string */ function human_date($time, $local = null) { return \fast\Date::human($time, $local); } } if (!function_exists('cdnurl')) { /** * 获取上传资源的CDN的地址 * @param string $url 资源相对地址 * @param boolean $domain 是否显示域名 或者直接传入域名 * @return string */ function cdnurl($url, $domain = false) { $regex = "/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i"; $url = preg_match($regex, $url) ? $url : \think\Config::get('upload.cdnurl') . $url; if ($domain && !preg_match($regex, $url)) { $domain = is_bool($domain) ? request()->domain() : $domain; $url = $domain . $url; } return $url; } } if (!function_exists('is_really_writable')) { /** * 判断文件或文件夹是否可写 * @param string $file 文件或目录 * @return bool */ function is_really_writable($file) { if (DIRECTORY_SEPARATOR === '/') { return is_writable($file); } if (is_dir($file)) { $file = rtrim($file, '/') . '/' . md5(mt_rand()); if (($fp = @fopen($file, 'ab')) === false) { return false; } fclose($fp); @chmod($file, 0777); @unlink($file); return true; } elseif (!is_file($file) or ($fp = @fopen($file, 'ab')) === false) { return false; } fclose($fp); return true; } } if (!function_exists('rmdirs')) { /** * 删除文件夹 * @param string $dirname 目录 * @param bool $withself 是否删除自身 * @return boolean */ function rmdirs($dirname, $withself = true) { if (!is_dir($dirname)) { return false; } $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($dirname, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST ); foreach ($files as $fileinfo) { $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink'); $todo($fileinfo->getRealPath()); } if ($withself) { @rmdir($dirname); } return true; } } if (!function_exists('copydirs')) { /** * 复制文件夹 * @param string $source 源文件夹 * @param string $dest 目标文件夹 */ function copydirs($source, $dest) { if (!is_dir($dest)) { mkdir($dest, 0755, true); } foreach ( $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST ) as $item ) { if ($item->isDir()) { $sontDir = $dest . DS . $iterator->getSubPathName(); if (!is_dir($sontDir)) { mkdir($sontDir, 0755, true); } } else { copy($item, $dest . DS . $iterator->getSubPathName()); } } } } if (!function_exists('mb_ucfirst')) { function mb_ucfirst($string) { return mb_strtoupper(mb_substr($string, 0, 1)) . mb_strtolower(mb_substr($string, 1)); } } if (!function_exists('addtion')) { /** * 附加关联字段数据 * @param array $items 数据列表 * @param mixed $fields 渲染的来源字段 * @return array */ function addtion($items, $fields) { if (!$items || !$fields) { return $items; } $fieldsArr = []; if (!is_array($fields)) { $arr = explode(',', $fields); foreach ($arr as $k => $v) { $fieldsArr[$v] = ['field' => $v]; } } else { foreach ($fields as $k => $v) { if (is_array($v)) { $v['field'] = isset($v['field']) ? $v['field'] : $k; } else { $v = ['field' => $v]; } $fieldsArr[$v['field']] = $v; } } foreach ($fieldsArr as $k => &$v) { $v = is_array($v) ? $v : ['field' => $v]; $v['display'] = isset($v['display']) ? $v['display'] : str_replace(['_ids', '_id'], ['_names', '_name'], $v['field']); $v['primary'] = isset($v['primary']) ? $v['primary'] : ''; $v['column'] = isset($v['column']) ? $v['column'] : 'name'; $v['model'] = isset($v['model']) ? $v['model'] : ''; $v['table'] = isset($v['table']) ? $v['table'] : ''; $v['name'] = isset($v['name']) ? $v['name'] : str_replace(['_ids', '_id'], '', $v['field']); } unset($v); $ids = []; $fields = array_keys($fieldsArr); foreach ($items as $k => $v) { foreach ($fields as $m => $n) { if (isset($v[$n])) { $ids[$n] = array_merge(isset($ids[$n]) && is_array($ids[$n]) ? $ids[$n] : [], explode(',', $v[$n])); } } } $result = []; foreach ($fieldsArr as $k => $v) { if ($v['model']) { $model = new $v['model']; } else { //$model = $v['name'] ? \think\Db::name($v['name']) : \think\Db::table($v['table']); } $primary = $v['primary'] ? $v['primary'] : $model->getPk(); $result[$v['field']] = $model->where($primary, 'in', $ids[$v['field']])->column("{$primary},{$v['column']}"); } foreach ($items as $k => &$v) { foreach ($fields as $m => $n) { if (isset($v[$n])) { $curr = array_flip(explode(',', $v[$n])); $v[$fieldsArr[$n]['display']] = implode(',', array_intersect_key($result[$n], $curr)); } } } return $items; } } if (!function_exists('var_export_short')) { /** * 返回打印数组结构 * @param string $var 数组 * @param string $indent 缩进字符 * @return string */ function var_export_short($var, $indent = "") { switch (gettype($var)) { case "string": return '"' . addcslashes($var, "\\\$\"\r\n\t\v\f") . '"'; case "array": $indexed = array_keys($var) === range(0, count($var) - 1); $r = []; foreach ($var as $key => $value) { $r[] = "$indent " . ($indexed ? "" : var_export_short($key) . " => ") . var_export_short($value, "$indent "); } return "[\n" . implode(",\n", $r) . "\n" . $indent . "]"; case "boolean": return $var ? "TRUE" : "FALSE"; default: return var_export($var, true); } } } if (!function_exists('mbsubstr')) { function mbsubstr($str, $start = 0, $length, $charset = "utf-8", $suffix = true) { if (function_exists("mb_substr")) { $slice = mb_substr($str, $start, $length, $charset); } elseif (function_exists('iconv_substr')) { $slice = iconv_substr($str, $start, $length, $charset); } else { $re['utf-8'] = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef][x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/"; $re['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/"; $re['gbk'] = "/[x01-x7f]|[x81-xfe][x40-xfe]/"; $re['big5'] = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("", array_slice($match[0], $start, $length)); } $fix = ''; if (strlen($slice) < strlen($str)) { $fix = '...'; } return $suffix ? $slice . $fix : $slice; } } if (!function_exists('letter_avatar')) { /** * 首字母头像 * @param $text * @return string */ function letter_avatar($text) { $total = unpack('L', hash('adler32', $text, true))[1]; $hue = $total % 360; list($r, $g, $b) = hsv2rgb($hue / 360, 0.3, 0.9); $bg = "rgb({$r},{$g},{$b})"; $color = "#ffffff"; $first = mb_strtoupper(mb_substr($text, 0, 1)); $src = base64_encode('' . $first . ''); $value = 'data:image/svg+xml;base64,' . $src; return $value; } } if (!function_exists('hsv2rgb')) { function hsv2rgb($h, $s, $v) { $r = $g = $b = 0; $i = floor($h * 6); $f = $h * 6 - $i; $p = $v * (1 - $s); $q = $v * (1 - $f * $s); $t = $v * (1 - (1 - $f) * $s); switch ($i % 6) { case 0: $r = $v; $g = $t; $b = $p; break; case 1: $r = $q; $g = $v; $b = $p; break; case 2: $r = $p; $g = $v; $b = $t; break; case 3: $r = $p; $g = $q; $b = $v; break; case 4: $r = $t; $g = $p; $b = $v; break; case 5: $r = $v; $g = $p; $b = $q; break; } return [ floor($r * 255), floor($g * 255), floor($b * 255) ]; } } if(!function_exists('get_config_value')) { function get_config_value($str){ $data_arr=explode('-',$str); //字段 $data_zd=$data_arr['0']; //id $data_id=$data_arr['1']; //模型 $data_mod=$data_arr['2']; if(empty($data_mod)){ $data_mod="bonus_config"; } $info=Db::name($data_mod)->where('id',$data_id)->find(); return $info[$data_zd]; } } function get_user_level_text($k) { $info=db('user_level')->where(['id'=>$k])->find(); return $info['name']; } /** * 获取密码加密后的字符串 * @param string $password 密码 * @param string $salt 密码盐 * @return string */ if(!function_exists('getEncryptPassword')) { function getEncryptPassword($password, $salt = '') { return md5(md5($password) . $salt); } } function sendmsg($mobile,$content) { $url="http://dx.ipyy.net/sms.aspx?action=send&userid=&account=gxfc0430&password=49ur8t58yy6&mobile=".$mobile."&content=".$content; //初始化curl $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); //设置header curl_setopt($ch, CURLOPT_HEADER, FALSE); //要求结果为字符串且输出到屏幕上 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //post提交方式mobileVerify //运行curl $data = curl_exec($ch); $arr=xmlToArray($data); file_put_contents('1.txt',json_encode($arr)); return $arr; //返回结果 if($arr['returnstatus'] == 'Success'){ return true; }else{ return $arr; } } function xmlToArray($xml){ //禁止引用外部xml实体 libxml_disable_entity_loader(true); $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $val = json_decode(json_encode($xmlstring),true); return $val; } if(!function_exists('check_psdtwo')) { function check_psdtwo($pwd,$uid) { $info=get_user_data($uid); if(getEncryptPassword($pwd,$info['salt']) != $info['password2']) { return false; }else{ return true; } } } if(!function_exists('caiwu')) { function caiwu($data,$money_type) { $where = ['userid'=>$data['userid']]; $last=Db::name('detailed_'.strtolower($money_type))->where($where)->order('id desc')->find(); if($last) { $balance=$last['balance']+$data['money']; }else{ $user=Db::name('user')->where('id',$data['userid'])->find(); $balance=$user[$money_type]+$data['money']; } $changedata=[ 'userid'=>$data['userid'], 'type'=>$data['type'], 'money'=>$data['money'], 'balance'=>$balance, 'relevant_userid'=>$data['relevant_userid'], 'status'=>1, 'create_time'=>time(), 'remark'=>$data['remark'], 'user_name'=>get_user_data($data['userid'],'username'), 'relevant_name'=>$data['relevant_userid']>0?get_user_data($data['relevant_userid'],'username'):'系统', ]; $ids=Db::name('detailed_'.strtolower($money_type))->insertGetId($changedata); if($ids) { $iden=get_identification_by_type($changedata['type']); $userbalance[$money_type]=$changedata['balance']; Db::name('user')->where('id',$changedata['userid'])->update($userbalance); finance($changedata['type'], $changedata['money']); bonus_count($changedata['type'], $changedata['money'], $changedata['userid']); return true; }else{ return false; } } } /*推荐奖*/ function bonusorder($userid,$money) { $user=db('user')->where(['id'=>$userid])->find(); db('user')->where(['id'=>$userid])->setInc("reg_money",$money); if($user['refereeid']>0) { db('user')->where(['id'=>['in',$user['refereeids']]])->setInc("total_pv",$money); $bcf=db('bonus_config')->where(['id'=>3])->find(); if($bcf) { $bonusMoney = round($money * $bcf['value'] * 0.01, 2); if ($bonusMoney > 0) { $changedata = [ 'type' => 16, 'money' => $bonusMoney, 'userid' =>$user['refereeid'], 'relevant_userid' => $userid, 'remark' => $user['mobile'] . '竞拍' . $money . '元藏品推荐人得奖励:' . $bonusMoney, ]; caiwu($changedata, 'bonus'); db('user')->where(['id'=>$user['refereeid']])->setInc("total_bonus",$bonusMoney); } } } } function addtrade($gid) { $goodsinfo=db('goods')->where(['id'=>$gid])->find(); if($goodsinfo['topprice']<=$goodsinfo['price1']) { $sum=0; for($i=1;$i<=(int)$goodsinfo['son_nums'];$i++) { if($i < (int)$goodsinfo['son_nums']) { $price=round(($goodsinfo['price1']/$goodsinfo['son_nums']),0); $sum+=$price; }else{ $price=$goodsinfo['price1']-$sum; } $data=[ 'catid'=>$goodsinfo['catid'], 'title'=>$goodsinfo['title'].$i, 'description'=>$goodsinfo['description'], 'content'=>$goodsinfo['content'], 'image'=>$goodsinfo['image'], 'images'=>$goodsinfo['images'], 'on_sale'=>0, 'price'=>$price, 'price1'=>$price, 'topprice'=>$goodsinfo['topprice'], 'son_nums'=>$goodsinfo['son_nums'], 'utime'=>time(), 'isnew'=>1, 'istrade'=>0, 'stuid'=>$goodsinfo['stuid'], 'userid'=>$goodsinfo['userid'], ]; $ids=db('goods')->insertGetId($data); } db('goods')->where(['id'=>$goodsinfo['id']])->update(['on_sale'=>0,'price1'=>0,'price'=>0]); db('trade')->where(['goodsid'=>$goodsinfo['id'],'status'=>3])->update(['isout'=>1]); } } if(!function_exists('get_user_data')) { function get_user_data($userid,$field='') { $info=Db::name('user')->where('id',$userid)->find(); if(empty($field)) { return $info; }else{ return $info[$field]; } } } function get_user_info($userid,$field1='',$field2='') { $info=db('user')->where('id',$userid)->find(); return $info[$field1].'('.$info[$field2].')'; } if(!function_exists('finance')) { /* 公司收入-支出 */ function finance($changetype,$money){ $today=strtotime('today'); $money=abs($money); $map = ['ctime'=>$today]; $info=Db::name("finance")->where($map)->find(); $expend_arr =Db::name('bonus_type')->where('status',1)->column('type');//奖金支出 $income_arr = array('1'); if(!empty($info)){ if(in_array($changetype, $expend_arr)){ $data['expend']=$info['expend']+$money; }elseif(in_array($changetype, $income_arr)){ $data['income']=$info['income']+$money; } if(!empty($data)){ Db::name("finance")->where($map)->update($data); } }else{ $data['ctime']=$today; if(in_array($changetype, $expend_arr)){ $data['expend']=$money; }elseif(in_array($changetype, $income_arr)){ $data['income']=$money; } if(!empty($data)){ Db::name("finance")->insertGetId($data); } } } } if(!function_exists('bonus_count')) { function bonus_count($changetype,$money,$userid) { $count_date=strtotime('today'); $typemap=Db::name('bonus_type')->where(array('status'=>1))->column('type'); $countinfo=Db::name("bonus_count")->where(['statistime'=>$count_date,'userid'=>$userid])->find(); if($countinfo) { if(in_array($changetype, $typemap)){ $iden=get_identification_by_type($changetype); $data[$iden]=$countinfo[$iden]+$money; $data['total']=$countinfo['total']+$money; $data['cumulative']=$countinfo['cumulative']+$money; Db::name("bonus_count")->where(['statistime'=>$count_date,'userid'=>$userid])->update($data); } }else{ if(in_array($changetype, $typemap)){ $iden=get_identification_by_type($changetype); $data[$iden]=$money; $data['total']=$money; $data['statistime']=$count_date; $data['userid']=$userid; $data['username']=get_user_data($userid,'username'); $lastCount=Db::name('bonus_count')->where(['statistime'=>['lt',$count_date],'userid'=>$userid])->order('id desc')->find(); if($lastCount) { $data['cumulative']=$lastCount['cumulative']+$money; }else{ $data['cumulative']=$money; } Db::name("bonus_count")->insertGetId($data); } } } } if(!function_exists('get_identification_by_type')) { function get_identification_by_type($type) { $info=Db::name("bonus_type")->where('type',$type)->find(); return $info['identification']; } } if(!function_exists('get_detailed_type_text')) { function get_detailed_type_text($k){ $info=Db::name('detailed_type')->where('id',$k)->find(); return $info['title']; } } if(!function_exists('list_to_arr')) { $arr=[]; function list_to_arr($list,$k,$v){ foreach ($list as $vo){ $arr[$vo[$k]]=$vo[$v]?$vo[$v]:0; } return $arr; } } if(!function_exists('put_file_from_url_content')) { function put_file_from_url_content($url, $saveName, $path) { // 设置运行时间为无限制 set_time_limit ( 0 ); $url = trim ( $url ); $curl = curl_init (); // 设置你需要抓取的URL curl_setopt ( $curl, CURLOPT_URL, $url ); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 设置header //curl_setopt ( $curl, CURLOPT_HEADER, 0 ); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。 //curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 ); // 运行cURL,请求网页 $file = curl_exec ( $curl ); //var_dump($file); // 关闭URL请求 curl_close ( $curl ); // 将文件写入获得的数据 $filename = $path . $saveName; $write = @fopen ( $filename, "w" ); if ($write == false) { return false; } if (fwrite ( $write, $file ) == false) { return false; } if (fclose ( $write ) == false) { return false; } } }