| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- /**
- *
- * @copyright ©2020 点小铺
- * @author hanj
- * @link: https://dyuit.com
- * Created by VSCode
- */
- namespace app\common\model;
- use think\Cache;
- use think\db\Query;
- /**
- * Class Certificate
- *
- * @Author: Yeshihao
- * @DateTime: 2024/11/26 13:37
- * @package app\common\model
- */
- class Certificate extends BaseModel
- {
- protected $name = 'certificate';
- /**
- * 文章详情
- *
- * @param $id
- * @return null|static
- * @throws \think\exception\DbException
- */
- public static function detail($id)
- {
- return self::get($id, ['file', 'category']);
- }
- /**
- * 软删除
- *
- * @return false|int
- */
- public function setDelete()
- {
- return $this->save(['is_delete' => 1]);
- }
- /**
- * [category]
- * 关联分类
- *
- * @Author: Yeshihao
- * @DateTime: 2024/11/26 14:38
- * @return \think\model\relation\BelongsTo
- */
- public function category()
- {
- return $this->belongsTo(CertificateCategory::class, 'certificate_category_id', 'id');
- }
- /**
- * [file]
- * 关联文件
- *
- * @Author: Yeshihao
- * @DateTime: 2024/11/26 14:48
- * @return \think\model\relation\BelongsTo
- */
- public function file()
- {
- return $this->belongsTo('UploadFile', 'file_id', 'file_id');
- }
- /**
- * [getCertificateList]
- *
- * @Author: Yeshihao
- * @DateTime: 2024/11/27 10:43
- * @param array $where
- * @param string $field
- * @return bool|\PDOStatement|string|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getCertificateList($where = [], $field = '*')
- {
- $model = new static;
- !empty($where) && $model->where($where);
- return $model->field($field)->select();
- }
- /**
- * [handlerSearch]
- *
- * @Author: Yeshihao
- * @DateTime: 2024/12/2 15:53
- * @param Query $query
- * @param array $param
- * @return Query
- */
- public function handlerSearch(Query $query, array $param)
- {
- //所属分类
- if (!empty($param['certificate_category_id'])) {
- $query->where('certificate_category_id', $param['certificate_category_id']);
- }
- //资质名称
- if (!empty($param['name'])) {
- $query->where('name', "like", "%{$param['name']}%");
- }
- return $query;
- }
- }
|