fix: 修改艺考资讯模块
This commit is contained in:
parent
eca1239a2c
commit
620d38ad40
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\ExaminationInformation\infoArticle;
|
||||
namespace app\admin\controller\ExaminationInformation;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\ExaminationInformation\infoArticle\infoArticle as ModelinfoArticle;
|
||||
use app\common\model\ExaminationInformation\InfoArticle as ModelinfoArticle;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
@ -15,30 +15,31 @@ use think\facade\Db;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class infoArticle extends BaseController
|
||||
class InfoArticle extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取资讯文章列表
|
||||
*/
|
||||
public function getinfoArticleList(Request $request): array
|
||||
{
|
||||
$con = Tool::getOptionalQuery(
|
||||
['b.info_article_delete_time', 'NULL'],
|
||||
);
|
||||
$params = $request->param();
|
||||
$con = [];
|
||||
|
||||
$con = Tool::getOptionalQuery(['info_article_title', 'LIKE'],);
|
||||
$con = Tool::getOptionalQuery(['info_article_title', 'LIKE'],['a.info_article_type_guid', '=']);
|
||||
|
||||
$query = ModelinfoArticle::where($con)
|
||||
->field([
|
||||
'info_article_id',
|
||||
'info_article_guid',
|
||||
'info_article_title',
|
||||
'info_article_cover',
|
||||
'info_article_content',
|
||||
'info_article_order'
|
||||
'a.info_article_id',
|
||||
'a.info_article_guid',
|
||||
'a.info_article_type_guid',
|
||||
'b.info_article_type_name',
|
||||
'a.info_article_title',
|
||||
'a.info_article_cover',
|
||||
'a.info_article_content',
|
||||
'a.info_article_order'
|
||||
])
|
||||
->alias('a')
|
||||
->leftjoin('info_article_type b','a.info_article_type_guid = b.info_article_type_guid')
|
||||
->order('info_article_order', 'asc');
|
||||
|
||||
return msg("获取资讯文章列表成功!", $query);
|
||||
@ -51,6 +52,7 @@ class infoArticle extends BaseController
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'info_article_type_guid|文章类型' => 'require',
|
||||
'info_article_title|文章标题' => 'require',
|
||||
'info_article_cover|文章封面' => 'require',
|
||||
'info_article_content|文章内容' => 'require',
|
||||
@ -62,6 +64,7 @@ class infoArticle extends BaseController
|
||||
$model->allowField([
|
||||
'info_article_update_user_guid',
|
||||
'info_article_title',
|
||||
'info_article_type_guid',
|
||||
'info_article_cover',
|
||||
'info_article_content',
|
||||
'info_article_order'
|
||||
@ -76,6 +79,7 @@ class infoArticle extends BaseController
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'info_article_type_guid|文章类型' => 'require',
|
||||
'info_article_title|文章标题' => 'require',
|
||||
'info_article_cover|文章封面' => 'require',
|
||||
'info_article_content|文章内容' => 'require',
|
||||
@ -86,6 +90,7 @@ class infoArticle extends BaseController
|
||||
'info_article_guid',
|
||||
'info_article_create_user_guid',
|
||||
'info_article_update_user_guid',
|
||||
'info_article_type_guid',
|
||||
'info_article_title',
|
||||
'info_article_cover',
|
||||
'info_article_content',
|
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\ExaminationInformation\infoArticleType;
|
||||
namespace app\admin\controller\ExaminationInformation;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\ExaminationInformation\infoArticleType\infoArticleType as ModelinfoArticleType;
|
||||
use app\common\model\ExaminationInformation\InfoArticleType as ModelinfoArticleType;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
@ -15,16 +15,13 @@ use think\facade\Db;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class infoArticleType extends BaseController
|
||||
class InfoArticleType extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取资讯文章类型列表
|
||||
*/
|
||||
public function getinfoArticleTypeList(Request $request): array
|
||||
{
|
||||
$con = Tool::getOptionalQuery(
|
||||
['b.info_article_type_delete_time', 'NULL'],
|
||||
);
|
||||
$params = $request->param();
|
||||
$con = [];
|
||||
|
||||
@ -92,12 +89,13 @@ class infoArticleType extends BaseController
|
||||
'info_article_type_sort'
|
||||
]);
|
||||
Db::commit();
|
||||
return msg('编辑成功!');
|
||||
return msg('添加成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除资讯文章类型
|
||||
*/
|
||||
@ -122,34 +120,31 @@ class infoArticleType extends BaseController
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出Excel
|
||||
*/
|
||||
public function exportExcel(Request $request)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params = $request->param();
|
||||
$select = ModelinfoArticleType::field([
|
||||
'info_article_type_name',
|
||||
'info_article_type_sort'
|
||||
])
|
||||
->order('info_article_type_update_time', 'desc')
|
||||
->select();
|
||||
Db::commit();
|
||||
return msg('编辑成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
$params = $request->param();
|
||||
$params['limit'] = 10000;
|
||||
// if (isset($params['signup_guids']) && $params['signup_guids']) {
|
||||
// $con['signup.signup_guid'] = explode(',', $params['signup_guids']);
|
||||
// }
|
||||
$select = self::getinfoArticleTypeList($request)['data'];
|
||||
return ModelinfoArticleType::exportExcel($select);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载导入模板
|
||||
*/
|
||||
public function downloadTemplate(Request $request)
|
||||
{
|
||||
$params = $request->param();
|
||||
$data = array_values(ModelinfoArticleType::EXCELFIELD);
|
||||
$data = [
|
||||
array_values(ModelinfoArticleType::EXCELFIELD),
|
||||
['招生新闻', '1']
|
||||
];
|
||||
$excel = (new Excel())->exporTsheet($data);
|
||||
$excel->save('资讯文章类型导入模板.xlsx');
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\ExaminationInformation\infoArticle;
|
||||
namespace app\api\controller\ExaminationInformation;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\ExaminationInformation\infoArticle\infoArticle as ModelinfoArticle;
|
||||
use app\common\model\ExaminationInformation\InfoArticle as ModelinfoArticle;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
@ -15,7 +15,7 @@ use app\common\exception\Tool;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class infoArticle extends BaseController
|
||||
class InfoArticle extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取资讯文章列表
|
||||
@ -25,17 +25,22 @@ class infoArticle extends BaseController
|
||||
$params = $request->param();
|
||||
$con = [];
|
||||
|
||||
$con = Tool::getOptionalQuery(['info_article_title', 'LIKE'],);
|
||||
$this->validate($params, [
|
||||
'info_article_type_id|文章类型id' => 'require',
|
||||
]);
|
||||
$con = Tool::getOptionalQuery(['b.info_article_type_id', '='],);
|
||||
|
||||
$query = ModelinfoArticle::where($con)
|
||||
->field([
|
||||
'info_article_id',
|
||||
'info_article_guid',
|
||||
'info_article_title',
|
||||
'info_article_cover',
|
||||
'info_article_content',
|
||||
'info_article_order'
|
||||
'a.info_article_id',
|
||||
'a.info_article_type_guid',
|
||||
'b.info_article_type_name',
|
||||
'a.info_article_title',
|
||||
'a.info_article_cover',
|
||||
])
|
||||
->alias('a')
|
||||
->leftjoin('info_article_type b','a.info_article_type_guid = b.info_article_type_guid')
|
||||
->hidden(['info_article_type_guid'])
|
||||
->order('info_article_order', 'asc');
|
||||
|
||||
|
||||
@ -54,7 +59,6 @@ class infoArticle extends BaseController
|
||||
|
||||
$find = ModelinfoArticle::field([
|
||||
'info_article_id',
|
||||
'info_article_guid',
|
||||
'info_article_title',
|
||||
'info_article_cover',
|
||||
'info_article_content',
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\ExaminationInformation;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\ExaminationInformation\InfoArticleType as ModelinfoArticleType;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Filesystem;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\common\arw\adjfut\src\UploadFile;
|
||||
use think\facade\Db;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class InfoArticleType extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取资讯文章类型列表
|
||||
*/
|
||||
public function getinfoArticleTypeList(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$con = [];
|
||||
|
||||
$con = Tool::getOptionalQuery();
|
||||
|
||||
$query = ModelinfoArticleType::where($con)
|
||||
->field([
|
||||
'info_article_type_id',
|
||||
'info_article_type_name',
|
||||
])
|
||||
->order('info_article_type_sort', 'asc')
|
||||
->select();
|
||||
|
||||
return msg(0, "获取资讯文章类型列表成功!", [
|
||||
'data' => $query,
|
||||
'count' => count($query)
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\ExaminationInformation\infoArticleType;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\ExaminationInformation\infoArticleType\infoArticleType as ModelinfoArticleType;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Filesystem;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\common\arw\adjfut\src\UploadFile;
|
||||
use think\facade\Db;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class infoArticleType extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取资讯文章类型列表
|
||||
*/
|
||||
public function getinfoArticleTypeList(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$con = [];
|
||||
|
||||
$con = Tool::getOptionalQuery();
|
||||
|
||||
$query = ModelinfoArticleType::where($con)
|
||||
->field([
|
||||
'info_article_type_id',
|
||||
'info_article_type_guid',
|
||||
'info_article_type_name',
|
||||
'info_article_type_sort'
|
||||
])
|
||||
->order('info_article_type_sort', 'asc');
|
||||
|
||||
|
||||
|
||||
return msg("获取资讯文章类型列表成功!", $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资讯文章类型详情
|
||||
*/
|
||||
public function getinfoArticleTypeInfo(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
|
||||
$this->validate($params, ['info_article_type_guid' => 'require']);
|
||||
|
||||
$find = ModelinfoArticleType::field([
|
||||
'info_article_type_id',
|
||||
'info_article_type_guid',
|
||||
'info_article_type_name',
|
||||
'info_article_type_sort'
|
||||
])
|
||||
->where('info_article_type_guid', $params['info_article_type_guid'])
|
||||
->find();
|
||||
|
||||
return msg(0, '获取资讯文章类型详情成功!', ['data' => $find]);
|
||||
}
|
||||
}
|
183
app/common/model/ExaminationInformation/InfoArticle.php
Normal file
183
app/common/model/ExaminationInformation/InfoArticle.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\ExaminationInformation;
|
||||
|
||||
use app\common\arw\adjfut\src\Validate;
|
||||
use app\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\Request;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
|
||||
class InfoArticle extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
// 删除字段
|
||||
protected $deleteTime = 'info_article_delete_time';
|
||||
// 设置主键名
|
||||
protected $pk = 'info_article_guid';
|
||||
// 设置废弃字段
|
||||
protected $disuse = [];
|
||||
// 设置字段信息
|
||||
protected $schema = [
|
||||
|
||||
"info_article_id" => "int",
|
||||
|
||||
"info_article_guid" => "string",
|
||||
|
||||
"info_article_type_guid" => "string",
|
||||
|
||||
"info_article_title" => "string",
|
||||
|
||||
"info_article_cover" => "string",
|
||||
|
||||
"info_article_content" => "string",
|
||||
|
||||
"info_article_order" => "int",
|
||||
|
||||
"info_article_create_time" => "datetime",
|
||||
|
||||
"info_article_create_user_guid" => "string",
|
||||
|
||||
"info_article_update_time" => "datetime",
|
||||
|
||||
"info_article_update_user_guid" => "string",
|
||||
|
||||
"info_article_delete_time" => "datetime",
|
||||
|
||||
"info_article_delete_user_guid" => "string",
|
||||
|
||||
];
|
||||
// 设置json类型字段
|
||||
protected $json = [''];
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
// 创建时间
|
||||
protected $createTime = 'info_article_create_time';
|
||||
// 修改时间
|
||||
protected $updateTime = 'info_article_update_time';
|
||||
|
||||
|
||||
// excel导入/下载模板表头
|
||||
public const EXCELFIELD = [
|
||||
'info_article_title' => '文章标题',
|
||||
'info_article_cover' => '文章封面',
|
||||
'info_article_content' => '文章内容',
|
||||
'info_article_order' => '文章排序',
|
||||
];
|
||||
|
||||
//排序字段
|
||||
public $order_field = 'info_article_order';
|
||||
/**
|
||||
* 新增前
|
||||
*/
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
Tool::sortInsertProc(
|
||||
self::class,
|
||||
$model->info_article_order,
|
||||
['info_article_type_guid' => $model->info_article_type_guid]
|
||||
);
|
||||
// self::checkRepeatData($model);
|
||||
$model->completeCreateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新前
|
||||
*/
|
||||
public static function onBeforeUpdate(self $model): void
|
||||
{
|
||||
Tool::sortEditProc(
|
||||
self::class,
|
||||
$model->info_article_guid,
|
||||
$model->info_article_order,
|
||||
['info_article_type_guid' => $model->info_article_type_guid]
|
||||
);
|
||||
// self::checkRepeatData($model);
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前
|
||||
*/
|
||||
public static function onBeforeDelete(self $model): void
|
||||
{
|
||||
Tool::sortDeleteProc(self::class, $model->info_article_guid);
|
||||
$model->completeDeleteField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出Excel
|
||||
*/
|
||||
public static function exportExcel($select)
|
||||
{
|
||||
$data = [[
|
||||
'文章标题',
|
||||
'文章封面',
|
||||
// '文章内容',
|
||||
'文章排序'
|
||||
]];
|
||||
foreach ($select as $key => $val) {
|
||||
$data[] = [
|
||||
$val['info_article_title'],
|
||||
Excel::ExportImgFiled($val['info_article_cover']),
|
||||
// $val['info_article_content'],
|
||||
$val['info_article_order'],
|
||||
];
|
||||
}
|
||||
$excel = (new Excel())->exporTsheet($data);
|
||||
$excel->save('资讯文章.xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入excel
|
||||
*/
|
||||
public static function importExcel($file)
|
||||
{
|
||||
$msg = [];
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$excel = new Excel($file);
|
||||
$data = $excel->parseExcel(
|
||||
Tool::getExcelRule(self::EXCELFIELD),
|
||||
[
|
||||
'titleLine' => [1]
|
||||
]
|
||||
);
|
||||
if (!$data) throwErrorMsg('excel无数据', 1);
|
||||
$msg = [];
|
||||
foreach ($data as $line => $value) {
|
||||
try {
|
||||
$model = self::importExcelInit($value);
|
||||
$msg[] = "{$line} <span style='color:#27af49'>新增成功!</span><br>";
|
||||
} catch (\Throwable $th) {
|
||||
$msg[] = "{$line} <span style='color:red'>{$th->getMessage()}</span><br>";
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return implode(', ', $msg);
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入excel初始化
|
||||
*/
|
||||
public static function importExcelInit($value)
|
||||
{
|
||||
$info_article_title = $value['info_article_title'];
|
||||
$info_article_cover = $value['info_article_cover'];
|
||||
$info_article_content = $value['info_article_content'];
|
||||
$info_article_order = $value['info_article_order'];
|
||||
return self::create([
|
||||
'info_article_title' => $info_article_title,
|
||||
'info_article_cover' => $info_article_cover,
|
||||
'info_article_content' => $info_article_content,
|
||||
'info_article_order' => $info_article_order,
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\ExaminationInformation\InfoArticleType;
|
||||
namespace app\common\model\ExaminationInformation;
|
||||
|
||||
use app\common\arw\adjfut\src\Validate;
|
||||
use app\BaseModel;
|
||||
@ -69,10 +69,8 @@ class InfoArticleType extends BaseModel
|
||||
{
|
||||
Tool::sortInsertProc(
|
||||
self::class,
|
||||
$model->info_article_type_order,
|
||||
// ['subject_guid' => $model->subject_guid]
|
||||
$model->info_article_type_sort,
|
||||
);
|
||||
// self::checkRepeatData($model);
|
||||
$model->completeCreateField();
|
||||
}
|
||||
|
||||
@ -85,7 +83,6 @@ class InfoArticleType extends BaseModel
|
||||
self::class,
|
||||
$model->info_article_type_guid,
|
||||
$model->info_article_type_sort,
|
||||
// ['subject_guid' => $model->info_article_type_guid]
|
||||
);
|
||||
// self::checkRepeatData($model);
|
||||
$model->completeUpdateField();
|
||||
@ -140,7 +137,7 @@ class InfoArticleType extends BaseModel
|
||||
foreach ($data as $line => $value) {
|
||||
try {
|
||||
$model = self::importExcelInit($value);
|
||||
$msg[] = "{$line} <span style='color:#27af49'>新增成功!</span><br>";
|
||||
$msg[] = "{$line} <span style='color:#27af49'>【{$value->info_article_type_name}】新增成功!</span><br>";
|
||||
} catch (\Throwable $th) {
|
||||
$msg[] = "{$line} <span style='color:red'>{$th->getMessage()}</span><br>";
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\ExaminationInformation\InfoArticle;
|
||||
|
||||
use app\common\arw\adjfut\src\Validate;
|
||||
use app\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\Request;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
|
||||
class InfoArticle extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
// 删除字段
|
||||
protected $deleteTime = 'info_article_delete_time';
|
||||
// 设置主键名
|
||||
protected $pk = 'info_article_guid';
|
||||
// 设置废弃字段
|
||||
protected $disuse = [];
|
||||
// 设置字段信息
|
||||
protected $schema = [
|
||||
|
||||
"info_article_id" => "int",
|
||||
|
||||
"info_article_guid" => "string",
|
||||
|
||||
"info_article_title" => "string",
|
||||
|
||||
"info_article_cover" => "string",
|
||||
|
||||
"info_article_content" => "string",
|
||||
|
||||
"info_article_order" => "int",
|
||||
|
||||
"info_article_create_time" => "datetime",
|
||||
|
||||
"info_article_create_user_guid" => "string",
|
||||
|
||||
"info_article_update_time" => "datetime",
|
||||
|
||||
"info_article_update_user_guid" => "string",
|
||||
|
||||
"info_article_delete_time" => "datetime",
|
||||
|
||||
"info_article_delete_user_guid" => "string",
|
||||
|
||||
];
|
||||
// 设置json类型字段
|
||||
protected $json = [''];
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
// 创建时间
|
||||
protected $createTime = 'info_article_create_time';
|
||||
// 修改时间
|
||||
protected $updateTime = 'info_article_update_time';
|
||||
|
||||
|
||||
// excel导入/下载模板表头
|
||||
public const EXCELFIELD = [
|
||||
'info_article_title' => '文章标题',
|
||||
'info_article_cover' => '文章封面',
|
||||
'info_article_content' => '文章内容',
|
||||
'info_article_order' => '文章排序',
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 新增前
|
||||
*/
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
// self::checkRepeatData($model);
|
||||
$model->completeCreateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新前
|
||||
*/
|
||||
public static function onBeforeUpdate(self $model): void
|
||||
{
|
||||
// self::checkRepeatData($model);
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前
|
||||
*/
|
||||
public static function onBeforeDelete(self $model): void
|
||||
{
|
||||
$model->completeDeleteField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出Excel
|
||||
*/
|
||||
public static function exportExcel($select)
|
||||
{
|
||||
$data = [[
|
||||
'文章标题',
|
||||
'文章封面',
|
||||
'文章内容',
|
||||
'文章排序'
|
||||
]];
|
||||
foreach ($select as $key => $val) {
|
||||
$data[] = [
|
||||
$val['info_article_title'],
|
||||
Excel::ExportImgFiled($val['info_article_cover']),
|
||||
$val['info_article_content'],
|
||||
$val['info_article_order'],
|
||||
];
|
||||
}
|
||||
$excel = (new Excel())->exporTsheet($data);
|
||||
$excel->save('资讯文章.xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入excel
|
||||
*/
|
||||
public static function importExcel($file)
|
||||
{
|
||||
$msg = [];
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$excel = new Excel($file);
|
||||
$data = $excel->parseExcel(
|
||||
Tool::getExcelRule(self::EXCELFIELD),
|
||||
[
|
||||
'titleLine' => [1]
|
||||
]);
|
||||
if (!$data) throwErrorMsg('excel无数据', 1);
|
||||
$msg = [];
|
||||
foreach ($data as $line => $value) {
|
||||
try {
|
||||
$model = self::importExcelInit($value);
|
||||
$msg[] = "{$line} <span style='color:#27af49'>新增成功!</span><br>";
|
||||
} catch (\Throwable $th) {
|
||||
$msg[] = "{$line} <span style='color:red'>{$th->getMessage()}</span><br>";
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return implode(', ', $msg);
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入excel初始化
|
||||
*/
|
||||
public static function importExcelInit($value)
|
||||
{
|
||||
$info_article_title = $value['info_article_title'];$info_article_cover = $value['info_article_cover'];$info_article_content = $value['info_article_content'];$info_article_order = $value['info_article_order'];
|
||||
return self::create([
|
||||
'info_article_title' => $info_article_title,
|
||||
'info_article_cover' => $info_article_cover,
|
||||
'info_article_content' => $info_article_content,
|
||||
'info_article_order' => $info_article_order,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user