Certificate.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\model;
  10. use think\Cache;
  11. /**
  12. * Class Certificate
  13. *
  14. * @Author: Yeshihao
  15. * @DateTime: 2024/11/26 13:37
  16. * @package app\common\model
  17. */
  18. class Certificate extends BaseModel
  19. {
  20. protected $name = 'certificate';
  21. /**
  22. * 文章详情
  23. * @param $id
  24. * @return null|static
  25. * @throws \think\exception\DbException
  26. */
  27. public static function detail($id)
  28. {
  29. return self::get($id, ['file', 'category']);
  30. }
  31. /**
  32. * 软删除
  33. *
  34. * @return false|int
  35. */
  36. public function setDelete()
  37. {
  38. return $this->save(['is_delete' => 1]);
  39. }
  40. /**
  41. * [category]
  42. * 关联分类
  43. *
  44. * @Author: Yeshihao
  45. * @DateTime: 2024/11/26 14:38
  46. * @return \think\model\relation\BelongsTo
  47. */
  48. public function category()
  49. {
  50. return $this->belongsTo(CertificateCategory::class, 'certificate_category_id', 'id');
  51. }
  52. /**
  53. * [file]
  54. * 关联文件
  55. *
  56. * @Author: Yeshihao
  57. * @DateTime: 2024/11/26 14:48
  58. * @return \think\model\relation\BelongsTo
  59. */
  60. public function file()
  61. {
  62. return $this->belongsTo('UploadFile', 'file_id', 'file_id')
  63. ->bind(['file_path', 'file_name', 'file_url']);
  64. }
  65. /**
  66. * [getCertificateList]
  67. *
  68. * @Author: Yeshihao
  69. * @DateTime: 2024/11/27 10:43
  70. * @param array $where
  71. * @param string $field
  72. * @return bool|\PDOStatement|string|\think\Collection
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. * @throws \think\exception\DbException
  76. */
  77. public static function getCertificateList($where = [], $field = '*')
  78. {
  79. $model = new static;
  80. !empty($where) && $model->where($where);
  81. return $model->field($field)->where('is_delete', '=', 0)->select();
  82. }
  83. }