Certificate.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. use think\db\Query;
  12. /**
  13. * Class Certificate
  14. *
  15. * @Author: Yeshihao
  16. * @DateTime: 2024/11/26 13:37
  17. * @package app\common\model
  18. */
  19. class Certificate extends BaseModel
  20. {
  21. protected $name = 'certificate';
  22. /**
  23. * 文章详情
  24. *
  25. * @param $id
  26. * @return null|static
  27. * @throws \think\exception\DbException
  28. */
  29. public static function detail($id)
  30. {
  31. return self::get($id, ['file', 'category']);
  32. }
  33. /**
  34. * 软删除
  35. *
  36. * @return false|int
  37. */
  38. public function setDelete()
  39. {
  40. return $this->save(['is_delete' => 1]);
  41. }
  42. /**
  43. * [category]
  44. * 关联分类
  45. *
  46. * @Author: Yeshihao
  47. * @DateTime: 2024/11/26 14:38
  48. * @return \think\model\relation\BelongsTo
  49. */
  50. public function category()
  51. {
  52. return $this->belongsTo(CertificateCategory::class, 'certificate_category_id', 'id');
  53. }
  54. /**
  55. * [file]
  56. * 关联文件
  57. *
  58. * @Author: Yeshihao
  59. * @DateTime: 2024/11/26 14:48
  60. * @return \think\model\relation\BelongsTo
  61. */
  62. public function file()
  63. {
  64. return $this->belongsTo('UploadFile', 'file_id', 'file_id');
  65. }
  66. /**
  67. * [getCertificateList]
  68. *
  69. * @Author: Yeshihao
  70. * @DateTime: 2024/11/27 10:43
  71. * @param array $where
  72. * @param string $field
  73. * @return bool|\PDOStatement|string|\think\Collection
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. * @throws \think\exception\DbException
  77. */
  78. public static function getCertificateList($where = [], $field = '*')
  79. {
  80. $model = new static;
  81. !empty($where) && $model->where($where);
  82. return $model->field($field)->where('is_delete', '=', 0)->select();
  83. }
  84. /**
  85. * [handlerSearch]
  86. *
  87. * @Author: Yeshihao
  88. * @DateTime: 2024/12/2 15:53
  89. * @param Query $query
  90. * @param array $param
  91. * @return Query
  92. */
  93. public function handlerSearch(Query $query, array $param)
  94. {
  95. //所属分类
  96. if (!empty($param['certificate_category_id'])) {
  97. $query->where('certificate_category_id', $param['certificate_category_id']);
  98. }
  99. //资质名称
  100. if (!empty($param['name'])) {
  101. $query->where('name', "like", "%{$param['name']}%");
  102. }
  103. return $query;
  104. }
  105. }