Category.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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 $data
  25. * @return false|int
  26. */
  27. public function add(array $data)
  28. {
  29. // 保存记录
  30. $data['store_id'] = self::$storeId;
  31. return $this->save($data);
  32. }
  33. /**
  34. * 编辑记录
  35. * @param $data
  36. * @return bool|int
  37. */
  38. public function edit(array $data)
  39. {
  40. // 保存记录
  41. return $this->save($data);
  42. }
  43. /**
  44. * 删除商品分类
  45. * @param int $categoryId
  46. * @return bool
  47. * @throws \Exception
  48. */
  49. public function remove(int $categoryId)
  50. {
  51. // 判断是否存在文章
  52. $articleCount = ArticleModel::getArticleTotal(['category_id' => $categoryId]);
  53. if ($articleCount > 0) {
  54. $this->error = '该分类下存在' . $articleCount . '个文章,不允许删除';
  55. return false;
  56. }
  57. // 删除记录
  58. return $this->delete();
  59. }
  60. }