init
This commit is contained in:
parent
2e19b59e85
commit
575dea7f7d
187
app/admin/controller/News/News.php
Normal file
187
app/admin/controller/News/News.php
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\News;
|
||||||
|
|
||||||
|
use app\BaseController;
|
||||||
|
use app\common\model\News\News as ModelNews;
|
||||||
|
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 app\common\exception\Tool;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Env;
|
||||||
|
|
||||||
|
|
||||||
|
class News extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取新闻列表
|
||||||
|
*/
|
||||||
|
public function getNewsList(Request $request, $isExport = false): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$con = [];
|
||||||
|
|
||||||
|
$con = Tool::getOptionalQuery(['news_type','='],['news_title','LIKE'],);
|
||||||
|
|
||||||
|
$query = ModelNews::where($con)
|
||||||
|
->field([
|
||||||
|
'news_id',
|
||||||
|
'news_guid',
|
||||||
|
'news_type',
|
||||||
|
'news_title',
|
||||||
|
'news_intro',
|
||||||
|
'news_source',
|
||||||
|
'news_link',
|
||||||
|
'news_issue_date',
|
||||||
|
'news_views_num',
|
||||||
|
'news_sort',
|
||||||
|
'news_content'
|
||||||
|
])
|
||||||
|
->order('news_sort', 'asc');
|
||||||
|
|
||||||
|
return $isExport ? $query->select()->toArray() : msg("获取新闻列表成功!",$query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加新闻
|
||||||
|
*/
|
||||||
|
public function addNews(Request $request): array
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
Tool::adminLockTableWrite('news');
|
||||||
|
try {
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'news_type|新闻类型'=>'require',
|
||||||
|
'news_title|新闻标题'=>'require',
|
||||||
|
'news_sort|新闻排序'=>'require'
|
||||||
|
]);
|
||||||
|
$model = ModelNews::create($params,[
|
||||||
|
'news_type',
|
||||||
|
'news_title',
|
||||||
|
'news_intro',
|
||||||
|
'news_source',
|
||||||
|
'news_link',
|
||||||
|
'news_issue_date',
|
||||||
|
'news_views_num',
|
||||||
|
'news_sort',
|
||||||
|
'news_content',
|
||||||
|
'news_guid',
|
||||||
|
'news_create_user_guid',
|
||||||
|
'news_update_user_guid'
|
||||||
|
]);
|
||||||
|
Db::commit();
|
||||||
|
Tool::unlockTable();
|
||||||
|
return msg('添加成功!');
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Db::rollback();
|
||||||
|
Tool::unlockTable();
|
||||||
|
throw $th;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑新闻
|
||||||
|
*/
|
||||||
|
public function editNews(Request $request): array
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
Tool::adminLockTableWrite('news');
|
||||||
|
try {
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'news_type|新闻类型'=>'require',
|
||||||
|
'news_title|新闻标题'=>'require',
|
||||||
|
'news_sort|新闻排序'=>'require'
|
||||||
|
]);
|
||||||
|
$model = ModelNews::where('news_guid',$params['news_guid'])->find();
|
||||||
|
if (!$model) throwErrorMsg("该新闻不存在", 1);
|
||||||
|
$model->allowField([
|
||||||
|
'news_type',
|
||||||
|
'news_title',
|
||||||
|
'news_intro',
|
||||||
|
'news_source',
|
||||||
|
'news_link',
|
||||||
|
'news_issue_date',
|
||||||
|
'news_views_num',
|
||||||
|
'news_sort',
|
||||||
|
'news_content',
|
||||||
|
'news_update_user_guid'
|
||||||
|
])->save($params);
|
||||||
|
Db::commit();
|
||||||
|
Tool::unlockTable();
|
||||||
|
return msg('编辑成功!');
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Db::rollback();
|
||||||
|
Tool::unlockTable();
|
||||||
|
throw $th;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除新闻
|
||||||
|
*/
|
||||||
|
public function deleteNews(Request $request): array
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
Tool::adminLockTableWrite('news');
|
||||||
|
try {
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'news_guid' => 'require',
|
||||||
|
]);
|
||||||
|
$news = ModelNews::where([
|
||||||
|
'news_guid' => explode(',', $params['news_guid'])
|
||||||
|
])->select();
|
||||||
|
$news->delete();
|
||||||
|
Db::commit();
|
||||||
|
Tool::unlockTable();
|
||||||
|
return msg('删除成功!');
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Db::rollback();
|
||||||
|
Tool::unlockTable();
|
||||||
|
throw $th;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出Excel
|
||||||
|
*/
|
||||||
|
public function exportExcel(Request $request):void
|
||||||
|
{
|
||||||
|
ModelNews::exportExcel(self::getNewsList($request, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载导入模板
|
||||||
|
*/
|
||||||
|
public function downloadTemplate(Request $request):void
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$data = [
|
||||||
|
array_values(ModelNews::EXCELFIELD),
|
||||||
|
['默认值1','默认值2','默认值3','默认值4','默认值5','默认值6','默认值7','默认值8','默认值9',]
|
||||||
|
];
|
||||||
|
$excel = (new Excel())->exporTsheet($data);
|
||||||
|
$excel->save('新闻导入模板.xlsx');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入excel
|
||||||
|
*/
|
||||||
|
public function importExcel(Request $request):array
|
||||||
|
{
|
||||||
|
$file = new UploadFile('uploads', 'fileExt:xlsx');
|
||||||
|
$file->putFile('news');
|
||||||
|
$msg = ModelNews::importExcel($file);
|
||||||
|
return [
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => $msg
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
163
app/admin/controller/Products/Product.php
Normal file
163
app/admin/controller/Products/Product.php
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\Products;
|
||||||
|
|
||||||
|
use app\BaseController;
|
||||||
|
use app\common\model\Products\Product as ModelProduct;
|
||||||
|
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 app\common\exception\Tool;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Env;
|
||||||
|
|
||||||
|
|
||||||
|
class Product extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取产品列表
|
||||||
|
*/
|
||||||
|
public function getProductList(Request $request, $isExport = false): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$con = [];
|
||||||
|
|
||||||
|
$con = Tool::getOptionalQuery(['a.product_type_guid', '='], ['product_name', 'LIKE'],);
|
||||||
|
|
||||||
|
$query = ModelProduct::alias('a')
|
||||||
|
->leftjoin('product_type b', 'a.product_type_guid = b.product_type_guid')
|
||||||
|
->where($con)
|
||||||
|
->field([
|
||||||
|
'a.product_id',
|
||||||
|
'a.product_guid',
|
||||||
|
'a.product_type_guid',
|
||||||
|
'b.product_type_name',
|
||||||
|
'a.product_name',
|
||||||
|
'a.product_img',
|
||||||
|
'a.product_description',
|
||||||
|
'a.product_link',
|
||||||
|
'a.product_details',
|
||||||
|
'a.product_sort'
|
||||||
|
])
|
||||||
|
->order('product_sort', 'asc');
|
||||||
|
|
||||||
|
return $isExport ? $query->select()->toArray() : msg("获取产品列表成功!", $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加产品
|
||||||
|
*/
|
||||||
|
public function addProduct(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'product_type_guid|产品类目' => 'require',
|
||||||
|
'product_name|产品名称' => 'require',
|
||||||
|
'product_img|产品图片' => 'require',
|
||||||
|
'product_sort|产品排序' => 'require'
|
||||||
|
]);
|
||||||
|
$model = ModelProduct::create($params, [
|
||||||
|
'product_type_guid',
|
||||||
|
'product_name',
|
||||||
|
'product_img',
|
||||||
|
'product_description',
|
||||||
|
'product_link',
|
||||||
|
'product_details',
|
||||||
|
'product_sort',
|
||||||
|
'product_guid',
|
||||||
|
'product_create_user_guid',
|
||||||
|
'product_update_user_guid'
|
||||||
|
]);
|
||||||
|
return msg('添加成功!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑产品
|
||||||
|
*/
|
||||||
|
public function editProduct(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'product_type_guid|产品类目' => 'require',
|
||||||
|
'product_name|产品名称' => 'require',
|
||||||
|
'product_img|产品图片' => 'require',
|
||||||
|
'product_sort|产品排序' => 'require'
|
||||||
|
]);
|
||||||
|
$model = ModelProduct::where('product_guid', $params['product_guid'])->find();
|
||||||
|
if (!$model) throwErrorMsg("该产品不存在", 1);
|
||||||
|
$model->allowField([
|
||||||
|
'product_type_guid',
|
||||||
|
'product_name',
|
||||||
|
'product_img',
|
||||||
|
'product_description',
|
||||||
|
'product_link',
|
||||||
|
'product_details',
|
||||||
|
'product_sort',
|
||||||
|
'product_update_user_guid'
|
||||||
|
])->save($params);
|
||||||
|
return msg('编辑成功!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除产品
|
||||||
|
*/
|
||||||
|
public function deleteProduct(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'product_guid' => 'require',
|
||||||
|
]);
|
||||||
|
$product = ModelProduct::where([
|
||||||
|
'product_guid' => explode(',', $params['product_guid'])
|
||||||
|
])->select();
|
||||||
|
$product->delete();
|
||||||
|
return msg('删除成功!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出Excel
|
||||||
|
*/
|
||||||
|
public function exportExcel(Request $request): void
|
||||||
|
{
|
||||||
|
ModelProduct::exportExcel(self::getProductList($request, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载导入模板
|
||||||
|
*/
|
||||||
|
public function downloadTemplate(Request $request): void
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$data = [
|
||||||
|
array_values(ModelProduct::EXCELFIELD),
|
||||||
|
[
|
||||||
|
'软件工具',
|
||||||
|
'Arm Development StudioArm',
|
||||||
|
'http://localhost:3000/uploads/ProductImg/20230628/f5a7065c3db295c1e3e2a26b36cb41ed.jpg',
|
||||||
|
'Arm全面端到端的嵌入式开发工具',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'1',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$excel = (new Excel())->exporTsheet($data);
|
||||||
|
$excel->save('产品导入模板.xlsx');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入excel
|
||||||
|
*/
|
||||||
|
public function importExcel(Request $request): array
|
||||||
|
{
|
||||||
|
$file = new UploadFile('uploads', 'fileExt:xlsx');
|
||||||
|
$file->putFile('product');
|
||||||
|
$msg = ModelProduct::importExcel($file);
|
||||||
|
return [
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => $msg
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
237
app/admin/controller/Products/ProductType.php
Normal file
237
app/admin/controller/Products/ProductType.php
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\Products;
|
||||||
|
|
||||||
|
use app\BaseController;
|
||||||
|
use app\common\model\Products\ProductType as ModelProductType;
|
||||||
|
use app\common\arw\adjfut\src\Traverse;
|
||||||
|
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 app\common\exception\Tool;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Env;
|
||||||
|
|
||||||
|
|
||||||
|
class ProductType extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取产品类目树形列表接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @date 2023-03-25
|
||||||
|
* @example
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getProductTypeTree(Request $request): array
|
||||||
|
{
|
||||||
|
$con = Tool::getOptionalQuery(
|
||||||
|
['b.product_delete_time', 'NULL'],
|
||||||
|
['a.product_type_name', 'LIKE']
|
||||||
|
);
|
||||||
|
|
||||||
|
$product_type = ModelProductType::field([
|
||||||
|
'a.product_type_parent_guid',
|
||||||
|
'a.product_type_guid',
|
||||||
|
'a.product_type_name',
|
||||||
|
'b.product_type_name' => "product_type_parent_name",
|
||||||
|
'a.product_type_title',
|
||||||
|
'a.product_type_link',
|
||||||
|
'a.product_type_icon',
|
||||||
|
'a.product_type_order',
|
||||||
|
])
|
||||||
|
->alias('a')
|
||||||
|
->leftjoin('product_type b', 'a.product_type_parent_guid = b.product_type_guid')
|
||||||
|
->where($con)
|
||||||
|
->order(['product_type_order' => 'asc'])
|
||||||
|
->select()->toArray();
|
||||||
|
|
||||||
|
$Traverse = new Traverse('product_type_guid', 'product_type_parent_guid');
|
||||||
|
$product_type_tree = $Traverse->tree($product_type, '0', function ($v) {
|
||||||
|
return [
|
||||||
|
'product_type_guid' => $v['product_type_guid'],
|
||||||
|
'product_type_parent_guid' => $v['product_type_parent_guid'],
|
||||||
|
'product_type_name' => $v['product_type_name'],
|
||||||
|
'product_type_parent_name' => $v['product_type_parent_name'],
|
||||||
|
'product_type_title' => $v['product_type_title'],
|
||||||
|
'product_type_link' => $v['product_type_link'],
|
||||||
|
'product_type_icon' => $v['product_type_icon'],
|
||||||
|
'product_type_order' => $v['product_type_order'],
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return msg("获取产品类目列表成功!", $product_type_tree);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑产品类目接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @date 2023-03-25
|
||||||
|
* @example
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function editProductType(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'product_type_guid|产品类目guid' => 'require',
|
||||||
|
'product_type_name|产品类目名称' => 'require',
|
||||||
|
'product_type_order|产品类目排序' => 'require',
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
$model = ModelProductType::where('product_type_guid', $params['product_type_guid'])->find();
|
||||||
|
if (!$model) throwErrorMsg("该产品类目不存在", 1);
|
||||||
|
|
||||||
|
ModelProductType::isDuplicateName($params['product_type_name'], $params['product_type_guid']);
|
||||||
|
|
||||||
|
$params['product_type_ancestors_guid'] = ModelProductType::buildAncestorsGuid($params['product_type_parent_guid']);
|
||||||
|
|
||||||
|
$model->allowField([
|
||||||
|
'product_type_update_user_guid',
|
||||||
|
'product_type_name',
|
||||||
|
'product_type_title',
|
||||||
|
'product_type_link',
|
||||||
|
'product_type_icon',
|
||||||
|
'product_type_ancestors_guid',
|
||||||
|
'product_type_parent_guid',
|
||||||
|
'product_type_order',
|
||||||
|
])->save($params);
|
||||||
|
return msg('编辑成功!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加产品类目接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @date 2023-03-25
|
||||||
|
* @example
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function addProductType(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'product_type_name|产品类型名称' => 'require',
|
||||||
|
'product_type_order|产品类目排序' => 'require'
|
||||||
|
]);
|
||||||
|
|
||||||
|
ModelProductType::isDuplicateName($params['product_type_name']);
|
||||||
|
|
||||||
|
$product_type_parent_where = [];
|
||||||
|
if (!empty($params['product_type_parent_guid'])) {
|
||||||
|
$params['product_type_ancestors_guid'] = ModelProductType::buildAncestorsGuid($params['product_type_parent_guid']);
|
||||||
|
$product_type_parent_where['product_type_parent_guid'] = $params['product_type_parent_guid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelProductType::create($params, [
|
||||||
|
'product_type_guid',
|
||||||
|
'product_type_create_user_guid',
|
||||||
|
'product_type_update_user_guid',
|
||||||
|
'product_type_parent_guid',
|
||||||
|
'product_type_ancestors_guid',
|
||||||
|
'product_type_name',
|
||||||
|
'product_type_title',
|
||||||
|
'product_type_link',
|
||||||
|
'product_type_icon',
|
||||||
|
'product_type_order'
|
||||||
|
]);
|
||||||
|
return msg('添加成功!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除产品类目接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @date 2023-03-25
|
||||||
|
* @example
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function deleteProductType(Request $request): array
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'product_type_guid|产品类目guid' => 'require',
|
||||||
|
]);
|
||||||
|
$guids = explode(',', $params['product_type_guid']);
|
||||||
|
|
||||||
|
ModelProductType::where(['product_type_guid' => $guids])->select()->delete();
|
||||||
|
Db::commit();
|
||||||
|
return msg('删除成功!');
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Db::rollback();
|
||||||
|
throw $th;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出Excel接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @date 2023-03-25
|
||||||
|
* @example
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function exportExcel(Request $request)
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$select = ModelProductType::field([
|
||||||
|
'product_type_title',
|
||||||
|
'product_type_icon',
|
||||||
|
'product_type_cover'
|
||||||
|
])
|
||||||
|
->order('product_type_update_time', 'desc')
|
||||||
|
->select();
|
||||||
|
return ModelProductType::exportExcel($select);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载导入模板接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @date 2023-03-25
|
||||||
|
* @example
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function downloadTemplate(Request $request)
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$data = array_values(ModelProductType::EXCELFIELD);
|
||||||
|
$excel = (new Excel())->exporTsheet($data);
|
||||||
|
$excel->save('产品类目导入模板.xlsx');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入excel接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @date 2023-03-25
|
||||||
|
* @example
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function importExcel(Request $request)
|
||||||
|
{
|
||||||
|
$file = new UploadFile('uploads', 'fileExt:xlsx');
|
||||||
|
$file->putFile('product_type');
|
||||||
|
|
||||||
|
$msg = ModelProductType::importExcel($file);
|
||||||
|
return [
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => $msg
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
205
app/common/model/News/News.php
Normal file
205
app/common/model/News/News.php
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\News;
|
||||||
|
|
||||||
|
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 News extends BaseModel
|
||||||
|
{
|
||||||
|
use SoftDelete;
|
||||||
|
// 删除字段
|
||||||
|
protected $deleteTime = 'news_delete_time';
|
||||||
|
// 设置主键名
|
||||||
|
protected $pk = 'news_guid';
|
||||||
|
// 设置废弃字段
|
||||||
|
protected $disuse = [];
|
||||||
|
// 设置字段信息
|
||||||
|
protected $schema = [
|
||||||
|
'news_id' => 'int' ,
|
||||||
|
'news_guid' => 'string' ,
|
||||||
|
'news_type' => 'int' ,
|
||||||
|
'news_title' => 'string' ,
|
||||||
|
'news_intro' => 'string' ,
|
||||||
|
'news_source' => 'string' ,
|
||||||
|
'news_link' => 'string' ,
|
||||||
|
'news_issue_date' => '' ,
|
||||||
|
'news_views_num' => 'int' ,
|
||||||
|
'news_sort' => 'int' ,
|
||||||
|
'news_content' => '' ,
|
||||||
|
'news_create_time' => 'datetime' ,
|
||||||
|
'news_create_user_guid' => 'string' ,
|
||||||
|
'news_update_time' => 'datetime' ,
|
||||||
|
'news_update_user_guid' => 'string' ,
|
||||||
|
'news_delete_time' => 'datetime' ,
|
||||||
|
'news_delete_user_guid' => 'string' ,
|
||||||
|
|
||||||
|
];
|
||||||
|
// 设置json类型字段
|
||||||
|
protected $json = [''];
|
||||||
|
// 开启自动写入时间戳字段
|
||||||
|
protected $autoWriteTimestamp = 'datetime';
|
||||||
|
// 创建时间
|
||||||
|
protected $createTime = 'news_create_time';
|
||||||
|
// 修改时间
|
||||||
|
protected $updateTime = 'news_update_time';
|
||||||
|
|
||||||
|
//排序字段
|
||||||
|
public $order_field = 'news_sort';
|
||||||
|
|
||||||
|
// excel导入/下载模板表头
|
||||||
|
public const EXCELFIELD = [
|
||||||
|
'news_type' => '新闻类型',
|
||||||
|
'news_title' => '新闻标题',
|
||||||
|
'news_intro' => '新闻简介',
|
||||||
|
'news_source' => '文章来源',
|
||||||
|
'news_link' => '跳转链接',
|
||||||
|
'news_issue_date' => '发布日期',
|
||||||
|
'news_views_num' => '浏览次数',
|
||||||
|
'news_sort' => '新闻排序',
|
||||||
|
'news_content' => '新闻内容',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增前
|
||||||
|
*/
|
||||||
|
public static function onBeforeInsert(self $model): void
|
||||||
|
{
|
||||||
|
Tool::dataAddSortProc($model);
|
||||||
|
$model->completeCreateField();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新前
|
||||||
|
*/
|
||||||
|
public static function onBeforeUpdate(self $model): void
|
||||||
|
{
|
||||||
|
Tool::dataEditSortProc($model);
|
||||||
|
$model->completeUpdateField();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除前
|
||||||
|
*/
|
||||||
|
public static function onBeforeDelete(self $model): void
|
||||||
|
{
|
||||||
|
Tool::dataDeleteSortProc($model);
|
||||||
|
$model->completeDeleteField();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出Excel
|
||||||
|
*
|
||||||
|
* @param array $select 导出的数据
|
||||||
|
*/
|
||||||
|
public static function exportExcel(array $select): void
|
||||||
|
{
|
||||||
|
$data = [[
|
||||||
|
'新闻类型',
|
||||||
|
'新闻标题',
|
||||||
|
'新闻简介',
|
||||||
|
'文章来源',
|
||||||
|
'跳转链接',
|
||||||
|
'发布日期',
|
||||||
|
'浏览次数',
|
||||||
|
'新闻排序',
|
||||||
|
'新闻内容'
|
||||||
|
]];
|
||||||
|
foreach ($select as $key => $val) {
|
||||||
|
$data[] = [
|
||||||
|
$val['news_type'],
|
||||||
|
$val['news_title'],
|
||||||
|
$val['news_intro'],
|
||||||
|
$val['news_source'],
|
||||||
|
$val['news_link'],
|
||||||
|
$val['news_issue_date'],
|
||||||
|
$val['news_views_num'],
|
||||||
|
$val['news_sort'],
|
||||||
|
$val['news_content'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$excel = (new Excel())->exporTsheet($data);
|
||||||
|
$excel->save('新闻.xlsx');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入excel
|
||||||
|
*
|
||||||
|
* @param \app\common\arw\adjfut\src\UploadFile $file excel
|
||||||
|
*/
|
||||||
|
public static function importExcel(\app\common\arw\adjfut\src\UploadFile $file): string
|
||||||
|
{
|
||||||
|
$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初始化
|
||||||
|
*
|
||||||
|
* @param array $value excel每行数据
|
||||||
|
*/
|
||||||
|
public static function importExcelInit(array $value):void
|
||||||
|
{
|
||||||
|
$news_type = $value['news_type'];$news_title = $value['news_title'];$news_intro = $value['news_intro'];$news_source = $value['news_source'];$news_link = $value['news_link'];$news_issue_date = $value['news_issue_date'];$news_views_num = $value['news_views_num'];$news_sort = $value['news_sort'];$news_content = $value['news_content'];
|
||||||
|
|
||||||
|
self::create(
|
||||||
|
['news_type' => $news_type,
|
||||||
|
'news_title' => $news_title,
|
||||||
|
'news_intro' => $news_intro,
|
||||||
|
'news_source' => $news_source,
|
||||||
|
'news_link' => $news_link,
|
||||||
|
'news_issue_date' => $news_issue_date,
|
||||||
|
'news_views_num' => $news_views_num,
|
||||||
|
'news_sort' => $news_sort,
|
||||||
|
'news_content' => $news_content,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'news_type',
|
||||||
|
'news_title',
|
||||||
|
'news_intro',
|
||||||
|
'news_source',
|
||||||
|
'news_link',
|
||||||
|
'news_issue_date',
|
||||||
|
'news_views_num',
|
||||||
|
'news_sort',
|
||||||
|
'news_content',
|
||||||
|
'news_guid',
|
||||||
|
'news_create_user_guid',
|
||||||
|
'news_update_user_guid'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
202
app/common/model/Products/Product.php
Normal file
202
app/common/model/Products/Product.php
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\Products;
|
||||||
|
|
||||||
|
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;
|
||||||
|
use app\common\model\Products\ProductType as ModelProductType;
|
||||||
|
|
||||||
|
class Product extends BaseModel
|
||||||
|
{
|
||||||
|
use SoftDelete;
|
||||||
|
// 删除字段
|
||||||
|
protected $deleteTime = 'product_delete_time';
|
||||||
|
// 设置主键名
|
||||||
|
protected $pk = 'product_guid';
|
||||||
|
// 设置废弃字段
|
||||||
|
protected $disuse = [];
|
||||||
|
// 设置字段信息
|
||||||
|
protected $schema = [
|
||||||
|
'product_id' => 'int',
|
||||||
|
'product_guid' => 'string',
|
||||||
|
'product_type_guid' => 'string',
|
||||||
|
'product_name' => 'string',
|
||||||
|
'product_img' => 'string',
|
||||||
|
'product_description' => 'string',
|
||||||
|
'product_link' => 'string',
|
||||||
|
'product_details' => '',
|
||||||
|
'product_sort' => 'int',
|
||||||
|
'product_create_time' => 'datetime',
|
||||||
|
'product_create_user_guid' => 'string',
|
||||||
|
'product_update_time' => 'datetime',
|
||||||
|
'product_update_user_guid' => 'string',
|
||||||
|
'product_delete_time' => 'datetime',
|
||||||
|
'product_delete_user_guid' => 'string',
|
||||||
|
|
||||||
|
];
|
||||||
|
// 设置json类型字段
|
||||||
|
protected $json = [''];
|
||||||
|
// 开启自动写入时间戳字段
|
||||||
|
protected $autoWriteTimestamp = 'datetime';
|
||||||
|
// 创建时间
|
||||||
|
protected $createTime = 'product_create_time';
|
||||||
|
// 修改时间
|
||||||
|
protected $updateTime = 'product_update_time';
|
||||||
|
|
||||||
|
// excel导入/下载模板表头
|
||||||
|
public const EXCELFIELD = [
|
||||||
|
'product_type_guid' => '产品类目',
|
||||||
|
'product_name' => '产品名称',
|
||||||
|
'product_img' => '产品图片',
|
||||||
|
'product_description' => '产品描述',
|
||||||
|
'product_link' => '产品跳转链接',
|
||||||
|
'product_details' => '产品详情',
|
||||||
|
'product_sort' => '产品排序',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增前
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
*
|
||||||
|
* @param array $select 导出的数据
|
||||||
|
*/
|
||||||
|
public static function exportExcel(array $select): void
|
||||||
|
{
|
||||||
|
$data = [[
|
||||||
|
'产品类目',
|
||||||
|
'产品名称',
|
||||||
|
'产品图片',
|
||||||
|
'产品描述',
|
||||||
|
'产品跳转链接',
|
||||||
|
'产品排序'
|
||||||
|
]];
|
||||||
|
foreach ($select as $key => $val) {
|
||||||
|
|
||||||
|
$product_type = ModelProductType::where('product_type_guid',$val['product_type_guid'])->find();
|
||||||
|
if(!$product_type) throwErrorMsg("产品类目:【{$val['product_type_guid']}】不存在");
|
||||||
|
$product_type_name = $product_type->product_type_name;
|
||||||
|
|
||||||
|
$data[] = [
|
||||||
|
$product_type_name,
|
||||||
|
$val['product_name'],
|
||||||
|
Excel::ExportImgFiled($val['product_img']),
|
||||||
|
$val['product_description'],
|
||||||
|
$val['product_link'],
|
||||||
|
$val['product_sort'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$excel = (new Excel())->exporTsheet($data);
|
||||||
|
$excel->save('产品.xlsx');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入excel
|
||||||
|
*
|
||||||
|
* @param \app\common\arw\adjfut\src\UploadFile $file excel
|
||||||
|
*/
|
||||||
|
public static function importExcel(\app\common\arw\adjfut\src\UploadFile $file): string
|
||||||
|
{
|
||||||
|
$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'>商品:【{$value['product_name']}】新增成功!</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初始化
|
||||||
|
*
|
||||||
|
* @param array $value excel每行数据
|
||||||
|
*/
|
||||||
|
public static function importExcelInit(array $value): void
|
||||||
|
{
|
||||||
|
$product_type_guid = $value['product_type_guid'];
|
||||||
|
$product_name = $value['product_name'];
|
||||||
|
$product_img = $value['product_img'];
|
||||||
|
$product_description = $value['product_description'];
|
||||||
|
$product_link = $value['product_link'];
|
||||||
|
$product_details = $value['product_details'];
|
||||||
|
$product_sort = $value['product_sort'];
|
||||||
|
|
||||||
|
$product_type = ModelProductType::where('product_type_name',$product_type_guid)->find();
|
||||||
|
if(!$product_type) throwErrorMsg("产品类目:【{$product_type_guid}】不存在");
|
||||||
|
$product_type_guid = $product_type->product_type_guid;
|
||||||
|
|
||||||
|
self::create(
|
||||||
|
[
|
||||||
|
'product_type_guid' => $product_type_guid,
|
||||||
|
'product_name' => $product_name,
|
||||||
|
'product_img' => $product_img,
|
||||||
|
'product_description' => $product_description,
|
||||||
|
'product_link' => $product_link,
|
||||||
|
'product_details' => $product_details,
|
||||||
|
'product_sort' => $product_sort,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'product_type_guid',
|
||||||
|
'product_name',
|
||||||
|
'product_img',
|
||||||
|
'product_description',
|
||||||
|
'product_link',
|
||||||
|
'product_details',
|
||||||
|
'product_sort',
|
||||||
|
'product_guid',
|
||||||
|
'product_create_user_guid',
|
||||||
|
'product_update_user_guid'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
181
app/common/model/Products/ProductType.php
Normal file
181
app/common/model/Products/ProductType.php
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\Products;
|
||||||
|
|
||||||
|
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 ProductType extends BaseModel
|
||||||
|
{
|
||||||
|
use SoftDelete;
|
||||||
|
// 删除字段
|
||||||
|
protected $deleteTime = 'product_type_delete_time';
|
||||||
|
// 设置主键名
|
||||||
|
protected $pk = 'product_type_guid';
|
||||||
|
// 设置废弃字段
|
||||||
|
protected $disuse = [];
|
||||||
|
// 设置字段信息
|
||||||
|
protected $schema = [
|
||||||
|
"product_type_id" => "int",
|
||||||
|
"product_type_guid" => "string",
|
||||||
|
"product_type_parent_guid" => "string",
|
||||||
|
"product_type_ancestors_guid" => "string",
|
||||||
|
"product_type_name" => "string",
|
||||||
|
"product_type_icon" => "string",
|
||||||
|
"product_type_title" => "string",
|
||||||
|
"product_type_link" => "string",
|
||||||
|
"product_type_order" => "int",
|
||||||
|
"product_type_create_time" => "datetime",
|
||||||
|
"product_type_create_user_guid" => "string",
|
||||||
|
"product_type_update_time" => "datetime",
|
||||||
|
"product_type_update_user_guid" => "string",
|
||||||
|
"product_type_delete_time" => "datetime",
|
||||||
|
"product_type_delete_user_guid" => "string",
|
||||||
|
];
|
||||||
|
// 设置json类型字段
|
||||||
|
protected $json = [''];
|
||||||
|
// 开启自动写入时间戳字段
|
||||||
|
protected $autoWriteTimestamp = 'datetime';
|
||||||
|
// 创建时间
|
||||||
|
protected $createTime = 'product_type_create_time';
|
||||||
|
// 修改时间
|
||||||
|
protected $updateTime = 'product_type_update_time';
|
||||||
|
|
||||||
|
// excel导入/下载模板表头
|
||||||
|
public const EXCELFIELD = [
|
||||||
|
'product_type_name' => '产品类目名称',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增前
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品类目祖级guid构建
|
||||||
|
*
|
||||||
|
* @param string $product_type_parent_guid 产品类目父级guid
|
||||||
|
*/
|
||||||
|
public static function buildAncestorsGuid(string $product_type_parent_guid): string
|
||||||
|
{
|
||||||
|
if ($product_type_parent_guid == "0") return $product_type_parent_guid;
|
||||||
|
$product_type = self::where('product_type_guid', $product_type_parent_guid)->find();
|
||||||
|
if (!$product_type) throwErrorMsg('该父级产品类目不存在!');
|
||||||
|
return $product_type->product_type_ancestors_guid . ',' . $product_type_parent_guid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品类目重名验证
|
||||||
|
*
|
||||||
|
* @param string $product_type_name 产品类目名称
|
||||||
|
* @param string $product_type_guid 产品类目guid
|
||||||
|
*/
|
||||||
|
public static function isDuplicateName(string $product_type_name, string $product_type_guid = null): void
|
||||||
|
{
|
||||||
|
$con = [
|
||||||
|
['product_type_name', '=', $product_type_name]
|
||||||
|
];
|
||||||
|
if ($product_type_guid) {
|
||||||
|
$con[] = ['product_type_guid', '<>', $product_type_guid];
|
||||||
|
}
|
||||||
|
if (self::where($con)->find()) {
|
||||||
|
throwErrorMsg('产品类目不可重名!');
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出Excel
|
||||||
|
*/
|
||||||
|
public static function exportExcel($select)
|
||||||
|
{
|
||||||
|
$data = [[
|
||||||
|
'产品类目标题',
|
||||||
|
'产品类目图标',
|
||||||
|
'产品类目封面'
|
||||||
|
]];
|
||||||
|
foreach ($select as $key => $val) {
|
||||||
|
$data[] = [
|
||||||
|
$val['product_type_title'],
|
||||||
|
$val['product_type_icon'],
|
||||||
|
Excel::ExportImgFiled($val['product_type_cover']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$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)
|
||||||
|
{
|
||||||
|
$product_type_title = $value['product_type_title'];
|
||||||
|
$product_type_icon = $value['product_type_icon'];
|
||||||
|
$product_type_cover = $value['product_type_cover'];
|
||||||
|
return self::create([
|
||||||
|
'product_type_title' => $product_type_title,
|
||||||
|
'product_type_icon' => $product_type_icon,
|
||||||
|
'product_type_cover' => $product_type_cover,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user