1190 lines
33 KiB
PHP
1190 lines
33 KiB
PHP
<?php
|
||
|
||
use think\facade\Cache;
|
||
|
||
function crul_post($url, $data=array()){
|
||
error_log('提交的地址是'.$url);
|
||
error_log('提交的数据是'.json_encode($data));
|
||
$ch = curl_init ();
|
||
// print_r($ch);
|
||
curl_setopt ( $ch, CURLOPT_URL, $url );
|
||
curl_setopt ( $ch, CURLOPT_TIMEOUT, 5 ); // 设置超时限制防止死循环
|
||
curl_setopt ( $ch, CURLOPT_POST, 1 );
|
||
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
|
||
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
||
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
|
||
$res = curl_exec ( $ch );
|
||
if (curl_errno ( $ch )) {
|
||
$res= 'curl:Errno'.curl_error($ch);
|
||
}
|
||
curl_close ( $ch );
|
||
error_log('返回的数据是'.$res);
|
||
return $res;
|
||
}
|
||
|
||
function crul_get_check($url){
|
||
$ch = curl_init();
|
||
$timeout = 3;
|
||
curl_setopt ($ch, CURLOPT_URL, $url);
|
||
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||
$res = curl_exec ( $ch );
|
||
|
||
$httpcode=curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||
if($httpcode !== 200){ //检查$targe是否存在
|
||
error_log('文件读取不正确:'.$httpcode." ".$url);
|
||
curl_close ( $ch );
|
||
return false;
|
||
}
|
||
|
||
if (curl_errno ( $ch )) {
|
||
//$res= 'curl:Errno'.curl_error($ch);
|
||
$res=false;
|
||
}
|
||
curl_close ( $ch );
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 获取客户端IP地址
|
||
* @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字
|
||
* @param boolean $adv 是否进行高级模式获取(有可能被伪装)
|
||
* @return mixed
|
||
*/
|
||
function get_client_ip($type = 0,$adv=false) {
|
||
$type = $type ? 1 : 0;
|
||
static $ip = NULL;
|
||
if ($ip !== NULL) return $ip[$type];
|
||
if($adv){
|
||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||
$pos = array_search('unknown',$arr);
|
||
if(false !== $pos) unset($arr[$pos]);
|
||
$ip = trim($arr[0]);
|
||
}elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
|
||
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||
}elseif (isset($_SERVER['REMOTE_ADDR'])) {
|
||
$ip = $_SERVER['REMOTE_ADDR'];
|
||
}
|
||
}elseif (isset($_SERVER['REMOTE_ADDR'])) {
|
||
$ip = $_SERVER['REMOTE_ADDR'];
|
||
}
|
||
// IP地址合法验证
|
||
$long = sprintf("%u",ip2long($ip));
|
||
$ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
|
||
return $ip[$type];
|
||
}
|
||
|
||
function before_asyn(){
|
||
ignore_user_abort(TRUE);//如果客户端断开连接,不会引起脚本abort
|
||
set_time_limit(60);//重新设置脚本执行超时的上限
|
||
header("Content-Encoding: none\r\n");
|
||
if (ob_get_level() == 0) ob_start();
|
||
error_log('输出完成');
|
||
echo str_pad('ok',4096)."\n";
|
||
@ob_flush();
|
||
@flush();
|
||
@ob_end_flush();
|
||
//@ob_end_clean();
|
||
}
|
||
|
||
// 不区分大小写的in_array实现
|
||
function in_array_case($value,$array){
|
||
return in_array(strtolower($value),array_map('strtolower',$array));
|
||
}
|
||
|
||
/**
|
||
* 将管理员菜单转换成关系树
|
||
* @param array $menus 菜单无关系一维数组
|
||
* @param int $p_id 父类id
|
||
* @param int $deep 各级菜单深度
|
||
* @param araay
|
||
*/
|
||
function transform_menu_tree($menu, $p_id = 0, $deep = 0)
|
||
{
|
||
|
||
$menu_tree = array();
|
||
$deep++;
|
||
foreach ($menu as $k => $sub) {
|
||
if ($p_id == $sub['p_id']) {
|
||
|
||
$sub_pid = $sub['menu_id'];
|
||
$menu_tree[$k] = $sub;
|
||
$menu_tree[$k]['deep'] = $deep;
|
||
unset($menu[$k]);
|
||
$menu_tree[$k]['sub_menu'] = transform_menu_tree($menu, $sub_pid, $deep);
|
||
}
|
||
}
|
||
return $menu_tree;
|
||
}
|
||
|
||
/**
|
||
* 将将菜单关系树转换成垂直结构
|
||
* @param array $menu_tree 菜单关系树多维数组
|
||
* @param array
|
||
*/
|
||
function transform_menu_tree_line($menu_tree)
|
||
{
|
||
$menu_line = array();
|
||
foreach ($menu_tree as $k => $item) {
|
||
$sub_menu = $item['sub_menu'];
|
||
unset($item['sub_menu']);
|
||
$menu_key = $item['menu_id'] . "_" . $item['p_id'];
|
||
$menu_line[$menu_key] = $item;
|
||
if ($sub_menu) {
|
||
$sub = transform_menu_tree_line($sub_menu);
|
||
$menu_line = array_merge($menu_line, $sub);
|
||
}
|
||
}
|
||
return $menu_line;
|
||
}
|
||
|
||
/**
|
||
* 重新设置菜单关系树的键值为menu_id
|
||
* @param array $menu_tree 菜单关系树多维数组
|
||
* @param array
|
||
*/
|
||
function reset_menu_key($menu_tree)
|
||
{
|
||
|
||
$reset_menu = array();
|
||
foreach ($menu_tree as $k => $item) {
|
||
|
||
$sub_menu = $item['sub_menu'];
|
||
unset($item['sub_menu']);
|
||
$menu_key = $item['menu_id'];
|
||
$reset_menu[$menu_key] = $item;
|
||
|
||
if ($sub_menu) {
|
||
$sub = reset_menu_key($sub_menu);
|
||
$reset_menu[$menu_key]['sub_menu'] = $sub;
|
||
}
|
||
}
|
||
return $reset_menu;
|
||
}
|
||
|
||
/**
|
||
* 搜查菜单关系树的键值为menu_id的数据
|
||
* @param array $menu_tree 菜单关系树多维数组
|
||
* @param array
|
||
*/
|
||
function find_menu_key($menu_tree,$menu_id) {
|
||
|
||
$find_menu = array();
|
||
$flag = false;
|
||
foreach($menu_tree as $k => $item){
|
||
|
||
if ($item['menu_id'] == $menu_id) {
|
||
$find_menu = $item;
|
||
$flag = true;
|
||
}
|
||
$sub_menu = $item['sub_menu'];
|
||
if ($sub_menu && !$flag) {
|
||
$result_menu = find_menu_key($sub_menu,$menu_id);
|
||
$find_menu = array_merge($find_menu,$result_menu);
|
||
}
|
||
}
|
||
return $find_menu;
|
||
}
|
||
|
||
/**
|
||
* 获取选择的菜单信息:面包屑导航以及设置选中class
|
||
* @param array $menu_tree 菜单关系树多维数组
|
||
* @param array
|
||
*/
|
||
function select_menu_item($menu_tree, $url_data)
|
||
{
|
||
$reset_menu = array();
|
||
$bread_nav = array();
|
||
$controller = $url_data['controller'];
|
||
$action = $url_data['action'];
|
||
|
||
foreach ($menu_tree as $k => $item) {
|
||
$sub_menu = $item['sub_menu'];
|
||
$class_style = '';
|
||
if (strcasecmp($item['controller'], $controller) == 0 && strcasecmp($item['action'], $action) == 0) {
|
||
$class_style = "active";
|
||
$tmp = array();
|
||
$tmp['menu_name'] = $item['menu_name'];
|
||
$tmp['active'] = 1;
|
||
$bread_nav[] = $tmp;
|
||
}
|
||
$item['class'] = $class_style;
|
||
if ($item['is_show'] == 1) {
|
||
$reset_menu[$k] = $item;
|
||
}
|
||
|
||
if ($sub_menu) {
|
||
$sub_return = select_menu_item($sub_menu, $url_data);
|
||
$return_menu_tree = $sub_return['menu_tree'];
|
||
$return_bread_nav = $sub_return['bread_nav'];
|
||
|
||
if ($item['is_show'] == 1) {
|
||
$reset_menu[$k]['sub_menu'] = $return_menu_tree;
|
||
}
|
||
|
||
if (!empty($return_bread_nav)) {
|
||
$reset_menu[$k]['class'] = "open active";
|
||
$tmp = array();
|
||
$tmp['menu_name'] = $item['menu_name'];
|
||
$tmp['active'] = 0;
|
||
$bread_nav[] = $tmp;
|
||
}
|
||
$bread_nav = array_merge($bread_nav, $return_bread_nav);
|
||
}
|
||
}
|
||
|
||
$reset_data['menu_tree'] = $reset_menu;
|
||
$reset_data['bread_nav'] = $bread_nav;
|
||
|
||
return $reset_data;
|
||
}
|
||
|
||
/**
|
||
* 将管理员操作功能转换成关系树
|
||
* @param array $menus 菜单无关系一维数组
|
||
* @param int $p_id 父类id
|
||
* @param int $deep 各级菜单深度
|
||
* @param araay
|
||
*/
|
||
function transform_action_tree($action, $p_id = 0, $deep = 0)
|
||
{
|
||
|
||
$action_tree = array();
|
||
$deep++;
|
||
foreach ($action as $k => $sub) {
|
||
if ($p_id == $sub['p_id']) {
|
||
$sub_pid = $sub['operate_id'];
|
||
$action_tree[$k] = $sub;
|
||
$action_tree[$k]['deep'] = $deep;
|
||
unset($action[$k]);
|
||
$action_tree[$k]['sub_action'] = transform_action_tree($action, $sub_pid, $deep);
|
||
}
|
||
}
|
||
return $action_tree;
|
||
}
|
||
|
||
/**
|
||
* 将将菜单关系树转换成垂直结构
|
||
* @param array $menu_tree 菜单关系树多维数组
|
||
* @param array
|
||
*/
|
||
function transform_action_tree_line($action_tree)
|
||
{
|
||
$action_line = array();
|
||
foreach ($action_tree as $k => $item) {
|
||
$sub_action = $item['sub_action'];
|
||
unset($item['sub_action']);
|
||
$action_key = $item['operate_id'] . "_" . $item['p_id'];
|
||
$action_line[$action_key] = $item;
|
||
if ($sub_action) {
|
||
$sub = transform_action_tree_line($sub_action);
|
||
$action_line = array_merge($action_line, $sub);
|
||
}
|
||
}
|
||
return $action_line;
|
||
}
|
||
|
||
/**
|
||
* 重新设置菜单关系树的键值为menu_id
|
||
* @param array $menu_tree 菜单关系树多维数组
|
||
* @param array
|
||
*/
|
||
function reset_action_key($action_tree)
|
||
{
|
||
|
||
$reset_action = array();
|
||
foreach ($action_tree as $k => $item) {
|
||
|
||
$sub_action = $item['sub_action'];
|
||
unset($item['sub_action']);
|
||
$action_key = $item['operate_id'];
|
||
$reset_action[$action_key] = $item;
|
||
|
||
if ($sub_action) {
|
||
$sub = reset_action_key($sub_action);
|
||
$reset_action[$action_key]['sub_action'] = $sub;
|
||
}
|
||
}
|
||
return $reset_action;
|
||
}
|
||
|
||
/**
|
||
* 搜查操作功能关系树的键值为operate_id的数据
|
||
* @param array $action_tree 菜单关系树多维数组
|
||
* @param array
|
||
*/
|
||
function find_action_key($action_tree,$operate_id) {
|
||
|
||
$find_action = array();
|
||
$flag = false;
|
||
foreach($action_tree as $k => $item){
|
||
|
||
if ($item['operate_id'] == $operate_id) {
|
||
$find_action = $item;
|
||
$flag = true;
|
||
}
|
||
$sub_action = $item['sub_action'];
|
||
if ($sub_action && !$flag) {
|
||
$result_action = find_action_key($sub_action,$operate_id);
|
||
$find_action = array_merge($find_action,$result_action);
|
||
}
|
||
}
|
||
return $find_action;
|
||
}
|
||
|
||
/**
|
||
* 将多级金融产品分类转换成关系树
|
||
* @param int $pid 父类id
|
||
* @param array $cates 金融产品无关系一维数组
|
||
* @param int $deep 各级金融产品深度
|
||
* @param araay
|
||
*/
|
||
function transform_cate_tree($cates, $pid = 0, $pnid = '', $deep = -1, $link_name = array())
|
||
{
|
||
|
||
$cate_tree = array();
|
||
$deep++;
|
||
foreach ($cates as $k => $sub) {
|
||
if ($pid == $sub['pid']) {
|
||
|
||
$sub_pid = $sub['cate_id'];
|
||
$cate_tree[$k] = $sub;
|
||
$cate_tree[$k]['deep'] = $deep;
|
||
$link_nid = $pnid . $sub['nid'];
|
||
|
||
$cate_name = array();
|
||
array_push($cate_name, $sub['name']);
|
||
|
||
$cate_tree[$k]['link_nid'] = $link_nid;
|
||
$cate_tree[$k]['link_name'] = array_merge($link_name, $cate_name);
|
||
|
||
unset($cates[$k]);
|
||
$cate_tree[$k]['sub_cate'] = transform_cate_tree($cates, $sub_pid, $link_nid, $deep, $cate_tree[$k]['link_name']);
|
||
}
|
||
}
|
||
|
||
return $cate_tree;
|
||
}
|
||
|
||
function transform_cate_tree_special($cates, $pid = 0, $pnid = '', $deep = -1, $link_name = array())
|
||
{
|
||
|
||
$cate_tree = array();
|
||
$deep++;
|
||
foreach ($cates as $k => $sub) {
|
||
if ($pid == $sub['pid']) {
|
||
|
||
$sub_pid = $sub['cate_id'];
|
||
$cate_tree[$k] = $sub;
|
||
$cate_tree[$k]['deep'] = $deep;
|
||
$link_nid = $pnid . $sub['nid'];
|
||
|
||
$cate_name = array();
|
||
array_push($cate_name, $sub['name']);
|
||
|
||
$cate_tree[$k]['link_nid'] = $link_nid;
|
||
$cate_tree[$k]['link_name'] = array_merge($link_name, $cate_name);
|
||
|
||
unset($cates[$k]);
|
||
|
||
if ($deep < 1) {
|
||
$cate_tree[$k]['sub_cate'] = transform_cate_tree_special($cates, $sub_pid, $link_nid, $deep, $cate_tree[$k]['link_name']);
|
||
} else {
|
||
$cate_tree[$k]['sub_cate'] = array();
|
||
}
|
||
}
|
||
}
|
||
|
||
return $cate_tree;
|
||
}
|
||
|
||
/**
|
||
* 将多级金融产品关系树转换成垂直结构
|
||
* @param int $pid 父类id
|
||
* @param array $cates 金融产品无关系一维数组
|
||
* @param int $deep 各级金融产品深度
|
||
* @param araay
|
||
*/
|
||
function transform_tree_line($tree, $pnid = '')
|
||
{
|
||
|
||
$cates = array();
|
||
foreach ($tree as $k => $item) {
|
||
|
||
$sub_cate = $item['sub_cate'];
|
||
unset($item['sub_cate']);
|
||
$cate_key = $pnid . $item['nid'];
|
||
$cates[$cate_key] = $item;
|
||
if ($sub_cate) {
|
||
$sub = transform_tree_line($sub_cate, $cate_key);
|
||
$cates = array_merge($cates, $sub);
|
||
}
|
||
}
|
||
return $cates;
|
||
}
|
||
|
||
|
||
/**
|
||
* 将商品分类转换成关系树
|
||
* @param array $cates 金融产品无关系一维数组
|
||
* @param int $pid 父类id
|
||
* @param int $deep 各级金融产品深度
|
||
* @param araay
|
||
*/
|
||
function transform_goods_cate_tree($cates, $pid = 0, $deep = -1)
|
||
{
|
||
|
||
$cate_tree = array();
|
||
$deep++;
|
||
|
||
foreach ($cates as $k => $sub) {
|
||
if ($pid == $sub['pid']) {
|
||
|
||
$sub_pid = $sub['cate_id'];
|
||
$cate_tree[$k] = $sub;
|
||
$cate_tree[$k]['deep'] = $deep;
|
||
unset($cates[$k]);
|
||
$cate_tree[$k]['sub_cate'] = transform_goods_cate_tree($cates, $sub_pid, $deep);
|
||
}
|
||
}
|
||
return $cate_tree;
|
||
}
|
||
|
||
/**
|
||
* 将商品分类转换成关系树 只取前2级
|
||
* @param array $cates 金融产品无关系一维数组
|
||
* @param int $pid 父类id
|
||
* @param int $deep 各级金融产品深度
|
||
* @param araay
|
||
*/
|
||
function transform_goods_cate_tree_special($cates, $pid = 0, $deep = -1)
|
||
{
|
||
|
||
$cate_tree = array();
|
||
$deep++;
|
||
|
||
foreach ($cates as $k => $sub) {
|
||
|
||
if ($pid == $sub['pid']) {
|
||
$sub_pid = $sub['cate_id'];
|
||
$cate_tree[$k] = $sub;
|
||
$cate_tree[$k]['deep'] = $deep;
|
||
unset($cates[$k]);
|
||
if ($deep < 1) {
|
||
$cate_tree[$k]['sub_cate'] = transform_goods_cate_tree_special($cates, $sub_pid, $deep);
|
||
} else {
|
||
$cate_tree[$k]['sub_cate'] = array();
|
||
}
|
||
}
|
||
}
|
||
|
||
return $cate_tree;
|
||
}
|
||
|
||
/**
|
||
* 将将商品分类关系树转换成垂直结构
|
||
* @param int $pid 父类id
|
||
* @param array $cates 金融产品无关系一维数组
|
||
* @param int $deep 各级金融产品深度
|
||
* @param araay
|
||
*/
|
||
function transform_goods_cate_tree_line($tree)
|
||
{
|
||
|
||
$cates = array();
|
||
foreach ($tree as $k => $item) {
|
||
$sub_cate = $item['sub_cate'];
|
||
unset($item['sub_cate']);
|
||
$cate_key = $item['nid'];
|
||
$cates[$cate_key] = $item;
|
||
|
||
if ($sub_cate) {
|
||
$sub = transform_goods_cate_tree_line($sub_cate);
|
||
$cates = array_merge($cates, $sub);
|
||
}
|
||
}
|
||
|
||
return $cates;
|
||
}
|
||
|
||
/**
|
||
* 搜查菜单关系树的键值为cate_id的数据
|
||
* @param array $menu_tree 菜单关系树多维数组
|
||
* @param array
|
||
*/
|
||
function find_cate_key($cate_tree,$cate_id) {
|
||
|
||
$find_cate = array();
|
||
$flag = false;
|
||
foreach($cate_tree as $k => $item){
|
||
|
||
if ($item['cate_id'] == $cate_id) {
|
||
$find_cate = $item;
|
||
$flag = true;
|
||
}
|
||
$sub_cate = $item['sub_cate'];
|
||
if ($sub_cate && !$flag) {
|
||
$result_cate = find_cate_key($sub_cate,$cate_id);
|
||
$find_cate = array_merge($find_cate,$result_cate);
|
||
}
|
||
}
|
||
return $find_cate;
|
||
}
|
||
|
||
/**
|
||
* 强制返回到浏览器
|
||
*/
|
||
|
||
function ajax_return($res_return){
|
||
header('Content-Type:application/json; charset=utf-8');
|
||
exit(json_encode($res_return));
|
||
}
|
||
|
||
/**
|
||
* 生成订单号20位
|
||
* @return string
|
||
*/
|
||
function generate_order_sn($user_id = '0000'){
|
||
|
||
$now_microtime = get_micro_time();
|
||
$order_sn = date('ymdHi').$now_microtime[0];
|
||
$len = strlen($user_id);
|
||
if($len < 4){
|
||
$fix = '';
|
||
for($i=0;$i<(4-$len);$i++){
|
||
$fix .= "0";
|
||
}
|
||
$order_sn .= $fix.$user_id;
|
||
}else{
|
||
$order_sn .= substr($user_id, 0, 4);
|
||
}
|
||
$order_sn .= mt_rand(100,999);
|
||
|
||
return $order_sn;
|
||
}
|
||
|
||
/**
|
||
* 获取毫秒时间 *
|
||
* @return 数组,第一个值为毫秒数(加0字符串),第二个值为时间戳(秒)
|
||
*/
|
||
function get_micro_time() {
|
||
$time = explode(" ", microtime());
|
||
$time[0] = sprintf("%03d",round($time[0]*1000));
|
||
return $time;
|
||
}
|
||
|
||
|
||
/**
|
||
* 发起异步请求
|
||
* @param $url
|
||
* @param string $data
|
||
* @return bool
|
||
*/
|
||
function call_async_curl($url,$data=''){
|
||
|
||
$row = parse_url($url);
|
||
$host = $row['host']??"127.0.0.1";
|
||
$port = $row['port']??80;
|
||
$file = $row['path']??'';
|
||
$query = $row['query']??'';
|
||
|
||
$post = $errno = $errstr = '';
|
||
while (list($k,$v) = fun_adm_each($data)) {
|
||
$post .= $k."=".$v."&";
|
||
}
|
||
|
||
$post = substr( $post , 0 , -1 );
|
||
$len = strlen($post);
|
||
$fp = @fsockopen( $host ,$port, $errno, $errstr, 10);
|
||
if (!$fp) {
|
||
error_log('链接失败');
|
||
return false;
|
||
} else {
|
||
error_log('发送数据'.$post);
|
||
$out = "POST ".$file."?".$query." HTTP/1.1\r\n";
|
||
error_log($out);
|
||
$out .= "Host: $host\r\n";
|
||
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
|
||
$out .= "Connection: Close\r\n";
|
||
$out .= "Content-Length: $len\r\n\r\n";
|
||
$out .= $post;
|
||
fwrite($fp, $out);
|
||
//收到第一个输出再退出,便于防止没有成功触发程序,本机测试可以,但服务器上却会等待完成,原因不明,暂注释,不影响触发
|
||
error_log('打开时读取');
|
||
$receive = fread($fp, 1);
|
||
error_log('关闭前读取');
|
||
//以下测试时用
|
||
/*while (!feof($fp)) {
|
||
$receive .= fgets($fp, 128);
|
||
}*/
|
||
error_log($receive);
|
||
fclose($fp);
|
||
return true;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 替代each()
|
||
* @param $array
|
||
* @return array|bool
|
||
*/
|
||
function fun_adm_each(&$array){
|
||
$res = array();
|
||
$key = key($array);
|
||
if($key !== null){
|
||
next($array);
|
||
$res[1] = $res['value'] = $array[$key];
|
||
$res[0] = $res['key'] = $key;
|
||
}else{
|
||
$res = false;
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 检测当前终端是否为微信
|
||
*/
|
||
function is_wechat_client(){
|
||
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
|
||
function myResult($type,$data,$code=200,$msg='请求成功'){
|
||
$result = [
|
||
'code'=>$code,
|
||
'msg'=>$msg,
|
||
'message_type'=>$type,
|
||
'data'=>$data
|
||
];
|
||
return json_encode($result);
|
||
}
|
||
|
||
//判断是user_id还是session值
|
||
function checkGuestFlag($user_store_id){
|
||
if (strlen($user_store_id)>10) {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
function RemoveXSS($val) {
|
||
$val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val);
|
||
|
||
$search = 'abcdefghijklmnopqrstuvwxyz';
|
||
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||
$search .= '1234567890!@#$%^&*()';
|
||
$search .= '~`";:?+/={}[]-_|\'\\';
|
||
|
||
for ($i = 0; $i < strlen($search); $i++) {
|
||
$val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val);
|
||
$val = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $val);
|
||
}
|
||
$ra1 = array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base');
|
||
$ra2 = array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
|
||
$ra = array_merge($ra1, $ra2);
|
||
|
||
for ($i = 0; $i < sizeof($ra); $i++) {
|
||
$pattern = '/';
|
||
for ($j = 0; $j < strlen($ra[$i]); $j++) {
|
||
if ($j > 0) {
|
||
$pattern .= '(';
|
||
$pattern .= '(&#[xX]0{0,8}([9ab]);)';
|
||
$pattern .= '|';
|
||
$pattern .= '|(�{0,8}([9|10|13]);)';
|
||
$pattern .= ')*';
|
||
}
|
||
$pattern .= $ra[$i][$j];
|
||
}
|
||
$pattern .= '/i';
|
||
|
||
$replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2);
|
||
$val = preg_replace($pattern, $replacement, $val);
|
||
}
|
||
return $val;
|
||
}
|
||
|
||
function curlCookie($url, $header, $content=[],$backHeader=0,$cookie='',$post=true,$retry=2){
|
||
$ch = curl_init();
|
||
if(substr($url,0,5)=='https'){
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在:0/2
|
||
}
|
||
if(!isset($header[0])){//将索引数组转为键值数组
|
||
foreach($header as $hk=>$hv){
|
||
unset($header[$hk]);
|
||
$header[]=$hk.':'.$hv;
|
||
}
|
||
}
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||
curl_setopt($ch, CURLOPT_URL, $url);
|
||
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,15);
|
||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||
|
||
if(!Cache::get('HY_PORXY_IP')){
|
||
setCurlAgentIp(true);
|
||
}
|
||
//获取代理ip
|
||
//curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //http
|
||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); //sock5
|
||
curl_setopt($ch, CURLOPT_PROXY, Cache::get('HY_PORXY_IP'));
|
||
|
||
if ($post) {
|
||
curl_setopt($ch, CURLOPT_POST, true);
|
||
if(count($content)){
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS,$content);
|
||
}
|
||
}
|
||
if(!empty($cookie)){
|
||
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
|
||
}
|
||
curl_setopt($ch, CURLOPT_HEADER,$backHeader); // 显示返回的Header区域内容
|
||
$response = curl_exec($ch);
|
||
if($error=curl_error($ch)){
|
||
//die($error);
|
||
if ($retry>0) {
|
||
curl_close($ch);
|
||
return curlCookie($url, $header, $content,$backHeader,$cookie,$post,$retry-1);
|
||
} else {
|
||
curl_close($ch);
|
||
return $error;
|
||
}
|
||
}
|
||
curl_close($ch);
|
||
return $response;
|
||
}
|
||
|
||
//流通商品代理ip获取
|
||
function setCurlAgentIp($use_proxy_ip=false){
|
||
if ($use_proxy_ip){
|
||
//sockets5代理
|
||
//指定地区+运营商:阜阳+电信
|
||
$get_porxy_ip_url = "http://http.tiqu.alicdns.com/getip3?num=1&type=2&pro=340000&city=341200&yys=100017&port=2&time=1&ts=0&ys=1&cs=1&lb=1&sb=0&pb=4&mr=1®ions=&gm=4";
|
||
//不指定地区+运营商
|
||
//$get_porxy_ip_url = "http://http.tiqu.alicdns.com/getip3?num=1&type=2&pro=&city=0&yys=0&port=2&time=1&ts=0&ys=0&cs=0&lb=1&sb=0&pb=4&mr=1®ions=&gm=4";
|
||
//http代理
|
||
//$get_porxy_ip_url = "http://http.tiqu.alicdns.com/getip3?num=1&type=2&pro=&city=0&yys=0&port=1&time=1&ts=0&ys=0&cs=0&lb=1&sb=0&pb=4&mr=2®ions=&gm=4";
|
||
$_porxy_ip = Cache::get('HY_PORXY_IP');
|
||
if(!$_porxy_ip){
|
||
//$str = '{"code":0,"success":true,"msg":"0","data":[{"ip":"27.40.111.221","port":"4252"}]}';
|
||
$request_porxy_ip = json_decode(file_get_contents($get_porxy_ip_url),true);
|
||
if($request_porxy_ip['code'] == 0 && $request_porxy_ip['success'] == true){
|
||
$_porxy_ip = 'http://'.$request_porxy_ip['data'][0]['ip'].':'.$request_porxy_ip['data'][0]['port'];
|
||
Cache::set("HY_PORXY_IP", $_porxy_ip, 300);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function getCookieValue($response) {
|
||
$preg_cookie = '/Set-Cookie: (.*?);/mi';
|
||
if(preg_match_all($preg_cookie,$response,$cookie)){
|
||
$cookie = implode(';', $cookie['1']);
|
||
}
|
||
return $cookie;
|
||
}
|
||
|
||
function getJsonValue($response) {
|
||
$preg_json = '/{(.*?)}/mi';
|
||
if (preg_match($preg_json, $response, $json)) {
|
||
$json = $json['0'];
|
||
}
|
||
return $json;
|
||
}
|
||
|
||
function getBetween($input, $start, $end,$init_pos=0) {
|
||
$start_pos=strpos($input, $start,$init_pos);
|
||
if ($start_pos!==false) {
|
||
$start_pos=strlen($start)+$start_pos;
|
||
$end_pos=strpos($input,$end,$start_pos);
|
||
if ($end_pos!==false) {
|
||
$result['value'] = substr($input, $start_pos, $end_pos-$start_pos);
|
||
$result['start_pos']=$start_pos;
|
||
$result['end_pos']=$start_pos;
|
||
return $result;
|
||
} else {
|
||
return false;
|
||
}
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
function getMutiBetween($input,$start,$end) {
|
||
$result=[];
|
||
$init_pos=0;
|
||
while ($tmp_result=getBetween($input,$start,$end,$init_pos)) {
|
||
$result[]=$tmp_result['value'];
|
||
$init_pos=$tmp_result['end_pos'];
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
|
||
function async_curl_post($url,$data=array()){
|
||
error_log('提交的地址是'.$url);
|
||
error_log('提交的数据是'.json_encode($data));
|
||
|
||
$ch = curl_init ();
|
||
if (stripos($url, 'https') !== false) {
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
|
||
}
|
||
|
||
curl_setopt ( $ch, CURLOPT_URL, $url );
|
||
curl_setopt ( $ch, CURLOPT_NOSIGNAL, 1);
|
||
curl_setopt ( $ch, CURLOPT_TIMEOUT_MS, 500 ); // 设置超时限制防止死循环 500s执行退出
|
||
curl_setopt ( $ch, CURLOPT_POST, 1 );
|
||
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
|
||
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
||
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
|
||
$res = curl_exec ( $ch );
|
||
if (curl_errno ( $ch )) {
|
||
$res= 'curl:Errno'.curl_error($ch);
|
||
}
|
||
curl_close ( $ch );
|
||
error_log('返回的数据是'.$res);
|
||
return $res;
|
||
}
|
||
|
||
function toChineseNumber($money){
|
||
$money = number_format(round($money,2),2,'.','');
|
||
if ($money=='0.00') {
|
||
return '零圆';
|
||
}
|
||
$cnynums = array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
|
||
$cnyunits = array("圆","角","分");
|
||
$cnygrees = array("拾","佰","仟","万","拾","佰","仟","亿");
|
||
list($int,$dec) = explode(".",$money,2);
|
||
$dec = array_filter(array($dec[1],$dec[0]));
|
||
$ret = array_merge($dec,array(implode("",cnyMapUnit(str_split($int),$cnygrees)),""));
|
||
$ret = implode("",array_reverse(cnyMapUnit($ret,$cnyunits)));
|
||
return str_replace(array_keys($cnynums),$cnynums,$ret);
|
||
}
|
||
function cnyMapUnit($list,$units) {
|
||
$ul=count($units);
|
||
$xs=array();
|
||
foreach (array_reverse($list) as $x) {
|
||
$l=count($xs);
|
||
if ($x!="0" || !($l%4)) {
|
||
$n=($x=='0'?'':$x).($units[($l-1)%$ul]??'');
|
||
} else {
|
||
$n=is_numeric($xs[0][0]??'')?$x:'';
|
||
}
|
||
array_unshift($xs,$n);
|
||
}
|
||
return $xs;
|
||
}
|
||
|
||
/**
|
||
* 获取订单状态描述
|
||
*/
|
||
function get_order_status_str($item){
|
||
$order_status_str = '';
|
||
switch ($item['status']){
|
||
case 0:
|
||
if ($item['deadline_time'] > date("Y-m-d H:i:s")){
|
||
if ($item['agent'] == 1){
|
||
$order_status_str = '<span class="orange_txColor">待确认</span>';
|
||
}else{
|
||
$order_status_str = "待确认";
|
||
}
|
||
}else{
|
||
if ($item['agent'] == 1){
|
||
$order_status_str = '<span class="text-default">已取消</span>';
|
||
}else{
|
||
$order_status_str = "已取消";
|
||
}
|
||
}
|
||
break;
|
||
case 1:
|
||
if ($item['agent'] == 1) {
|
||
$order_status_str = '<span class="text-success">已完成</span>';
|
||
}else{
|
||
$order_status_str = "已完成";
|
||
}
|
||
break;
|
||
case 2:
|
||
case 3:
|
||
case 4:
|
||
if ($item['agent'] == 1) {
|
||
$order_status_str = '<span class="text-default">已取消</span>';
|
||
}else{
|
||
$order_status_str = '已取消';
|
||
}
|
||
break;
|
||
case 5:
|
||
if ($item['agent'] == 1) {
|
||
$order_status_str = '<span class="text-warning">已退款</span>';
|
||
}else{
|
||
$order_status_str = '已退款';
|
||
}
|
||
break;
|
||
case 6:
|
||
if($item['pay_type'] == 1){
|
||
if ($item['express_status'] == 0){
|
||
if ($item['pay_status'] == 1){
|
||
if ($item['agent'] == 1) {
|
||
$order_status_str = '<span class="text-active">待收货</span>';
|
||
}else{
|
||
$order_status_str = '待收货';
|
||
}
|
||
} else{
|
||
if ($item['agent'] == 1) {
|
||
$order_status_str = '<span class="text-primary">待收货,未付款</span>';
|
||
}else{
|
||
$order_status_str = '待收货,未付款';
|
||
}
|
||
}
|
||
} else {
|
||
if ($item['pay_status'] == 1){
|
||
if ($item['agent'] == 1) {
|
||
$order_status_str = '<span class="text-info">待收货</span>';
|
||
}else{
|
||
$order_status_str = '待收货';
|
||
}
|
||
} else{
|
||
if ($item['agent'] == 1) {
|
||
$order_status_str = '<span class="text-primary">待收货,未付款</span>';
|
||
}else{
|
||
$order_status_str = '待收货,未付款';
|
||
}
|
||
}
|
||
}
|
||
}else{
|
||
//线下支付
|
||
if ($item['pay_status'] == 0){
|
||
if ($item['agent'] == 1) {
|
||
$order_status_str = '<span class="text-danger">待付款</span>';
|
||
}else{
|
||
$order_status_str = '待付款';
|
||
}
|
||
} else {
|
||
|
||
if ($item['agent'] == 1) {
|
||
$order_status_str = '<span class="text-info">待收货</span>';
|
||
}else{
|
||
$order_status_str = '待收货';
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 7:
|
||
if ($item['agent'] == 1) {
|
||
$order_status_str = '<span class="orange_txColor">退款处理中</span>';
|
||
}else{
|
||
$order_status_str = '退款处理中';
|
||
}
|
||
break;
|
||
}
|
||
|
||
return $order_status_str;
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 获取订单状态描述
|
||
*/
|
||
function get_order_status_text($order_status){
|
||
$order_status_str = '';
|
||
switch ($order_status){
|
||
case 0:
|
||
break;
|
||
case 1:
|
||
$order_status_str = '待付款';
|
||
break;
|
||
case 2:
|
||
case 5:
|
||
$order_status_str = '待发货';
|
||
break;
|
||
case 3:
|
||
$order_status_str = '已完成';
|
||
break;
|
||
case 4:
|
||
$order_status_str = '已取消';
|
||
break;
|
||
case 6:
|
||
$order_status_str = '待收货';
|
||
break;
|
||
}
|
||
return $order_status_str;
|
||
}
|
||
|
||
/**
|
||
* 订单详情页ICON状态
|
||
* @param $item
|
||
* @param $now_time
|
||
* @return int
|
||
*/
|
||
function get_order_icon_status($item,$now_time){
|
||
$order_status = 0;
|
||
if($item['pay_status'] == 0 && $item['status'] == 6){
|
||
return 1;
|
||
}
|
||
if($item['pay_status'] == 0 && $item['status'] == 0){
|
||
return 1;
|
||
}
|
||
|
||
if($item['status'] == 6 && in_array($item['pay_type'],[2,3,4,5]) && $item['express_status'] == 0 && $item['pay_status'] == 1){
|
||
return 2;
|
||
}
|
||
|
||
if($item['status'] == 6 && $item['pay_type'] == 1 && $item['express_status'] == 0){
|
||
return 2;
|
||
}
|
||
|
||
if($item['status'] == 1 or $item['status'] == 7){
|
||
return 3;
|
||
}
|
||
|
||
if(in_array($item['status'],[2,3,4]) || ($item['status'] == 0 && $item['deadline_time'] < $now_time)){
|
||
return 4;
|
||
}
|
||
|
||
if($item['status'] == 0 && $item['deadline_time'] > $now_time){
|
||
return 5;
|
||
}
|
||
|
||
if($item['express_status'] == 1 && !in_array($item['status'],[1,7])){
|
||
return 6;
|
||
}
|
||
|
||
if($item['status'] == 6 && $item['pay_type'] == 2 && $item['express_status'] == 1 && $item['pay_status'] == 1){
|
||
return 6;
|
||
}
|
||
return $order_status;
|
||
}
|
||
|
||
/**
|
||
* 获取时间
|
||
*/
|
||
function get_left_time($time) {
|
||
$str = '';
|
||
if ($time > 86400){
|
||
$day = floor($time / 86400);
|
||
$str .= $day . '天';
|
||
$time = $time - 86400 * $day;
|
||
}
|
||
|
||
if ($time > 3600){
|
||
$hour = floor($time / 3600);
|
||
$str .= $hour."小时";
|
||
$time = $time - 3600 * $hour;
|
||
}
|
||
|
||
if ($time > 0){
|
||
$minute = ceil($time / 60);
|
||
$str .= $minute."分钟";
|
||
}
|
||
|
||
return $str;
|
||
}
|
||
function initSysConstant(){
|
||
//初始化系统常量
|
||
$system_constant = \think\facade\Cache::get("SYSTEM_CONSTANT");
|
||
if (!$system_constant) {
|
||
$list = \think\Db::name('constants')->column("param_value","param_name");
|
||
$system_constant = array();
|
||
foreach ($list as $k => $v) {
|
||
$system_constant[$k] = json_decode($v,true);
|
||
}
|
||
\think\facade\Cache::set('SYSTEM_CONSTANT', $system_constant,120);
|
||
}
|
||
//注意区别于缓存,config方式只对当前请求有效
|
||
config('SYSTEM_CONSTANT',$system_constant);
|
||
|
||
return $system_constant;
|
||
}
|
||
|
||
function getShippingFee($price,$num){
|
||
if($price > 2000){
|
||
$fee = 0;
|
||
}else{
|
||
$fee = ceil($num/300) * 20;
|
||
}
|
||
return $fee;
|
||
}
|
||
|
||
/**
|
||
*资质类型文字
|
||
*/
|
||
function get_certificate_type_text($certificate){
|
||
$text = '';
|
||
switch ($certificate){
|
||
case 'business_license':
|
||
$text = '企业营业执照';
|
||
break;
|
||
case 'peer_list':
|
||
$text = '随货同行单(票)样式';
|
||
break;
|
||
case 'gsp_license':
|
||
$text = '药品经营质量管理规范认证证书';
|
||
break;
|
||
case 'trade_license':
|
||
$text = '药品经营许可证';
|
||
break;
|
||
case 'purchase_identity':
|
||
$text = '采购人员身份证';
|
||
break;
|
||
case 'authority_purchase':
|
||
$text = '采购委托书';
|
||
break;
|
||
case 'tax_regcate':
|
||
$text = '税务登记证';
|
||
break;
|
||
case 'year_report':
|
||
$text = '企业年度报告公示 ';
|
||
break;
|
||
case 'make_license':
|
||
$text = '药品生产许可证';
|
||
break;
|
||
case 'gmp_license':
|
||
$text = '药品GMP证书';
|
||
break;
|
||
case 'principal_identity':
|
||
$text = '委托人身份证';
|
||
break;
|
||
case 'sales_commission':
|
||
$text = '销售委托书';
|
||
break;
|
||
case 'quality_agreement':
|
||
$text = '药品质量保证协议书';
|
||
break;
|
||
case 'acting_prove':
|
||
$text = '委托代理证明';
|
||
break;
|
||
case 'medical_license':
|
||
$text = '医疗机构执业许可证';
|
||
break;
|
||
}
|
||
return $text;
|
||
}
|
||
|
||
/**
|
||
*资质类型样图
|
||
*/
|
||
function get_certificate_type_img($certificate){
|
||
$text = 'https://ydyd-develop-file.oss-cn-hangzhou.aliyuncs.com/license/';
|
||
$text = $text.$certificate.'.jpg';
|
||
return $text;
|
||
}
|
||
|
||
//手机验证
|
||
if (!function_exists('is_mobile')){
|
||
function is_mobile($phone){
|
||
$rule = '/^1[0-9]{10}$/';
|
||
$result = preg_match($rule, $phone);
|
||
if ($result) {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
} |