wysf
parent
2638e94d1a
commit
98a2fb0f06
@ -0,0 +1,149 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\admin\controller; |
||||
|
||||
use think\response\Json; |
||||
use cores\library\Version; |
||||
use app\store\model\UploadFile as UploadFileModel; |
||||
|
||||
/** |
||||
* 文件库管理 |
||||
* Class Files |
||||
* @package app\store\controller |
||||
*/ |
||||
class Files extends Controller |
||||
{ |
||||
/** |
||||
* 文件列表 |
||||
* @return Json |
||||
* @throws \cores\exception\BaseException |
||||
* @throws \think\db\exception\DbException |
||||
*/ |
||||
public function list(): Json |
||||
{ |
||||
$this->env(); |
||||
$model = new UploadFileModel; |
||||
$list = $model->getList($this->request->param()); |
||||
return $this->renderSuccess(compact('list')); |
||||
} |
||||
|
||||
/** |
||||
* 编辑文件 |
||||
* @param int $fileId |
||||
* @return Json |
||||
*/ |
||||
public function edit(int $fileId): Json |
||||
{ |
||||
// 文件详情 |
||||
$model = UploadFileModel::detail($fileId); |
||||
// 更新记录 |
||||
if ($model->edit($this->postForm())) { |
||||
return $this->renderSuccess('更新成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '更新失败'); |
||||
} |
||||
|
||||
/** |
||||
* 删除文件(批量) |
||||
* @param array $fileIds 文件id集 |
||||
* @return Json |
||||
* @throws \think\Exception |
||||
* @throws \think\db\exception\DataNotFoundException |
||||
* @throws \think\db\exception\DbException |
||||
* @throws \think\db\exception\ModelNotFoundException |
||||
*/ |
||||
public function delete(array $fileIds): Json |
||||
{ |
||||
$model = new UploadFileModel; |
||||
if (!$model->setDelete($fileIds)) { |
||||
return $this->renderError($model->getError() ?: '操作失败'); |
||||
} |
||||
return $this->renderSuccess('操作成功'); |
||||
} |
||||
|
||||
/** |
||||
* 移动文件到指定分组(批量) |
||||
* @param int $groupId |
||||
* @param array $fileIds |
||||
* @return Json |
||||
*/ |
||||
public function moveGroup(int $groupId, array $fileIds): Json |
||||
{ |
||||
$model = new UploadFileModel; |
||||
if (!$model->moveGroup($groupId, $fileIds)) { |
||||
return $this->renderError($model->getError() ?: '操作失败'); |
||||
} |
||||
return $this->renderSuccess('操作成功'); |
||||
} |
||||
|
||||
/** |
||||
* 临时方法:环境检测并删除废弃的库文件 |
||||
* 文件:vendor/topthink/framework/src/think/Filesystem.php |
||||
* 文件:vendor/topthink/framework/src/think/facade/Filesystem.php |
||||
* 文件:vendor/topthink/framework/tests/FilesystemTest.php |
||||
* 目录:vendor/topthink/framework/src/think/filesystem |
||||
* @return void |
||||
* @throws \cores\exception\BaseException |
||||
*/ |
||||
private function env() |
||||
{ |
||||
// 判断当前版本小于2.2.7则不执行 |
||||
if (Version::compare(Version::getVersion(), '2.2.7') === -1) { |
||||
return; |
||||
} |
||||
// 要删除的文件列表 |
||||
$files = [ |
||||
'vendor/topthink/framework/src/think/Filesystem.php', |
||||
'vendor/topthink/framework/src/think/facade/Filesystem.php', |
||||
'vendor/topthink/framework/tests/FilesystemTest.php' |
||||
]; |
||||
foreach ($files as $file) { |
||||
$filePath = root_path() . $file; |
||||
file_exists($filePath) && unlink($filePath); |
||||
} |
||||
// 要删除的目录列表 |
||||
$folders = ['vendor/topthink/framework/src/think/filesystem/']; |
||||
foreach ($folders as $folder) { |
||||
$folderPath = root_path() . $folder; |
||||
is_dir($folderPath) && $this->deleteFolder($folderPath); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 临时方法:递归删除指定目录下所有文件 |
||||
* @param $path |
||||
* @return void |
||||
*/ |
||||
private function deleteFolder($path): void |
||||
{ |
||||
if (!is_dir($path)) { |
||||
return; |
||||
} |
||||
// 扫描一个文件夹内的所有文件夹和文件 |
||||
foreach (scandir($path) as $val) { |
||||
// 排除目录中的.和.. |
||||
if (!in_array($val, ['.', '..', '.gitignore'])) { |
||||
// 如果是目录则递归子目录,继续操作 |
||||
if (is_dir($path . $val)) { |
||||
// 子目录中操作删除文件夹和文件 |
||||
$this->deleteFolder($path . $val . '/'); |
||||
// 目录清空后删除空文件夹 |
||||
rmdir($path . $val . '/'); |
||||
} else { |
||||
// 如果是文件直接删除 |
||||
unlink($path . $val); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,80 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\admin\controller; |
||||
|
||||
use think\facade\Db; |
||||
use think\response\Json; |
||||
|
||||
/** |
||||
* 商城管理 |
||||
* Class Store |
||||
* @package app\admin\controller |
||||
*/ |
||||
class Goods extends Controller |
||||
{ |
||||
/** |
||||
* 强制验证当前访问的控制器方法method |
||||
* @var array |
||||
*/ |
||||
protected array $methodRules = [ |
||||
'index' => 'GET', |
||||
'recycle' => 'GET', |
||||
'add' => 'POST', |
||||
'move' => 'POST', |
||||
'delete' => 'POST', |
||||
]; |
||||
|
||||
/** |
||||
* 商城列表 |
||||
* @return Json |
||||
* @throws \think\db\exception\DbException |
||||
*/ |
||||
public function index(): Json |
||||
{ |
||||
|
||||
$params = $this->request->param(); |
||||
$sort = $this->request->param('sort', 'id'); |
||||
$order = $this->request->param('order', 'desc'); |
||||
$where = []; |
||||
if (isset($params['channel']) && $params['channel']) { |
||||
$where[] = ['channel', '=', $params['channel']]; |
||||
} |
||||
if (isset($params['min_profit_rate']) && $params['min_profit_rate']) { |
||||
$where[] = ['profit_rate', '>=', $params['min_profit_rate']]; |
||||
} |
||||
if (isset($params['max_profit_rate']) && $params['max_profit_rate']) { |
||||
$where[] = ['profit_rate', '<=', $params['max_profit_rate']]; |
||||
} |
||||
if (isset($params['min_price']) && $params['min_price']) { |
||||
$where[] = ['net_price', '>=', $params['min_price']]; |
||||
} |
||||
if (isset($params['max_price']) && $params['max_price']) { |
||||
$where[] = ['net_price', '<=', $params['max_price']]; |
||||
} |
||||
if (!empty($params['catalog_name'])) { |
||||
$where[] = ['catalog_name', 'like', "%{$params["catalog_name"]}%"]; |
||||
} |
||||
$list = Db::connect("dataCenterMysql")->table('goods_sku') |
||||
->where($where) |
||||
->order($sort, $order) |
||||
->paginate($this->request->param('per_page', 15))->each(function ($item, $key) { |
||||
$item['create_time'] = date("Y-m-d H:i:s", $item['create_time']); |
||||
$item['update_time'] = date("Y-m-d H:i:s", $item['update_time']); |
||||
$item['channel'] = config('app.platformList')[$item['channel']] ?? ""; |
||||
return $item; |
||||
}); |
||||
return $this->renderSuccess(compact('list')); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,86 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\admin\controller\files; |
||||
|
||||
use think\response\Json; |
||||
use app\admin\controller\Controller; |
||||
use app\store\model\UploadGroup as GroupModel; |
||||
|
||||
/** |
||||
* 文件分组 |
||||
* Class Group |
||||
* @package app\store\controller\content |
||||
*/ |
||||
class Group extends Controller |
||||
{ |
||||
/** |
||||
* 文件分组列表 |
||||
* @return Json |
||||
* @throws \think\db\exception\DataNotFoundException |
||||
* @throws \think\db\exception\DbException |
||||
* @throws \think\db\exception\ModelNotFoundException |
||||
*/ |
||||
public function list(): Json |
||||
{ |
||||
$model = new GroupModel; |
||||
$list = $model->getList(); |
||||
return $this->renderSuccess(compact('list')); |
||||
} |
||||
|
||||
/** |
||||
* 添加文件分组 |
||||
* @return Json |
||||
*/ |
||||
public function add(): Json |
||||
{ |
||||
// 新增记录 |
||||
$model = new GroupModel; |
||||
if ($model->add($this->postForm())) { |
||||
return $this->renderSuccess('添加成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '添加失败'); |
||||
} |
||||
|
||||
/** |
||||
* 编辑文件分组 |
||||
* @param int $groupId |
||||
* @return Json |
||||
* @throws \think\db\exception\DataNotFoundException |
||||
* @throws \think\db\exception\DbException |
||||
* @throws \think\db\exception\ModelNotFoundException |
||||
*/ |
||||
public function edit(int $groupId): Json |
||||
{ |
||||
// 分组详情 |
||||
$model = GroupModel::detail($groupId); |
||||
// 更新记录 |
||||
if ($model->edit($this->postForm())) { |
||||
return $this->renderSuccess('更新成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '更新失败'); |
||||
} |
||||
|
||||
/** |
||||
* 删除文件分组 |
||||
* @param int $groupId |
||||
* @return Json |
||||
*/ |
||||
public function delete(int $groupId): Json |
||||
{ |
||||
$model = GroupModel::detail($groupId); |
||||
if (!$model->remove()) { |
||||
return $this->renderError($model->getError() ?: '删除失败'); |
||||
} |
||||
return $this->renderSuccess('删除成功'); |
||||
} |
||||
} |
Loading…
Reference in new issue