Files
pgserver3.0/pgserver/application/common.php
2026-04-23 18:25:35 +08:00

1695 lines
64 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Env;
use think\facade\Log;
use think\Db;
// 腾讯云cos - 使用Composer自动加载
// 应用公共文件
function p($a,$flag){
echo "<pre>";
print_r($a);
if($flag) die;
}
/* * 根据分类获取数据字典
* @param $type string
* @return array
*/
function getdictionary($type) {
// 暂时去掉缓存
/* static $list;
if (empty($list)) {
$list = cache('dic_list');
}*/
$key = "{$type}";
/*
if (isset($list[$key])) {
$dic = $list[$key];
} else {
*/
$info = Db::name('dictionary')->where(['type' => $type, 'status' => 1])->field('code,valname')->order('sort')->select();
$list[$key] = $info;
$dic = $list[$key];
cache('dic_list', $list, 3600);
// }
return $dic;
}
/**
* 获取数据字典选中值
* @param string $type
* @param string $status
*/
function getDictionaryName($type, $status) {
$res = getdictionary($type);
$name = '';
if (!empty($res)) {
foreach ($res as $k => $v) {
if ($v['code'] == $status) {
$name = $v['valname'];
break;
}
}
}
return $name;
}
function getDictionaryNameFromDictList($dict_list, $status) {
$name = '';
if (!empty($dict_list)) {
foreach ($dict_list as $k => $v) {
if ($v['code'] == $status) {
$name = $v['valname'];
break;
}
}
}
return $name;
}
/**
* 获取数据字典[Options_automation]选中值
* @param type $type
* @param type $status
*/
function getDictionaryName_opa($type, $status) {
$res = getdictionary_opa($type);
$name = '';
$arr = [];
if (!empty($res)) {
if(strstr($status , ',')){
foreach (explode(',',$status) as $key => $value) {
foreach ($res as $k => $v) {
if ($v['code'] == $value) {
$arr[] = $v['name'];
break;
}
}
}
$name = implode(',', $arr);
}else{
foreach ($res as $k => $v) {
if ($v['code'] == $status) {
$name = $v['name'];
break;
}
}
}
}
return $name;
}
/**
* 获取 Options_automation表里的字段
*
* @param [type] $type
* @return void
*/
function getdictionary_opa($type) {
static $list;
$key = "{$type}";
if (isset($list[$key])) {
$dic = $list[$key];
} else {
$info = Db::name('options_automation')->where(['key' => $type])->field('code,name,type')->select();
$list[$key] = $info;
$dic = $list[$key];
cache('options_list', $list, 3600);
}
return $dic;
}
/**
* 获取数据字典code
* @param type $type
* @param type $name
* @return int
*/
function getDictionaryCode($type, $name) {
return Db::name('dictionary')
->where(['type'=>$type,'valname'=>$name])
->field('code')
->find();
}
/**
* 批量获取数据字典
* @param type $arr array
* @return array
*/
function getdictionarylist($arr) {
if (is_array($arr)) {
foreach ($arr as $value) {
$data[strtolower($value)] = getdictionary($value);
}
} else {
$data[strtolower($arr)] = getdictionary($arr);
}
return $data;
}
/**
* 上传文件到阿里云OSS
* @param string $object 文件名称(uploads/xxx/xxx)
* @param string $filePath 绝对路径
* @return array
*/
function ossUpload_ali($object, $filePath) {
try {
$cosClient = new \OSS\OssClient(config('uploadFile.access_key_id'), config('uploadFile.access_key_secret'), config('uploadFile.endpoint'));
//上传到阿里云
$cosClient->uploadFile(config('uploadFile.bucket'), $object, $filePath);
return ['code' => 1];
} catch (\Exception $e) {
return ['code' => -1, 'msg' => $e->getMessage()];
}
}
/**
* 上传文件到腾讯云COS
* @param string $object 文件名称(uploads/xxx/xxx)
* @param string $filePath 绝对路径
* @return array
*/
function ossUpload($object, $filePath) {
try {
// 创建 COS 客户端实例
$cosClient = new Qcloud\Cos\Client([
'region' => config('uploadFile.endpoint'),
'credentials' => [
'secretId' => config('uploadFile.access_key_id'),
'secretKey' => config('uploadFile.access_key_secret')
]
]);
// 上传文件到腾讯云
$cosClient->putObject([
'Bucket' => config('uploadFile.bucket'),
'Key' => $object,
'Body' => fopen($filePath, 'rb')
]);
return ['code' => 1];
} catch (\Exception $e) {
return ['code' => -1, 'msg' => $e->getMessage()];
}
}
/**
* Upload file to Tencent Cloud COS storage
*
* @param string $object The target path and filename in COS bucket
* @param string $filePath The local file path to upload
* @return mixed Returns upload result
*/
function ossDetele($object, $filePath) {
try {
// 创建 COS 客户端实例
$cosClient = new Qcloud\Cos\Client([
'region' => config('uploadFile.endpoint'),
'credentials' => [
'secretId' => config('uploadFile.access_key_id'),
'secretKey' => config('uploadFile.access_key_secret')
]
]);
// 删除文件
$cosClient->deleteObject([
'Bucket' => config('uploadFile.bucket'),
'Key' => $object
]);
return ['code' => 1];
} catch (\Exception $e) {
return ['code' => -1, 'msg' => $e->getMessage()];
}
}
/**
* 下载图片到本地
* @param $url
* @param $path
*/
function downLocal($url, $path) {
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //获取https图片
$file = curl_exec($ch);
curl_close($ch);
$filename = pathinfo($url, PATHINFO_BASENAME);
$resource = fopen($path . $filename, 'a');
fwrite($resource, $file);
fclose($resource);
return ['code' => 1, 'path' => $path . $filename]; //返回图片的绝对路径
} catch (\Exception $e) {
return ['code' => -1, 'msg' => $e->getMessage()];
}
}
function getQueryDateTime($field,$start_time,$end_time) {
$start_time_stamp = strtotime($start_time);
$end_time_stamp = strtotime($end_time);
$date_params = '';
if ($start_time && $end_time) {
if ($start_time_stamp > $end_time_stamp) {
$date_params = [$field,'between', [$end_time_stamp, $start_time_stamp + 86400 - 1]];
} else if ($start_time_stamp < $end_time_stamp) {
$date_params = [$field,'between', [$start_time_stamp, $end_time_stamp + 86400 - 1]];
} else {
$date_params = [$field,'between', [$start_time_stamp, $end_time_stamp + 86400 - 1]];
}
} else {
$start_time && $date_params = [$field,'egt', $start_time_stamp];
$end_time && $date_params = [$field,'elt', $end_time_stamp + 86400 - 1];
}
return $date_params;
}
/**
* 时间段查询 时间
*/
function getQueryDate($field, $start_time, $end_time) {
$start_time_stamp = strtotime($start_time);
$end_time_stamp = strtotime($end_time);
$date_params = '';
if ($start_time_stamp && $end_time_stamp) {
if ($start_time_stamp > $end_time_stamp) {
$date_params = [$field, 'between', [date('Y-m-d H:i:s', $end_time_stamp), date('Y-m-d 23:59:59', $start_time_stamp)]];
} else if ($start_time_stamp < $end_time_stamp) {
$date_params = [$field, 'between', [date('Y-m-d H:i:s', $start_time_stamp), date('Y-m-d 23:59:59', $end_time_stamp)]];
} else {
$date_params = [$field, 'between', [date('Y-m-d H:i:s', $start_time_stamp), date('Y-m-d 23:59:59', $start_time_stamp)]];
}
} else {
$start_time_stamp && $date_params = [$field, 'egt', date('Y-m-d H:i:s', $start_time_stamp)];
$end_time_stamp && $date_params = [$field, 'elt', date('Y-m-d 23:59:59', $end_time_stamp)];
}
return $date_params;
}
/**
* 其他字段区间范围筛选
*/
function getQuery($field, $start_length, $end_length) {
$date_params = '';
if ($start_length != null && $end_length != null) {
if ($start_length > $end_length) {
$date_params = [$field, 'between', [$end_length, $start_length]];
} else if ($start_length < $end_length) {
$date_params = [$field, 'between', [$start_length, $end_length]];
} else {
$date_params = [$field, 'between', [$start_length, $end_length]];
}
} else {
($start_length != null) && $date_params = [$field, 'egt', $start_length];
($end_length != null) && $date_params = [$field, 'elt', $end_length];
}
return $date_params;
}
/**
* 导出通用方法
* @param $list
* @param $filename
* @param array $indexKey
* @param array $indexValue
* @throws PHPExcel_Exception
* @throws PHPExcel_Writer_Exception
*/
function exportExcel($list, $filename, $indexKey = [], $indexValue = []){
$header_arr = ['A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
// 初始化PHPExcel()
$objPHPExcel = new \PHPExcel();
$PHPExcel_Cell_DataType =new \PHPExcel_Cell_DataType();
// 设置保存版本格式
$objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
// 接下来就是写数据到表格里面去
$objActSheet = $objPHPExcel -> getActiveSheet();
// 设置当前活动sheet的名称
$objActSheet->setTitle($filename);
$i = 1;
$j = 2;
// 设置表头
foreach ( $indexValue as $key => $value ){
// 这个比较有用,能自适应列宽
$objActSheet->getColumnDimension($header_arr[$key])->setAutoSize(true);
$objStyleA5 = $objActSheet->getStyle($header_arr[$key]);
//设置对齐方式
$objAlignA5 = $objStyleA5->getAlignment();
$objAlignA5->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objAlignA5->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objActSheet->setCellValue($header_arr[$key].$i,$value);
}
// 设置主要内容
foreach ($list as $row) {
foreach ($indexKey as $key => $value){
// if(!isset($row[$value]))
// continue;
// 这里是设置单元格的内容
// $objActSheet->setCellValueExplicit($header_arr[$key].$j,$row[$value], $PHPExcel_Cell_DataType::TYPE_STRING);
$objActSheet->setCellValue($header_arr[$key].$j,$row[$value]);
}
$j++;
}
// 下载这个表格,在浏览器输出就好了
// header("Pragma: public");
// header("Expires: 0");
// header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
// header("Content-Type:application/force-download");
// header("Content-Type:application/vnd.ms-execl;charset=UTF-8");
// header("Content-Type:application/octet-stream");
// header("Content-Type:application/download");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
header('Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition:attachment;filename='.$filename.'.xlsx');
// header("Content-Transfer-Encoding:binary");
// header("Access-Control-Expose-Headers:content-disposition");
$objWriter -> save(ROOT_PATH . 'public' . DS . 'uploads' . DS .$filename.'.xlsx');
if(file_exists(ROOT_PATH . 'public' . DS . 'uploads' . DS .$filename.'.xlsx')){
return Env::get('uploadFile.host_url') . '/' . 'uploads' . '/' .$filename.'.xlsx';
}else{
return "";
}
// 下载这个表格,在浏览器输出就好了
/*header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl;charset=UTF-8");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header('Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition:attachment;filename='.$filename.'.xlsx');
header("Content-Transfer-Encoding:binary");
header("Access-Control-Expose-Headers:content-disposition");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter -> save('php://output');*/
}
/**
* 通过excel获得结果集
* @param mixed $file $this->request->file('file');
* @param mixed $colname['dbcol'] = [] 数据库表字段名数组
* @param mixed $colname['excelcol'] = [] Excel表字段名数组
* @return Array
*/
function getArrayByExcel( $file,$sheet_index=0 )
{
if(!$file)
{
return [ 'code'=>-1,'msg'=>'文件不存在或文件出错','data'=>null];
}
try{
$excel = PHPExcel_IOFactory::load($file->getRealPath());
$sheet = $excel->getSheet($sheet_index);
$rows = $sheet->toArray(null, true, true, true);
// var_dump($rows);
}catch( Exception $e )
{
//log( '读取Excel文件出错'.$e->getMessage() );
return [ 'code'=>-1,'msg'=>'读取Excel文件出错'.$e->getMessage(),'data'=>null];
}
$data = array();
$i = 0;
// 第0行是字段描述不读取
// 第1行代表字段名 读取数据库表字段名
$dbFields = array();
foreach( $rows[2] as $field )
{
if( $field == '')
{
break;
}
$dbFields[] = $field;
}
//从第2行读取
// 获取数据
$data = array();
for ($i = 3; $i <= count($rows); $i++)
{
$row = array();
foreach ($dbFields as $j => $field)
{
$value = isset($rows[$i][chr($j+65)]) ? trim($rows[$i][chr($j+65)]) : null;
if( $j ==0 && ($value == '0' || $value == ''))
{
break;
}
$row[$field] = $value;
}
if (!empty($row))
{
$data[] = $row;
}
}
return[ 'code'=>1,'msg'=>'','data'=>$data];
}
/**
* 将数值金额转换为中文大写金额
* @param $amount float 金额(支持到分)
* @param $type int 补整类型,0:到角补整;1:到元补整
* @return mixed 中文大写金额
*/
function convertAmountToCn($amount, $type = 1) {
$c1 = "零壹贰叁肆伍陆柒捌玖";
$c2 = "分角元拾佰仟万拾佰仟亿";
// 确保 $amount 是数值类型
if (!is_numeric($amount)) {
$amount = 0;
}
$num = round($amount, 2);
$num = $num * 100;
// 转换为整数后再转换为字符串
$num_str = (string)(int)$num;
if (strlen($num_str) > 14) {
return "数据太长,检查下";
}
$i = 0;
$c = "";
$num_int = (int)$num_str;
while (1) {
if ($i == 0) {
$n = substr($num_str, strlen($num_str)-1, 1);
} else {
$n = $num_int % 10;
}
$p1 = substr($c1, 3 * $n, 3);
$p2 = substr($c2, 3 * $i, 3);
if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
$c = $p1 . $p2 . $c;
} else {
$c = $p1 . $c;
}
$i = $i + 1;
$num_int = $num_int / 10;
$num_int = (int)$num_int;
if ($num_int == 0) {
break;
}
}
$j = 0;
$slen = strlen($c);
while ($j < $slen) {
$m = substr($c, $j, 6);
if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
$left = substr($c, 0, $j);
$right = substr($c, $j + 3);
$c = $left . $right;
$j = $j-3;
$slen = $slen-3;
}
$j = $j + 3;
}
if (substr($c, strlen($c)-3, 3) == '零') {
$c = substr($c, 0, strlen($c)-3);
}
if (empty($c)) {
return "人民币零元整";
}else{
return "人民币". $c . "";
}
return $result;
}
//数字转大写
function numToWordone($num){
$chiNum = array('○', '一', '二', '三', '四', '五', '六', '七', '八', '九');
$chiUni = array('','十');
$chiStr = '';
$num_str = (string)$num;
$count = strlen($num_str);
$last_flag = true; //上一个 是否为0
$zero_flag = true; //是否第一个
$temp_num = null; //临时数字
$chiStr = '';//拼接结果
if ($count == 2) {//两位
$temp_num = $num_str[0];
$chiStr = $temp_num == 1 ? $chiUni[1] : $chiNum[$temp_num].$chiUni[1];
$temp_num = $num_str[1];
$chiStr .= $temp_num == 0 ? '' : $chiNum[$temp_num];
}else if($count > 2){
$index = 0;
for ($i=$count-1; $i >= 0 ; $i--) {
$temp_num = $num_str[$i];
$chiStr = $chiNum[$temp_num].$chiStr;
$index ++;
}
}else{
$chiStr = $chiNum[$num_str[0]];
}
return $chiStr;
}
/**
* 消息提醒公用方法
*
* @author cavan
*
* @param $quot_id //询价主表id
* @param $type //消息归属
* @param $message_type //消息类型
* @param $property_cert_info_id //物业表id
*/
function PublicMessage($quot_id="" ,$type="" , $message_type="", $property_cert_info_id="") {
if(!$quot_id){
return array("code"=>0,"msg"=>"缺少必要参数询价主表id");
}
if(!$type){
return array("code"=>0,"msg"=>"缺少必要参数消息归属");
}
if(!$message_type){
return array("code"=>0,"msg"=>"缺少必要参数消息类型");
}
if(in_array($message_type,[6,7,8])){
if(!$property_cert_info_id){
return array("code"=>0,"msg"=>"缺少必要参数物业表id");
}
}
$where["i.id"] = $quot_id;
if($property_cert_info_id){
$where["ii.id"] = $property_cert_info_id;
}
$inquiry = Db::name("inquiry")
->alias("i")
->join('pg_property_cert_info ii','ii.quot_id=i.id','LEFT')
->where($where)
->group("ii.quot_id")
->field("i.order_no,i.user_id,i.user_name,i.type,ii.property_full_name,ii.survey_user_id,ii.survey_user_name,i.is_auto")
->find();
if(empty($inquiry)){
return array("code"=>0,"msg"=>"未查得相关物业信息");
}
$type_arr = array(9,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,32); //需要用到报告信息的状态
if(in_array($message_type,$type_arr)){
//报告编号
$report = Db::name("report")
->where("quot_id",$quot_id)
->field("id,report_no,producer_id,producer_name")
->find();
if(empty($inquiry)){
return array("code"=>0,"msg"=>"未查得相关报告信息");
}
}
//消息内容处理
$message_content = "";
$name = "";
$query = array();
$apptype = $title = $s_id = "";
$user_id_arr = array();
$flag = 1;
$apiAuth = new app\lib\AuthApi();
$FbbService = new app\lib\FbbService();
$where = array();
switch ($message_type)
{
case 1:
$flag = 2;
$roleCodes = array("roleCodes"=>'Technical_manager,Deputy_manager,Evaluation_Assistant'); //技术部经理,技术部副经理,评估助理
$message_content = "单号".$inquiry['order_no']."待询价员回价,请及时处理(物业名称:".$inquiry['property_full_name'].",业务员:".$inquiry['user_name']."";
// //前端跳转方法和参数
// $type1 = ($inquiry['type'] == 1)?"priceReturnAllProjectUrgentProjectHouseList":"priceReturnAllProjectBusinessList";
// $name = "priceReturn-detail";
// $query = array(
// "id"=>$quot_id,
// "countdownPage"=>true,
// "isAllowOpenType"=>1,
// "type"=>1,
// "status"=>1,
// "from"=>$type1,
// );
if($inquiry['is_auto'] == 1){ //是否自动估价
//前端跳转方法和参数
$type1 = "home";
$name = "priceReturn-detail";
$query = array(
"id"=>$quot_id,
"countdownPage"=>true,
"isAllowOpenType"=>1,
"type"=>1,
"status"=>1,
"from"=>$type1,
);
}else{
//前端跳转方法和参数
$type1 = ($inquiry['type'] == 1)?"priceReturnAllProjectUrgentProjectHouseList":"priceReturnAllProjectBusinessList";
$name = "priceReturn-detail";
$query = array(
"id"=>$quot_id,
"countdownPage"=>true,
"isAllowOpenType"=>1,
"type"=>1,
"status"=>1,
"from"=>$type1,
);
}
break;
case 2:
$apptype = 401;
$title = "询价员已回价";
$user_id = $inquiry['user_id'];
$message_content = "单号".$inquiry['order_no']."询价员已回价,点击查看详情";
$where = ["message_type"=>1,"quot_id"=>$quot_id];
//前端跳转方法和参数
$inquiry_details = Db::name('property_cert_info')
->alias('a')
->join(['pg_return_price' => 'b'], 'b.property_cert_info_id = a.id','left')
->whereIn('a.quot_id', $quot_id)
->field([
'a.id', 'a.city','a.property_full_name', 'a.size','b.eva_unit_price','b.eva_total_value','b.eva_net_value'
])
->group('a.id')
->order('b.create_time', 'desc')
->select();
$name = "businessManage-businessInfo-inquiry-detail";
$query = array(
"id"=>$quot_id,
"order_no"=>$inquiry['order_no'],
"type"=>$inquiry['type'],
"inquiry_details"=>json_encode($inquiry_details)
);
break;
case 3:
$flag = 2;
$roleCodes = array("roleCodes"=>'Technical_manager,Deputy_manager,Evaluation_Assistant'); //技术部经理,技术部副经理,评估助理
$message_content = "单号".$inquiry['order_no']."待询价员调价,请及时处理(物业名称:".$inquiry['property_full_name'].",业务员:".$inquiry['user_name']."";
// $where = ["message_type"=>2,"quot_id"=>$quot_id];
//前端跳转方法和参数
// $type1 = ($inquiry['type'] == 1)?"priceReturnAllProjectUrgentProjectHouseList":"priceReturnAllProjectBusinessList";
$name = "priceReturn-detail";
$query = array(
"id"=>$property_cert_info_id,
"countdownPage"=>true,
"isAllowOpenType"=>1,
"type"=>1,
"status"=>2,
"adjust"=>1,
"from"=>"home",
);
break;
case 4:
$apptype = 402;
$title = "询价员已调价";
$user_id = $inquiry['user_id'];
$message_content = "单号".$inquiry['order_no']."询价员已调价,点击查看详情";
$where = ["message_type"=>3,"quot_id"=>$quot_id];
//前端跳转方法和参数
$inquiry_details = Db::name('property_cert_info')
->alias('a')
->join(['pg_return_price' => 'b'], 'b.property_cert_info_id = a.id','left')
->whereIn('a.quot_id', $quot_id)
->field([
'a.id', 'a.city','a.property_full_name', 'a.size','b.eva_unit_price','b.eva_total_value','b.eva_net_value'
])
->group('a.id')
->order('b.create_time', 'desc')
->select();
$name = "businessManage-businessInfo-inquiry-detail";
$query = array(
"id"=>$quot_id,
"order_no"=>$inquiry['order_no'],
"type"=>$inquiry['type'],
"inquiry_details"=>json_encode($inquiry_details)
);
break;
case 5:
$flag = 2;
$roleCodes = array("roleCodes"=>'He_Xikun'); //特殊用户-何喜琨
$message_content = "单号".$inquiry['order_no']."查勘待派单,请及时处理(物业名称:".$inquiry['property_full_name'].",业务员:".$inquiry['user_name']."";
$where = [["message_type","in","2,4"],["quot_id","=",$quot_id]];
break;
case 6:
$apptype = 403;
$title = "查勘待跟进";
//app推送消息需要查看表id
$s_id = Db::name("survey")->where(["order_no"=>$inquiry['order_no'],"property_cert_info_id"=>$property_cert_info_id])->value("id");
$user_id =Db::name("survey")->where(["order_no"=>$inquiry['order_no'],"property_cert_info_id"=>$property_cert_info_id])->value("user_id");
$message_content = "单号".$inquiry['order_no']."查勘待跟进,请及时处理(物业名称:".$inquiry['property_full_name'].",业务员:".$inquiry['user_name']."";
$where = [["message_type","in","5,8"],["quot_id","=",$quot_id]];
//前端跳转方法和参数
$name = "surveyManageSurveyManageSurveyWaitFollowList";
$query = array();
break;
case 7:
$type2 = Db::name("survey")->where(["order_no"=>$inquiry['order_no'],"property_cert_info_id"=>$property_cert_info_id])->value("survey_type");
if($type2 == 1){
$apptype = 404;
$title = "查勘已完成";
}else{
$apptype = 405;
$title = "查勘已完成";
}
//app推送消息需要查看表id
$s_id = Db::name("survey")->where(["order_no"=>$inquiry['order_no'],"property_cert_info_id"=>$property_cert_info_id])->value("id");
$user_id = $inquiry['user_id'];
$message_content = "单号".$inquiry['order_no'].",物业名称:".$inquiry['property_full_name'].",查勘已完成";
$where = ["message_type"=>6,"quot_id"=>$quot_id];
//前端跳转方法和参数
$res=Db::name("survey")->alias('survey')
->join('property_cert_info ind','survey.property_cert_info_id=ind.id','LEFT')
->join('inquiry i','ind.quot_id=i.id','LEFT')
->field('ind.id,survey.id as survey_id,i.order_no,ind.city,ind.city_id,ind.property_full_name,i.is_multiple,i.type,survey.id as survey_id,survey.status,survey.create_time,survey.user_name as surver_username,i.user_name,survey.assign_time,survey.complete_time,survey.return_reason,ind.id as property_cert_info_id,survey.area,survey.survey_type,i.status as inquiry_status')
->where(["survey.order_no"=>$inquiry['order_no'],"survey.property_cert_info_id"=>$property_cert_info_id])
->group('survey.id')
->find();
$name = "surveyManage-surveyCompleteDetail";
if(!empty($res)){
$query = array(
"id"=>$res['id'],
"type"=>$res['type'],
"city_id"=>$res['city_id'],
"survey_id"=>$res['survey_id'],
"order_no"=>$res['order_no'],
"survey_type"=>$res['survey_type'],
"inquiry_status"=>$res['inquiry_status'],
"property_cert_info_id"=>$res['property_cert_info_id'],
"from"=>"surveyManage-surveyCompleteList",
);
}
break;
case 8:
$flag = 2;
$roleCodes = array("roleCodes"=>'He_Xikun'); //特殊用户-何喜琨
$message_content = "单号".$inquiry['order_no']."查勘被退回,待派单,请及时处理(物业名称:".$inquiry['property_full_name'].",业务员:".$inquiry['user_name']."";
$where = ["message_type"=>7,"quot_id"=>$quot_id];
break;
case 9:
$flag = 2;
$roleCodes = array("roleCodes"=>'Assistant_appraiser'); //估计师
$message_content = "报告编号".$report['report_no']."报告待制作,请及时处理(物业名称:".$inquiry['property_full_name']."";
$where = ["message_type"=>7,"quot_id"=>$quot_id];
//前端跳转方法和参数
$name = "report-detail";
$query = array(
"reportid"=>$report['id'],
"type"=>$inquiry['type'],
"from"=>'waitMake',
"isReset"=>true,
);
break;
case 10:
$flag = 2;
$roleCodes = array("roleCodes"=>'Review_quality_inspection'); //审查质检
$message_content = "报告编号".$report['report_no']."报告待审核,请及时处理(物业名称:".$inquiry['property_full_name'].",制作员:".$report['producer_name']."";
$where = [["message_type","in","7,9,12"],["quot_id","=",$quot_id]];
//前端跳转方法和参数
$name = "report-examineDetail";
$query = array(
"reportid"=>$report['id'],
"type"=>$inquiry['type'],
"state"=> 'check',
"from"=>'waitApproval',
"isReset"=>true,
);
break;
case 11:
$apptype = 406;
$title = "报告已完成";
$user_id = $inquiry['user_id'];
$message_content = "单号".$inquiry['order_no']."报告已完成";
$where = [["message_type","in","10,13"],["quot_id","=",$quot_id]];
break;
case 12:
$user_id = $report['producer_id'];
$message_content = "报告编号".$report['report_no']."报告退回待制作,请及时处理(物业名称:".$inquiry['property_full_name']."";
$where = ["message_type"=>11,"quot_id"=>$quot_id];
//前端跳转方法和参数
$name = "report-examineDetail";
$query = array(
"reportid"=>$report['id'],
"type"=>$inquiry['type'],
"from"=>'waitMake',
"isReset"=>true,
);
break;
case 13:
$flag = 2;
$roleCodes = array("roleCodes"=>'Review_quality_inspection'); //审查质检
$message_content = "报告编号".$report['report_no']."报告退回待审核,请及时处理(物业名称:".$inquiry['property_full_name']."";
// $where = ["message_type"=>12,"quot_id"=>$quot_id];
//前端跳转方法和参数
$name = "report-examineDetail";
$query = array(
"reportid"=>$report['id'],
"type"=>$inquiry['type'],
"state"=> 'check',
"from"=>'waitApproval',
"isReset"=>true,
);
break;
case 14:
$user_id = $inquiry['user_id'];
$message_content = "报告编号".$report['report_no']."报告待领取";
// $where = ["message_type"=>13,"quot_id"=>$quot_id];
break;
case 15:
$flag = 2;
$roleCodes = array("roleCodes"=>'Business_manager'); //待部门经理审批:角色=业务经理的用户
$refund_type = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_type");
if($refund_type == 1) { //申请退费
$message_content = "报告编号" . $report['report_no'] . "申请退报告费,待部门经理审批,请及时处理(物业名称:" . $inquiry['property_full_name'] . ",业务员:" . $inquiry['user_name'] . "";
}else if($refund_type == 2){ //申请优惠
$message_content = "报告编号" . $report['report_no'] . "申请优惠,待部门经理审批,请及时处理(物业名称:" . $inquiry['property_full_name'] . ",业务员:" . $inquiry['user_name'] . "";
}
$where = ["message_type"=>14,"quot_id"=>$quot_id];
//前端跳转方法和参数
$refund_id = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_id");
$name = "costManage-financialManage-detailPage-applySubmitDetail";
$query = array(
"id"=>$refund_id,
"pathName"=>"financialDrawBackManage",
);
break;
case 16:
$apptype = 407;
$title = "部门经理审批已通过";
$user_id = $inquiry['user_id'];
$refund_type = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_type");
if($refund_type == 1) { //申请退费
$message_content = "报告编号" . $report['report_no'] . "申请退报告费,部门经理审批通过";
}else if($refund_type == 2){ //申请优惠
$message_content = "报告编号" . $report['report_no'] . "申请优惠,部门经理审批通过";
}
$where = ["message_type"=>15,"quot_id"=>$quot_id];
//前端跳转方法和参数
$refund_id = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_id");
$name = "businessManage-detailPage-applyDetail";
$query = array(
"id"=>$refund_id
);
break;
case 17:
$apptype = 407;
$title = "部门经理审批已驳回";
$user_id = $inquiry['user_id'];
$refund_type = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_type");
if($refund_type == 1) { //申请退费
$message_content = "报告编号" . $report['report_no'] . "申请退报告费,部门经理审批驳回";
}else if($refund_type == 2){ //申请优惠
$message_content = "报告编号" . $report['report_no'] . "申请优惠,部门经理审批驳回";
}
$where = ["message_type"=>15,"quot_id"=>$quot_id];
//前端跳转方法和参数
$refund_id = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_id");
$name = "businessManage-detailPage-applyDetail";
$query = array(
"id"=>$refund_id
);
break;
case 18:
$apptype = 407;
$title = "总经理审批已通过";
$user_id = $inquiry['user_id'];
$refund_type = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_type");
if($refund_type == 1) { //申请退费
$message_content = "报告编号" . $report['report_no'] . "申请退报告费,总经理审批通过";
}else if($refund_type == 2){ //申请优惠
$message_content = "报告编号" . $report['report_no'] . "申请优惠,总经理审批通过";
}
$where = ["message_type"=>32,"quot_id"=>$quot_id];
//前端跳转方法和参数
$refund_id = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_id");
$name = "businessManage-detailPage-applyDetail";
$query = array(
"id"=>$refund_id
);
break;
case 19:
$apptype = 407;
$title = "总经理审批已驳回";
$user_id = $inquiry['user_id'];
$refund_type = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_type");
if($refund_type == 1) { //申请退费
$message_content = "报告编号" . $report['report_no'] . "申请退报告费,总经理审批驳回";
}else if($refund_type == 2){ //申请优惠
$message_content = "报告编号" . $report['report_no'] . "申请优惠,总经理审批驳回";
}
$where = ["message_type"=>32,"quot_id"=>$quot_id];
//前端跳转方法和参数
$refund_id = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_id");
$name = "businessManage-detailPage-applyDetail";
$query = array(
"id"=>$refund_id
);
break;
case 20:
$flag = 2;
$roleCodes = array("roleCodes"=>'Finance_CSPG'); //财务
$refund_type = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_type");
if($refund_type == 1) { //申请退费
$message_content = "报告编号".$report['report_no']."申请退报告费,待财务审批,请及时处理(物业名称:".$inquiry['property_full_name'].",业务员:".$inquiry['user_name']."";
}else if($refund_type == 2){ //申请优惠
$message_content = "报告编号".$report['report_no']."申请优惠,待财务审批,请及时处理(物业名称:".$inquiry['property_full_name'].",业务员:".$inquiry['user_name']."";
}
$where = [["message_type","in","18,19"],["quot_id","=",$quot_id]];
//前端跳转方法和参数
$refund_id = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_id");
$name = "costManage-financialManage-detailPage-applySubmitDetail";
$query = array(
"id"=>$refund_id,
"pathName"=>"financialDrawBackManage"
);
break;
case 21:
$apptype = 408;
$title = "财务审批已通过";
$user_id = $inquiry['user_id'];
$refund_type = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_type");
if($refund_type == 1) { //申请退费
$message_content = "报告编号".$report['report_no']."申请退报告费,财务审批通过";
}else if($refund_type == 2){ //申请优惠
$message_content = "报告编号".$report['report_no']."申请优惠,财务审批通过";
}
$where = ["message_type"=>20,"quot_id"=>$quot_id];
//前端跳转方法和参数
$refund_id = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_id");
$name = "businessManage-detailPage-applyDetail";
$query = array(
"id"=>$refund_id
);
break;
case 22:
$apptype = 408;
$title = "财务审批已驳回";
$user_id = $inquiry['user_id'];
$refund_type = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_type");
if($refund_type == 1) { //申请退费
$message_content = "报告编号".$report['report_no']."申请退报告费,财务审批驳回";
}else if($refund_type == 2){ //申请优惠
$message_content = "报告编号".$report['report_no']."申请优惠,财务审批驳回";
}
$where = ["message_type"=>20,"quot_id"=>$quot_id];
//前端跳转方法和参数
$refund_id = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_id");
$name = "businessManage-detailPage-applyDetail";
$query = array(
"id"=>$refund_id
);
break;
case 23:
$flag = 2;
$roleCodes = array("roleCodes"=>'general_manager'); //魏总
$message_content = "单号".$inquiry['order_no']."待总经理审批,请及时处理(物业名称:".$inquiry['property_full_name'].",业务员:".$inquiry['user_name']."";
// $where = ["message_type"=>18,"quot_id"=>$quot_id];
//前端跳转方法和参数
// $refund_id = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_id");
// $name = "costManage-financialManage-detailPage-applySubmitDetail";
// $query = array(
// "id"=>$refund_id,
// "pathName"=>"waitAuditTicket"
// );
$bill_id = Db::name("bill")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("bill_id");
$name = "costManage-billManage-detailPage-applyChargeDetail";
$query = array(
"id"=>$bill_id,
"type"=>1,
"pathName"=>"waitAuditTicket"
);
break;
case 24:
$apptype = 409;
$title = "总经理审批已通过";
$user_id = $inquiry['user_id'];
$message_content = "单号".$inquiry['order_no']."总经理审批通过";
$where = ["message_type"=>23,"quot_id"=>$quot_id];
//前端跳转方法和参数
$bill_id = Db::name("bill")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("bill_id");
$name = "businessManage-detailPage-applyChargeDetail";
$query = array(
"id"=>$bill_id,
"type"=>3,
"pathName"=>'mineInvoice',
);
break;
case 25:
$apptype = 409;
$title = "总经理审批已驳回";
$user_id = $inquiry['user_id'];
$message_content = "单号".$inquiry['order_no']."总经理审批驳回";
$where = ["message_type"=>23,"quot_id"=>$quot_id];
//前端跳转方法和参数
$bill_id = Db::name("bill")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("bill_id");
$name = "businessManage-detailPage-applyChargeDetail";
$query = array(
"id"=>$bill_id,
"type"=>3,
"pathName"=>'mineInvoice',
);
break;
case 26:
$flag = 2;
$roleCodes = array("roleCodes"=>'general_manager'); //财务
$message_content = "单号".$inquiry['order_no']."待财务开票,请及时处理(物业名称:".$inquiry['property_full_name'].",业务员:".$inquiry['user_name']."";
$where = [["message_type","in","24,25"],["quot_id","=",$quot_id]];
//前端跳转方法和参数
$bill_id = Db::name("bill")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("bill_id");
$name = "costManage-billManage-detailPage-applyChargeDetail";
$query = array(
"id"=>$bill_id,
"type"=>2,
"pathName"=>'waitOpenTicket',
);
break;
case 27:
$apptype = 410;
$title = "财务已开具票据";
$user_id = $inquiry['user_id'];
$message_content = "单号".$inquiry['order_no']."财务已开具票据";
$where = ["message_type"=>26,"quot_id"=>$quot_id];
//前端跳转方法和参数
$bill_id = Db::name("bill")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("bill_id");
$name = "costManage-billManage-detailPage-applyChargeDetail";
$query = array(
"id"=>$bill_id,
"type"=>3,
"pathName"=>'waitGetTicket',
);
break;
case 28:
$apptype = 410;
$title = "财务已驳回";
$user_id = $inquiry['user_id'];
$message_content = "单号".$inquiry['order_no']."财务已驳回";
$where = ["message_type"=>26,"quot_id"=>$quot_id];
//前端跳转方法和参数
$bill_id = Db::name("bill")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("bill_id");
$name = "costManage-billManage-detailPage-applyChargeDetail";
$query = array(
"id"=>$bill_id,
"type"=>3,
"pathName"=>'waitGetTicket',
);
break;
case 29:
$flag = 2;
$roleCodes = array("roleCodes"=>'Technical_manager,Deputy_manager,Evaluation_Assistant'); //技术部经理,技术部副经理,评估助理
$message_content = "单号".$inquiry['order_no']."(简易)待询价员回价,请及时处理(物业名称:".$inquiry['property_full_name'].",业务员:".$inquiry['user_name']."";
// $where = ["message_type"=>22,"quot_id"=>$quot_id];
break;
case 30:
$flag = 2;
$roleCodes = array("roleCodes"=>'Assistant_appraiser,Review_quality_inspection'); //角色=估价师助理 ,审查质检 的用户
$message_content = "单号".$inquiry['order_no']."(简易)报告待制作,请及时处理(物业名称:".$inquiry['property_full_name']."";
$where = ["message_type"=>29,"quot_id"=>$quot_id];
//前端跳转方法和参数
$inquiry_details = Db::name('property_cert_info')->alias('a')
->join(['pg_return_price' => 'b'], 'b.property_cert_info_id = a.id','left')
->whereIn('a.quot_id', $quot_id)
->field(['a.id','a.size','a.property_full_name','a.remark','b.eva_unit_price','b.eva_total_value','b.eva_net_value','a.remark'])
->group('a.id')
->order('b.create_time', 'desc')
->select();
$name = "priceReturn-allProject-simple-detail";
$query = array(
"isReset"=>true,
"from"=>"priceReturnAllProjectSimpleList",
"quot_id"=>$quot_id,
"property_cert_info_id"=>!empty($inquiry_details)?$inquiry_details[0]['id']:"",
"inquiry_details"=>json_encode($inquiry_details)
);
break;
case 31:
$apptype = 411;
$title = "报告已完成";
$user_id = $inquiry['user_id'];
$message_content = "单号".$inquiry['order_no']."报告已完成";
$where = ["message_type"=>30,"quot_id"=>$quot_id];
break;
case 32:
$flag = 2;
$roleCodes = array("roleCodes"=>'general_manager'); //待总经理审批:魏总
$refund_type = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_type");
if($refund_type == 1) { //申请退费
$message_content = "报告编号" . $report['report_no'] . "申请退报告费,待总经理审批,请及时处理(物业名称:" . $inquiry['property_full_name'] . ",业务员:" . $inquiry['user_name'] . "";
}else if($refund_type == 2){ //申请优惠
$message_content = "报告编号" . $report['report_no'] . "申请优惠,待总经理审批,请及时处理(物业名称:" . $inquiry['property_full_name'] . ",业务员:" . $inquiry['user_name'] . "";
}
$where = [["message_type","in","16,17"],["quot_id","=",$quot_id]];
//前端跳转方法和参数
$refund_id = Db::name("refund")->where("order_no",$inquiry['order_no'])->where("report_no",$report['report_no'])->value("refund_id");
$name = "costManage-financialManage-detailPage-applySubmitDetail";
$query = array(
"id"=>$refund_id,
"pathName"=>"financialDrawBackManage"
);
break;
default:
}
$time = time();
$request = Request::instance();
if($flag == 1){
$insert_data = array();
$insert_data['user_id'] = $user_id;
$insert_data['quot_id'] = $quot_id;
$insert_data['name'] = $name;
$insert_data['query'] = json_encode($query);
if($property_cert_info_id){
$insert_data["property_cert_info_id"] = $property_cert_info_id;
}
$insert_data['type'] = $type;
$insert_data['message_type'] = $message_type;
$insert_data['message_content'] = $message_content;
$insert_data['create_time'] = date("Y-m-d H:i:s",$time);
$id = Db::name("message")->insertGetId($insert_data);
if($id){
//app推送消息
if($apptype){
$params = array();
$params['oa_user_id'] = $user_id;
$params['type'] = $apptype;
$params['unique_id'] = $s_id?$s_id:$quot_id;
$params['title'] = $title;
$params['content'] = $message_content;
$re = $FbbService->addAppBsMessage($params);
}
//pc推送消息
sock_post($request->domain() .":".$_SERVER["SERVER_PORT"]. $request->root()."/admin/MessageRemind/messagePush",["user_id"=>$user_id,"message_content"=>$message_content]);
}
}else{
//获取相应的用户列表
$userinfo = $apiAuth->getUser($roleCodes);
if($userinfo == "-4001"){
return array("code"=>0,"msg"=>"获取角色用户失败");
}else{
$userinfo = json_decode($userinfo,true);
if($userinfo['code'] == "0000"){
$user_id_arr = array_column($userinfo['data'],"oid");
}
}
if(!empty($user_id_arr)){
foreach ($user_id_arr as $k => $v){
$insert_data = array();
$insert_data['user_id'] = $v;
$insert_data['quot_id'] = $quot_id;
$insert_data['name'] = $name;
$insert_data['query'] = json_encode($query);
if($property_cert_info_id){
$insert_data["property_cert_info_id"] = $property_cert_info_id;
}
$insert_data['type'] = $type;
$insert_data['message_type'] = $message_type;
$insert_data['message_content'] = $message_content;
$insert_data['create_time'] = date("Y-m-d H:i:s",$time);
$id = Db::name("message")->insertGetId($insert_data);
if($id){
//app推送消息
if($apptype){
$params = array();
$params['oa_user_id'] = $v;
$params['type'] = $apptype;
$params['unique_id'] = $s_id?$s_id:$quot_id;
$params['title'] = $title;
$params['content'] = $message_content;
$re = $FbbService->addAppBsMessage($params);
}
//pc推送消息
sock_post($request->domain() . $request->root()."/admin/MessageRemind/messagePush",["user_id"=>$v,"message_content"=>$message_content]);
}
}
}
}
if(!empty($where)){ //修改其它未读状态数据状态
Db::name("message")->where($where)->update(array("status"=>2));
}
return array("code"=>1,"msg"=>"操作成功");
}
/**
* 消息已阅读公用方法
*
* @author cavan
*
* @param $id //消息表od
*/
function MessageRead($id=""){
if(!$id){
return array("code"=>0,"msg"=>"缺少必要参数信息表id");
}
$message_type = Db::name("message")->where("id",$id)->value("message_type");
if($message_type == 31){ //消息为最后一个状态 则处理当前状态的信息为无效数据
$update_data['issee'] = 1;
$update_data['status'] = 2;
}else{
$update_data['issee'] = 1;
}
Db::name("message")->where("id",$id)->update($update_data);
if($message_type == 14){
$quot_id = Db::name("message")->where("id",$id)->value("quot_id");
Db::name("message")->where("quot_id",$quot_id)->where("message_type",14)->update(array("status"=>2));
}
return array("code"=>1,"msg"=>"操作成功");
}
/**
* 推送消息
* @param array or string $to 用户id
* @param string $content 消息内容
*/
function sendMessage($to, $content)
{
if (!$to) {
return;
}
$to = str2arr($to);
foreach ($to as $uid) {
$data = [
'to' => $uid,
'type' => 'publish',
'content' => $content
];
$result = curlPostMessage($data);
}
return $result;
}
function curlPostMessage($data)
{
$url = Env::get('push.host') . ':' . Env::get('push.port');
$ch = curl_init();
$data = http_build_query($data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));
$return = curl_exec($ch);
curl_close($ch);
Log::write("返回:".$return."--请求:".$ch,'workermanCurl');
return $return;
}
/** 字符串转数组
* @param $str 要分割的字符串
* @param string $glue 分隔符
* @return array
*/
function str2arr($str, $glue = ',')
{
return explode($glue, $str);
}
//php 异步执行
function sock_post($url, $query) {
$_post = strval(null);
if (!empty($query)) {
$_post = "query=" . urlencode(json_encode($query));
}
$info = parse_url($url);
$fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
if (!$fp) {
echo "$errstr($errno)<br />\n";
} else {
stream_set_blocking($fp, 0); //开启非阻塞模式
stream_set_timeout($fp, 3); //设置超时时间s
$head = "POST " . $info['path'] . "?" . $_post . " HTTP/1.1\r\n";
$head .= "Host: " . $info['host'] . "\r\n";
$head .= "Referer: http://" . $info['host'] . $info['path'] . "\r\n";
$head .= "Content-type: application/x-www-form-urlencoded\r\n";
$head .= "Content-Length: " . strlen(trim($_post)) . "\r\n";
$head .= "\r\n";
$head .= trim($_post);
fwrite($fp, $head);
Log::write("fp:".$fp."---head:".$head,'workerman');
fclose($fp);
}
}
//获取当前日期前一天工作日(避开周末)
//2022-01-05更新
//因接口调用失效或收费需要废弃重写该方法
/* function getCostDate($date) {
$valuation_time = '';
$workday_api = config('serviceConfig.API_WORKDAY_URL');
for ($i = 1; $i <= 30 ; $i++) {
$res_date = date('Ymd', strtotime("$date -$i day"));
$valuation_time = date('Y-m-d', strtotime("$date -$i day"));
$getData = file_get_contents($workday_api. $res_date);
$result = json_decode($getData, true);
if (!empty($result['workday']) && $result['workday'] == 1) {
break;
}
}
return $valuation_time;
} */
function getCostDate($date) {
$valuation_time = '';
for ($i = 1; $i <= 30 ; $i++) {
$res_date = date('Ymd', strtotime("$date -$i day"));
$valuation_time = date('Y-m-d', strtotime("$date -$i day"));
$result = Db::name('holiday')->where(['holiday_date'=>$res_date])->find();
if ($result) {
if ($result['holiday_type']==2) {
break;
}
} elseif (date('N', strtotime("$date -$i day"))<6) {
break;
}
}
return $valuation_time;
}
// 获取系统参数配置
function getSystemConfig($key_name){
return Db::name('system_config')->where(['name'=>$key_name])->value('value');
}
function getCity($city_name){
$where[] = ['name|shortname', 'eq', $city_name];
return Db::name('region')->where($where)->field('id,shortname')->find();
}
// 获取用户排序权重
function getSort($user_id){
$sorts = ['149'=>100,'178'=>99];
return !empty($sorts[$user_id]) ? $sorts[$user_id] : 0;
}
/**
* 前端控制台打印消息
* @param object $log
*/
function console($log='') {
switch (empty($log)) {
case False:
$out = json_encode($log);
$GLOBALS['console'] .= 'console.log('.$out.');';
break;
default:
echo '<script type="text/javascript">'.$GLOBALS['console'].'</script>';
}
}
/**
* 过滤Emoji字符串
*/
function removeEmoji($text)
{
// Match Emoticons
$regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
$clean_text = preg_replace($regexEmoticons, '', $text);
// Match Miscellaneous Symbols and Pictographs
$regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
$clean_text = preg_replace($regexSymbols, '', $clean_text);
// Match Transport And Map Symbols
$regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
$clean_text = preg_replace($regexTransport, '', $clean_text);
// Match Miscellaneous Symbols
$regexMisc = '/[\x{2600}-\x{26FF}]/u';
$clean_text = preg_replace($regexMisc, '', $clean_text);
// Match Dingbats
$regexDingbats = '/[\x{2700}-\x{27BF}]/u';
$clean_text = preg_replace($regexDingbats, '', $clean_text);
$clean_text = preg_replace_callback(
'/./u',
function (array $match) {
return strlen($match[0]) >= 4 ? '' : $match[0];
},
$clean_text);
return trim($clean_text);
}
/**
* 通用cURL请求封装
*
* @param string $url 请求地址
* @param string $method 请求方法 (GET|POST|PUT|DELETE|PATCH)
* @param mixed $data 请求数据,数组或字符串形式
* @param array $headers 请求头数组,如 ['Content-Type: application/json']
* @param array $files 文件上传数组,格式为 ['field_name' => '/path/to/file']
* @param array $auth 基础认证 ['username' => '', 'password' => '']
* @param int $timeout 超时时间(秒)默认60
* @param bool $verifySSL 是否验证SSL证书默认false(不验证)
* @return array 返回数组包含:
* 'code' => HTTP状态码,
* 'data' => 响应内容,
* 'error' => 错误信息,
* 'info' => curl_getinfo信息
*/
function curlRequest(
string $url,
string $method = 'GET',
$data = null,
array $headers = [],
array $files = [],
array $auth = [],
int $timeout = 60,
bool $verifySSL = false
): array {
$ch = curl_init();
$method = strtoupper($method);
// 1. 基础配置
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, false);
// 2. SSL配置[2,6](@ref)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verifySSL ? 2 : 0);
// 3. 处理文件上传 (优先于普通数据)[8](@ref)
if (!empty($files)) {
foreach ($files as $field => $filePath) {
if (file_exists($filePath)) {
$data[$field] = new CURLFile($filePath);
}
}
}
// 4. 请求数据处理
if (!empty($data)) {
// JSON数据[4](@ref)
if (in_array('Content-Type: application/json', $headers)) {
$payload = is_array($data) ? json_encode($data) : $data;
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
}
// 表单数据/文件上传
else {
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
}
// 5. Header处理[4,2](@ref)
if (!empty($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
// 6. 认证处理[4](@ref)
if (!empty($auth['username']) && !empty($auth['password'])) {
curl_setopt($ch, CURLOPT_USERPWD, "{$auth['username']}:{$auth['password']}");
}
// 7. 执行请求
$response = curl_exec($ch);
$error = curl_error($ch);
$info = curl_getinfo($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [
'code' => $httpCode,
'data' => $response,
'error' => $error ?: null,
'info' => $info
];
}
//启动事物
function t_begin() {
Db::startTrans();
}
//提交事物
function t_commit() {
Db::commit();
}
//回滚事物
function t_rollback() {
Db::rollback();
}
/**
*
* @param type $data
* @param type $code
*/
function apiErrMsg($msg = '请勿异常操作', $code = 99999) {
$api = [
'code' => $code,
'msg' => empty($msg) ? \app\admin\service\ApiService::getMsg($code) : $msg,
];
exit(json_encode($api, JSON_UNESCAPED_UNICODE));
// $response = think\facade\Response::create(compact('code', 'msg'), 'json');
// throw new \think\exception\HttpResponseException($response);
}
function writeLog($log = '', $level = "writelog") {
$logConfig = \think\facade\Config::pull('log');
$logConfig['level'][] = $level;
$logConfig['apart_level'][] = $level;
\think\facade\Log::init($logConfig);
\think\facade\Log::write($log, $level);
}
/**
* 推送消息给所有WebSocket客户端
* @param string $eventName 事件名称
* @param array $data 推送的数据
* @return bool
*/
function pushToAllClients($eventName, $data) {
$socketUrl = 'http://127.0.0.1:2121';
$postData = [
'type' => 'broadcast',
'event' => $eventName,
'data' => json_encode($data)
];
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($postData),
'timeout' => 5
]
];
$context = stream_context_create($options);
$result = file_get_contents($socketUrl, false, $context);
writeLog("Push result - event: $eventName, data: " . json_encode($data) . ", result: '$result'", 'push_log');
return $result === 'ok';
}
/**
* 推送未回价数量更新
* @param int $count 未回价数量
* @return bool
*/
function pushUnreturnedPriceCount($count) {
return pushToAllClients('updateUnreturnedCount', ['count' => $count]);
}
/**
* 获取未回价数量
* @return int
*/
function getUnreturnedPriceCount() {
$Inquiry = new \app\model\Inquiry();
return $Inquiry->where('return_price_status', 2)->where('status', 1)->count();
}
/**
* 获取未回价数量并推送给所有客户端
* @return bool
*/
function fetchAndPushUnreturnedPriceCount() {
$count = getUnreturnedPriceCount();
return pushUnreturnedPriceCount($count);
}
$GLOBALS['console'] = '';