123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- use think\Db;
- // 获取模板区域
- function get_city_area()
- {
- $field=['id','pid','name'];
- $list=Db::name('china_area')->where('pid',0)->field($field)->select();
- foreach ($list as $k=>&$v){
- $v['children']= Db::name('china_area')->where('pid',$v['id'])->field($field)->select();
- }
- return $list;
- }
- function http_curl($url,$type='get',$res='json',$arr=''){
- $headers = array();
- //根据API的要求,定义相对应的Content-Type
- array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8;application/json");
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $type);
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_FAILONERROR, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HEADER, false);
- $output = curl_exec($curl);
- curl_close($curl);
- if($res=='json'){
- if($output === false){
- //请求失败,返回错误信息
- return curl_error($curl);
- }else{
- //请求成功,返回信息
- return json_decode($output,true);
- }
- }
- }
- function curl_get($url)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $output = curl_exec($ch);
- curl_close($ch);
- if($output === false){
- return curl_error($ch);
- }else{
- return json_decode($output,true);
- }
- }
- /**
- * 把返回的数据集转换成Tree
- * @param array $list 要转换的数据集
- * @param string $pk 自增字段(栏目id)
- * @param string $pid parent标记字段
- * @return array
- */
- function make_tree($list,$pk='id',$pid='pid',$child='children',$root=0){
- if(is_object($list)) $list = $list->toArray();
- $tree=array();
- $packData=array();
- foreach ($list as $data) {
- $packData[$data[$pk]] = $data;
- }
- foreach ($packData as $key =>$val){
- if($val[$pid]==$root){//代表跟节点
- $tree[]=& $packData[$key];
- }else{
- $packData[$val[$pid]][$child][]=& $packData[$key]; //找到其父类
- }
- }
- return $tree;
- }
- //判断字段存在并不为空
- function isset_full($arr, $key)
- {
- if (isset($arr[$key]) && !empty($arr[$key])) {
- return true;
- } else {
- return false;
- }
- }
- //判断字段存在并不为空 并且等于验证值
- function isset_full_check($arr, $key,$check_val)
- {
- if (isset($arr[$key]) && !empty($arr[$key]) && $arr[$key] == $check_val) {
- return true;
- } else {
- return false;
- }
- }
- function all_pay_type()
- {
- return [ '--','微信[H5]','支付宝[H5]','微信[APP]','支付宝[APP]','微信[公众号]' ];
- }
- /**
- * 生成32位随机数
- */
- function get32Str($length='32'){
- $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- $len = strlen($str)-1;
- $randstr = '';
- for ($i=0;$i<$length;$i++) {
- $num=mt_rand(0,$len);
- $randstr .= $str[$num];
- }
- return $randstr;
- }
|