$params['name'], 'sort' => $params['sort'], 'is_show' => $params['is_show'], 'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE), ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑项目分类 * @param array $params * @return bool * @author likeadmin * @date 2024/01/16 13:23 */ public static function edit(array $params): bool { Db::startTrans(); try { ItemCate::where('id', $params['id'])->update([ 'name' => $params['name'], 'sort' => $params['sort'], 'is_show' => $params['is_show'], 'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE), ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除项目分类 * @param array $params * @return bool * @author likeadmin * @date 2024/01/16 13:23 */ public static function delete(array $params): bool { return ItemCate::destroy($params['id']); } /** * @notes 获取项目分类详情 * @param $params * @return array * @author likeadmin * @date 2024/01/16 13:23 */ public static function detail($params): array { $itemCate = ItemCate::findOrEmpty($params['id'])->toArray(); $langs = json_decode($articleCate['langs'], true); if(empty($langs)){ $langs = []; } $itemCate['langs'] = $langs; return $itemCate; } /** * @notes 更改项目分类状态 * @param array $params * @return bool * @author heshihu * @date 2022/2/21 18:04 */ public static function updateStatus(array $params) { ItemCate::update([ 'id' => $params['id'], 'is_show' => $params['is_show'] ]); return true; } /** * @notes 项目分类数据 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2022/10/13 10:53 */ public static function getAllData() { return ItemCate::where(['is_show' => YesNoEnum::YES]) ->order(['sort' => 'desc', 'id' => 'desc']) ->select() ->toArray(); } }