init: 项目初始代码
This commit is contained in:
153
app/api/controller/v1/Investment.php
Normal file
153
app/api/controller/v1/Investment.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Investment as InvestmentModel;
|
||||
use app\api\validate\Investment as InvestmentValidate;
|
||||
use think\facade\Db;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
/**
|
||||
* 招商引资信息留言控制器
|
||||
*/
|
||||
class Investment extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new InvestmentModel();
|
||||
$this->validate = new InvestmentValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*/
|
||||
public function index():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$this->focus['platform_id'] = $inputData['platform_id'] = $this->platformId;
|
||||
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
|
||||
//判断是否需要分页
|
||||
if (isset($inputData['page']) && $inputData['page'] != 0) {
|
||||
$this->page = (int)$inputData['page'];
|
||||
}
|
||||
if (isset($inputData['size']) && $inputData['size'] != 0) {
|
||||
$this->size = (int)$inputData['size'];
|
||||
}
|
||||
|
||||
if (isset($inputData['create_time']) && $inputData['create_time'] != '') {
|
||||
$this->order['create_time'] = $inputData['create_time'];
|
||||
}
|
||||
|
||||
if (isset($inputData['keyword']) && $inputData['keyword'] != '') {
|
||||
$this->simple['keyword'] = $inputData['keyword'];
|
||||
}
|
||||
|
||||
$result = $this->model->getIndexList($this->page,$this->size,$this->field,$this->simple,$this->focus,$this->order);
|
||||
|
||||
if (isset($result['data']) && !empty($result['data'])) {
|
||||
foreach ($result['data'] as $key => $item) {
|
||||
$result['data'][$key]['province_id'] = $this->model->getAreaNameById($item['province_id']);
|
||||
$result['data'][$key]['city_id'] = $this->model->getAreaNameById($item['city_id']);
|
||||
}
|
||||
}
|
||||
//构建返回数据结构
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格导出数据前置方法
|
||||
*/
|
||||
public function export():\think\Response\Json
|
||||
{
|
||||
$ids = $this->request->param();
|
||||
if ($this->commonValidate(__FUNCTION__,$ids)) {
|
||||
return $this->msg(-1,'获取列表成功');
|
||||
}
|
||||
$data = $this->model->getExportData($ids);
|
||||
$fields = [
|
||||
'id','platform_id','language_id','site_id','country_id',
|
||||
'province_id','city_id','area','from','phone','name','email',
|
||||
'wechat','qq','desc','sort','is_open','create_time','update_time'
|
||||
];
|
||||
//处理数据
|
||||
// foreach ($data as &$datum) {
|
||||
// $datum['admin_id'] = $datum['admin_name'];
|
||||
// $datum['country_timezone_id'] = $datum['country_name'];
|
||||
// $datum['is_cooperation'] = $datum['is_cooperation'] == 0 ? "无" : "有";
|
||||
// $datum['follow_up_stage_id'] = !empty($datum['follow_up_stage_name']) ?$datum['follow_up_stage_name']: '无';
|
||||
// $datum['customer_from_id'] = !empty($datum['customer_from_name']) ?$datum['customer_from_name'] : '无';
|
||||
// $datum['customer_level_id'] = !empty($datum['customer_level_name']) ? $datum['customer_level_name']: '无';
|
||||
// foreach ($datum as $key => $value) {
|
||||
// if (!in_array($key,$fields)) {
|
||||
// unset($datum[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
|
||||
$this->importHeadType = 'name';
|
||||
$table = $this->model->getTable();
|
||||
$database = Env::get('database.database');
|
||||
//字段名与注释的数组,
|
||||
$fieldArr = [];
|
||||
$list = Db::query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
|
||||
foreach ($list as $v) {
|
||||
if (in_array($v['COLUMN_NAME'],$fields)) {
|
||||
if ($this->importHeadType == 'comment') {
|
||||
$fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME'];
|
||||
} else {
|
||||
$fieldArr[$v['COLUMN_NAME']] = $v['COLUMN_COMMENT'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$newData = [];/*表格数据*/
|
||||
$newHeader = [];/*表格表头*/
|
||||
$cols = []; /*分别占用表格哪几列*/
|
||||
if (array_key_exists(0,$data)) {
|
||||
$header = array_keys($data[0]);
|
||||
foreach ($header as $k => $v) {
|
||||
if ($k <= 25) {
|
||||
$newHeader[chr($k+65).'1'] = $fieldArr[$v]?:$v;
|
||||
$cols[$k] = chr($k+65);
|
||||
} else {
|
||||
$newHeader[chr(65).chr($k-26+65).'1'] = $fieldArr[$v]?:$v;
|
||||
$cols[$k] = chr(65).chr($k-26+65);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $k => $v) {
|
||||
$index = 0;
|
||||
foreach ($v as $v1) {
|
||||
if ($index <= 25) {
|
||||
$header = chr($index+65);
|
||||
$header .= $k+2;
|
||||
$newData[$header] = $v1;/*获取表头*/
|
||||
} else {
|
||||
$header = chr(65).chr($index-26+65);
|
||||
$header .= $k+2;
|
||||
$newData[$header] = $v1;/*获取表头*/
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
$newData = array_merge($newHeader,$newData);
|
||||
$options = [
|
||||
'print' =>false,
|
||||
'freezePane'=>'A2',
|
||||
// 'setWidth'=>['A'=>40,'B'=>30,'C'=>20,'D'=>25,'E'=>20,'F'=>15,'G'=>10,'H'=>10],
|
||||
'setBorder'=>true,
|
||||
'alignCenter'=>$cols,
|
||||
'bold'=>array_keys($newHeader),
|
||||
];
|
||||
return $this->excelExport($newData,count($fields),'招商信息导出-'.date('YmdHis',time()).'.xlsx',$options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user