first commit

This commit is contained in:
annnj-company
2026-04-17 18:29:53 +08:00
parent e49fa5a215
commit 130c1026c4
5615 changed files with 1639145 additions and 0 deletions

View File

@@ -0,0 +1,698 @@
<?php
namespace app\admin\controller;
use app\model\Inquiry;
use app\model\Report as ReportModel;
use app\common\validate\ReportValidate;
use app\model\ReportTemplateDetail;
use app\util\ReturnCode;
use think\Db;
use think\db\Where;
use Mpdf\Mpdf;
use app\model\ReportTemplate;
use app\model\ReportTemplateDetailSimple;
use app\util\OffsiteOneTemplate;
/**
* 报告控制器
*
* Class Report
* @package app\admin\controller
*/
class Report extends Base
{
/**
* @api {get} admin/report/index 我的报告列表
* @author zdc
*/
public function index(ReportModel $report)
{
$data = $this->request->get();
//2020年5月24日14:03:28 cavan
if(empty($this->userInfo)){
return $this->buildFailed("获取报告列表失败,因用户信息为空,请重新登录","",ReturnCode::AUTH_ERROR);
}
if (!$this->isAdmin() && !$this->isAppraiser()) {
//$data['user_id'] = $this->userInfo['user_ids'] ? implode(',', $this->userInfo['user_ids']) : ''; //权限
$data['user_id'] = array($this->userInfo['user_id']);
}
$res = $report->getReportList($this->getPage(), $data);
return $this->buildSuccess($res);
}
/**
* @api {post} admin/report/reportDetail 报告详情
* @author zdc
*/
public function reportDetail(ReportModel $report)
{
$data = $this->request->post();
if (empty($data['id'])) return $this->buildFailed('参数不能为空!');
$res = $report->getReportDetail($data);
return $this->buildSuccess($res);
}
/**
* @api {post} admin/report/addReportTemplate 新增报告模板
* @author zdc
*/
public function addReportTemplate() {
$id = input('id');
$name = input('name', '', 'trim');
$content = input('content/a');
if (empty($name)) return $this->buildFailed('请输入报告名称!');
if (empty($content)) return $this->buildFailed('请填写报告模板!');
$detailModel = new ReportTemplateDetail();
if (empty($id)) {
$check = Db::name('report_template')->where(['name' => $name, 'status' => 1])->value('id');
if (!empty($check)) return $this->buildFailed('报告模板已存在!');
Db::startTrans();
$data = ['name' => $name, 'create_uid' => $this->userInfo['user_id'], 'create_time' => time(), 'update_time' => time()];
$id = Db::name('report_template')->insertGetId($data);
if ($id <= 0) {
Db::rollback();
return $this->buildFailed('新增报告模板失败!');
}
$detail = [];
foreach ($content as $key => $value) {
if (empty($value['content'])) {
Db::rollback();
return $this->buildFailed('报告模板内容不能为空!');
}
$list = [];
$list['report_tmpl_id'] = $id;
$list['content'] = $value['content'];
$list['create_time'] = $list['update_time'] = time();
$detail[] = $list;
}
$detailModel->saveAll($detail);
Db::commit();
} else {
Db::startTrans();
$data = ['name' => $name, 'update_time' => time()];
if (!Db::name('report_template')->where('id', $id)->update($data)) {
Db::rollback();
return $this->buildFailed('更新报告模板失败!');
}
$detail = [];
$ids = [];
foreach ($content as $key => $value) {
if (empty($value['content'])) {
Db::rollback();
return $this->buildFailed('报告模板内容不能为空!');
}
$list = [];
$list['report_tmpl_id'] = $id;
$list['content'] = $value['content'];
$list['update_time'] = time();
if (!empty($value['id'])) {
if (!$detailModel->where('id', $value['id'])->update($list)) {
Db::rollback();
return $this->buildFailed('更新报告模板内容失败!');
}
$detail_id = $value['id'];
} else {
$list['create_time'] = time();
$detail_id = $detailModel->insertGetId($list);
if ($detail_id <= 0) {
Db::rollback();
return $this->buildFailed('添加报告模板内容失败!');
}
}
$ids[] = $detail_id;
}
Db::commit();
$detailModel->where('report_tmpl_id', $id)->whereNotIn('id', $ids)->update(['status' => -1, 'update_time' => time()]);
}
return $this->buildSuccess();
}
/**
* 产生合同号
*
* @param [type] $r_type
* @return void
*/
public function generateContractNo( )
{
$str_no = "";
$param = $this->request->post();
$c_type = $param['c_type'];
$quot_id = $param['quot_id'];
// 创建或打开文件,以读写模式
$file = fopen("gSNO.txt", "c+");
if (!$file) {
$res = "文件打开失败!";
return $this->buildFailed($res);
}
else
{
// 读取文件中的gSNO值
fseek($file, 0);
$gSNO = intval(fread($file, filesize("gSNO.txt")));
// 更新文件中的gSNO值
$gSNO++;
fseek($file, 0);
fwrite($file, strval($gSNO));
fclose($file);
$year = date("Y");
$str_no = "err_no:-003";
$str_no_prefix = "深国中";
$str_no_tail = "委字[".$year."]第".$gSNO."";
switch ($c_type) {
case "1": //"评估类"
$str_no = $str_no_prefix."".$str_no_tail;break;
case "2": //"咨询类"
$str_no = $str_no_prefix."".$str_no_tail;break;
case "3": //"资产类"
$str_no = $str_no_prefix."".$str_no_tail;break;
default:
$str_no = "err_no:-002";
}
// 合同号写入inquiry表里
$inquiryModal = new Inquiry();
$inquiryModal->updateContractNo( $quot_id, $str_no);
$res = $str_no;
return $this->buildSuccess($str_no);
}
}
/**
* @api {post} admin/report/reportTemplateList 报告模板列表
* @author zdc
*/
public function reportTemplateList() {
$search_text = input('search_text');
$subordinates = input('subordinates');
$where = [];
$where['status'] = 1;
if (!empty($subordinates) && $subordinates == 1) {
$where['type'] = ['in', [1,2]];
} elseif (!empty($subordinates) && $subordinates == 2) {
$where['type'] = ['=', 1];
}
if (!empty($search_text)) {
$ids = Db::name('report_template')->where(new Where(['name' => ['like', '%'.$search_text.'%'], 'status' => 1]))->column('id');
if (empty($ids)) {
return $this->buildSuccess([]);
}
$where['id|trunk_id'] = ['in', $ids];
}
$res = Db::name('report_template')->field('id,name,trunk,type,update_time,status')->where(new Where($where))->order('update_time', 'desc')->paginate($this->getPage())
->each(function ($item){
$item['update_time'] = !empty($item['update_time']) ? date('Y-m-d H:i:s', $item['update_time']) : '';
$item['type_str'] = $item['type'] == 1 ? '主干' : '分支';
return $item;
})
->toArray();
return $this->buildSuccess(['data' => $res['data'], 'count' => $res['total']]);
}
/**
* @api {post} admin/report/setTemplateStatus 设置模板状态
* @author zdc
*/
public function setTemplateStatus() {
$id = input('id');
$status = input('status');
if (empty($id) || empty($status)) return $this->buildFailed('参数不能为空!');
if (!Db::name('report_template')->where('id', $id)->update(['status' => $status, 'update_time' => time()])) {
return $this->buildFailed('更新状态失败!');
}
return $this->buildSuccess();
}
/**
* @api {post} admin/report/getReportTemplateInfo 获取报告模板信息
* @author zdc
*/
public function getReportTemplateInfo() {
$id = input('id');
if (empty($id)) return $this->buildFailed('参数不能为空!');
$res = Db::name('report_template')->field('id,name,report_detail_id')->where('id', $id)->find();
if (empty($res)) return $this->buildFailed('报告模板信息不存在!');
$res['report_detail_id'] = explode(',', $res['report_detail_id']);
$detailModel = new ReportTemplateDetail();
$ids = implode(',', $res['report_detail_id']);
if(empty($ids)){
$res['info'] = array();
return $this->buildSuccess($res);
}
$sql = "SELECT `module_name`,`id`,`content`,`type` FROM `pg_report_template_detail` WHERE `id` IN ($ids) ORDER BY field(id,$ids)";
$list = Db::name('report_template_detail')->query($sql);
$res['info'] = $list;
return $this->buildSuccess($res);
}
/**
* @api {post} admin/report/getSimpleReportTemplateInfo 获取简易报告模板信息
* @author zdc
*/
public function getSimpleReportTemplateInfo() {
// $detailModel = new ReportTemplateDetail();
$where['status']=1;
$list = Db::name('report_template_detail_simple')->field('id,content')->whereIn('report_tmpl_id', 99)->where($where)->select();
$res['info'] = $list;
return $this->buildSuccess($res);
}
/**
* @api {post} admin/report/updateSimpleReportTemplate 新增报告模板
* @author zdc
*/
public function updateSimpleReportTemplate() {
$id = 99;
// $name = input('name', '', 'trim');
$content = input('content/a');
// if (empty($name)) return $this->buildFailed('请输入报告名称!');
if (empty($content)) return $this->buildFailed('请填写报告模板!');
$detailModel = new ReportTemplateDetailSimple();
Db::startTrans();
// $data = ['name' => $name, 'update_time' => time()];
// if (!Db::name('report_template')->where('id', $id)->update($data)) {
// Db::rollback();
// return $this->buildFailed('更新报告模板失败!');
// }
$detail = [];
$ids = [];
foreach ($content as $key => $value) {
if (empty($value['content'])) {
Db::rollback();
return $this->buildFailed('报告模板内容不能为空!');
}
$list = [];
$list['report_tmpl_id'] = $id;
$list['content'] = $value['content'];
$list['update_time'] = time();
if (!empty($value['id'])) {
if (!$detailModel->where('id', $value['id'])->update($list)) {
Db::rollback();
return $this->buildFailed('更新报告模板内容失败!');
}
$detail_id = $value['id'];
} else {
$list['create_time'] = time();
$detail_id = $detailModel->insertGetId($list);
if ($detail_id <= 0) {
Db::rollback();
return $this->buildFailed('添加报告模板内容失败!');
}
}
$ids[] = $detail_id;
}
Db::commit();
$detailModel->where('report_tmpl_id', $id)->whereNotIn('id', $ids)->update(['status' => -1, 'update_time' => time()]);
return $this->buildSuccess();
}
//预览
public function templatePreview() {
$id = input('id');
$report_detail_id = input('report_detail_id/a');
//if (empty($content)) return $this->buildFailed('参数不能为空!');
if (!empty($id)) {
$res = ReportTemplate::field('id,report_info')->where('id', $id)->find();
$template = $res['report_info'];
}
if (!empty($report_detail_id)) {
$detailModel = new ReportTemplateDetail();
$template = $detailModel->field('id,content,module_name')->whereIn('id', $report_detail_id)->select();
}
$extract = date('YmdHis', time());
set_time_limit(0);
ini_set('max_execution_time', '100');
$config = array(
'mode' => 'zh-cn',//zh-cn中文符号不会出现乱码
'format' => 'A4',
'default_font_size' => 14,
);
//设置中文字体
$mpdf = new Mpdf($config);
$mpdf->SetDisplayMode('fullpage');
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->list_symbol_size = 14;
ob_end_clean();
//加水印
$img_water = ROOT_PATH . 'public' . DS . 'static/background.png';
$mpdf->SetWatermarkImage($img_water, 0.1, 10);//参数一是图片的位置(图片相对目录 为处理脚本的相对目录)参数二是透明度0.1-1
$mpdf->showWatermarkImage = true;
//设置自动分页符
$mpdf->SetAutoPageBreak(TRUE);
$start = 0;
$end = 999;
foreach ($template as $k => $v) {
$content = $v['content'];
$data = <<<EOF
$content
EOF;
$mpdf->AddPage('','', '','','','','','', 15);//留出页脚高度
if ($k === 0) {
$img_file10 = ROOT_PATH . 'public' . DS . 'static/logo3.png';//首页右上角logo
$mpdf->Image($img_file10, 60, 10, 85, 32, '', '', true, true);
// $img_file = ROOT_PATH . 'public' . DS . 'static/bottom.png';
// $mpdf->Image($img_file, 30, 60);
} else {
$img_file10 = ROOT_PATH . 'public' . DS . 'static/logo3.png';
$header='<img src="' . $img_file10 . '" style="float:right;margin-top:-30px;" width="160px" height="65px"/>';
$mpdf->SetHTMLHeader($header, '', true);//页眉
}
if (strpos($v['module_name'], '目录') !== false) {
$start = $k;
$mpdf->pageNumStart = $k + 1;
}
if (strpos($v['module_name'], '估价对象位置') !== false) {
$end = $k;
}
if ($k >= $end) {
$footer = '';
$mpdf->SetHTMLFooter($footer);
} elseif ($start != 0 && $k > $start) {
$footer = '<table width="100%" style=" vertical-align: bottom; font-family:serif; font-size: 9pt; color: #000088;"><tr style="height:30px"></tr><tr><td width="10%"></td><td width="80%" align="center" style="font-size:14px;color:#A0A0A0">{PAGENO}</td><td width="10%" style="text-align: left;"></td></tr></table>';
$mpdf->SetHTMLFooter($footer);
}
$mpdf->WriteHTML($data);
}
$date = date('Ymd');
$Path = config('uploadFile.img_path') . DS . 'uploads' . DS . $date;
if (!file_exists($Path)) {
//检查是否有该文件夹,如果没有就创建,并给予最高权限
mkdir($Path, 0777, true);
}
//DestPDF输出的方式。I默认值在浏览器中打开D点击下载按钮 PDF文件会被下载下来F文件会被保存在服务器中SPDF会以字符串形式输出EPDF以邮件的附件输出
$filename = DS . 'uploads' . DS . $date . DS . $extract . ".pdf";
$filePath = $Path . DS . "$extract.pdf";
$mpdf->Output($Path . DS . "$extract.pdf", 'F');
$upload = ossUpload(trim(str_replace("\\", "/", $filename), '/'), $filePath);
unlink($filePath); //把本地图片删除(原图)
return $this->buildSuccess(['url' => config('uploadFile.url') . $filename]);
}
//简易报告预览
public function templatePreviewSimple() {
$report_detail_id = input('report_detail_id/a');
// if (!empty($report_detail_id)) {
$template = Db::name('report_template_detail_simple')->field('id,content')->whereIn('report_tmpl_id', 99)->select();
// }
// dump($template);die();
$extract = date('YmdHis', time());
set_time_limit(0);
ini_set('max_execution_time', '100');
$config = array(
'mode' => 'zh-cn',//zh-cn中文符号不会出现乱码
'format' => 'A4',
'default_font_size' => 14,
);
$mpdf = new Mpdf($config);
$mpdf->SetDisplayMode('fullpage');
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->list_symbol_size = 14;
ob_end_clean();
//加水印
$img_water = ROOT_PATH . 'public' . DS . 'static/background.png';
$mpdf->SetWatermarkImage($img_water, 0.1, 10);//参数一是图片的位置(图片相对目录 为处理脚本的相对目录)参数二是透明度0.1-1
$mpdf->showWatermarkImage = true;
//设置自动分页符
$mpdf->SetAutoPageBreak(TRUE);
$start = 0;
foreach ($template as $k => $v) {
$content = $v['content'];
$data = <<<EOF
$content
EOF;
$mpdf->AddPage('','', '','','','','','', 15);//留出页脚高度
if ($k === 0) {
$img_file10 = ROOT_PATH . 'public' . DS . 'static/logo3.png';//首页右上角logo
$mpdf->Image($img_file10, 60, 10, 85, 32, '', '', true, true);
// $img_file = ROOT_PATH . 'public' . DS . 'static/bottom.png';
// $mpdf->Image($img_file, 30, 60);
} else {
$img_file10 = ROOT_PATH . 'public' . DS . 'static/logo3.png';
$header='<img src="' . $img_file10 . '" style="float:right;margin-top:-30px;" width="160px" height="65px"/>';
$mpdf->SetHTMLHeader($header, '', true);//页眉
}
// if (strpos($v['module_name'], '目录') !== false) {
// $start = $k;
// $mpdf->pageNumStart = $k + 1;
// }
if ($start != 0 && $k > $start) {
$footer = '<table width="100%" style=" vertical-align: bottom; font-family:serif; font-size: 9pt; color: #000088;"><tr style="height:30px"></tr><tr><td width="10%"></td><td width="80%" align="center" style="font-size:14px;color:#A0A0A0">{PAGENO}</td><td width="10%" style="text-align: left;"></td></tr></table>';
$mpdf->SetHTMLFooter($footer);
}
$mpdf->WriteHTML($data);
}
$date = date('Ymd');
$Path = config('uploadFile.img_path') . DS . 'uploads' . DS . $date;
if (!file_exists($Path)) {
//检查是否有该文件夹,如果没有就创建,并给予最高权限
mkdir($Path, 0777, true);
}
//DestPDF输出的方式。I默认值在浏览器中打开D点击下载按钮 PDF文件会被下载下来F文件会被保存在服务器中SPDF会以字符串形式输出EPDF以邮件的附件输出
$filename = DS . 'uploads' . DS . $date . DS . $extract . ".pdf";
$filePath = $Path . DS . "$extract.pdf";
$mpdf->Output($Path . DS . "$extract.pdf", 'F');
$upload = ossUpload(trim(str_replace("\\", "/", $filename), '/'), $filePath);
unlink($filePath); //把本地图片删除(原图)
return $this->buildSuccess(['url' => config('uploadFile.url') . $filename]);
}
//预览
public function templatePreviewleo() {
$report_id = input('id');
$reportInfo = Db::name('report')->where('id',$report_id)->find();
$reportDetailInfo = Db::name('report_detail')->where('report_id',$report_id)->select();
$estateNum = count($reportDetailInfo);
$id = input('id');
if (empty($id)) return $this->buildFailed('参数不能为空!');
$res = Db::name('report_template')->field('id,name')->where('id', $id)->find();
$detailModel = new ReportTemplateDetail();
$list = $detailModel->field('id,content')->where(['report_tmpl_id' => $id, 'status' => 1])->order('id', 'asc')->select();
$extract = date('YmdHis', time());
set_time_limit(0);
ini_set('max_execution_time', '100');
$pdf = new \TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
ob_end_clean();
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor("Author");
$pdf->SetTitle("pdf test");
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '1', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);//设置默认等宽字体
$pdf->SetMargins(PDF_MARGIN_LEFT, 24, PDF_MARGIN_RIGHT);//设置页面边幅
//$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (@file_exists(ROOT_PATH.'/vendor/tecnickcom/tcpdf/examples/lang/eng.php')) {
require_once(ROOT_PATH.'/vendor/tecnickcom/tcpdf/examples/lang/eng.php');
}
// $pdf->setLanguageArray($l);
$pdf->SetFont('stsongstdlight', '', 12);
foreach ($list as $k => $v) {
$template = $v['content'];
$pdf->AddPage();
$firstpageone = $template;
$pdf->writeHTML($firstpageone, true, false, true, false, '');
}
$Path=ROOT_PATH . 'public' . DS . 'uploads';
if (!file_exists($Path)) {
//检查是否有该文件夹,如果没有就创建,并给予最高权限
mkdir($Path, 0700, true);
}
//DestPDF输出的方式。I默认值在浏览器中打开D点击下载按钮 PDF文件会被下载下来F文件会被保存在服务器中SPDF会以字符串形式输出EPDF以邮件的附件输出
$pdf->Output($Path . DS ."$extract.pdf", 'I');
exit;
}
//保存模板
public function subModule() {
$id = input('id');
$name = input('name');
$report_detail_id = input('report_detail_id/a');
if (empty($report_detail_id)) return $this->buildFailed('请选择模块!');
if (empty($name)) return $this->buildFailed('报告模板名称不能为空!');
$ids = implode(',',$report_detail_id);
//$detailInfo = Db::name('report_template_detail')->field('id,module_name,content')->whereIn('id', $ids)->order('field(id,'.$ids.')')->select();
$sql = "SELECT `module_name`,`id`,`content` FROM `pg_report_template_detail` WHERE `id` IN ($ids) ORDER BY field(id,$ids)";
$detailInfo = Db::name('report_template_detail')->query($sql);
$data = array('name' => $name, 'report_detail_id' => implode(',', $report_detail_id), 'report_info' => json_encode($detailInfo), 'update_time' => time());
if (empty($id)) {
// 新增主干报告
$res['create_uid'] = $this->userInfo['user_id'];
$res['create_time'] = $res['update_time'] = time();
if (!Db::name('report_template')->insert($data)) {
return $this->buildFailed('新增主干报告模板失败!');
}
} else {
$res = Db::name('report_template')->where('id', $id)->field('report_detail_id,report_info')->find();
$res['type'] = 2;
$res['trunk_id'] = $id;
$res['trunk'] = Db::name('report_template')->where('id', $id)->value('name');
$res['name'] = date('Y年m月d日', time()) . '前模板';
$res['create_time'] = $res['update_time'] = time();
$res['create_uid'] = $this->userInfo['user_id'];
$check = Db::name('report_template')->where(new Where(['trunk_id' => $id, 'name' => $res['name']]))->value('id');
if ($check) {//更新当天分支
if (!Db::name('report_template')->where('id', $check)->update($res)) {
return $this->buildFailed('更新分支报告模板失败!');
}
} else {//新建分支
if (!Db::name('report_template')->insert($res)) {
return $this->buildFailed('新增分支报告模板失败!');
}
}
if (!Db::name('report_template')->where('id', $id)->update($data)) {
return $this->buildFailed('更新报告失败!');
}
}
return $this->buildSuccess();
}
//获取模块列表
public function getModuleList() {
$type = input('type');
$name = input('module_name');
if (empty($type)) return $this->buildFailed('模板类型不能为空!');
$map = [];
$map[] = ['type', '=', $type];
$map[] = ['status', '=', 1];
if ($name) {
$map[] = ['module_name', 'like', '%'.$name.'%'];
}
$res = Db::name('report_template_detail')->field('id,module_name')->where($map)->select();
return $this->buildSuccess($res);
}
//新增模块
public function addModule() {
$id = input('id');
$name = input('name');
$type = input('type');
$sort = input('sort');
$content = input('content');
if (empty($name)) return $this->buildFailed('模块名称不能为空!');
if (empty($type)) return $this->buildFailed('请选择模块类型!');
if (empty($content)) return $this->buildFailed('模块内容不能为空!');
if (empty($sort)) return $this->buildFailed('排序不能为空!');
$data = array('module_name' => $name, 'type' => $type, 'sort' => $sort, 'content' => $content, 'update_time' => time());
if (empty($id)) {
$data['create_time'] = time();
if (!Db::name('report_template_detail')->insert($data)) {
return $this->buildFailed('新增模块失败!');
}
} else {
if (!Db::name('report_template_detail')->where('id', $id)->update($data)) {
return $this->buildFailed('更新模块失败!');
}
//同步模板
$this->synchronizationTemplate($id);
}
return $this->buildSuccess();
}
//同步模板
public function synchronizationTemplate($id) {
$str = 'FIND_IN_SET(' . $id . ', report_detail_id)';
$res = Db::name('report_template')->where('', 'exp', $str)->where('type', 1)->field('id,name,report_detail_id,report_info')->select();
if ($res) {
foreach ($res as $key => $value) {
//新增分支
$data = [];
$data['type'] = 2;
$data['trunk_id'] = $value['id'];
$data['trunk'] = $value['name'];
$data['name'] = date('Y年m月d日', time()) . '前模板';
$data['report_detail_id'] = $value['report_detail_id'];
$data['report_info'] = $value['report_info'];
$data['create_time'] = $data['update_time'] = time();
$data['create_uid'] = $this->userInfo['user_id'];
$check = Db::name('report_template')->where(new Where(['trunk_id' => $value['id'], 'name' => $data['name']]))->value('id');
if ($check) {//更新当天分支
Db::name('report_template')->where('id', $check)->update($data);
} else {//新建分支
Db::name('report_template')->insert($data);
}
//更新主干
$ids = $value['report_detail_id'];
$sql = "SELECT `module_name`,`id`,`content` FROM `pg_report_template_detail` WHERE `id` IN ($ids) ORDER BY field(id,$ids)";
$detailInfo = Db::name('report_template_detail')->query($sql);
Db::name('report_template')->where('id', $value['id'])->update(['report_info' => json_encode($detailInfo), 'update_time' => time()]);
}
}
return true;
}
//获取模块信息
public function getModuleInfo() {
$id = input('id');
if (empty($id)) return $this->buildFailed('参数不能为空!');
$res = Db::name('report_template_detail')->where('id', $id)->find();
return $this->buildSuccess($res);
}
//模块列表
public function moduleList() {
$module_name = input('module_name');
$map = [];
$map[] = ['status', '=', 1];
if ($module_name) {
$map[] = ['module_name', 'like', '%'.$module_name.'%'];
}
$res = Db::name('report_template_detail')->field('id,module_name,type,sort,update_time')
->where($map)
->order('sort', 'desc')
->paginate($this->getPage())
->each(function ($item){
$item['update_time'] = !empty($item['update_time']) ? date('Y-m-d H:i:s', $item['update_time']) : "";
$item['type_str'] = $item['type'] == 1 ? "公共" : "私有";
return $item;
})
->toArray();
return $this->buildSuccess(['data' => $res['data'], 'count' => $res['total']]);
}
//更新模块排序
public function updateModuleSort() {
$id = input('id');
$sort = input('sort');
if (empty($id)) return $this->buildFailed('列表id不能为空');
if (empty($sort)) return $this->buildFailed('排序不能为空!');
if (!Db::name('report_template_detail')->where('id', $id)->update(['sort' => $sort, 'update_time' => time()])) {
return $this->buildFailed('更新模块失败!');
}
return $this->buildSuccess();
}
}