CertificateCategory.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\model;
  10. use app\common\model\CertificateCategory as CertificateCategoryModel;
  11. use app\store\model\Certificate as CertificateModel;
  12. class CertificateCategory extends CertificateCategoryModel
  13. {
  14. /**
  15. * [getALL]
  16. * 获取全部资质分类
  17. *
  18. * @Author: Yeshihao
  19. * @DateTime: 2024/11/26 14:19
  20. * @return array
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. * @throws \think\exception\DbException
  24. */
  25. public static function getALL()
  26. {
  27. $model = new static;
  28. return $model->where('is_delete', 0)->order(['create_time' => 'asc'])->select()->toArray();
  29. }
  30. /**
  31. * [add]
  32. *
  33. * @Author: Yeshihao
  34. * @DateTime: 2024/11/26 14:22
  35. * @param $data
  36. * @return false|int
  37. */
  38. public function add($data)
  39. {
  40. $data['wxapp_id'] = self::$wxapp_id;
  41. return $this->allowField(true)->save($data);
  42. }
  43. /**
  44. * [edit]
  45. *
  46. * @Author: Yeshihao
  47. * @DateTime: 2024/11/26 14:27
  48. * @param $data
  49. * @return false|int
  50. */
  51. public function edit($data)
  52. {
  53. return $this->allowField(true)->save($data);
  54. }
  55. /**
  56. * 删除商品分类
  57. *
  58. * @param $category_id
  59. * @return bool|int
  60. */
  61. public function remove($category_id)
  62. {
  63. // 判断是否存在文章
  64. $count = CertificateModel::getCertificateTotal(['certificate_category_id' => $category_id]);
  65. if ($count > 0) {
  66. $this->error = '该分类下存在'.$count.'个文章,不允许删除';
  67. return false;
  68. }
  69. return $this->delete();
  70. }
  71. }