$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 BD * @date 2024/03/11 01:58 */ public static function edit(array $params): bool { Db::startTrans(); try { GoodsCate::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 BD * @date 2024/03/11 01:58 */ public static function delete(array $params): bool { return GoodsCate::destroy($params['id']); } /** * @notes 获取商品分类详情 * @param $params * @return array * @author BD * @date 2024/03/11 01:58 */ public static function detail($params): array { return GoodsCate::findOrEmpty($params['id'])->toArray(); } /** * @notes 商品分类数据 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author BD * @date 2024/03/11 01:58 */ public static function getAllData() { return GoodsCate::where(['is_show' => YesNoEnum::YES]) ->order(['sort' => 'desc', 'id' => 'desc']) ->select() ->toArray(); } }