parent
74d4f5816d
commit
f88ad8e281
@ -0,0 +1,39 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\common\model; |
||||
|
||||
use cores\BaseModel; |
||||
use think\model\relation\BelongsTo; |
||||
|
||||
/** |
||||
* 文件库分组模型 |
||||
* Class UploadGroup |
||||
* @package app\common\model |
||||
*/ |
||||
class Maintenance extends BaseModel |
||||
{ |
||||
// 定义表名 |
||||
protected $name = 'maintenance'; |
||||
|
||||
|
||||
public static function detail(int $articleId, array $with = []) |
||||
{ |
||||
return self::get($articleId, $with); |
||||
} |
||||
|
||||
public function category(): BelongsTo |
||||
{ |
||||
$module = self::getCalledModule(); |
||||
return $this->BelongsTo("app\\{$module}\\model\\MaintenanceCategory", 'category_id'); |
||||
} |
||||
} |
@ -0,0 +1,54 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\common\model; |
||||
|
||||
use cores\BaseModel; |
||||
use think\model\relation\HasOne; |
||||
|
||||
/** |
||||
* 文章分类模型 |
||||
* Class Category |
||||
* @package app\common\model |
||||
*/ |
||||
class MaintenanceCategory extends BaseModel |
||||
{ |
||||
// 定义表名 |
||||
protected $name = 'maintenance_category'; |
||||
|
||||
|
||||
/** |
||||
* 分类详情 |
||||
* @param int $categoryId |
||||
* @return static|array|null |
||||
*/ |
||||
public static function detail(int $categoryId) |
||||
{ |
||||
return static::get($categoryId); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取列表 |
||||
* @param array $where |
||||
* @return \think\Collection |
||||
* @throws \think\db\exception\DataNotFoundException |
||||
* @throws \think\db\exception\DbException |
||||
* @throws \think\db\exception\ModelNotFoundException |
||||
*/ |
||||
public function getList(array $where = []): \think\Collection |
||||
{ |
||||
return $this->where($where) |
||||
->order(['sort', $this->getPk()]) |
||||
->select(); |
||||
} |
||||
} |
@ -0,0 +1,82 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\store\controller\content; |
||||
|
||||
use think\response\Json; |
||||
use app\store\controller\Controller; |
||||
use app\store\model\Maintenance as MaintenanceModel; |
||||
|
||||
/** |
||||
* 文章管理控制器 |
||||
* Class article |
||||
* @package app\store\controller\content |
||||
*/ |
||||
class Maintenance extends Controller |
||||
{ |
||||
/** |
||||
* 文章列表 |
||||
* @return Json |
||||
* @throws \think\db\exception\DbException |
||||
*/ |
||||
public function list(): Json |
||||
{ |
||||
$model = new MaintenanceModel; |
||||
$list = $model->getList($this->request->param()); |
||||
return $this->renderSuccess(compact('list')); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* @return Json |
||||
*/ |
||||
public function add(): Json |
||||
{ |
||||
// 新增记录 |
||||
$model = new MaintenanceModel; |
||||
if ($model->add($this->postForm())) { |
||||
return $this->renderSuccess('添加成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '添加失败'); |
||||
} |
||||
|
||||
/** |
||||
* @param int $articleId |
||||
* @return Json |
||||
*/ |
||||
public function edit(int $articleId): Json |
||||
{ |
||||
// 文章详情 |
||||
$model = MaintenanceModel::detail($articleId); |
||||
// 更新记录 |
||||
if ($model->edit($this->postForm())) { |
||||
return $this->renderSuccess('更新成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '更新失败'); |
||||
} |
||||
|
||||
/** |
||||
* 删除文章 |
||||
* @param int $articleId |
||||
* @return Json |
||||
*/ |
||||
public function delete(int $articleId): Json |
||||
{ |
||||
// 文章详情 |
||||
$model = MaintenanceModel::detail($articleId); |
||||
if (!$model->setDelete()) { |
||||
return $this->renderError($model->getError() ?: '删除失败'); |
||||
} |
||||
return $this->renderSuccess('删除成功'); |
||||
} |
||||
} |
@ -0,0 +1,83 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\store\controller\content; |
||||
|
||||
use think\response\Json; |
||||
use app\store\controller\Controller; |
||||
use app\store\model\MaintenanceCategory as MaintenanceCategoryModel; |
||||
|
||||
/** |
||||
* 文章分类 |
||||
* Class Category |
||||
* @package app\store\controller\content\article |
||||
*/ |
||||
class MaintenanceCategory 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 MaintenanceCategoryModel; |
||||
$list = $model->getList(); |
||||
return $this->renderSuccess(compact('list')); |
||||
} |
||||
|
||||
/** |
||||
* 添加文章分类 |
||||
* @return Json |
||||
*/ |
||||
public function add(): Json |
||||
{ |
||||
// 新增记录 |
||||
$model = new MaintenanceCategoryModel; |
||||
if ($model->add($this->postForm())) { |
||||
return $this->renderSuccess('添加成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '添加失败'); |
||||
} |
||||
|
||||
/** |
||||
* 编辑文章分类 |
||||
* @param int $categoryId |
||||
* @return Json |
||||
*/ |
||||
public function edit(int $categoryId): Json |
||||
{ |
||||
// 分类详情 |
||||
$model = MaintenanceCategoryModel::detail($categoryId); |
||||
// 更新记录 |
||||
if ($model->edit($this->postForm())) { |
||||
return $this->renderSuccess('更新成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '更新失败'); |
||||
} |
||||
|
||||
/** |
||||
* 删除文章分类 |
||||
* @param int $categoryId |
||||
* @return Json |
||||
*/ |
||||
public function delete(int $categoryId): Json |
||||
{ |
||||
$model = MaintenanceCategoryModel::detail($categoryId); |
||||
if (!$model->remove($categoryId)) { |
||||
return $this->renderError($model->getError() ?: '删除失败'); |
||||
} |
||||
return $this->renderSuccess('删除成功'); |
||||
} |
||||
} |
@ -0,0 +1,107 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\store\model; |
||||
|
||||
use app\common\model\Maintenance as MaintenanceModel; |
||||
|
||||
/** |
||||
* 文章模型 |
||||
* Class Article |
||||
* @package app\store\model |
||||
*/ |
||||
class Maintenance extends MaintenanceModel |
||||
{ |
||||
/** |
||||
* 获取列表 |
||||
* @param array $param |
||||
* @return \think\Paginator |
||||
* @throws \think\db\exception\DbException |
||||
*/ |
||||
public function getList(array $param = []): \think\Paginator |
||||
{ |
||||
// 查询参数 |
||||
$params = $this->setQueryDefaultValue($param, [ |
||||
'name' => '', |
||||
'categoryId' => 0, |
||||
'status' => -1, |
||||
]); |
||||
// 检索查询条件 |
||||
$filter = []; |
||||
!empty($params['name']) && $filter[] = ['name', 'like', "%{$params['title']}%"]; |
||||
$params['status'] > -1 && $filter[] = ['status', '=', $params['status']]; |
||||
$params['categoryId'] > 0 && $filter[] = ['category_id', '=', $params['categoryId']]; |
||||
// 查询列表数据 |
||||
$data = $this->where($filter) |
||||
->where('is_delete', '=', 0) |
||||
->order(['sort' => 'asc', 'create_time' => 'desc']) |
||||
->paginate(15); |
||||
|
||||
return self::preload($data, ['category']); |
||||
} |
||||
|
||||
/** |
||||
* 新增记录 |
||||
* @param array $data |
||||
* @return bool |
||||
*/ |
||||
public function add(array $data): bool |
||||
{ |
||||
|
||||
if (empty($data['name'])) { |
||||
$this->error = '请输入保修名称'; |
||||
return false; |
||||
} |
||||
|
||||
if (($data['parent_id']) != 0) { |
||||
if (empty($data['url'])) { |
||||
$this->error = '请输地址'; |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
$data['store_id'] = self::$storeId; |
||||
return $this->save($data); |
||||
} |
||||
|
||||
/** |
||||
* 更新记录 |
||||
* @param array $data |
||||
* @return bool |
||||
*/ |
||||
public function edit(array $data): bool |
||||
{ |
||||
if (empty($data['name'])) { |
||||
$this->error = '请输入保修名称'; |
||||
return false; |
||||
} |
||||
if (empty($data['url'])) { |
||||
$this->error = '请输入地址'; |
||||
return false; |
||||
} |
||||
return $this->save($data) !== false; |
||||
} |
||||
|
||||
/** |
||||
* 软删除 |
||||
* @return bool |
||||
*/ |
||||
public function setDelete(): bool |
||||
{ |
||||
return $this->save(['is_delete' => 1]); |
||||
} |
||||
|
||||
public static function getTotal(array $where = []): int |
||||
{ |
||||
return (new static)->where($where)->where('is_delete', '=', 0)->count(); |
||||
} |
||||
} |
@ -0,0 +1,68 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\store\model; |
||||
|
||||
use app\store\model\Maintenance as MaintenanceModel; |
||||
use app\common\model\MaintenanceCategory as MaintenanceCategoryModel; |
||||
|
||||
/** |
||||
* 文章分类模型 |
||||
* Class Category |
||||
* @package app\store\model\article |
||||
*/ |
||||
class MaintenanceCategory extends MaintenanceCategoryModel |
||||
{ |
||||
/** |
||||
* 添加新记录 |
||||
* @param array $data |
||||
* @return bool |
||||
*/ |
||||
public function add(array $data): bool |
||||
{ |
||||
// 保存记录 |
||||
$data['store_id'] = self::$storeId; |
||||
return $this->save($data); |
||||
} |
||||
|
||||
/** |
||||
* 编辑记录 |
||||
* @param array $data |
||||
* @return bool |
||||
*/ |
||||
public function edit(array $data): bool |
||||
{ |
||||
// 保存记录 |
||||
return $this->save($data); |
||||
} |
||||
|
||||
/** |
||||
* 删除商品分类 |
||||
* @param int $categoryId |
||||
* @return bool |
||||
*/ |
||||
public function remove(int $categoryId): bool |
||||
{ |
||||
// 判断是否存在文章 |
||||
$articleCount = MaintenanceModel::getTotal(['category_id' => $categoryId]); |
||||
if ($articleCount > 0) { |
||||
$this->error = '该分类下存在' . $articleCount . '个报修,不允许删除'; |
||||
return false; |
||||
} |
||||
// 删除记录 |
||||
return $this->delete(); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
|
Loading…
Reference in new issue