$params['type_id'], 'name' => $params['name'], 'price' => $params['price'], 'status' => $params['status'], ]); 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/10/18 09:58 */ public static function edit(array $params): bool { Db::startTrans(); try { FaultCode::where('id', $params['id'])->update([ 'type_id' => $params['type_id'], 'name' => $params['name'], 'price' => $params['price'], 'status' => $params['status'], ]); 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/10/18 09:58 */ public static function delete(array $params): bool { return FaultCode::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2024/10/18 09:58 */ public static function detail($params): array { return FaultCode::findOrEmpty($params['id'])->toArray(); } public static function lists($params) { $where = []; if (!empty($params['type_id'])) { $where[] = ['type_id', '=', $params['type_id']]; } $lists = FaultCode::where('status',1) ->where($where) ->field('id,name,price,type_id') ->limit(100) ->select() ->toArray(); return $lists; } }