Category.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\model\article;
  13. use app\store\model\Article as ArticleModel;
  14. use app\common\model\article\Category as CategoryModel;
  15. /**
  16. * 文章分类模型
  17. * Class Category
  18. * @package app\store\model\article
  19. */
  20. class Category extends CategoryModel
  21. {
  22. /**
  23. * 添加新记录
  24. * @param array $data
  25. * @return bool
  26. */
  27. public function add(array $data): bool
  28. {
  29. // 保存记录
  30. $data['store_id'] = self::$storeId;
  31. return $this->save($data);
  32. }
  33. /**
  34. * 编辑记录
  35. * @param array $data
  36. * @return bool
  37. */
  38. public function edit(array $data): bool
  39. {
  40. // 保存记录
  41. return $this->save($data);
  42. }
  43. /**
  44. * 删除商品分类
  45. * @param int $categoryId
  46. * @return bool
  47. */
  48. public function remove(int $categoryId): bool
  49. {
  50. // 判断是否存在文章
  51. $articleCount = ArticleModel::getArticleTotal(['category_id' => $categoryId]);
  52. if ($articleCount > 0) {
  53. $this->error = '该分类下存在' . $articleCount . '个文章,不允许删除';
  54. return false;
  55. }
  56. // 删除记录
  57. return $this->delete();
  58. }
  59. }