$userId, 'article_id' => $articleId]; $collect = ArticleCollect::where($where)->findOrEmpty(); if ($collect->isEmpty()) { ArticleCollect::create([ 'user_id' => $userId, 'article_id' => $articleId, 'status' => YesNoEnum::YES ]); } else { ArticleCollect::update([ 'id' => $collect['id'], 'status' => YesNoEnum::YES ]); } } /** * @notes 取消收藏 * @param $articleId * @param $userId * @author 段誉 * @date 2022/9/20 16:59 */ public static function cancelCollect($articleId, $userId) { ArticleCollect::update(['status' => YesNoEnum::NO], [ 'user_id' => $userId, 'article_id' => $articleId, 'status' => YesNoEnum::YES ]); } /** * @notes 文章分类 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2022/9/23 14:11 */ public static function cate() { return ArticleCate::field('id,name') ->where('is_show', '=', 1) ->order(['sort' => 'desc', 'id' => 'desc']) ->select()->toArray(); } }